Adding missing debian changelog. Modyfying hildon-banner to allow creation with null...
[hildon] / tests / check-hildon-system-sound.c
1 /*
2  * Copyright (C) 2006 Nokia Corporation.
3  *
4  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22
23 #include <stdlib.h>
24 #include <check.h>
25 #include <gtk/gtkmain.h>
26 #include <gconf/gconf-client.h>
27 #include "test_suites.h"
28 #include "hildon-system-sound.h"
29
30 /* This define was copied from the hildon-system-sound.c */
31 #define ALARM_GCONF_PATH "/apps/osso/sound/system_alert_volume"
32 #define DEFAULT_BEEP "/usr/share/sounds/ui-default_beep.wav"
33
34 /* -------------------- Fixtures -------------------- */
35
36 static void
37 fx_setup_default_defines ()
38 {
39   int argc = 0;
40
41   gtk_init(&argc, NULL);
42 }
43
44 static void
45 fx_teardown_default_defines ()
46 {
47 }
48 /* -------------------- Test cases -------------------- */
49
50 /* ----- Test case for hildon_play_system_sound -----*/
51
52 /**
53  * Purpose: test playing a system sound
54  * Cases considered:
55  *    - Play /usr/share/sounds/ui-default_beep.wav with default volume
56  *    - Play /usr/share/sounds/ui-default_beep.wav with volume = 0
57  *    - Play /usr/share/sounds/ui-default_beep.wav with volume = 1
58  *    - Play /usr/share/sounds/ui-default_beep.wav with the value given by gconf
59  */
60 START_TEST (test_hildon_play_system_sound_regular)
61 {
62   GConfClient *client = NULL;
63   GError *error = NULL;
64
65   /* Get a gconf client */
66   client = gconf_client_get_default();
67   fail_if (client == NULL, 
68            "hildon-system-sound: Could not get a GConf client");
69
70   /* Play a system sound */
71   hildon_play_system_sound (DEFAULT_BEEP);
72
73   /* Mute the volume and then play */
74   gconf_client_set_int (client, ALARM_GCONF_PATH, 0, &error);
75   hildon_play_system_sound (DEFAULT_BEEP);
76
77   /* Set the volume to 1 */
78   gconf_client_set_int (client, ALARM_GCONF_PATH, 1, &error);
79   hildon_play_system_sound (DEFAULT_BEEP);
80
81   /* Unset the value of the key */
82   gconf_client_unset (client, ALARM_GCONF_PATH, &error);
83   hildon_play_system_sound (DEFAULT_BEEP);
84 }
85 END_TEST
86
87 /**
88  * Purpose: test playing a sound with invalid parameters
89  * Cases considered:
90  *    - Play a NULL path
91  *    - Play a file that does not exist
92  */
93 START_TEST (test_hildon_play_system_sound_invalid)
94 {
95   GConfClient *client = NULL;
96
97   /* Get a gconf client */
98   client = gconf_client_get_default();
99   fail_if (client == NULL, 
100            "hildon-system-sound: Could not get a GConf client");
101
102   /* Test 1 */
103   hildon_play_system_sound (NULL);
104
105   /* Test 2 */
106   hildon_play_system_sound ("file_that_does_not_exist.wav");
107 }
108 END_TEST
109
110 /* ---------- Suite creation ---------- */
111
112 Suite *create_hildon_system_sound_suite()
113 {
114   /* Create the suite */
115   Suite *s = suite_create("HildonSystemSound");
116
117   /* Create test cases and add them to the suite */
118   TCase *tc1 = tcase_create("hildon_play_system_sound");
119
120   tcase_add_checked_fixture(tc1, fx_setup_default_defines, fx_teardown_default_defines);
121   tcase_add_test(tc1, test_hildon_play_system_sound_regular);
122   tcase_add_test(tc1, test_hildon_play_system_sound_invalid);
123   suite_add_tcase (s, tc1);
124
125   /* Return created suite */
126   return s;
127 }