static void gpdb_fixture_setup (GamePositionDbFixture *fixture, gconstpointer test_data) { gchar *source = g_strdup("db/gpdb-ffo.txt"); GamePositionDb *db; GamePositionDbSyntaxErrorLog *syntax_error_log; FILE *fp; GError *error; /* Loads the game position database. */ fp = fopen(source, "r"); if (!fp) { g_test_message("Unable to open database test file \"%s\" for reading.\n", source); g_test_fail(); } g_assert(fp); db = gpdb_new(g_strdup("FFOTEST database")); syntax_error_log = NULL; error = NULL; gpdb_load(fp, source, db, &syntax_error_log, &error); fclose(fp); g_free(source); /* Removes the tmp file, frees the resources. */ g_free(error); if (syntax_error_log) gpdb_syntax_error_log_free(syntax_error_log); fixture->db = db; g_assert (fixture->db != NULL); }
static void test_layout (gconstpointer d) { const gchar *filename = d; gchar *expected_file; GError *error = NULL; GString *dump; gchar *diff; expected_file = get_expected_filename (filename); dump = g_string_sized_new (0); test_file (filename, dump); diff = diff_with_file (expected_file, dump->str, dump->len, &error); g_assert_no_error (error); if (diff && diff[0]) { g_printerr ("Contents don't match expected contents:\n%s", diff); g_test_fail (); g_free (diff); } g_string_free (dump, TRUE); g_free (expected_file); }
static void test_set_content_property_again(gs_grid_storage_t * gs) { gs_error_t **err = NULL; gchar **result = NULL; char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); hc_ul_content_from_file(gs, nameCont, "Content", "file_test.txt", err); gs_content_t *content = gs_get_content_from_path(container, "Content", err); char *props = "key1=value1"; char *props2 = "key1=value2"; hc_set_content_property(content, &props, err); hc_set_content_property(content, &props2, err); g_assert_true(err == NULL); hc_get_content_properties(content, &result, err); if (strcmp(result[0], "key1=value2")) g_test_fail(); gs_content_free(content); test_end(gs, nameRef, container); }
static void test_sc_do_optional_mount_failure(gconstpointer snap_debug) { if (g_test_subprocess()) { sc_break("mount", broken_mount); if (GPOINTER_TO_INT(snap_debug) == 1) { g_setenv("SNAP_CONFINE_DEBUG", "1", true); } (void)sc_do_optional_mount("/foo", "/bar", "ext4", MS_RDONLY, NULL); g_test_message("expected sc_do_mount not to return"); sc_reset_faults(); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); if (GPOINTER_TO_INT(snap_debug) == 0) { g_test_trap_assert_stderr ("cannot perform operation: mount -t ext4 -o ro /foo /bar: Permission denied\n"); } else { /* with snap_debug the debug output hides the actual mount commands *but* * they are still shown if there was an error */ g_test_trap_assert_stderr ("DEBUG: performing operation: (disabled) use debug build to see details\n" "cannot perform operation: mount -t ext4 -o ro /foo /bar: Permission denied\n"); } }
static void test_bug_726548 (TestFixture *fixture) { gboolean success; gchar *text; const gchar *expected_plain = "aaa\n" " 1. a\n" " 2. b\n" " 3. c\n"; /* This test is known to fail, skip it. */ printf ("SKIPPED "); return; if (!test_utils_run_simple_test (fixture, "mode:plain\n" "type:aaa\\n\n" "action:style-list-number\n" "type:a\\nb\\nc\\n\\n\n" "seq:C\n" "type:ac\n" "seq:c\n", HTML_PREFIX "<div style=\"width: 71ch;\">aaa</div>" "<ol style=\"width: 65ch;\">" "<li>a</li><li>b</li><li>c</li></ol>" "<div style=\"width: 71ch;\"><br></div>" HTML_SUFFIX, expected_plain)) { g_test_fail (); return; } text = test_utils_get_clipboard_text (FALSE); success = test_utils_html_equal (fixture, text, expected_plain); if (!success) { g_warning ("%s: clipboard Plain text \n---%s---\n does not match expected Plain\n---%s---", G_STRFUNC, text, expected_plain); g_free (text); g_test_fail (); } else { g_free (text); } }
static void test_bug_750657 (TestFixture *fixture) { if (!test_utils_process_commands (fixture, "mode:html\n")) { g_test_fail (); return; } test_utils_insert_content (fixture, "<html><head></head><body>\n" "<blockquote type=\"cite\">\n" "<div>This is the first paragraph of a quoted text which has some long text to test. It has the second sentence as well.</div>\n" "<div><br></div>\n" "<div>This is the third paragraph of a quoted text which has some long text to test. It has the second sentence as well.</div>\n" "<blockquote type=\"cite\">\n" "<div>This is the first paragraph of a sub-quoted text which has some long text to test. It has the second sentence as well.</div>\n" "<br>\n" "</blockquote>\n" "<div>This is the fourth paragraph of a quoted text which has some long text to test. It has the second sentence as well.</div>\n" "</blockquote>\n" "<div><br></div>\n" "</body></html>", E_CONTENT_EDITOR_INSERT_TEXT_HTML); if (!test_utils_run_simple_test (fixture, "seq:uuuSuusD\n", HTML_PREFIX "<blockquote type=\"cite\">\n" "<div>This is the first paragraph of a quoted text which has some long text to test. It has the second sentence as well.</div>\n" "<div><br></div>\n" "<div>This is the third paragraph of a quoted text which has some long text to test. It has the second sentence as well.</div>\n" "<blockquote type=\"cite\">\n" "<div><br></div>\n" "</blockquote>\n" "<div>This is the fourth paragraph of a quoted text which has some long text to test. It has the second sentence as well.</div>\n" "</blockquote>\n" "<div><br></div>" HTML_SUFFIX, NULL)) { g_test_fail (); return; } }
static const char *init_hugepagefs(void) { #ifdef CONFIG_LINUX static const char *hugepagefs; const char *path = getenv("QTEST_HUGETLBFS_PATH"); struct statfs fs; int ret; if (hugepagefs) { return hugepagefs; } if (!path) { return NULL; } if (access(path, R_OK | W_OK | X_OK)) { g_test_message("access on path (%s): %s", path, strerror(errno)); g_test_fail(); return NULL; } do { ret = statfs(path, &fs); } while (ret != 0 && errno == EINTR); if (ret != 0) { g_test_message("statfs on path (%s): %s", path, strerror(errno)); g_test_fail(); return NULL; } if (fs.f_type != HUGETLBFS_MAGIC) { g_test_message("Warning: path not on HugeTLBFS: %s", path); g_test_fail(); return NULL; } hugepagefs = path; return hugepagefs; #else return NULL; #endif }
static void test_bug_760989 (TestFixture *fixture) { if (!test_utils_process_commands (fixture, "mode:html\n" "type:a\n")) { g_test_fail (); return; } test_utils_insert_content (fixture, "<html><head></head><body>\n" "One line before quotation<br>\n" "<blockquote type=\"cite\">\n" "<div>Single line quoted.</div>\n" "</blockquote>\n" "</body></html>", E_CONTENT_EDITOR_INSERT_TEXT_HTML); if (!test_utils_run_simple_test (fixture, "seq:ChcD\n", HTML_PREFIX "<div>One line before quotation</div>\n" "<blockquote type=\"cite\">\n" "<div>Single line quoted.</div>\n" "</blockquote>" HTML_SUFFIX, "One line before quotation\n" "> Single line quoted.")) { g_test_fail (); return; } if (!test_utils_run_simple_test (fixture, "seq:Cecb\n", HTML_PREFIX "<div>One line before quotation</div>\n" "<blockquote type=\"cite\">\n" "<div>Single line quoted</div>\n" "</blockquote>" HTML_SUFFIX, "One line before quotation\n" "> Single line quoted")) { g_test_fail (); return; } }
static void test_bug_771131 (TestFixture *fixture) { if (!test_utils_process_commands (fixture, "mode:plain\n")) { g_test_fail (); return; } test_utils_insert_content (fixture, "<body><pre>On <date1>, <name1> wrote:\n" "<blockquote type=\"cite\">\n" "Hello\n" "\n" "Goodbye</blockquote>" "<div><span>the 3rd line text</span></div>" "</pre><span class=\"-x-evo-to-body\" data-credits=\"On Sat, 2016-09-10 at 20:00 +0000, [email protected] wrote:\"></span>" "<span class=\"-x-evo-cite-body\"></span></body>", E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML); if (!test_utils_run_simple_test (fixture, "", HTML_PREFIX "<div style=\"width: 71ch;\">On Sat, 2016-09-10 at 20:00 +0000, [email protected] wrote:</div>" "<blockquote type=\"cite\">" "<div style=\"width: 71ch;\">> On <date1>, <name1> wrote:</div>" "<blockquote type=\"cite\">" "<div style=\"width: 71ch;\">> > Hello</div>" "<div style=\"width: 71ch;\">> > <br></div>" "<div style=\"width: 71ch;\">> > Goodbye</div>" "</blockquote>" "<div style=\"width: 71ch;\">> <br></div>" "<div style=\"width: 71ch;\">> the 3rd line text</div>" "</blockquote>" HTML_SUFFIX, "On Sat, 2016-09-10 at 20:00 +0000, [email protected] wrote:\n" "> On <date1>, <name1> wrote:\n" "> > Hello\n" "> > \n" "> > Goodbye\n" "> \n" "> the 3rd line text")) g_test_fail (); }
static void test_ui_file (GFile *file) { char *ui_file, *reference_file; cairo_surface_t *ui_image, *reference_image, *diff_image; GtkStyleProvider *provider; ui_file = g_file_get_path (file); provider = add_extra_css (ui_file, ".css"); ui_image = reftest_snapshot_ui_file (ui_file); reference_file = get_test_file (ui_file, ".ref.ui", TRUE); if (reference_file) reference_image = reftest_snapshot_ui_file (reference_file); else { reference_image = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); g_test_message ("No reference image."); g_test_fail (); } g_free (reference_file); diff_image = reftest_compare_surfaces (ui_image, reference_image); save_image (ui_image, ui_file, ".out.png"); save_image (reference_image, ui_file, ".ref.png"); if (diff_image) { save_image (diff_image, ui_file, ".diff.png"); if (known_fail(ui_file)) { printf("KNOWN FAILURE - %s\n", ui_file); g_test_message ("KNOWN FAIL: %s", ui_file); } else g_test_fail (); } remove_extra_css (provider); }
GamePosition * get_gp_from_db (GamePositionDb *db, gchar *id) { GamePositionDbEntry *entry = gpdb_lookup(db, id); if (!entry) { g_test_message("The entry \"%s\" is missing from game position database.\n", id); g_test_fail(); } g_assert(entry); return entry->game_position; }
static void render_test (gconstpointer user_data) { const char *filename = user_data; char *basename; LsmDomDocument *document; LsmDomView *view; LsmBox viewport; unsigned int width, height; cairo_t *cairo; cairo_surface_t *surface; basename = g_path_get_basename (filename); document = lsm_dom_document_new_from_path (filename, NULL); g_assert (LSM_IS_DOM_DOCUMENT (document)); view = lsm_dom_document_create_view (document); g_assert (LSM_IS_DOM_VIEW (view)); viewport.x = 0.0; viewport.y = 0.0; viewport.width = 480.0; viewport.height = 360.0; lsm_dom_view_set_resolution (view, 96); lsm_dom_view_set_viewport_pixels (view, &viewport); lsm_dom_view_get_size_pixels (LSM_DOM_VIEW (view), &width, &height, NULL); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); cairo = cairo_create (surface); cairo_surface_destroy (surface); if (cairo_status (cairo) == CAIRO_STATUS_SUCCESS) { lsm_dom_view_render (LSM_DOM_VIEW (view), cairo, 1, 1); if (cairo_status (cairo) != CAIRO_STATUS_SUCCESS) { g_test_message ("cairo_status = %s", cairo_status_to_string (cairo_status (cairo))); if (!g_key_file_get_boolean (suite_options, basename, "ignore-cairo-status", NULL)) { g_test_message ("incorrect cairo status"); g_test_fail (); } } } cairo_destroy (cairo); g_object_unref (view); g_object_unref (document); g_free (basename); }
static void test_sc_string_append_char__NULL_buf() { if (g_test_subprocess()) { sc_string_append_char(NULL, 2, 'a'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot append character: buffer is NULL\n"); }
static void test_sc_string_init__NULL_buf() { if (g_test_subprocess()) { sc_string_init(NULL, 1); g_test_message("expected sc_string_init not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot initialize string, buffer is NULL\n"); }
static void test_sc_must_snprintf__fail() { if (g_test_subprocess()) { char buf[5]; sc_must_snprintf(buf, sizeof buf, "12345"); g_test_message("expected sc_must_snprintf not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot format string: 1234\n"); }
static void test_sc_snap_name_validate__respects_error_protocol() { if (g_test_subprocess()) { sc_snap_name_validate("hello world", NULL); g_test_message("expected sc_snap_name_validate to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("snap name must use lower case letters, digits or dashes\n"); }
static void test_bug_771044 (TestFixture *fixture) { if (!test_utils_run_simple_test (fixture, "type:123 456\\n789 abc\\n\n" "seq:uuhSdsD\n", HTML_PREFIX "<div>789 abc</div>" "<div><br></div>" HTML_SUFFIX, "789 abc\n")) g_test_fail (); }
// Sanity check, ensure that the namespace filesystem identifier is what we // expect, aka NSFS_MAGIC. static void test_nsfs_fs_id() { struct utsname uts; if (uname(&uts) < 0) { g_test_message("cannot use uname(2)"); g_test_fail(); return; } int major, minor; if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) { g_test_message("cannot use sscanf(2) to parse kernel release"); g_test_fail(); return; } if (major < 3 || (major == 3 && minor < 19)) { g_test_skip("this test needs kernel 3.19+"); return; } struct statfs buf; int err = statfs("/proc/self/ns/mnt", &buf); g_assert_cmpint(err, ==, 0); g_assert_cmpint(buf.f_type, ==, NSFS_MAGIC); }
static void test_bug_772918 (TestFixture *fixture) { if (!test_utils_run_simple_test (fixture, "mode:html\n" "type:a b c d\n" "seq:lll\n" "type:1 2 3 \n" "undo:undo:6\n" "undo:redo:6\n", HTML_PREFIX "<div>a b 1 2 3 c d</div>" HTML_SUFFIX, "a b 1 2 3 c d")) g_test_fail (); }
static void test_set_container_storage_policy_wrong(gs_grid_storage_t * gs) // to be improved { char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); gs_error_t *err = hc_set_container_storage_policy(container, "Wrong_stgpol"); if (err == NULL) g_test_fail(); test_end(gs, nameRef, container); }
static void test_sc_string_quote_NULL_str() { if (g_test_subprocess()) { char buf[16] = { 0 }; sc_string_quote(buf, sizeof buf, NULL); g_test_message("expected sc_string_quote not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot quote string: string is NULL\n"); }
static void test_ui_file (GFile *file) { gchar *ui_file, *in_file, *out_file; GString *record; GError *error = NULL; ui_file = g_file_get_path (file); in_file = get_test_file (ui_file, ".in", TRUE); out_file = get_test_file (ui_file, ".out", TRUE); record = g_string_new (""); record_events (ui_file, in_file, record); if (out_file) { char *diff = diff_with_file (out_file, record->str, record->len, &error); g_assert_no_error (error); if (diff && diff[0]) { g_printerr ("Contents don't match expected contents:\n%s", diff); g_test_fail (); g_free (diff); } } else if (record->str[0]) { g_test_message ("Expected a reference file:\n%s", record->str); g_test_fail (); } g_string_free (record, TRUE); g_free (in_file); g_free (out_file); g_free (ui_file); }
// Check that rm_rf_tmp doesn't remove things outside of /tmp static void test_rm_rf_tmp() { if (access("/nonexistent", F_OK) == 0) { g_test_message ("/nonexistent exists but this test doesn't want it to"); g_test_fail(); return; } if (g_test_subprocess()) { rm_rf_tmp("/nonexistent"); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
static void test_get_reference_property_wrong_key(gs_grid_storage_t * gs) //to be improved { char **prop_array = parameters_init(); char *nameRef = test_init(gs, "Ref_params", prop_array); char *keys = "key_error"; gchar **result = NULL; hc_get_reference_property(gs, nameRef, &keys, &result); if (result != NULL) g_test_fail(); parameters_delete(prop_array); test_end(gs, nameRef, NULL); }
static void test_bug_771493 (TestFixture *fixture) { if (!test_utils_process_commands (fixture, "mode:plain\n")) { g_test_fail (); return; } test_utils_insert_content (fixture, "<body><pre><br>" "----- Original Message -----\n" "<blockquote type=\"cite\">\n" "This week summary:" "</blockquote>" "</pre><span class=\"-x-evo-to-body\" data-credits=\"On Thu, 2016-09-15 at 08:08 -0400, user wrote:\"></span>" "<span class=\"-x-evo-cite-body\"></span></body>", E_CONTENT_EDITOR_INSERT_REPLACE_ALL | E_CONTENT_EDITOR_INSERT_TEXT_HTML); if (!test_utils_run_simple_test (fixture, "", HTML_PREFIX "<div style=\"width: 71ch;\">On Thu, 2016-09-15 at 08:08 -0400, user wrote:</div>" "<blockquote type=\"cite\">" "<div style=\"width: 71ch;\">> <br></div>" "<div style=\"width: 71ch;\">> ----- Original Message -----</div>" "<blockquote type=\"cite\">" "<div style=\"width: 71ch;\">> > This week summary:</div>" "</blockquote>" "</blockquote>" HTML_SUFFIX, "On Thu, 2016-09-15 at 08:08 -0400, user wrote:\n" "> \n" "> ----- Original Message -----\n" "> > This week summary:")) g_test_fail (); }
static void test_set_content_storage_policy_bad_path(gs_grid_storage_t * gs) // to be improved { gs_error_t **err = NULL; char *nameRef = test_init(gs, "Ref_linked", NULL); char *nameCont = gen_random(7); gs_container_t *container = container_init(gs, nameCont); hc_set_content_storage_policy(container, "Content", "TWOCOPIES", err); if (err == NULL) g_test_fail(); test_end(gs, nameRef, container); }
// Check that `src' cannot be NULL. static void test_sc_string_append__NULL_str() { if (g_test_subprocess()) { char buf[4]; sc_string_append(buf, sizeof buf, NULL); g_test_message("expected sc_string_append not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot append string: string is NULL\n"); }
static void test_sc_string_append_char__uninitialized_buf() { if (g_test_subprocess()) { char buf[2] = { 0xFF, 0xFF }; sc_string_append_char(buf, sizeof buf, 'a'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("cannot append character: dst is unterminated\n"); }
static void test_sc_string_append_char__overflow() { if (g_test_subprocess()) { char buf[1] = { 0 }; sc_string_append_char(buf, sizeof buf, 'a'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("cannot append character: not enough space\n"); }
static void test_sc_string_append_char__invalid_zero() { if (g_test_subprocess()) { char buf[2] = { 0 }; sc_string_append_char(buf, sizeof buf, '\0'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("cannot append character: cannot append string terminator\n"); }