int main (int argc, char **argv) { const GType *otypes; guint i; gchar *schema_dir; GTestDBus *bus; GMainLoop *loop; gint result; /* These must be set before before gtk_test_init */ g_setenv ("GIO_USE_VFS", "local", TRUE); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); g_setenv ("G_ENABLE_DIAGNOSTIC", "0", TRUE); gtk_test_init (&argc, &argv); gtk_test_register_all_types(); /* g_test_build_filename must be called after gtk_test_init */ schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL); g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE); /* Create one test bus for all tests, as we have a lot of very small * and quick tests. */ bus = g_test_dbus_new (G_TEST_DBUS_NONE); g_test_dbus_up (bus); otypes = gtk_test_list_all_types (NULL); for (i = 0; otypes[i]; i++) { gchar *testname; if (otypes[i] == GTK_TYPE_FILE_CHOOSER_NATIVE) continue; testname = g_strdup_printf ("/Default Values/%s", g_type_name (otypes[i])); g_test_add_data_func (testname, &otypes[i], test_type); g_free (testname); } result = g_test_run(); /* Work around the annoying issue that g_test_dbus_down is giving * us an "Error while sending AddMatch" that comes out of an idle */ loop = g_main_loop_new (NULL, FALSE); g_timeout_add (1000, (GSourceFunc)g_main_loop_quit, loop); g_main_loop_run (loop); g_main_loop_unref (loop); g_test_dbus_down (bus); g_object_unref (bus); g_free (schema_dir); return result; }
static int test_common_start(test_t * test, x11spice_server_t * server, xdummy_t *xserver, gconstpointer user_data) { int rc; if (!xserver->running) { g_test_skip("No server"); return -1; } test->xserver = xserver; test->name = user_data; test->logfile = g_test_build_filename(G_TEST_BUILT, "run", test->name, "test.log", NULL); if (!test->logfile) { g_warning("Failed to create logfile"); g_test_fail(); return -1; } memset(server, 0, sizeof(*server)); rc = x11spice_start(server, test); if (rc) { g_warning("Failed to start x11spice"); g_test_fail(); return rc; } return 0; }
gchar * test_get_sample_db_path (void) { return g_test_build_filename (G_TEST_DIST, "test", "testdb", NULL); }
gchar * test_get_invalid_db_path (void) { return g_test_build_filename (G_TEST_DIST, "test", "invalid", NULL); }
gchar * test_get_manifest_db_path (void) { return g_test_build_filename (G_TEST_DIST, "test", "manifest.json", NULL); }
int main (int argc, char *argv[]) { GDir *dir; GError *error = NULL; const gchar *name; gchar *path; g_setenv ("LC_ALL", "C", TRUE); setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); /* allow to easily generate expected output for new test cases */ if (argc > 1) { GString *string; string = g_string_sized_new (0); test_file (argv[1], string); g_print ("%s", string->str); return 0; } path = g_test_build_filename (G_TEST_DIST, "layouts", NULL); dir = g_dir_open (path, 0, &error); g_free (path); g_assert_no_error (error); while ((name = g_dir_read_name (dir)) != NULL) { if (!strstr (name, "markup")) continue; path = g_strdup_printf ("/layout/%s", name); g_test_add_data_func_full (path, g_test_build_filename (G_TEST_DIST, "layouts", name, NULL), test_layout, g_free); g_free (path); } g_dir_close (dir); return g_test_run (); }
int main (int argc, char **argv) { gchar *schema_dir; /* These must be set before before gtk_test_init */ g_setenv ("GIO_USE_VFS", "local", TRUE); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); /* initialize test program */ gtk_test_init (&argc, &argv); /* g_test_build_filename must be called after gtk_test_init */ schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL); g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE); /* This environment variable cooperates with gtk_widget_destroy() * to assert that all automated compoenents are properly finalized * when a given composite widget is destroyed. */ g_assert (g_setenv ("GTK_WIDGET_ASSERT_COMPONENTS", "1", TRUE)); g_test_add_func ("/Template/GtkDialog/Basic", test_dialog_basic); g_test_add_func ("/Template/GtkDialog/OverrideProperty", test_dialog_override_property); g_test_add_func ("/Template/GtkMessageDialog/Basic", test_message_dialog_basic); g_test_add_func ("/Template/GtkAboutDialog/Basic", test_about_dialog_basic); g_test_add_func ("/Template/GtkInfoBar/Basic", test_info_bar_basic); g_test_add_func ("/Template/GtkLockButton/Basic", test_lock_button_basic); g_test_add_func ("/Template/GtkAssistant/Basic", test_assistant_basic); g_test_add_func ("/Template/GtkScaleButton/Basic", test_scale_button_basic); g_test_add_func ("/Template/GtkVolumeButton/Basic", test_volume_button_basic); g_test_add_func ("/Template/GtkStatusBar/Basic", test_statusbar_basic); g_test_add_func ("/Template/GtkSearchBar/Basic", test_search_bar_basic); g_test_add_func ("/Template/GtkActionBar/Basic", test_action_bar_basic); g_test_add_func ("/Template/GtkAppChooserWidget/Basic", test_app_chooser_widget_basic); g_test_add_func ("/Template/GtkAppChooserDialog/Basic", test_app_chooser_dialog_basic); g_test_add_func ("/Template/GtkColorChooserDialog/Basic", test_color_chooser_dialog_basic); g_test_add_func ("/Template/GtkFileChooserWidget/Basic", test_file_chooser_widget_basic); g_test_add_func ("/Template/GtkFileChooserDialog/Basic", test_file_chooser_dialog_basic); g_test_add_func ("/Template/GtkFileChooserButton/Basic", test_file_chooser_button_basic); g_test_add_func ("/Template/GtkFontButton/Basic", test_font_button_basic); g_test_add_func ("/Template/GtkFontChooserWidget/Basic", test_font_chooser_widget_basic); g_test_add_func ("/Template/GtkFontChooserDialog/Basic", test_font_chooser_dialog_basic); g_test_add_func ("/Template/GtkRecentChooserWidget/Basic", test_recent_chooser_widget_basic); #ifdef HAVE_UNIX_PRINT_WIDGETS g_test_add_func ("/Template/UnixPrint/GtkPageSetupUnixDialog/Basic", test_page_setup_unix_dialog_basic); g_test_add_func ("/Template/UnixPrint/GtkPrintUnixDialog/Basic", test_print_unix_dialog_basic); #endif g_free (schema_dir); return g_test_run(); }
static void test_schema_do_compile (gpointer data) { SchemaTest *test = (SchemaTest *) data; gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL); gchar *path = g_test_build_filename (G_TEST_DIST, "schema-tests", filename, NULL); gchar *argv[] = { "../glib-compile-schemas", "--strict", "--dry-run", "--schema-file", path, (gchar *)test->opt, NULL }; gchar *envp[] = { NULL }; execve (argv[0], argv, envp); g_assert_not_reached (); }
static gboolean run_xmlrpc_test (char **argv, char **stdout_out, char **stderr_out, GError **error) { gboolean ok; int status; argv[0] = g_test_build_filename (G_TEST_BUILT, "xmlrpc-test", NULL); ok = g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, stdout_out, stderr_out, &status, error); g_free (argv[0]); if (!ok) return FALSE; return g_spawn_check_exit_status (status, error); }
static void openFont(const char* fontFile) { #if GLIB_CHECK_VERSION(2,37,2) gchar* path = g_test_build_filename(G_TEST_DIST, fontFile, NULL); #else gchar* path = g_strdup(fontFile); #endif FT_Error ft_error; if ((ft_error = FT_New_Face (ft_library, path, 0, &ft_face))) { g_free(path); abort(); } g_free(path); if ((ft_error = FT_Set_Char_Size (ft_face, 2000, 1000, 0, 0))) abort(); hb_font = hb_ft_font_create (ft_face, NULL); hb_face = hb_ft_face_create_cached(ft_face); }
int main (int argc, char *argv[]) { GError *error; gint ret; gchar *path; g_test_init (&argc, &argv, NULL); /* all the tests rely on a shared main loop */ loop = g_main_loop_new (NULL, FALSE); session_bus_up (); /* this is safe; testserver will exit once the bus goes away */ path = g_test_build_filename (G_TEST_BUILT, "gdbus-testserver", NULL); g_assert (g_spawn_command_line_async (path, NULL)); g_free (path); /* wait for the service to come up */ usleep (500 * 1000); /* Create the connection in the main thread */ error = NULL; c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); g_assert_no_error (error); g_assert (c != NULL); g_test_add_func ("/gdbus/connection-loss", test_connection_loss); ret = g_test_run(); g_object_unref (c); return ret; }
int main (int argc, char **argv) { GModule *module_self, *module_a, *module_b; gchar *plugin_a, *plugin_b; SimpleFunc f_a, f_b, f_self; GModuleFunc gmod_f; g_test_init (&argc, &argv, NULL); if (!g_module_supported ()) g_error ("dynamic modules not supported"); plugin_a = g_test_build_filename (G_TEST_BUILT, "libmoduletestplugin_a", NULL); plugin_b = g_test_build_filename (G_TEST_BUILT, "libmoduletestplugin_b", NULL); /* module handles */ module_self = g_module_open (NULL, G_MODULE_BIND_LAZY); if (!module_self) g_error ("error: %s", g_module_error ()); if (!g_module_symbol (module_self, "g_module_close", (gpointer *) &f_self)) g_error ("error: %s", g_module_error ()); module_a = g_module_open (plugin_a, G_MODULE_BIND_LAZY); if (!module_a) g_error ("error: %s", g_module_error ()); module_b = g_module_open (plugin_b, G_MODULE_BIND_LAZY); if (!module_b) g_error ("error: %s", g_module_error ()); /* get plugin state vars */ if (!g_module_symbol (module_a, "gplugin_a_state", (gpointer *) &gplugin_a_state)) g_error ("error: %s", g_module_error ()); if (!g_module_symbol (module_b, "gplugin_b_state", (gpointer *) &gplugin_b_state)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, "check-init"); /* get plugin specific symbols and call them */ if (!g_module_symbol (module_a, "gplugin_a_func", (gpointer *) &f_a)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); if (!g_module_symbol (module_b, "gplugin_b_func", (gpointer *) &f_b)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); f_a (); test_states (NULL, "Hello world", NULL); f_b (); test_states (NULL, NULL, "Hello world"); /* get and call globally clashing functions */ if (!g_module_symbol (module_self, "g_clash_func", (gpointer *) &f_self)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); if (!g_module_symbol (module_a, "g_clash_func", (gpointer *) &f_a)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); if (!g_module_symbol (module_b, "g_clash_func", (gpointer *) &f_b)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); f_self (); test_states ("global clash", NULL, NULL); f_a (); test_states (NULL, "global clash", NULL); f_b (); test_states (NULL, NULL, "global clash"); /* get and call clashing plugin functions */ if (!g_module_symbol (module_a, "gplugin_clash_func", (gpointer *) &f_a)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); if (!g_module_symbol (module_b, "gplugin_clash_func", (gpointer *) &f_b)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); plugin_clash_func = f_a; plugin_clash_func (); test_states (NULL, "plugin clash", NULL); plugin_clash_func = f_b; plugin_clash_func (); test_states (NULL, NULL, "plugin clash"); /* call gmodule function from A */ if (!g_module_symbol (module_a, "gplugin_a_module_func", (gpointer *) &gmod_f)) g_error ("error: %s", g_module_error ()); test_states (NULL, NULL, NULL); gmod_f (module_b); test_states (NULL, NULL, "BOOH"); gmod_f (module_a); test_states (NULL, "BOOH", NULL); /* unload plugins */ if (!g_module_close (module_a)) g_error ("error: %s", g_module_error ()); if (!g_module_close (module_b)) g_error ("error: %s", g_module_error ()); g_free (plugin_a); g_free (plugin_b); g_module_close (module_self); return 0; }
gint main (gint argc, gchar * argv[]) { GIOChannel *gio_r, *gio_w ; GError *gerr = NULL; GString *buffer; char *filename; gint rlength = 0; glong wlength = 0; gsize length_out; const gchar encoding[] = "EUC-JP"; GIOStatus status; g_test_init (&argc, &argv, NULL); filename = g_test_build_filename (G_TEST_DIST, "iochannel-test-infile", NULL); setbuf (stdout, NULL); /* For debugging */ gio_r = g_io_channel_new_file (filename, "r", &gerr); if (gerr) { g_warning ("Unable to open file %s: %s", filename, gerr->message); g_clear_error (&gerr); return 1; } gio_w = g_io_channel_new_file ("iochannel-test-outfile", "w", &gerr); if (gerr) { g_warning ("Unable to open file %s: %s", "iochannel-test-outfile", gerr->message); g_clear_error (&gerr); return 1; } g_io_channel_set_encoding (gio_r, encoding, &gerr); if (gerr) { g_warning ("%s", gerr->message); /* Keep going if this is just a case of iconv not supporting EUC-JP, see bug 428048 */ if (gerr->code != G_CONVERT_ERROR_NO_CONVERSION) return 1; g_clear_error (&gerr); } g_io_channel_set_buffer_size (gio_r, BUFFER_SIZE); status = g_io_channel_set_flags (gio_r, G_IO_FLAG_NONBLOCK, &gerr); if (status == G_IO_STATUS_ERROR) { g_warning ("%s", gerr->message); g_clear_error (&gerr); } buffer = g_string_sized_new (BUFFER_SIZE); while (TRUE) { do status = g_io_channel_read_line_string (gio_r, buffer, NULL, &gerr); while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) break; rlength += buffer->len; do status = g_io_channel_write_chars (gio_w, buffer->str, buffer->len, &length_out, &gerr); while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) break; wlength += length_out; if (length_out < buffer->len) g_warning ("Only wrote part of the line."); #ifdef VERBOSE g_print ("%s", buffer->str); #endif g_string_truncate (buffer, 0); } switch (status) { case G_IO_STATUS_EOF: break; case G_IO_STATUS_ERROR: g_warning ("%s", gerr->message); g_clear_error (&gerr); break; default: g_warning ("Abnormal exit from write loop."); break; } do status = g_io_channel_flush (gio_w, &gerr); while (status == G_IO_STATUS_AGAIN); if (status == G_IO_STATUS_ERROR) { g_warning ("%s", gerr->message); g_clear_error (&gerr); } #ifdef VERBOSE g_print ("read %d bytes, wrote %ld bytes\n", rlength, wlength); #endif g_io_channel_unref(gio_r); g_io_channel_unref(gio_w); test_small_writes (); g_free (filename); g_string_free (buffer, TRUE); return 0; }
int main (int argc, char **argv) { FILE *infile; char buffer[1024]; char **strings; char *filename; const char *locale; const char *test; const char *expected; char *convert; char *current_locale = setlocale (LC_CTYPE, NULL); gint result = 0; g_test_init (&argc, &argv, NULL); filename = g_test_build_filename (G_TEST_DIST, "casemap.txt", NULL); infile = fopen (filename, "r"); if (!infile) { fprintf (stderr, "Failed to open %s\n", filename ); exit (1); } while (fgets (buffer, sizeof(buffer), infile)) { if (buffer[0] == '#') continue; strings = g_strsplit (buffer, "\t", -1); locale = strings[0]; if (!locale[0]) locale = "C"; if (strcmp (locale, current_locale) != 0) { setlocale (LC_CTYPE, locale); current_locale = setlocale (LC_CTYPE, NULL); if (strncmp (current_locale, locale, 2) != 0) { fprintf (stderr, "Cannot set locale to %s, skipping\n", locale); goto next; } } test = strings[1]; /* gen-casemap-txt.py uses an empty string when a single character * doesn't have an equivalent in a particular case; since that behavior * is nonsense for multicharacter strings, it would make more sense * to put the expected result .. the original character unchanged. But * for now, we just work around it here and take the empty string to mean * "same as original" */ convert = g_utf8_strup (test, -1); expected = strings[4][0] ? strings[4] : test; if (strcmp (convert, expected) != 0) { fprintf (stderr, "Failure: toupper(%s) == %s, should have been %s\n", test, convert, expected); result = 1; } g_free (convert); convert = g_utf8_strdown (test, -1); expected = strings[2][0] ? strings[2] : test; if (strcmp (convert, expected) != 0) { fprintf (stderr, "Failure: tolower(%s) == %s, should have been %s\n", test, convert, expected); result = 1; } g_free (convert); next: g_strfreev (strings); } fclose (infile); g_free (filename); filename = g_test_build_filename (G_TEST_DIST, "casefold.txt", NULL); infile = fopen (filename, "r"); if (!infile) { fprintf (stderr, "Failed to open %s\n", filename ); g_free (filename); exit (1); } while (fgets (buffer, sizeof(buffer), infile)) { if (buffer[0] == '#') continue; buffer[strlen(buffer) - 1] = '\0'; strings = g_strsplit (buffer, "\t", -1); test = strings[0]; convert = g_utf8_casefold (test, -1); if (strcmp (convert, strings[1]) != 0) { fprintf (stderr, "Failure: casefold(%s) == '%s', should have been '%s'\n", test, convert, strings[1]); result = 1; } g_free (convert); g_strfreev (strings); } fclose (infile); g_free (filename); return result; }
int main (int argc, char **argv) { const GType *all_types; guint n_types = 0, i; gchar *schema_dir; GTestDBus *bus; gint result; /* These must be set before before gtk_test_init */ g_setenv ("GIO_USE_VFS", "local", TRUE); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); /* initialize test program */ gtk_test_init (&argc, &argv); gtk_test_register_all_types (); /* g_test_build_filename must be called after gtk_test_init */ schema_dir = g_test_build_filename (G_TEST_BUILT, "", NULL); g_setenv ("GSETTINGS_SCHEMA_DIR", schema_dir, TRUE); /* Create one test bus for all tests, as we have a lot of very small * and quick tests. */ bus = g_test_dbus_new (G_TEST_DBUS_NONE); g_test_dbus_up (bus); all_types = gtk_test_list_all_types (&n_types); for (i = 0; i < n_types; i++) { if (g_type_is_a (all_types[i], G_TYPE_OBJECT) && G_TYPE_IS_INSTANTIATABLE (all_types[i]) && !G_TYPE_IS_ABSTRACT (all_types[i]) && #ifdef GDK_WINDOWING_X11 all_types[i] != GDK_TYPE_X11_WINDOW && all_types[i] != GDK_TYPE_X11_CURSOR && all_types[i] != GDK_TYPE_X11_SCREEN && all_types[i] != GDK_TYPE_X11_DISPLAY && all_types[i] != GDK_TYPE_X11_DEVICE_MANAGER_XI2 && all_types[i] != GDK_TYPE_X11_DISPLAY_MANAGER && all_types[i] != GDK_TYPE_X11_GL_CONTEXT && #endif /* Not allowed to finalize a GdkPixbufLoader without calling gdk_pixbuf_loader_close() */ all_types[i] != GDK_TYPE_PIXBUF_LOADER && all_types[i] != gdk_pixbuf_simple_anim_iter_get_type()) { gchar *test_path = g_strdup_printf ("/FinalizeObject/%s", g_type_name (all_types[i])); g_test_add_data_func (test_path, GSIZE_TO_POINTER (all_types[i]), test_finalize_object); g_free (test_path); } } result = g_test_run(); g_test_dbus_down (bus); g_object_unref (bus); g_free (schema_dir); return result; }