aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-find-toolbar.c
blob: dbe7eda831c3574ea1853d31ba3213f3d9725dc9 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * This file is a part of hildon tests
 *
 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
 *
 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@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; version 2.1 of
 * the License.
 *
 * 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 "test_suites.h"
#include "check_utils.h"
#include <string.h>

#include "hildon-find-toolbar.h"
#include "hildon-window.h"

/* -------------------- Fixtures -------------------- */

static HildonFindToolbar *find_toolbar = NULL;
static GtkWidget *showed_window = NULL;

static void 
fx_setup_default_find_toolbar ()
{
  int argc = 0;
  gtk_init(&argc, NULL);

  /* Creates a find toolbar */
  find_toolbar = HILDON_FIND_TOOLBAR(hildon_find_toolbar_new(TEST_STRING));
  /* Check find toolbar object has been created properly */
  fail_if(!HILDON_IS_FIND_TOOLBAR(find_toolbar), 
          "hildon-find-toolbar: Creation failed.");

  showed_window =  create_test_window ();
  
  hildon_window_add_toolbar(HILDON_WINDOW(showed_window), GTK_TOOLBAR(find_toolbar));

  /* Displays the widget and the window */
  show_all_test_window (showed_window);

}

static void 
fx_setup_model_find_toolbar ()
{
  int argc = 0;
  GtkListStore *model;
  GtkTreeIter iter;
  GValue value = {0,};

  gtk_init(&argc, NULL);

  /* Creates a find toolbar with a model */
  model = gtk_list_store_new(1, G_TYPE_STRING);
  gtk_list_store_append(model, &iter);
  gtk_list_store_set (model, &iter, 0, "hildon", -1);
  gtk_list_store_append(model, &iter);
  gtk_list_store_set (model, &iter, 0, "nokia", -1);
  find_toolbar = HILDON_FIND_TOOLBAR(hildon_find_toolbar_new_with_model(NULL, model, 0));
  /* Check find toolbar object has been created properly */
  fail_if(!HILDON_IS_FIND_TOOLBAR(find_toolbar), 
          "hildon-find-toolbar: Creation failed.");

  /* Check model is set */
  g_value_init (&value, GTK_TYPE_LIST_STORE);
  g_object_get_property(G_OBJECT(find_toolbar), "list", &value);

  fail_if (model != g_value_get_object(&value),
           "hildon-find-toolbar: Creation with model failed, model retrieved is different from model set in new_with_model");

  showed_window =  create_test_window ();
  
  hildon_window_add_toolbar(HILDON_WINDOW(showed_window), GTK_TOOLBAR(find_toolbar));

  /* Displays the widget and the window */
  show_all_test_window (showed_window);
}

static void 
fx_teardown_find_toolbar()
{

  gtk_widget_destroy(GTK_WIDGET(showed_window)); 
  
}

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

/* ----- Test case for set/get_property "label"  -----*/

/**
 * Purpose: Check that property "label" is set and get properly.
 * Cases considered:
 *    - Set and get with a regular string
 *    - Set and get with value ""
 */
START_TEST (test_set_get_property_label_regular)
{
  GValue value_set = {0,};
  GValue value_get = {0,};

  g_value_init(&value_set,G_TYPE_STRING);
  g_value_init(&value_get,G_TYPE_STRING);

  /* Test1: set/get of a regular string */
  g_value_set_string(&value_set, TEST_STRING);
  g_object_set_property(G_OBJECT(find_toolbar), "label", &value_set);
  g_object_get_property(G_OBJECT(find_toolbar), "label", &value_get);
  fail_if (strcmp(g_value_get_string(&value_get), g_value_get_string(&value_set)) != 0,
	   "hildon-find-toolbar: Property \"label\" was set to value \"%s\", but get_property retrieved value \"%s\"", 
	   g_value_get_string(&value_set), g_value_get_string(&value_get));

  /* Test2: set/get of label "" */
  g_value_set_string(&value_set, "");
  g_object_set_property(G_OBJECT(find_toolbar), "label", &value_set);
  g_object_get_property(G_OBJECT(find_toolbar), "label", &value_get);
  fail_if (strcmp(g_value_get_string(&value_get), g_value_get_string(&value_set)) != 0,
	   "hildon-find-toolbar: Property \"label\" was set to value \"%s\", but get_property retrieved value \"%s\"", 
	   g_value_get_string(&value_set), g_value_get_string(&value_get));
}
END_TEST

/**
 * Purpose: Check handling of invalid values for property "label"
 * Cases considered:
 *    - Set and get with NULL value
 */
START_TEST (test_set_get_property_label_invalid)
{
  GValue value_set = {0,};
  GValue value_get = {0,};

  g_value_init(&value_set,G_TYPE_STRING);

  /* Test1: set/get of NULL label */
  g_value_set_string(&value_set, NULL);
  g_object_set_property(G_OBJECT(find_toolbar), "label", &value_set);
  g_object_get_property(G_OBJECT(find_toolbar), "label", &value_get);
  fail_if (g_value_get_string(&value_get) != NULL,
	   "hildon-find-toolbar: Property \"label\" was set to value NULL, but get_property retrieved value \"%s\"", 
	   g_value_get_string(&value_get));
}
END_TEST

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

Suite *create_hildon_find_toolbar_suite()
{
  /* Create the suite */
  Suite *s = suite_create("HildonFindToolbar");

  /* Create test cases */
  TCase *tc1 = tcase_create("set_get_property_label");
  TCase *tc2 = tcase_create("model_set_get_property_label");

  /* Create unit tests for set/get of property "label" and add it to the suite */
  tcase_add_checked_fixture(tc1, fx_setup_default_find_toolbar, fx_teardown_find_toolbar);
  tcase_add_test(tc1, test_set_get_property_label_regular);
  tcase_add_test(tc1, test_set_get_property_label_invalid);
  suite_add_tcase (s, tc1);

  /* Create unit tests for set/get of property "label" and add it to the suite */
  tcase_add_checked_fixture(tc2, fx_setup_model_find_toolbar, fx_teardown_find_toolbar);
  tcase_add_test(tc2, test_set_get_property_label_regular);
  tcase_add_test(tc2, test_set_get_property_label_invalid);
  suite_add_tcase (s, tc2);

  /* Return created suite */
  return s;
}