Ensure HildonAppMenu size is correct after rotation
[hildon] / tests / check-hildon-dialoghelp.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #include <stdlib.h>
26 #include <check.h>
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtksignal.h>
29 #include <glib/gprintf.h>
30 #include "test_suites.h"
31 #include "check_utils.h"
32
33 #include <gdk/gdkx.h>
34 #include <hildon/hildon-dialoghelp.h>
35
36 /* -------------------- Fixtures -------------------- */
37 static GtkWidget * dialoghelp = NULL;
38
39 static void
40 change_help_status (GtkDialog *dialog, gpointer func_data)
41 {
42   gboolean * data = func_data;
43   *data = TRUE;
44 }
45
46 static void 
47 fx_setup_default_dialoghelp ()
48 {
49   int argc = 0;
50   gtk_init(&argc, NULL);
51     
52   dialoghelp = gtk_dialog_new();
53   /* Check that the dialog help object has been created properly */
54   fail_if(!GTK_IS_DIALOG (dialoghelp), "hildon-dialoghelp: Creation failed");
55
56   /* Displays the widget */
57   show_all_test_window (dialoghelp);
58
59 }
60
61 static void 
62 fx_teardown_default_dialoghelp ()
63 {
64   gtk_widget_destroy(GTK_WIDGET(dialoghelp)); 
65 }
66
67 /* -------------------- Test cases -------------------- */
68
69 /* ----- Test case for enable_dialoghelp -----*/
70 /**
71  * Purpose: test gtk_dialog_help_enable/gtk_dialog_help_disable connecting help signal 
72  * Cases considered:
73  *    - Test if gtk_dialog_help_enable actually enables help dialog status
74  *    - Test if gtk_dialog_help_enable actually adds help atom to atoms' list
75  *    - Test if gtk_dialog_help_disable actually removes help atom to atoms' list
76  */
77 START_TEST (test_enable_dialoghelp_regular)
78 {
79   gboolean help_enabled = FALSE;
80   GdkWindow *window=NULL;
81   GdkDisplay *display;
82   Atom *list;
83   Atom helpatom;
84   int amount = 0;
85   int i = 0;
86   gboolean helpAtom = FALSE;
87     
88   gtk_dialog_help_enable(GTK_DIALOG(dialoghelp));    
89   gtk_signal_connect(GTK_OBJECT(dialoghelp),"help",GTK_SIGNAL_FUNC(change_help_status),&help_enabled);   
90   gtk_signal_emit_by_name(GTK_OBJECT(dialoghelp),"help");
91     
92   /* Test 1: Test if gtk_dialog_help_enable actually enables help dialog status */
93   fail_if(help_enabled!=TRUE,"hildon-dialoghelp: Enable help failed");
94         
95   /* In order to obtain dialog->window. */
96   gtk_widget_realize(GTK_WIDGET(dialoghelp));
97   window = GTK_WIDGET(dialoghelp)->window;
98   display = gdk_drawable_get_display (window);
99
100   XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
101                   &list, &amount);
102
103   helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
104     
105   /* search if the help_atom is in the atoms' list */
106   for (i=0; i<amount; i++) 
107     {
108       if (list[i] == helpatom) 
109         {
110           helpAtom = TRUE;
111           break;
112         }
113     }
114   XFree (list);
115
116   /* Test 2: Test if gtk_dialog_help_enable actually adds help atom to atoms' list */
117   fail_if(helpAtom!=TRUE,"hildon-dialoghelp: Help atom is not in the atoms' list");
118     
119     
120   helpAtom = FALSE;
121   gtk_dialog_help_disable(GTK_DIALOG(dialoghelp)); 
122   XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
123                   &list, &amount);
124   helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
125     
126   /* search if the help_atom is in the atoms' list */
127   for (i=0; i<amount; i++)
128     {
129       if (list[i] == helpatom)
130         {
131           helpAtom = TRUE;
132           break;
133         }
134     }
135   XFree (list);
136   /* Test 3: Test if gtk_dialog_help_disable actually removes help atom to atoms' list */
137   fail_if(helpAtom==TRUE,"hildon-dialoghelp: Help atom is in the atoms' list");  
138 }
139 END_TEST
140
141 /**
142  * Purpose: test gtk_dialog_help_enable connecting help signal 
143  * Cases considered:
144  *    - Enable help dialog on NULL object.
145  *    - Disable help dialog on NULL object.
146  */
147 START_TEST (test_enable_dialoghelp_invalid)
148 {
149   gtk_dialog_help_enable(NULL);
150   gtk_dialog_help_disable(NULL);
151 }
152 END_TEST
153
154
155 /* ---------- Suite creation ---------- */
156
157 Suite *create_hildon_dialoghelp_suite()
158 {
159   /* Create the suite */
160   Suite *s = suite_create("HildonDialogHelp");
161
162   /* Create test cases */
163   TCase *tc1 = tcase_create("dialog_help_enable");
164
165   /* Create test case for gtk_dialog_help_enable and add it to the suite */
166   tcase_add_checked_fixture(tc1, fx_setup_default_dialoghelp, fx_teardown_default_dialoghelp);
167   tcase_add_test(tc1, test_enable_dialoghelp_regular);
168   tcase_add_test(tc1, test_enable_dialoghelp_invalid);
169   suite_add_tcase (s, tc1);
170
171   /* Return created suite */
172   return s;             
173 }