| 1 |
/* templates.c |
| 2 |
* Copyright (C) 2013 Openismus GmbH |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Library General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Library General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Library General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
* |
| 17 |
* Authors: Tristan Van Berkom <[email protected]> |
| 18 |
*/ |
| 19 |
#include <gtk/gtk.h> |
| 20 |
|
| 21 |
#ifdef HAVE_UNIX_PRINT_WIDGETS |
| 22 |
# include <gtk/gtkunixprint.h> |
| 23 |
#endif |
| 24 |
|
| 25 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 26 |
|
| 27 |
static gboolean |
| 28 |
main_loop_quit_cb (gpointer data) |
| 29 |
{ |
| 30 |
gboolean *done = data; |
| 31 |
|
| 32 |
*done = TRUE; |
| 33 |
|
| 34 |
g_main_context_wakeup (NULL); |
| 35 |
|
| 36 |
return FALSE; |
| 37 |
} |
| 38 |
|
| 39 |
static void |
| 40 |
show_and_wait (GtkWidget *widget) |
| 41 |
{ |
| 42 |
gboolean done = FALSE; |
| 43 |
|
| 44 |
g_timeout_add (500, main_loop_quit_cb, &done); |
| 45 |
gtk_widget_set_visible (widget, TRUE); |
| 46 |
while (!done) |
| 47 |
g_main_context_iteration (NULL, FALSE); |
| 48 |
} |
| 49 |
|
| 50 |
static void |
| 51 |
test_dialog_basic (void) |
| 52 |
{ |
| 53 |
GtkWidget *dialog; |
| 54 |
|
| 55 |
dialog = gtk_dialog_new (); |
| 56 |
g_assert_true (GTK_IS_DIALOG (dialog)); |
| 57 |
g_assert_nonnull (gtk_dialog_get_content_area (GTK_DIALOG (dialog))); |
| 58 |
|
| 59 |
gtk_window_destroy (GTK_WINDOW (dialog)); |
| 60 |
} |
| 61 |
|
| 62 |
static void |
| 63 |
test_dialog_override_property (void) |
| 64 |
{ |
| 65 |
GtkWidget *dialog; |
| 66 |
|
| 67 |
dialog = g_object_new (GTK_TYPE_DIALOG, |
| 68 |
"use-header-bar", 1, |
| 69 |
NULL); |
| 70 |
g_assert_true (GTK_IS_DIALOG (dialog)); |
| 71 |
|
| 72 |
gtk_window_destroy (GTK_WINDOW (dialog)); |
| 73 |
} |
| 74 |
|
| 75 |
static void |
| 76 |
test_message_dialog_basic (void) |
| 77 |
{ |
| 78 |
GtkWidget *dialog; |
| 79 |
|
| 80 |
dialog = gtk_message_dialog_new (NULL, 0, |
| 81 |
GTK_MESSAGE_INFO, |
| 82 |
GTK_BUTTONS_CLOSE, |
| 83 |
"Do it hard !"); |
| 84 |
g_assert_true (GTK_IS_DIALOG (dialog)); |
| 85 |
gtk_window_destroy (GTK_WINDOW (dialog)); |
| 86 |
} |
| 87 |
|
| 88 |
static void |
| 89 |
test_about_dialog_basic (void) |
| 90 |
{ |
| 91 |
GtkWidget *dialog; |
| 92 |
|
| 93 |
dialog = gtk_about_dialog_new (); |
| 94 |
g_assert_true (GTK_IS_ABOUT_DIALOG (dialog)); |
| 95 |
gtk_window_destroy (GTK_WINDOW (dialog)); |
| 96 |
} |
| 97 |
|
| 98 |
static void |
| 99 |
test_about_dialog_show (void) |
| 100 |
{ |
| 101 |
GtkWidget *dialog; |
| 102 |
|
| 103 |
dialog = gtk_about_dialog_new (); |
| 104 |
g_assert_true (GTK_IS_ABOUT_DIALOG (dialog)); |
| 105 |
show_and_wait (dialog); |
| 106 |
gtk_window_destroy (GTK_WINDOW (dialog)); |
| 107 |
} |
| 108 |
|
| 109 |
static void |
| 110 |
test_info_bar_basic (void) |
| 111 |
{ |
| 112 |
GtkWidget *infobar; |
| 113 |
|
| 114 |
infobar = gtk_info_bar_new (); |
| 115 |
g_assert_true (GTK_IS_INFO_BAR (infobar)); |
| 116 |
g_object_unref (g_object_ref_sink (infobar)); |
| 117 |
} |
| 118 |
|
| 119 |
static void |
| 120 |
test_lock_button_basic (void) |
| 121 |
{ |
| 122 |
GtkWidget *button; |
| 123 |
GPermission *permission; |
| 124 |
|
| 125 |
permission = g_simple_permission_new (TRUE); |
| 126 |
button = gtk_lock_button_new (permission); |
| 127 |
g_assert_true (GTK_IS_LOCK_BUTTON (button)); |
| 128 |
g_object_unref (g_object_ref_sink (button)); |
| 129 |
g_object_unref (permission); |
| 130 |
} |
| 131 |
|
| 132 |
static void |
| 133 |
test_assistant_basic (void) |
| 134 |
{ |
| 135 |
GtkWidget *widget; |
| 136 |
|
| 137 |
widget = gtk_assistant_new (); |
| 138 |
g_assert_true (GTK_IS_ASSISTANT (widget)); |
| 139 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 140 |
} |
| 141 |
|
| 142 |
static void |
| 143 |
test_assistant_show (void) |
| 144 |
{ |
| 145 |
GtkWidget *widget; |
| 146 |
|
| 147 |
widget = gtk_assistant_new (); |
| 148 |
g_assert_true (GTK_IS_ASSISTANT (widget)); |
| 149 |
show_and_wait (widget); |
| 150 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 151 |
} |
| 152 |
|
| 153 |
static void |
| 154 |
test_scale_button_basic (void) |
| 155 |
{ |
| 156 |
GtkWidget *widget; |
| 157 |
|
| 158 |
widget = gtk_scale_button_new (0, 100, 10, NULL); |
| 159 |
g_assert_true (GTK_IS_SCALE_BUTTON (widget)); |
| 160 |
g_object_unref (g_object_ref_sink (widget)); |
| 161 |
} |
| 162 |
|
| 163 |
static void |
| 164 |
test_volume_button_basic (void) |
| 165 |
{ |
| 166 |
GtkWidget *widget; |
| 167 |
|
| 168 |
widget = gtk_volume_button_new (); |
| 169 |
g_assert_true (GTK_IS_VOLUME_BUTTON (widget)); |
| 170 |
g_object_unref (g_object_ref_sink (widget)); |
| 171 |
} |
| 172 |
|
| 173 |
static void |
| 174 |
test_statusbar_basic (void) |
| 175 |
{ |
| 176 |
GtkWidget *widget; |
| 177 |
|
| 178 |
widget = gtk_statusbar_new (); |
| 179 |
g_assert_true (GTK_IS_STATUSBAR (widget)); |
| 180 |
g_object_unref (g_object_ref_sink (widget)); |
| 181 |
} |
| 182 |
|
| 183 |
static void |
| 184 |
test_search_bar_basic (void) |
| 185 |
{ |
| 186 |
GtkWidget *widget; |
| 187 |
|
| 188 |
widget = gtk_search_bar_new (); |
| 189 |
g_assert_true (GTK_IS_SEARCH_BAR (widget)); |
| 190 |
g_object_unref (g_object_ref_sink (widget)); |
| 191 |
} |
| 192 |
|
| 193 |
static void |
| 194 |
test_action_bar_basic (void) |
| 195 |
{ |
| 196 |
GtkWidget *widget; |
| 197 |
|
| 198 |
widget = gtk_action_bar_new (); |
| 199 |
g_assert_true (GTK_IS_ACTION_BAR (widget)); |
| 200 |
g_object_unref (g_object_ref_sink (widget)); |
| 201 |
} |
| 202 |
|
| 203 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS |
| 204 |
|
| 205 |
static void |
| 206 |
test_app_chooser_widget_basic (void) |
| 207 |
{ |
| 208 |
GtkWidget *widget; |
| 209 |
|
| 210 |
widget = gtk_app_chooser_widget_new (NULL); |
| 211 |
g_assert_true (GTK_IS_APP_CHOOSER_WIDGET (widget)); |
| 212 |
g_object_unref (g_object_ref_sink (widget)); |
| 213 |
} |
| 214 |
|
| 215 |
static void |
| 216 |
test_app_chooser_dialog_basic (void) |
| 217 |
{ |
| 218 |
GtkWidget *widget; |
| 219 |
gboolean done = FALSE; |
| 220 |
|
| 221 |
widget = gtk_app_chooser_dialog_new_for_content_type (NULL, 0, "text/plain"); |
| 222 |
g_assert_true (GTK_IS_APP_CHOOSER_DIALOG (widget)); |
| 223 |
|
| 224 |
/* GtkAppChooserDialog bug, if destroyed before spinning |
| 225 |
* the main context then app_chooser_online_get_default_ready_cb() |
| 226 |
* will be eventually called and segfault. |
| 227 |
*/ |
| 228 |
g_timeout_add (500, main_loop_quit_cb, &done); |
| 229 |
while (!done) |
| 230 |
g_main_context_iteration (NULL, TRUE); |
| 231 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 232 |
} |
| 233 |
|
| 234 |
G_GNUC_END_IGNORE_DEPRECATIONS |
| 235 |
|
| 236 |
static void |
| 237 |
test_color_chooser_dialog_basic (void) |
| 238 |
{ |
| 239 |
GtkWidget *widget; |
| 240 |
|
| 241 |
/* This test also tests the internal GtkColorEditor widget */ |
| 242 |
widget = gtk_color_chooser_dialog_new (NULL, NULL); |
| 243 |
g_assert_true (GTK_IS_COLOR_CHOOSER_DIALOG (widget)); |
| 244 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 245 |
} |
| 246 |
|
| 247 |
static void |
| 248 |
test_color_chooser_dialog_show (void) |
| 249 |
{ |
| 250 |
GtkWidget *widget; |
| 251 |
|
| 252 |
/* This test also tests the internal GtkColorEditor widget */ |
| 253 |
widget = gtk_color_chooser_dialog_new (NULL, NULL); |
| 254 |
g_assert_true (GTK_IS_COLOR_CHOOSER_DIALOG (widget)); |
| 255 |
show_and_wait (widget); |
| 256 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 257 |
} |
| 258 |
|
| 259 |
/* Avoid warnings from GVFS-RemoteVolumeMonitor */ |
| 260 |
static gboolean |
| 261 |
ignore_gvfs_warning (const char *log_domain, |
| 262 |
GLogLevelFlags log_level, |
| 263 |
const char *message, |
| 264 |
gpointer user_data) |
| 265 |
{ |
| 266 |
if (g_strcmp0 (log_domain, "GVFS-RemoteVolumeMonitor") == 0) |
| 267 |
return FALSE; |
| 268 |
|
| 269 |
return TRUE; |
| 270 |
} |
| 271 |
|
| 272 |
static void |
| 273 |
test_file_chooser_widget_basic (void) |
| 274 |
{ |
| 275 |
GtkWidget *widget; |
| 276 |
gboolean done = FALSE; |
| 277 |
|
| 278 |
/* This test also tests the internal GtkPathBar widget */ |
| 279 |
g_test_log_set_fatal_handler (ignore_gvfs_warning, NULL); |
| 280 |
|
| 281 |
widget = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); |
| 282 |
g_assert_true (GTK_IS_FILE_CHOOSER_WIDGET (widget)); |
| 283 |
|
| 284 |
/* XXX BUG: |
| 285 |
* |
| 286 |
* Spin the mainloop for a bit, this allows the file operations |
| 287 |
* to complete, GtkFileChooserWidget has a bug where it leaks |
| 288 |
* GtkTreeRowReferences to the internal shortcuts_model |
| 289 |
* |
| 290 |
* Since we assert all automated children are finalized we |
| 291 |
* can catch this |
| 292 |
*/ |
| 293 |
g_timeout_add (100, main_loop_quit_cb, &done); |
| 294 |
while (!done) |
| 295 |
g_main_context_iteration (NULL, TRUE); |
| 296 |
|
| 297 |
g_object_unref (g_object_ref_sink (widget)); |
| 298 |
} |
| 299 |
|
| 300 |
static void |
| 301 |
test_file_chooser_dialog_basic (void) |
| 302 |
{ |
| 303 |
GtkWidget *widget; |
| 304 |
gboolean done; |
| 305 |
|
| 306 |
g_test_log_set_fatal_handler (ignore_gvfs_warning, NULL); |
| 307 |
|
| 308 |
widget = gtk_file_chooser_dialog_new ("The Dialog", NULL, |
| 309 |
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
| 310 |
"_OK", GTK_RESPONSE_OK, |
| 311 |
NULL); |
| 312 |
|
| 313 |
g_assert_true (GTK_IS_FILE_CHOOSER_DIALOG (widget)); |
| 314 |
done = FALSE; |
| 315 |
g_timeout_add (100, main_loop_quit_cb, &done); |
| 316 |
while (!done) |
| 317 |
g_main_context_iteration (NULL, TRUE); |
| 318 |
|
| 319 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 320 |
} |
| 321 |
|
| 322 |
static void |
| 323 |
test_file_chooser_dialog_show (void) |
| 324 |
{ |
| 325 |
GtkWidget *widget; |
| 326 |
|
| 327 |
g_test_log_set_fatal_handler (ignore_gvfs_warning, NULL); |
| 328 |
|
| 329 |
widget = gtk_file_chooser_dialog_new ("The Dialog", NULL, |
| 330 |
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, |
| 331 |
"_OK", GTK_RESPONSE_OK, |
| 332 |
NULL); |
| 333 |
|
| 334 |
g_assert_true (GTK_IS_FILE_CHOOSER_DIALOG (widget)); |
| 335 |
show_and_wait (widget); |
| 336 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 337 |
} |
| 338 |
|
| 339 |
static void |
| 340 |
test_font_button_basic (void) |
| 341 |
{ |
| 342 |
GtkWidget *widget; |
| 343 |
|
| 344 |
widget = gtk_font_button_new (); |
| 345 |
g_assert_true (GTK_IS_FONT_BUTTON (widget)); |
| 346 |
g_object_unref (g_object_ref_sink (widget)); |
| 347 |
} |
| 348 |
|
| 349 |
static void |
| 350 |
test_font_chooser_widget_basic (void) |
| 351 |
{ |
| 352 |
GtkWidget *widget; |
| 353 |
|
| 354 |
widget = gtk_font_chooser_widget_new (); |
| 355 |
g_assert_true (GTK_IS_FONT_CHOOSER_WIDGET (widget)); |
| 356 |
g_object_unref (g_object_ref_sink (widget)); |
| 357 |
} |
| 358 |
|
| 359 |
static void |
| 360 |
test_font_chooser_dialog_basic (void) |
| 361 |
{ |
| 362 |
GtkWidget *widget; |
| 363 |
|
| 364 |
widget = gtk_font_chooser_dialog_new ("Choose a font !", NULL); |
| 365 |
g_assert_true (GTK_IS_FONT_CHOOSER_DIALOG (widget)); |
| 366 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 367 |
} |
| 368 |
|
| 369 |
static void |
| 370 |
test_font_chooser_dialog_show (void) |
| 371 |
{ |
| 372 |
GtkWidget *widget; |
| 373 |
|
| 374 |
widget = gtk_font_chooser_dialog_new ("Choose a font !", NULL); |
| 375 |
g_assert_true (GTK_IS_FONT_CHOOSER_DIALOG (widget)); |
| 376 |
show_and_wait (widget); |
| 377 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 378 |
} |
| 379 |
|
| 380 |
#ifdef HAVE_UNIX_PRINT_WIDGETS |
| 381 |
static void |
| 382 |
test_page_setup_unix_dialog_basic (void) |
| 383 |
{ |
| 384 |
GtkWidget *widget; |
| 385 |
|
| 386 |
widget = gtk_page_setup_unix_dialog_new ("Setup your Page !", NULL); |
| 387 |
g_assert_true (GTK_IS_PAGE_SETUP_UNIX_DIALOG (widget)); |
| 388 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 389 |
} |
| 390 |
|
| 391 |
static void |
| 392 |
test_page_setup_unix_dialog_show (void) |
| 393 |
{ |
| 394 |
GtkWidget *widget; |
| 395 |
|
| 396 |
widget = gtk_page_setup_unix_dialog_new ("Setup your Page !", NULL); |
| 397 |
g_assert_true (GTK_IS_PAGE_SETUP_UNIX_DIALOG (widget)); |
| 398 |
show_and_wait (widget); |
| 399 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 400 |
} |
| 401 |
|
| 402 |
static void |
| 403 |
test_print_unix_dialog_basic (void) |
| 404 |
{ |
| 405 |
GtkWidget *widget; |
| 406 |
|
| 407 |
widget = gtk_print_unix_dialog_new ("Go Print !", NULL); |
| 408 |
g_assert_true (GTK_IS_PRINT_UNIX_DIALOG (widget)); |
| 409 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 410 |
} |
| 411 |
|
| 412 |
static void |
| 413 |
test_print_unix_dialog_show (void) |
| 414 |
{ |
| 415 |
GtkWidget *widget; |
| 416 |
|
| 417 |
widget = gtk_print_unix_dialog_new ("Go Print !", NULL); |
| 418 |
g_assert_true (GTK_IS_PRINT_UNIX_DIALOG (widget)); |
| 419 |
show_and_wait (widget); |
| 420 |
gtk_window_destroy (GTK_WINDOW (widget)); |
| 421 |
} |
| 422 |
#endif |
| 423 |
|
| 424 |
int |
| 425 |
main (int argc, char **argv) |
| 426 |
{ |
| 427 |
/* These must be set before gtk_test_init */ |
| 428 |
g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); |
| 429 |
|
| 430 |
/* initialize test program */ |
| 431 |
gtk_test_init (&argc, &argv); |
| 432 |
|
| 433 |
/* This environment variable cooperates with widget dispose() |
| 434 |
* to assert that all automated compoenents are properly finalized |
| 435 |
* when a given composite widget is destroyed. |
| 436 |
*/ |
| 437 |
g_assert_true (g_setenv ("GTK_WIDGET_ASSERT_COMPONENTS", "1", TRUE)); |
| 438 |
|
| 439 |
g_test_add_func ("/template/GtkDialog/basic", test_dialog_basic); |
| 440 |
g_test_add_func ("/template/GtkDialog/OverrideProperty", test_dialog_override_property); |
| 441 |
g_test_add_func ("/template/GtkMessageDialog/basic", test_message_dialog_basic); |
| 442 |
g_test_add_func ("/template/GtkAboutDialog/basic", test_about_dialog_basic); |
| 443 |
g_test_add_func ("/template/GtkAboutDialog/show", test_about_dialog_show); |
| 444 |
g_test_add_func ("/template/GtkInfoBar/basic", test_info_bar_basic); |
| 445 |
g_test_add_func ("/template/GtkLockButton/basic", test_lock_button_basic); |
| 446 |
g_test_add_func ("/template/GtkAssistant/basic", test_assistant_basic); |
| 447 |
g_test_add_func ("/template/GtkAssistant/show", test_assistant_show); |
| 448 |
g_test_add_func ("/template/GtkScaleButton/basic", test_scale_button_basic); |
| 449 |
g_test_add_func ("/template/GtkVolumeButton/basic", test_volume_button_basic); |
| 450 |
g_test_add_func ("/template/GtkStatusBar/basic", test_statusbar_basic); |
| 451 |
g_test_add_func ("/template/GtkSearchBar/basic", test_search_bar_basic); |
| 452 |
g_test_add_func ("/template/GtkActionBar/basic", test_action_bar_basic); |
| 453 |
g_test_add_func ("/template/GtkAppChooserWidget/basic", test_app_chooser_widget_basic); |
| 454 |
g_test_add_func ("/template/GtkAppChooserDialog/basic", test_app_chooser_dialog_basic); |
| 455 |
g_test_add_func ("/template/GtkColorChooserDialog/basic", test_color_chooser_dialog_basic); |
| 456 |
g_test_add_func ("/template/GtkColorChooserDialog/show", test_color_chooser_dialog_show); |
| 457 |
g_test_add_func ("/template/GtkFileChooserWidget/basic", test_file_chooser_widget_basic); |
| 458 |
g_test_add_func ("/template/GtkFileChooserDialog/basic", test_file_chooser_dialog_basic); |
| 459 |
g_test_add_func ("/template/GtkFileChooserDialog/show", test_file_chooser_dialog_show); |
| 460 |
g_test_add_func ("/template/GtkFontButton/basic", test_font_button_basic); |
| 461 |
g_test_add_func ("/template/GtkFontChooserWidget/basic", test_font_chooser_widget_basic); |
| 462 |
g_test_add_func ("/template/GtkFontChooserDialog/basic", test_font_chooser_dialog_basic); |
| 463 |
g_test_add_func ("/template/GtkFontChooserDialog/show", test_font_chooser_dialog_show); |
| 464 |
|
| 465 |
#ifdef HAVE_UNIX_PRINT_WIDGETS |
| 466 |
g_test_add_func ("/template/GtkPageSetupUnixDialog/basic", test_page_setup_unix_dialog_basic); |
| 467 |
g_test_add_func ("/template/GtkPageSetupUnixDialog/show", test_page_setup_unix_dialog_show); |
| 468 |
g_test_add_func ("/template/GtkPrintUnixDialog/basic", test_print_unix_dialog_basic); |
| 469 |
g_test_add_func ("/template/GtkPrintUnixDialog/show", test_print_unix_dialog_show); |
| 470 |
#endif |
| 471 |
|
| 472 |
return g_test_run(); |
| 473 |
} |