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