1 /**
2 * @file ol_config_test.c
3 * @author Tiger Soldier <tigersoldi@gmail.com>
4 * @date Sun Jun 21 08:26:35 2009
5 *
6 * @brief Unit test for OlConfig
7 *
8 *
9 */
10 #include <assert.h>
11 #include <string.h>
12 #include <gtk/gtk.h>
13 #include "ol_config.h"
14
15 void
changed_handler(OlConfig * config,char * key,gpointer data)16 changed_handler (OlConfig *config, char *key, gpointer data)
17 {
18 printf ("%s has been changed\n", key);
19 }
20
21 void
test_singleton()22 test_singleton ()
23 {
24 printf ("%s\n", __FUNCTION__);
25 OlConfig *config = ol_config_get_instance ();
26 assert (config != NULL);
27 OlConfig *config2 = ol_config_get_instance ();
28 assert (config == config2);
29 }
30
31 void
test_default_value()32 test_default_value ()
33 {
34 printf ("%s\n", __FUNCTION__);
35 OlConfig *config = ol_config_get_instance ();
36 assert (config != NULL);
37 ol_config_get_int (config, "OSD", "width");
38 ol_config_get_double (config, "OSD", "xalign");
39 ol_config_get_double (config, "OSD", "yalign");
40 ol_config_get_double (config, "OSD", "font-size");
41 ol_config_get_bool (config, "OSD", "locked");
42 g_free (ol_config_get_string (config, "OSD", "font-family"));
43 g_strfreev (ol_config_get_str_list (config, "OSD", "active-lrc-color", NULL));
44 }
45
46 void
test_set_value()47 test_set_value ()
48 {
49 const int INT_VAL = 10;
50 const double DOUBLE_VAL = 0.75;
51 const char* STR_VAL = "string test";
52 char *colors[] = {"#123456", "#7890ab", "#cdef01", NULL};
53 /* printf ("%s\n", __FUNCTION__); */
54 OlConfig *config = ol_config_get_instance ();
55 assert (config != NULL);
56 g_signal_connect (config, "changed", G_CALLBACK (changed_handler), NULL);
57 ol_config_set_int (config, "OSD", "width", INT_VAL);
58 assert (ol_config_get_int (config, "OSD", "width") == INT_VAL);
59 ol_config_set_double (config, "OSD", "xalign", DOUBLE_VAL);
60 assert (ol_config_get_double (config, "OSD", "xalign") == DOUBLE_VAL);
61 ol_config_set_string (config, "OSD", "font-family", STR_VAL);
62 assert (strcmp (ol_config_get_string (config, "OSD", "font-family"), STR_VAL) == 0);
63 assert (strcmp (ol_config_get_string (config, "OSD", "font-family"), STR_VAL) == 0);
64 ol_config_set_bool (config, "OSD", "locked", FALSE);
65 assert (ol_config_get_bool (config, "OSD", "locked") == FALSE);
66 ol_config_set_bool (config, "OSD", "locked", TRUE);
67 assert (ol_config_get_bool (config, "OSD", "locked") == TRUE);
68 ol_config_set_str_list (config, "OSD", "active-lrc-color", (const char **)colors, 3);
69 g_strfreev (ol_config_get_str_list (config, "OSD", "active-lrc-color", NULL));
70 g_strfreev (ol_config_get_str_list (config, "OSD", "active-lrc-color", NULL));
71 }
72
73 int
main(int argc,char ** argv)74 main (int argc, char **argv)
75 {
76 gtk_init (&argc, &argv);
77 test_singleton ();
78 test_default_value ();
79 test_set_value ();
80 return 0;
81 }
82