1 /*
2 * Copyright (C) 2020 Purism SPC
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * Author: Alexander Mikhaylenko <alexander.mikhaylenko@puri.sm>
7 */
8
9 #include <adwaita.h>
10
11 int notified;
12
13 static void
notify_cb(GtkWidget * widget,gpointer data)14 notify_cb (GtkWidget *widget, gpointer data)
15 {
16 notified++;
17 }
18
19 static void
test_adw_tab_bar_view(void)20 test_adw_tab_bar_view (void)
21 {
22 g_autoptr (AdwTabBar) bar = NULL;
23 g_autoptr (AdwTabView) view = NULL;
24
25 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
26 g_assert_nonnull (bar);
27
28 notified = 0;
29 g_signal_connect (bar, "notify::view", G_CALLBACK (notify_cb), NULL);
30
31 g_object_get (bar, "view", &view, NULL);
32 g_assert_null (view);
33
34 adw_tab_bar_set_view (bar, NULL);
35 g_assert_cmpint (notified, ==, 0);
36
37 view = g_object_ref_sink (ADW_TAB_VIEW (adw_tab_view_new ()));
38 adw_tab_bar_set_view (bar, view);
39 g_assert_true (adw_tab_bar_get_view (bar) == view);
40 g_assert_cmpint (notified, ==, 1);
41
42 g_object_set (bar, "view", NULL, NULL);
43 g_assert_null (adw_tab_bar_get_view (bar));
44 g_assert_cmpint (notified, ==, 2);
45 }
46
47 static void
test_adw_tab_bar_start_action_widget(void)48 test_adw_tab_bar_start_action_widget (void)
49 {
50 g_autoptr (AdwTabBar) bar = NULL;
51 GtkWidget *widget = NULL;
52
53 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
54 g_assert_nonnull (bar);
55
56 notified = 0;
57 g_signal_connect (bar, "notify::start-action-widget", G_CALLBACK (notify_cb), NULL);
58
59 g_object_get (bar, "start-action-widget", &widget, NULL);
60 g_assert_null (widget);
61
62 adw_tab_bar_set_start_action_widget (bar, NULL);
63 g_assert_cmpint (notified, ==, 0);
64
65 widget = gtk_button_new ();
66 adw_tab_bar_set_start_action_widget (bar, widget);
67 g_assert_true (adw_tab_bar_get_start_action_widget (bar) == widget);
68 g_assert_cmpint (notified, ==, 1);
69
70 g_object_set (bar, "start-action-widget", NULL, NULL);
71 g_assert_null (adw_tab_bar_get_start_action_widget (bar));
72 g_assert_cmpint (notified, ==, 2);
73 }
74
75 static void
test_adw_tab_bar_end_action_widget(void)76 test_adw_tab_bar_end_action_widget (void)
77 {
78 g_autoptr (AdwTabBar) bar = NULL;
79 GtkWidget *widget = NULL;
80
81 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
82 g_assert_nonnull (bar);
83
84 notified = 0;
85 g_signal_connect (bar, "notify::end-action-widget", G_CALLBACK (notify_cb), NULL);
86
87 g_object_get (bar, "end-action-widget", &widget, NULL);
88 g_assert_null (widget);
89
90 adw_tab_bar_set_end_action_widget (bar, NULL);
91 g_assert_cmpint (notified, ==, 0);
92
93 widget = gtk_button_new ();
94 adw_tab_bar_set_end_action_widget (bar, widget);
95 g_assert_true (adw_tab_bar_get_end_action_widget (bar) == widget);
96 g_assert_cmpint (notified, ==, 1);
97
98 g_object_set (bar, "end-action-widget", NULL, NULL);
99 g_assert_null (adw_tab_bar_get_end_action_widget (bar));
100 g_assert_cmpint (notified, ==, 2);
101 }
102
103 static void
test_adw_tab_bar_autohide(void)104 test_adw_tab_bar_autohide (void)
105 {
106 g_autoptr (AdwTabBar) bar = NULL;
107 gboolean autohide = FALSE;
108
109 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
110 g_assert_nonnull (bar);
111
112 notified = 0;
113 g_signal_connect (bar, "notify::autohide", G_CALLBACK (notify_cb), NULL);
114
115 g_object_get (bar, "autohide", &autohide, NULL);
116 g_assert_true (autohide);
117
118 adw_tab_bar_set_autohide (bar, TRUE);
119 g_assert_cmpint (notified, ==, 0);
120
121 adw_tab_bar_set_autohide (bar, FALSE);
122 g_assert_false (adw_tab_bar_get_autohide (bar));
123 g_assert_cmpint (notified, ==, 1);
124
125 g_object_set (bar, "autohide", TRUE, NULL);
126 g_assert_true (adw_tab_bar_get_autohide (bar));
127 g_assert_cmpint (notified, ==, 2);
128 }
129
130 static void
test_adw_tab_bar_tabs_revealed(void)131 test_adw_tab_bar_tabs_revealed (void)
132 {
133 g_autoptr (AdwTabBar) bar = NULL;
134 g_autoptr (AdwTabView) view = NULL;
135 gboolean tabs_revealed = FALSE;
136 AdwTabPage *page;
137
138 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
139 g_assert_nonnull (bar);
140
141 notified = 0;
142 g_signal_connect (bar, "notify::tabs-revealed", G_CALLBACK (notify_cb), NULL);
143
144 g_object_get (bar, "tabs-revealed", &tabs_revealed, NULL);
145 g_assert_false (tabs_revealed);
146 g_assert_false (adw_tab_bar_get_tabs_revealed (bar));
147 g_assert_cmpint (notified, ==, 0);
148
149 adw_tab_bar_set_autohide (bar, FALSE);
150 g_assert_false (adw_tab_bar_get_tabs_revealed (bar));
151 g_assert_cmpint (notified, ==, 0);
152
153 view = g_object_ref_sink (ADW_TAB_VIEW (adw_tab_view_new ()));
154 adw_tab_bar_set_view (bar, view);
155 g_assert_true (adw_tab_bar_get_tabs_revealed (bar));
156 g_assert_cmpint (notified, ==, 1);
157
158 adw_tab_bar_set_autohide (bar, TRUE);
159 g_assert_false (adw_tab_bar_get_tabs_revealed (bar));
160 g_assert_cmpint (notified, ==, 2);
161
162 page = adw_tab_view_append_pinned (view, gtk_button_new ());
163 g_assert_true (adw_tab_bar_get_tabs_revealed (bar));
164 g_assert_cmpint (notified, ==, 3);
165
166 adw_tab_view_set_page_pinned (view, page, FALSE);
167 g_assert_false (adw_tab_bar_get_tabs_revealed (bar));
168 g_assert_cmpint (notified, ==, 4);
169
170 adw_tab_view_append (view, gtk_button_new ());
171 g_assert_true (adw_tab_bar_get_tabs_revealed (bar));
172 g_assert_cmpint (notified, ==, 5);
173
174 adw_tab_view_close_page (view, page);
175 g_assert_false (adw_tab_bar_get_tabs_revealed (bar));
176 g_assert_cmpint (notified, ==, 6);
177
178 adw_tab_bar_set_autohide (bar, FALSE);
179 g_assert_true (adw_tab_bar_get_tabs_revealed (bar));
180 g_assert_cmpint (notified, ==, 7);
181 }
182
183 static void
test_adw_tab_bar_expand_tabs(void)184 test_adw_tab_bar_expand_tabs (void)
185 {
186 g_autoptr (AdwTabBar) bar = NULL;
187 gboolean expand_tabs = FALSE;
188
189 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
190 g_assert_nonnull (bar);
191
192 notified = 0;
193 g_signal_connect (bar, "notify::expand-tabs", G_CALLBACK (notify_cb), NULL);
194
195 g_object_get (bar, "expand-tabs", &expand_tabs, NULL);
196 g_assert_true (expand_tabs);
197
198 adw_tab_bar_set_expand_tabs (bar, TRUE);
199 g_assert_cmpint (notified, ==, 0);
200
201 adw_tab_bar_set_expand_tabs (bar, FALSE);
202 g_assert_false (adw_tab_bar_get_expand_tabs (bar));
203 g_assert_cmpint (notified, ==, 1);
204
205 g_object_set (bar, "expand-tabs", TRUE, NULL);
206 g_assert_true (adw_tab_bar_get_expand_tabs (bar));
207 g_assert_cmpint (notified, ==, 2);
208 }
209
210 static void
test_adw_tab_bar_inverted(void)211 test_adw_tab_bar_inverted (void)
212 {
213 g_autoptr (AdwTabBar) bar = NULL;
214 gboolean inverted = FALSE;
215
216 bar = g_object_ref_sink (ADW_TAB_BAR (adw_tab_bar_new ()));
217 g_assert_nonnull (bar);
218
219 notified = 0;
220 g_signal_connect (bar, "notify::inverted", G_CALLBACK (notify_cb), NULL);
221
222 g_object_get (bar, "inverted", &inverted, NULL);
223 g_assert_false (inverted);
224
225 adw_tab_bar_set_inverted (bar, FALSE);
226 g_assert_cmpint (notified, ==, 0);
227
228 adw_tab_bar_set_inverted (bar, TRUE);
229 g_assert_true (adw_tab_bar_get_inverted (bar));
230 g_assert_cmpint (notified, ==, 1);
231
232 g_object_set (bar, "inverted", FALSE, NULL);
233 g_assert_false (adw_tab_bar_get_inverted (bar));
234 g_assert_cmpint (notified, ==, 2);
235 }
236
237 int
main(int argc,char * argv[])238 main (int argc,
239 char *argv[])
240 {
241 gtk_test_init (&argc, &argv, NULL);
242 adw_init ();
243
244 g_test_add_func ("/Adwaita/TabBar/view", test_adw_tab_bar_view);
245 g_test_add_func ("/Adwaita/TabBar/start_action_widget", test_adw_tab_bar_start_action_widget);
246 g_test_add_func ("/Adwaita/TabBar/end_action_widget", test_adw_tab_bar_end_action_widget);
247 g_test_add_func ("/Adwaita/TabBar/autohide", test_adw_tab_bar_autohide);
248 g_test_add_func ("/Adwaita/TabBar/tabs_revealed", test_adw_tab_bar_tabs_revealed);
249 g_test_add_func ("/Adwaita/TabBar/expand_tabs", test_adw_tab_bar_expand_tabs);
250 g_test_add_func ("/Adwaita/TabBar/inverted", test_adw_tab_bar_inverted);
251
252 return g_test_run ();
253 }
254