Bump the version number in configure.ac to 1.0.5
[moonshot-ui.git] / tests / basic.c
1 #include <glib.h>
2
3 #include "libmoonshot.h"
4
5 /* FIXME: Using XDG_HOME_DIR and a test runner, we could give
6  * moonshot-ui a set of test identities and assert that they
7  * are returned correctly
8  */
9
10 gpointer test_func (gpointer data)
11 {
12     MoonshotError **error = data;
13     gboolean        success;
14
15     char *nai,
16          *password,
17          *server_certificate_hash,
18          *ca_certificate,
19          *subject_name_constraint,
20          *subject_alt_name_constraint;
21
22     success = moonshot_get_default_identity (&nai,
23                                              &password,
24                                              &server_certificate_hash,
25                                              &ca_certificate,
26                                              &subject_name_constraint,
27                                              &subject_alt_name_constraint,
28                                              error);
29
30     /*if (success)
31         g_print ("Got id: %s %s\n", nai, password);*/
32
33     moonshot_free (nai);
34     moonshot_free (password);
35     moonshot_free (server_certificate_hash);
36     moonshot_free (ca_certificate);
37     moonshot_free (subject_name_constraint);
38     moonshot_free (subject_alt_name_constraint);
39
40     return GINT_TO_POINTER (success);
41 }
42
43
44 void test_connect ()
45 {
46     MoonshotError *error = NULL;
47     gboolean       success;
48
49     success = GPOINTER_TO_INT (test_func (&error));
50
51     if (success)
52         return;
53
54     g_print ("FAIL: %s\n", error->message);
55     g_assert_not_reached ();
56 }
57
58 void test_multithread ()
59 {
60     const int N = 100;
61
62     GThread       *thread[N];
63     MoonshotError *error[N];
64     gboolean       success[N];
65
66     GError *g_error = NULL;
67     int i;
68
69     for (i=0; i<N; i++) {
70         error[i] = NULL;
71         thread[i] = g_thread_create (test_func,
72                                      &error[i],
73                                      TRUE,
74                                      &g_error);
75         g_assert_no_error (g_error);
76     }
77
78     for (i=0; i<N; i++)
79         success[i] = GPOINTER_TO_INT (g_thread_join (thread[i]));
80
81     for (i=0; i<N; i++) {
82         if (! success[i]) {
83             g_print ("FAIL[%i]: %s\n", i, error[i]->message);
84             g_assert_not_reached ();
85         }
86     }
87 }
88
89 /* More stuff to test:
90  *   - server not available (dbus fail)
91  *   - no identities available (moonshot fail)
92  *   - valgrind
93  *   - mt
94  */
95
96 int main (int argc, char *argv[])
97 {
98     g_type_init ();
99     g_test_init (&argc, &argv, NULL);
100
101     g_test_add_func ("/basic/connect", test_connect);
102     g_test_add_func ("/basic/multithread", test_multithread);
103
104     g_test_run ();
105 }