summaryrefslogtreecommitdiff
path: root/test/test-window.c
blob: 0b47ac68b12fec3f8adabb58d922cb678344cd58 (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
/* Copyright 2013 Endless Mobile, Inc. */

#include <stdlib.h>
#include <gtk/gtk.h>
#include <endless/endless.h>
#include "endless/eostopbar-private.h"
#include "endless/eosmainarea-private.h"

#include "run-tests.h"

#define EXPECTED_TOP_BAR_HEIGHT 32
#define EXPECTED_NULL_APPLICATION_ERRMSG \
  "*In order to create a window, you must have an application for it to " \
  "connect to.*"

static void
test_assign_application (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));

  g_assert(EOS_APPLICATION (app)
           == EOS_APPLICATION (gtk_window_get_application (GTK_WINDOW (win))));

  gtk_widget_destroy (win);
}

static void
test_application_not_null (GApplication *app)
{
  /* Unix-only test */
  if (g_test_trap_fork(0 /* timeout */, G_TEST_TRAP_SILENCE_STDERR))
    {
      GtkWidget *win = eos_window_new (NULL);
      gtk_widget_destroy (win);
      exit (0);
    }

  g_test_trap_assert_failed ();
  g_test_trap_assert_stderr (EXPECTED_NULL_APPLICATION_ERRMSG);

  g_application_quit (app); /* No window, so otherwise won't quit */
}

static void
test_has_top_bar (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
  GtkWidget *top_bar = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_TOP_BAR);
  g_assert (top_bar != NULL);
  g_assert (EOS_IS_TOP_BAR (top_bar));

  gtk_widget_destroy (win);
}

static void
test_has_main_area (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
  GtkWidget *main_area = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_MAIN_AREA);
  g_assert (main_area != NULL);
  g_assert (EOS_IS_MAIN_AREA (main_area));

  gtk_widget_destroy (win);
}

static void
test_has_default_page_manager (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));

  EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win));
  g_assert (pm != NULL);

  g_object_get (win, "page-manager", &pm, NULL);
  g_assert (pm != NULL);

  gtk_widget_destroy (win);
}

static void
test_get_set_page_manager (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));

  EosPageManager *orig_pm = eos_window_get_page_manager (EOS_WINDOW (win));
  EosPageManager *new_pm = EOS_PAGE_MANAGER (eos_page_manager_new ());

  g_assert (orig_pm != new_pm);
  eos_window_set_page_manager(EOS_WINDOW (win), new_pm);
  EosPageManager *test_pm = eos_window_get_page_manager (EOS_WINDOW (win));
  g_assert (new_pm == test_pm);

  gtk_widget_destroy (win);
}

static void
test_prop_page_manager (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));

  EosPageManager *orig_pm;
  g_object_get(win, "page-manager", &orig_pm, NULL);
  EosPageManager *new_pm = EOS_PAGE_MANAGER (eos_page_manager_new ());

  g_assert (orig_pm != new_pm);
  g_object_set(win, "page-manager", new_pm, NULL);
  EosPageManager *test_pm;
  g_object_get(win, "page-manager", &test_pm, NULL);
  g_assert (new_pm == test_pm);

  gtk_widget_destroy (win);
}

static void
test_main_area_widgets_visibility (GApplication *app)
{
  GtkWidget *win = eos_window_new (EOS_APPLICATION (app));
  EosPageManager *pm = eos_window_get_page_manager (EOS_WINDOW (win));
  GtkWidget *main_area = container_find_descendant_with_type (GTK_CONTAINER (win), EOS_TYPE_MAIN_AREA);

  GtkWidget *page0 = gtk_label_new ("no-no");
  GtkWidget *page1 = gtk_label_new ("yes-no");
  GtkWidget *page2 = gtk_label_new ("no-yes");
  GtkWidget *page3 = gtk_label_new ("yes-yes");

  GtkWidget *toolbox1 = gtk_label_new ("toolbox1");
  GtkWidget *toolbox3 = gtk_label_new ("toolbox3");

  gtk_container_add (GTK_CONTAINER (pm), page0);
  gtk_container_add_with_properties (GTK_CONTAINER (pm), page1,
                                     "custom-toolbox-widget", toolbox1,
                                     NULL);
  gtk_container_add_with_properties (GTK_CONTAINER (pm), page2,
                                     "page-actions", TRUE,
                                     NULL);
  gtk_container_add_with_properties (GTK_CONTAINER (pm), page3,
                                     "custom-toolbox-widget", toolbox3,
                                     "page-actions", TRUE,
                                     NULL);

  GtkWidget *tb;
  gboolean actions;
  EosMainArea *ma = EOS_MAIN_AREA (main_area);

  eos_page_manager_set_visible_page (pm, page0);
  tb = eos_main_area_get_toolbox (ma);
  actions = eos_main_area_get_actions (ma);
  g_assert (tb == NULL);
  g_assert (actions == FALSE);

  eos_page_manager_set_visible_page (pm, page1);
  tb = eos_main_area_get_toolbox (ma);
  actions = eos_main_area_get_actions (ma);
  g_assert (tb == toolbox1);
  g_assert (actions == FALSE);

  eos_page_manager_set_visible_page (pm, page2);
  tb = eos_main_area_get_toolbox (ma);
  actions = eos_main_area_get_actions (ma);
  g_assert (tb == NULL);
  g_assert (actions == TRUE);

  eos_page_manager_set_visible_page (pm, page3);
  tb = eos_main_area_get_toolbox (ma);
  actions = eos_main_area_get_actions (ma);
  g_assert (tb == toolbox3);
  g_assert (actions == TRUE);

  gtk_widget_destroy (win);
}

void
add_window_tests (void)
{
  ADD_APP_WINDOW_TEST ("/window/assign-application", test_assign_application);
  ADD_APP_WINDOW_TEST ("/window/application-not-null",
                       test_application_not_null);
  ADD_APP_WINDOW_TEST ("/window/has-top-bar", test_has_top_bar);
  ADD_APP_WINDOW_TEST ("/window/has-main-area", test_has_main_area);
  ADD_APP_WINDOW_TEST ("/window/has-default-page-manager",
                       test_has_default_page_manager);
  ADD_APP_WINDOW_TEST ("/window/get-set-page-manager",
                       test_get_set_page_manager);
  ADD_APP_WINDOW_TEST ("/window/prop-page-manager", test_prop_page_manager);
  ADD_APP_WINDOW_TEST ("/window/main-area-widgets-visibility",
                       test_main_area_widgets_visibility);
}