summaryrefslogtreecommitdiff
path: root/test/endless/test-page-manager.c
blob: 98cdadcf1170fa3a27f32690af0120f1f3a3f3c8 (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include <gtk/gtk.h>
#include <endless/endless.h>

#include "run-tests.h"

#define PAGE1_NAME "page1"
#define PAGE2_NAME "page2"
#define PAGE3_NAME "page3"
#define PAGE1_PROP_STRING "prop1"
#define PAGE2_PROP_STRING "prop2"
#define PAGE3_PROP_STRING "prop3"
#define EXPECTED_PAGE_PROP_STRING PAGE2_PROP_STRING
#define EXPECTED_CHANGED_NAME "changed-name"
#define ADD_PAGE_MANAGER_TEST(path, test_func) \
  g_test_add ((path), PageManagerFixture, NULL, \
              pm_fixture_setup, (test_func), pm_fixture_teardown)
#define ADD_PAGE_MANAGER_TEST_WITH_ARGS(path, test_func, args) \
  g_test_add ((path), PageManagerFixture, args, \
              pm_fixture_setup, (test_func), pm_fixture_teardown)
#define BACKGROUND_SIZE_DEFAULT "100% 100%"
#define BACKGROUND_POSITION_DEFAULT "0% 0%"

typedef struct
{
  GtkWidget *pm;
  GtkWidget *page1;
  GtkWidget *page2;
  GtkWidget *page3;
} PageManagerFixture;

static void
pm_fixture_setup (PageManagerFixture *fixture,
                  gconstpointer       unused)
{
  fixture->pm = eos_page_manager_new ();
  fixture->page1 = gtk_label_new ("1");
  fixture->page2 = gtk_label_new ("2");
  fixture->page3 = gtk_label_new ("3");
  gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
                                     fixture->page1,
                                     "name", PAGE1_NAME,
                                     "background-uri", PAGE1_PROP_STRING,
                                     "background-size", PAGE1_PROP_STRING,
                                     "background-position", PAGE1_PROP_STRING,
                                     NULL);
  gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
                                     fixture->page2,
                                     "name", PAGE2_NAME,
                                     "background-uri", PAGE2_PROP_STRING,
                                     "background-size", PAGE2_PROP_STRING,
                                     "background-position", PAGE2_PROP_STRING,
                                     NULL);
  gtk_container_add_with_properties (GTK_CONTAINER (fixture->pm),
                                     fixture->page3,
                                     "name", PAGE3_NAME,
                                     "background-uri", PAGE3_PROP_STRING,
                                     "background-size", PAGE3_PROP_STRING,
                                     "background-position", PAGE3_PROP_STRING,
                                     "background-repeats", FALSE,
                                     NULL);
}

static void
pm_fixture_teardown (PageManagerFixture *fixture,
                     gconstpointer       unused)
{
  gtk_widget_destroy (fixture->pm);
}

static void
test_pm_get_set_background_repeats (PageManagerFixture *fixture,
                              gconstpointer unused)
{
  gboolean repeats;
  repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
                                               fixture->page1);
  g_assert (repeats == TRUE);
  repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
                                               fixture->page3);
  g_assert (repeats == FALSE);
  eos_page_manager_set_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
                                     fixture->page3,
                                     TRUE);
  repeats = eos_page_manager_get_page_background_repeats (EOS_PAGE_MANAGER (fixture->pm),
                                               fixture->page3);
  g_assert (repeats == TRUE);
}

static void
test_pm_child_prop_background_repeats (PageManagerFixture *fixture,
                                 gconstpointer unused)
{
  gboolean repeats;
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1,
                           "background-repeats", &repeats,
                           NULL);
  g_assert (repeats == TRUE);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
                           "background-repeats", &repeats,
                           NULL);
  g_assert (repeats == FALSE);
  gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page3,
                           "background-repeats", TRUE,
                           NULL);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
                           "background-repeats", &repeats,
                           NULL);
  g_assert (repeats == TRUE);
}

static void
test_pm_child_prop_string (PageManagerFixture *fixture,
                           gconstpointer       data)
{
  gchar *prop_name = (gchar *)data;
  gchar *prop_string;
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page1,
                           prop_name, &prop_string,
                           NULL);
  g_assert_cmpstr (prop_string, ==, PAGE1_PROP_STRING);
  g_free (prop_string);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
                           prop_name, &prop_string,
                           NULL);
  g_assert_cmpstr (prop_string, ==, PAGE2_PROP_STRING);
  g_free (prop_string);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page3,
                           prop_name, &prop_string,
                           NULL);
  g_assert_cmpstr (prop_string, ==, PAGE3_PROP_STRING);
  g_free (prop_string);
  gtk_container_child_set (GTK_CONTAINER (fixture->pm), fixture->page2,
                           prop_name, EXPECTED_CHANGED_NAME,
                           NULL);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), fixture->page2,
                           prop_name, &prop_string,
                           NULL);
  g_assert_cmpstr (prop_string, ==, EXPECTED_CHANGED_NAME);
  g_free (prop_string);
}

static void
test_pm_no_background_uri (PageManagerFixture *fixture,
                            gconstpointer       unused)
{
  const gchar *background_uri_get;
  gchar *background_uri_prop;
  GtkWidget *new_page = gtk_label_new("new");
  gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
  background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_uri_get, ==, NULL);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
                           "background-uri", &background_uri_prop,
                           NULL);
  g_assert_cmpstr (background_uri_prop, ==, NULL);
  g_free (background_uri_prop);
}

