tests: Silence compiler warnings.
[platform/upstream/evolution-data-server.git] / tests / libebook / test-ebook.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 #include <stdlib.h>
4 #include <libebook/libebook.h>
5
6 #include "ebook-test-utils.h"
7
8 #if 0  /* ACCOUNT_MGMT */
9 static void
10 print_email (EContact *contact)
11 {
12         const gchar *file_as = e_contact_get_const (contact, E_CONTACT_FILE_AS);
13         const gchar *name_or_org = e_contact_get_const (contact, E_CONTACT_NAME_OR_ORG);
14         GList *emails, *e;
15
16         printf ("Contact: %s\n", file_as);
17         printf ("Name or org: %s\n", name_or_org);
18         printf ("Email addresses:\n");
19         emails = e_contact_get (contact, E_CONTACT_EMAIL);
20         for (e = emails; e; e = e->next) {
21                 printf ("\t%s\n",  (gchar *) e->data);
22         }
23         g_list_foreach (emails, (GFunc) g_free, NULL);
24         g_list_free (emails);
25
26         printf ("\n");
27 }
28
29 static void
30 print_all_emails (EBook *book)
31 {
32         EBookQuery *query;
33         gboolean status;
34         GList *cards, *c;
35
36         query = e_book_query_field_exists (E_CONTACT_FULL_NAME);
37
38         status = e_book_get_contacts (book, query, &cards, NULL);
39
40         e_book_query_unref (query);
41
42         if (status == FALSE) {
43                 printf ("error %d getting card list\n", status);
44                 exit (0);
45         }
46
47         for (c = cards; c; c = c->next) {
48                 EContact *contact = E_CONTACT (c->data);
49
50                 print_email (contact);
51
52                 g_object_unref (contact);
53         }
54         g_list_free (cards);
55 }
56
57 static void
58 print_one_email (EBook *book)
59 {
60         EContact *contact;
61         GError *error = NULL;
62
63         if (!e_book_get_contact (book, "pas-id-0002023", &contact, &error)) {
64                 printf ("error %d getting card: %s\n", error->code, error->message);
65                 g_clear_error (&error);
66                 return;
67         }
68
69         print_email (contact);
70
71         g_object_unref (contact);
72 }
73 #endif /* ACCOUNT_MGMT */
74
75 gint
76 main (gint argc,
77       gchar **argv)
78 {
79 #if 0  /* ACCOUNT_MGMT */
80         EBook *book;
81
82         g_type_init ();
83
84         /*
85         ** the actual ebook foo
86         */
87
88         printf ("loading addressbook\n");
89         book = e_book_new_system_addressbook (NULL);
90         if (!book) {
91                 printf ("failed to create local addressbook\n");
92                 exit (0);
93         }
94
95         ebook_test_utils_book_open (book, FALSE);
96
97         printf ("printing one contact\n");
98         print_one_email (book);
99
100         printf ("printing all contacts\n");
101         print_all_emails (book);
102
103         g_object_unref (book);
104 #endif /* ACCOUNT_MGMT */
105
106         return 0;
107 }