tizen 2.4 release
[framework/uifw/libeom.git] / tests / eom-test-output.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <gio/gio.h>
4 #include <eom.h>
5
6 /* This test application consider only one output */
7
8 static void
9 test_eom_output_notify_cb_output_add (eom_output_notify_s *notify, void *user_data)
10 {
11     eom_output_notify_add_s *add_notify = (eom_output_notify_add_s*)notify;
12     printf ("output(%d) connected\n", add_notify->output_id);
13
14     /* already has one connected output */
15     if (output)
16         return;
17
18     output = eom_output_create (add_notify->output_id);
19     if (!output)
20         printf ("fail: creating output\n");
21 }
22
23 static void
24 test_eom_output_notify_cb_output_remove (eom_output_notify_s *notify, void *user_data)
25 {
26     eom_output_notify_remove_s *rm_notify = (eom_output_notify_remove_s*)notify;
27     printf ("output(%d) disconnected\n", rm_notify->output_id);
28
29     /* no connected output */
30     if (!output)
31         return;
32
33     if (eom_output_get_output_id (output) != rm_notify->output_id)
34     {
35         printf ("I'm not interested in this output(%d,%d)\n", eom_output_get_output_id (output), rm_notify->output_id);
36         return;
37     }
38
39     eom_output_destroy (output);
40     output = NULL;
41 }
42
43 static void
44 test_eom_check_connected_output (void)
45 {
46     int output_cnt;
47     eom_output_id *output_ids;
48
49     output_ids = eom_get_eom_output_ids (&output_cnt);
50     if (!output_ids)
51         goto done;
52
53     printf ("output(%d) connected\n", output_ids[0]);
54
55 done:
56     if (output_ids)
57         free (output_ids);
58 }
59
60 int
61 main(int argc, char *argv[])
62 {
63     GMainLoop *event_loop;
64
65     g_type_init();
66
67     if (eom_init ())
68         return 0;
69
70     eom_output_add_notify_cb (EOM_OUTPUT_NOTIFY_ADD, test_eom_output_notify_cb_output_add, NULL);
71     eom_output_add_notify_cb (EOM_OUTPUT_NOTIFY_REMOVE, test_eom_output_notify_cb_output_remove, NULL);
72
73     test_eom_check_connected_output ();
74
75     /* run event loop */
76     event_loop = g_main_loop_new (NULL, FALSE);
77     g_main_loop_run (event_loop);
78
79     if (output)
80         eom_output_destroy (output);
81
82     eom_output_remove_notify_cb (test_eom_output_notify_cb_output_add);
83     eom_output_remove_notify_cb (test_eom_output_notify_cb_output_remove);
84
85     eom_deinit ();
86
87     return 0;
88 }