summaryrefslogtreecommitdiff
path: root/test/test-splash-page-manager.c
blob: 06105aa5ce422de6a6b9453cf5018a1000d675b5 (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
#include <gtk/gtk.h>
#include <endless/endless.h>

#include "run-tests.h"

#define ADD_SPLASH_PAGE_MANAGER_TEST(path, test_func) \
  g_test_add ((path), SplashPageManagerFixture, NULL, \
              spm_fixture_setup, (test_func), spm_fixture_teardown)
#define ADD_EMPTY_SPLASH_PAGE_MANAGER_TEST(path, test_func) \
  g_test_add ((path), SplashPageManagerFixture, NULL, \
              empty_spm_fixture_setup, (test_func), spm_fixture_teardown);

typedef struct
{
  GtkWidget *spm;
  GtkWidget *first_splash_page;
  GtkWidget *second_splash_page;
  GtkWidget *first_main_page;
  GtkWidget *second_main_page;
} SplashPageManagerFixture;

static void
empty_spm_fixture_setup (SplashPageManagerFixture *fixture,
                         gconstpointer             unused)
{
  fixture->first_splash_page = gtk_label_new ("splash");
  fixture->second_splash_page = gtk_label_new ("ham sandwich");
  fixture->first_main_page = gtk_label_new ("main");
  fixture->second_main_page = gtk_label_new ("pikachu");
  fixture->spm = eos_splash_page_manager_new ();
}

static void
spm_fixture_setup (SplashPageManagerFixture *fixture,
                   gconstpointer             unused)
{
  empty_spm_fixture_setup (fixture, unused);
  eos_splash_page_manager_set_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm),
                                           fixture->first_splash_page);
  eos_splash_page_manager_set_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm),
                                         fixture->first_main_page);
}

static void
spm_fixture_teardown (SplashPageManagerFixture *fixture,
                      gconstpointer             unused)
{
  gtk_widget_destroy (fixture->spm);
}

static void
test_spm_get_set_splash_page (SplashPageManagerFixture *fixture,
                              gconstpointer             unused)
{
  GtkWidget *splash_page;
  splash_page = eos_splash_page_manager_get_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  g_assert (splash_page != fixture->second_splash_page);
  eos_splash_page_manager_set_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm),
                                           fixture->second_splash_page);
  splash_page = eos_splash_page_manager_get_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  g_assert (splash_page == fixture->second_splash_page);
}

static void
test_spm_prop_splash_page (SplashPageManagerFixture *fixture,
                           gconstpointer             unused)
{
  GtkWidget *splash_page;
  g_object_get (fixture->spm, "splash-page", &splash_page, NULL);
  g_assert (splash_page != fixture->second_splash_page);
  g_object_set (fixture->spm, "splash-page", fixture->second_splash_page, NULL);
  g_object_get (fixture->spm, "splash-page", &splash_page, NULL);
  g_assert (splash_page == fixture->second_splash_page);
}

static void
test_spm_get_set_main_page (SplashPageManagerFixture *fixture,
                            gconstpointer             unused)
{
  GtkWidget *main_page;
  main_page = eos_splash_page_manager_get_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  g_assert (main_page != fixture->second_main_page);
  eos_splash_page_manager_set_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm),
                                         fixture->second_main_page);
  main_page = eos_splash_page_manager_get_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  g_assert (main_page == fixture->second_main_page);
}

static void
test_spm_prop_main_page (SplashPageManagerFixture *fixture,
                         gconstpointer             unused)
{
  GtkWidget *main_page;
  g_object_get (fixture->spm, "main-page", &main_page, NULL);
  g_assert (main_page != fixture->second_main_page);
  g_object_set (fixture->spm, "main-page", fixture->second_main_page, NULL);
  g_object_get (fixture->spm, "main-page", &main_page, NULL);
  g_assert (main_page == fixture->second_main_page);
}

static void
test_spm_show_main_page (SplashPageManagerFixture *fixture,
                         gconstpointer             unused)
{
  GtkWidget *visible_page;
  visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm));
  g_assert (visible_page != fixture->first_main_page);
  eos_splash_page_manager_show_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm));
  g_assert (visible_page == fixture->first_main_page);
}


static void
test_spm_show_splash_page (SplashPageManagerFixture *fixture,
                           gconstpointer             unused)
{
  GtkWidget *visible_page;
  visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm));
  g_assert (visible_page == fixture->first_splash_page);
  eos_splash_page_manager_show_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm));
  g_assert (visible_page != fixture->first_splash_page);
  eos_splash_page_manager_show_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm));
  g_assert (visible_page == fixture->first_splash_page);
}

static void
test_spm_default_visible_splash (SplashPageManagerFixture *fixture,
                                 gconstpointer             unused)
{
  // Even though main page is added first splash page should be visible after it is added.
  GtkWidget *visible_page;
  eos_splash_page_manager_set_main_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm),
                                         fixture->first_main_page);
  eos_splash_page_manager_set_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm),
                                           fixture->first_splash_page);
  visible_page = eos_page_manager_get_visible_page (EOS_PAGE_MANAGER (fixture->spm));
  g_assert (visible_page == fixture->first_splash_page);
}

static void
test_spm_add_to_splash (SplashPageManagerFixture *fixture,
                        gconstpointer             unused)
{
  // Right now container add sets the splash page by default. This tests that
  // functionality.
  GtkWidget *splash_page;
  gtk_container_add (GTK_CONTAINER (fixture->spm),
                     fixture->first_splash_page);
  splash_page = eos_splash_page_manager_get_splash_page (EOS_SPLASH_PAGE_MANAGER (fixture->spm));
  g_assert (splash_page == fixture->first_splash_page);
}

void
add_splash_page_manager_tests (void)
{
  ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/show-main-page",
                                test_spm_show_main_page);
  ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/show-splash-page",
                                test_spm_show_splash_page);
  ADD_EMPTY_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/default-visible-splash",
                                      test_spm_default_visible_splash);
  ADD_EMPTY_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/add-to-splash",
                                      test_spm_add_to_splash);

  /* Disabled until https://bugzilla.gnome.org/show_bug.cgi?id=699756 is fixed
  [endlessm/eos-sdk#67] */
  if (FALSE)
    {
      ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/get-set-splash-page",
                                    test_spm_get_set_splash_page);
      ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/prop-splash-page",
                                    test_spm_prop_splash_page);
      ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/get-set-main-page",
                                    test_spm_get_set_main_page);
      ADD_SPLASH_PAGE_MANAGER_TEST ("/splash-page-manager/prop-main-page",
                                    test_spm_prop_main_page);
    }
}