static void
test_pm_get_set_background_uri (PageManagerFixture *fixture,
                                gconstpointer       unused)
{
  const gchar *background_uri_get;
  const gchar *background_uri_name_1 = "first background uri name";
  const gchar *background_uri_name_2 = "second background uri name";
  GtkWidget *new_page = gtk_label_new("new");
  gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
  eos_page_manager_set_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
                                            new_page,
                                            background_uri_name_1);
  background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_uri_get, ==, background_uri_name_1);

  eos_page_manager_set_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
                                            new_page,
                                            background_uri_name_2);
  background_uri_get = eos_page_manager_get_page_background_uri (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_uri_get, ==, background_uri_name_2);
}

static void
test_pm_default_background_size (PageManagerFixture *fixture,
                            gconstpointer       unused)
{
  const gchar *background_size_get;
  gchar *background_size_prop;
  GtkWidget *new_page = gtk_label_new("new");
  gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
  background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_size_get, ==, BACKGROUND_SIZE_DEFAULT);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
                           "background-size", &background_size_prop,
                           NULL);
  g_assert_cmpstr (background_size_prop, ==, BACKGROUND_SIZE_DEFAULT);
  g_free (background_size_prop);
}

static void
test_pm_get_set_background_size (PageManagerFixture *fixture,
                                gconstpointer       unused)
{
  const gchar *background_size_get;
  const gchar *background_size_name_1 = "first background size name";
  const gchar *background_size_name_2 = "second background size name";
  GtkWidget *new_page = gtk_label_new("new");
  gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
  eos_page_manager_set_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
                                            new_page,
                                            background_size_name_1);
  background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_size_get, ==, background_size_name_1);

  eos_page_manager_set_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
                                            new_page,
                                            background_size_name_2);
  background_size_get = eos_page_manager_get_page_background_size (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_size_get, ==, background_size_name_2);
}

static void
test_pm_default_background_position (PageManagerFixture *fixture,
                            gconstpointer       unused)
{
  const gchar *background_position_get;
  gchar *background_position_prop;
  GtkWidget *new_page = gtk_label_new("new");
  gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
  background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_position_get, ==, BACKGROUND_POSITION_DEFAULT);
  gtk_container_child_get (GTK_CONTAINER (fixture->pm), new_page,
                           "background-position", &background_position_prop,
                           NULL);
  g_assert_cmpstr (background_position_prop, ==, BACKGROUND_POSITION_DEFAULT);
  g_free (background_position_prop);
}

static void
test_pm_get_set_background_position (PageManagerFixture *fixture,
                                gconstpointer       unused)
{
  const gchar *background_position_get;
  const gchar *background_position_name_1 = "first background position name";
  const gchar *background_position_name_2 = "second background position name";
  GtkWidget *new_page = gtk_label_new("new");
  gtk_container_add (GTK_CONTAINER (fixture->pm), new_page);
  eos_page_manager_set_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
                                            new_page,
                                            background_position_name_1);
  background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_position_get, ==, background_position_name_1);

  eos_page_manager_set_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
                                            new_page,
                                            background_position_name_2);
  background_position_get = eos_page_manager_get_page_background_position (EOS_PAGE_MANAGER (fixture->pm),
                                                             new_page);
  g_assert_cmpstr (background_position_get, ==, background_position_name_2);
}

static void
test_pm_remove_page_by_name (PageManagerFixture *fixture,
                             gconstpointer       unused)
{
  GList *pages = gtk_container_get_children (GTK_CONTAINER (fixture->pm));
  guint length = g_list_length (pages);
  g_list_free (pages);

  eos_page_manager_remove_page_by_name (EOS_PAGE_MANAGER (fixture->pm),
                                        PAGE2_NAME);
  pages = gtk_container_get_children (GTK_CONTAINER (fixture->pm));
  g_assert_cmpuint (g_list_length (pages), ==, length - 1);
  g_assert (g_list_find (pages, fixture->page1) != NULL);
  g_assert (g_list_find (pages, fixture->page2) == NULL);
  g_assert (g_list_find (pages, fixture->page3) != NULL);
  g_list_free (pages);
}

void
add_page_manager_tests (void)
{
  ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-uri",
                                   test_pm_child_prop_string,
                                   "background-uri");
  ADD_PAGE_MANAGER_TEST ("/page-manager/no-background-uri",
                         test_pm_no_background_uri);
  ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-uri",
                         test_pm_get_set_background_uri);
  ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-size",
                                   test_pm_child_prop_string,
                                   "background-size");
  ADD_PAGE_MANAGER_TEST ("/page-manager/default-background-size",
                         test_pm_default_background_size);
  ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-size",
                         test_pm_get_set_background_size);
  ADD_PAGE_MANAGER_TEST_WITH_ARGS ("/page-manager/child-prop-background-position",
                                   test_pm_child_prop_string,
                                   "background-position");
  ADD_PAGE_MANAGER_TEST ("/page-manager/default-background-position",
                         test_pm_default_background_position);
  ADD_PAGE_MANAGER_TEST ("/page-manager/set-background-position",
                         test_pm_get_set_background_position);
  ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-background-repeats",
                         test_pm_get_set_background_repeats);
  ADD_PAGE_MANAGER_TEST ("/page-manager/child-prop-background-repeats",
                         test_pm_child_prop_background_repeats);
  ADD_PAGE_MANAGER_TEST ("/page-manager/remove-page-by-name",
                         test_pm_remove_page_by_name);
}