mapistore: add python bindings and tests for get_message_count()
authorbradh <bradh@71d39326-ef09-db11-b2a4-00e04c779ad1>
Sun, 27 Feb 2011 00:12:33 +0000 (00:12 +0000)
committerbradh <bradh@71d39326-ef09-db11-b2a4-00e04c779ad1>
Sun, 27 Feb 2011 00:12:33 +0000 (00:12 +0000)
git-svn-id: https://svn.openchange.org/openchange@2700 71d39326-ef09-db11-b2a4-00e04c779ad1

trunk/pyopenchange/pymapistore.c
trunk/pyopenchange/unittest/unittest_mapistoredb.py

index 6cb79bec646b5ca9c0ae9edccd221b458280725f..6d3a041f474217aacac132f1eae59d2a162f7039 100644 (file)
@@ -391,6 +391,27 @@ static PyObject *py_MAPIStore_get_folder_count(PyMAPIStoreObject *self, PyObject
        return PyInt_FromLong(folder_count);
 }
 
+static PyObject *py_MAPIStore_get_message_count(PyMAPIStoreObject *self, PyObject *args)
+{
+       uint32_t                context_id;
+       uint64_t                fid;
+       uint32_t                message_count;
+       enum MAPISTORE_ERROR    retval;
+
+       if (!PyArg_ParseTuple(args, "iK", &context_id, &fid)) {
+               return NULL;
+       }
+
+       retval = mapistore_get_message_count(self->mstore_ctx, context_id, fid, &message_count);
+
+       if (retval != MAPISTORE_SUCCESS) {
+               PyErr_SetString(PyExc_RuntimeError, mapistore_errstr(retval));
+               return NULL;
+       }
+       
+       return PyInt_FromLong(message_count);
+}
+
 static PyObject *py_MAPIStore_errstr(PyMAPIStoreObject *self, PyObject *args)
 {
        enum MAPISTORE_ERROR    retval;
@@ -455,6 +476,7 @@ static PyMethodDef mapistore_methods[] = {
        { "rmdir", (PyCFunction)py_MAPIStore_rmdir, METH_VARARGS },
        { "setprops", (PyCFunction)py_MAPIStore_setprops, METH_VARARGS },
        { "get_folder_count", (PyCFunction)py_MAPIStore_get_folder_count, METH_VARARGS },
+       { "get_message_count", (PyCFunction)py_MAPIStore_get_message_count, METH_VARARGS },
        { "errstr", (PyCFunction)py_MAPIStore_errstr, METH_VARARGS },
        { NULL },
 };
index d5ad32deaf002715de243d4171e4a601e667ebb1..56f81a65b3d2dc86af4edad14548cd857f95aebe 100755 (executable)
@@ -111,13 +111,17 @@ class TestMAPIStoreDB(unittest.TestCase):
                self.assertNotEqual(inbox_context_id, 0)
                self.assertNotEqual(inbox_fid, 0)
                num_folders = self.MAPIStore.get_folder_count(inbox_context_id, inbox_fid)
-               self.assertEqual(num_folders, 0);
+               self.assertEqual(num_folders, 0)
                test_subfolder_fid = self.MAPIStore.mkdir(inbox_context_id, inbox_fid, "Test Folder", "This is a test folder", mapistore.FOLDER_GENERIC)
                self.assertNotEqual(test_subfolder_fid, 0)
                num_folders = self.MAPIStore.get_folder_count(inbox_context_id, inbox_fid)
-               self.assertEqual(num_folders, 1);
+               self.assertEqual(num_folders, 1)
                num_folders = self.MAPIStore.get_folder_count(inbox_context_id, test_subfolder_fid)
-               self.assertEqual(num_folders, 0);
+               self.assertEqual(num_folders, 0)
+               num_messages = self.MAPIStore.get_message_count(inbox_context_id, inbox_fid)
+               self.assertEqual(num_messages, 0)
+               num_messages = self.MAPIStore.get_message_count(inbox_context_id, test_subfolder_fid)
+               self.assertEqual(num_messages, 0)
                retval = self.MAPIStore.opendir(context_id = inbox_context_id, parent_fid = inbox_fid, fid = test_subfolder_fid)
                self.assertEqual(retval, 0)
                # TODO: add getprops support, and check return values.