Add test for dbus get_unread_messages method.
authorJosé Dapena Paz <jdapena@igalia.com>
Tue, 26 Jan 2010 17:03:51 +0000 (18:03 +0100)
committerJosé Dapena Paz <jdapena@igalia.com>
Tue, 26 Jan 2010 17:03:51 +0000 (18:03 +0100)
libmodest-dbus-client/src/libmodest-dbus-client.c
tests/dbus_api/Makefile.am
tests/dbus_api/test_get_unread_msgs.c [new file with mode: 0644]

index 0b62155..aac04ce 100644 (file)
@@ -670,7 +670,7 @@ modest_dbus_message_iter_get_unread_messages_hit (DBusMessageIter *parent)
        hit->timestamp = _dbus_iter_get_int64 (&child); 
 
        res = dbus_message_iter_next (&child);
        hit->timestamp = _dbus_iter_get_int64 (&child); 
 
        res = dbus_message_iter_next (&child);
-       if (res == TRUE) {
+       if (res == FALSE) {
                error = TRUE;
                goto out;
        }       
                error = TRUE;
                goto out;
        }       
@@ -686,7 +686,7 @@ modest_dbus_message_iter_get_unread_messages_hit (DBusMessageIter *parent)
        hit->subject = _dbus_iter_get_string_or_null (&child);
 
        res = dbus_message_iter_next (&child);
        hit->subject = _dbus_iter_get_string_or_null (&child);
 
        res = dbus_message_iter_next (&child);
-       if (res == FALSE) {
+       if (res == TRUE) {
                error = TRUE;
                goto out;
        }
                error = TRUE;
                goto out;
        }
index 4908403..0cd0e2d 100644 (file)
@@ -25,6 +25,7 @@ noinst_PROGRAMS = \
        test_mail_to \
        test_open_message   \
        test_search         \
        test_mail_to \
        test_open_message   \
        test_search         \
+       test_get_unread_msgs  \
        test_delete_message \
        test_compose_mail \
        test_open_default_inbox \
        test_delete_message \
        test_compose_mail \
        test_open_default_inbox \
@@ -47,6 +48,9 @@ test_compose_mail_LDADD = $(objects)
 test_search_SOURCES = test_search.c
 test_search_LDADD = $(objects)
 
 test_search_SOURCES = test_search.c
 test_search_LDADD = $(objects)
 
+test_get_unread_msgs_SOURCES = test_get_unread_msgs.c
+test_get_unread_msgs_LDADD = $(objects)
+
 test_delete_message_SOURCES = test_delete_message.c
 test_delete_message_LDADD = $(objects)
 
 test_delete_message_SOURCES = test_delete_message.c
 test_delete_message_LDADD = $(objects)
 
diff --git a/tests/dbus_api/test_get_unread_msgs.c b/tests/dbus_api/test_get_unread_msgs.c
new file mode 100644 (file)
index 0000000..5825996
--- /dev/null
@@ -0,0 +1,55 @@
+#include <libmodest-dbus-client/libmodest-dbus-client.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib.h>
+
+int main (int argc, char *argv[])
+{
+       osso_context_t *osso_context;
+       gboolean res;
+       GList *hits, *iter;
+       gint number;
+
+       osso_context = osso_initialize ("test_search",
+                                       "0.0.1",
+                                       TRUE,
+                                       NULL);
+
+
+       /* Check that initialization was ok */
+       if (osso_context == NULL) {
+               g_printerr ("osso_initialize() failed.\n");
+               return OSSO_ERROR;
+       }
+
+       hits = NULL;
+
+       if (argc == 2) {
+         number = strtol (argv[1], NULL, 10);
+       } else {
+               number = 10;
+       }
+
+       g_print ("Starting get_unread_messages)...\n");
+
+       res = libmodest_dbus_client_get_unread_messages (osso_context,
+                                                        number,
+                                                        &hits);
+
+       g_print ("Search done. (success: %s)\n", res ? "yes" : "no");
+
+       for (iter = hits; iter; iter = iter->next) {
+               ModestAccountHits *hits = (ModestAccountHits *) iter->data;
+               GList *header_node;
+
+               g_print ("Account: id: %s name: %s\n", hits->account_id, hits->account_name);
+               for (header_node = hits->hits; header_node != NULL; header_node = g_list_next (header_node)) {
+                       ModestGetUnreadMessagesHit *hit = (ModestGetUnreadMessagesHit *) header_node->data;
+
+                       g_print ("    %s\n    %s\n", hit->subject, ctime (&(hit->timestamp)));
+               }
+       }
+       modest_account_hits_list_free (hits);
+
+       return res ? 0 : -1;
+}