aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-dialoghelp.c
blob: 92a3ab4fb54bccccbdca1b09d5e8f2de29fa06d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * Copyright (C) 2006 Nokia Corporation.
 *
 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <stdlib.h>
#include <check.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <glib/gprintf.h>
#include "test_suites.h"
#include "check_utils.h"

#include <gdk/gdkx.h>
#include "hildon-dialoghelp.h"

/* -------------------- Fixtures -------------------- */
static GtkWidget * dialoghelp = NULL;

static void
change_help_status (GtkDialog *dialog, gpointer func_data)
{
  gboolean * data = func_data;
  *data = TRUE;
}

static void 
fx_setup_default_dialoghelp ()
{
  int argc = 0;
  gtk_init(&argc, NULL);
    
  dialoghelp = gtk_dialog_new();
  /* Check that the dialog help object has been created properly */
  fail_if(!GTK_IS_DIALOG (dialoghelp), "hildon-dialoghelp: Creation failed");

  /* Displays the widget */
  show_all_test_window (dialoghelp);

}

static void 
fx_teardown_default_dialoghelp ()
{
  gtk_widget_destroy(GTK_WIDGET(dialoghelp)); 
}

/* -------------------- Test cases -------------------- */

/* ----- Test case for enable_dialoghelp -----*/
/**
 * Purpose: test gtk_dialog_help_enable/gtk_dialog_help_disable connecting help signal 
 * Cases considered:
 *    - Test if gtk_dialog_help_enable actually enables help dialog status
 *    - Test if gtk_dialog_help_enable actually adds help atom to atoms' list
 *    - Test if gtk_dialog_help_disable actually removes help atom to atoms' list
 */
START_TEST (test_enable_dialoghelp_regular)
{
  gboolean help_enabled = FALSE;
  GdkWindow *window=NULL;
  GdkDisplay *display;
  Atom *list;
  Atom helpatom;
  int amount = 0;
  int i = 0;
  gboolean helpAtom = FALSE;
    
  gtk_dialog_help_enable(GTK_DIALOG(dialoghelp));    
  gtk_signal_connect(GTK_OBJECT(dialoghelp),"help",GTK_SIGNAL_FUNC(change_help_status),&help_enabled);   
  gtk_signal_emit_by_name(GTK_OBJECT(dialoghelp),"help");
    
  /* Test 1: Test if gtk_dialog_help_enable actually enables help dialog status */
  fail_if(help_enabled!=TRUE,"hildon-dialoghelp: Enable help failed");
        
  /* In order to obtain dialog->window. */
  gtk_widget_realize(GTK_WIDGET(dialoghelp));
  window = GTK_WIDGET(dialoghelp)->window;
  display = gdk_drawable_get_display (window);

  XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
                  &list, &amount);

  helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
    
  /* search if the help_atom is in the atoms' list */
  for (i=0; i<amount; i++) 
    {
      if (list[i] == helpatom) 
        {
          helpAtom = TRUE;
          break;
        }
    }
  XFree (list);

  /* Test 2: Test if gtk_dialog_help_enable actually adds help atom to atoms' list */
  fail_if(helpAtom!=TRUE,"hildon-dialoghelp: Help atom is not in the atoms' list");
    
    
  helpAtom = FALSE;
  gtk_dialog_help_disable(GTK_DIALOG(dialoghelp)); 
  XGetWMProtocols(GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
                  &list, &amount);
  helpatom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_CONTEXT_HELP");
    
  /* search if the help_atom is in the atoms' list */
  for (i=0; i<amount; i++)
    {
      if (list[i] == helpatom)
        {
          helpAtom = TRUE;
          break;
        }
    }
  XFree (list);
  /* Test 3: Test if gtk_dialog_help_disable actually removes help atom to atoms' list */
  fail_if(helpAtom==TRUE,"hildon-dialoghelp: Help atom is in the atoms' list");  
}
END_TEST

/**
 * Purpose: test gtk_dialog_help_enable connecting help signal 
 * Cases considered:
 *    - Enable help dialog on NULL object.
 *    - Disable help dialog on NULL object.
 */
START_TEST (test_enable_dialoghelp_invalid)
{
  gtk_dialog_help_enable(NULL);
  gtk_dialog_help_disable(NULL);
}
END_TEST


/* ---------- Suite creation ---------- */

Suite *create_hildon_dialoghelp_suite()
{
  /* Create the suite */
  Suite *s = suite_create("HildonDialogHelp");

  /* Create test cases */
  TCase *tc1 = tcase_create("dialog_help_enable");

  /* Create test case for gtk_dialog_help_enable and add it to the suite */
  tcase_add_checked_fixture(tc1, fx_setup_default_dialoghelp, fx_teardown_default_dialoghelp);
  tcase_add_test(tc1, test_enable_dialoghelp_regular);
  tcase_add_test(tc1, test_enable_dialoghelp_invalid);
  suite_add_tcase (s, tc1);

  /* Return created suite */
  return s;             
}