void milter_assert_equal_list_string_with_sort_helper (GList *expected, GList *actual, const gchar *expression_expected, const gchar *expression_actual) { GList *sorted_expected, *sorted_actual; sorted_expected = g_list_sort(expected, (GCompareFunc)strcmp); sorted_actual = g_list_sort(actual, (GCompareFunc)strcmp); if (gcut_list_equal_string(sorted_expected, sorted_actual)) { cut_test_pass(); } else { const gchar *message; const gchar *inspected_expected, *inspected_actual; inspected_expected = cut_take_string(gcut_list_inspect_string(sorted_expected)); inspected_actual = cut_take_string(gcut_list_inspect_string(sorted_actual)); message = cut_take_printf("<%s == %s>\n" "expected: <%s>\n" " actual: <%s>", expression_expected, expression_actual, inspected_expected, inspected_actual); message = cut_append_diff(message, inspected_expected, inspected_actual); cut_test_fail(message); } }
void test_open_with_copy_tag(void) { const gchar *original_default_open_tag, *original_default_close_tag; unsigned int original_default_open_tag_len, original_default_close_tag_len; default_flags = GRN_SNIP_COPY_TAG; cut_assert_not_null(open_snip()); original_default_open_tag = cut_take_string(default_open_tag); original_default_open_tag_len = default_open_tag_len; original_default_close_tag = cut_take_string(default_close_tag); original_default_close_tag_len = default_close_tag_len; default_open_tag = NULL; default_open_tag_len = 0; default_close_tag = NULL; default_close_tag_len = 0; cut_assert_not_null(open_snip()); default_open_tag = g_strdup(original_default_open_tag); default_open_tag_len = original_default_open_tag_len; cut_assert_not_null(open_snip()); g_free(default_open_tag); default_open_tag = NULL; default_open_tag_len = 0; default_close_tag = g_strdup(original_default_open_tag); default_close_tag_len = original_default_open_tag_len; cut_assert_not_null(open_snip()); }
static const gchar * convert_encoding(const gchar *utf8, grn_encoding encoding) { const gchar *encoded; GError *error = NULL; switch (encoding) { case GRN_ENC_DEFAULT: case GRN_ENC_NONE: case GRN_ENC_UTF8: encoded = utf8; break; case GRN_ENC_EUC_JP: encoded = cut_take_string(g_convert(utf8, -1, "eucJP", "UTF-8", NULL, NULL, &error)); break; case GRN_ENC_SJIS: encoded = cut_take_string(g_convert(utf8, -1, "CP932", "UTF-8", NULL, NULL, &error)); break; case GRN_ENC_LATIN1: encoded = cut_take_string(g_convert(utf8, -1, "CP1252", "UTF-8", NULL, NULL, &error)); break; case GRN_ENC_KOI8R: encoded = cut_take_string(g_convert(utf8, -1, "KOI8-R", "UTF-8", NULL, NULL, &error)); break; } gcut_assert_error(error); return encoded; }
void cut_setup (void) { const gchar *dir = g_getenv("BASE_DIR"); dir = dir ? dir : "."; cut_set_fixture_data_dir(dir, "fixtures", NULL); docset001_path = cut_take_string(cut_build_fixture_data_path("docset001.txt", NULL)); docset002_path = cut_take_string(cut_build_fixture_data_path("docset002.txt", NULL)); doc = NULL; docset = NULL; pool = NULL; }
void test_register_too_long_name(void) { GString *long_name; const gchar *full_path; const gchar *error_message_without_path; const gchar *error_message_without_name; gint i, max_name_length; long_name = gcut_take_new_string(NULL); max_name_length = (PATH_MAX - strlen(plugins_dir) - 1) - 1; for (i = 0; i < max_name_length; i++) { g_string_append_c(long_name, 'x'); } full_path = cut_take_string(g_build_filename(plugins_dir, long_name->str, NULL)); error_message_without_path = "too long plugin path: <"; grn_test_assert_send_command_error( context, GRN_FILENAME_TOO_LONG, cut_take_printf("%s%.*s", error_message_without_path, (int)(GRN_CTX_MSGSIZE - strlen(error_message_without_path) - 1), full_path), cut_take_printf("register %s", long_name->str)); g_string_append_c(long_name, 'x'); full_path = cut_take_string(g_build_filename(plugins_dir, long_name->str, NULL)); error_message_without_name = cut_take_printf("plugin name is too long: %d (max: %d) <", (int)(long_name->len), max_name_length); grn_test_assert_send_command_error( context, GRN_INVALID_ARGUMENT, cut_take_printf("%s%.*s", error_message_without_name, (int)(GRN_CTX_MSGSIZE - strlen(error_message_without_name) - 1), full_path), cut_take_printf("register %s", long_name->str)); }
void test_attachment_save (void) { GList *attachments, *node; document = load_document ("attachment.pdf"); cut_assert_true (poppler_document_has_attachments (document)); attachments = poppler_document_get_attachments (document); gcut_take_list (attachments, attachment_unref); for (node = attachments; node; node = g_list_next (node)) { PopplerAttachment *attachment = node->data; const gchar *filename; gchar *contents; const gchar *expected_contents; GError *error = NULL; filename = cut_take_string (g_build_filename (tmp_dir, attachment->name, NULL)); poppler_attachment_save (attachment, filename, &error); gcut_assert_error (error); g_file_get_contents (filename, &contents, NULL, &error); gcut_assert_error (error); expected_contents = cut_get_fixture_data_string (attachment->name, NULL); cut_set_message ("%s", attachment->name); cut_assert_equal_string_with_free (expected_contents, contents); } }
static gboolean run(const gchar **test_case_names, const grn_test_data *data) { gint i; const gchar *test_dir; CutSubProcessGroup *group; test_dir = cut_take_string(g_build_filename(grn_test_get_base_dir(), "fixtures", NULL)); group = cut_take_new_sub_process_group(); for (i = 0; i < data->n_processes; i++) { CutSubProcess *sub_process; sub_process = cut_take_new_sub_process(test_dir); cut_sub_process_set_multi_thread(sub_process, data->multi_thread); cut_sub_process_set_fatal_failures(sub_process, TRUE); cut_sub_process_set_target_test_case_names(sub_process, test_case_names); cut_sub_process_group_add(group, sub_process); if (data->multi_thread) g_setenv(GRN_TEST_ENV_MULTI_THREAD, "TRUE", TRUE); else g_unsetenv(GRN_TEST_ENV_MULTI_THREAD); g_setenv(GRN_TEST_ENV_N_PROCESSES, cut_take_printf("%d", data->n_processes), TRUE); g_setenv(GRN_TEST_ENV_PROCESS_NUMBER, cut_take_printf("%d", i), TRUE); cut_sub_process_run_async(sub_process); sub_processes = g_list_append(sub_processes, sub_process); } return cut_sub_process_group_wait(group); }
static void create_short_text_table(const GList *texts) { const gchar *table_name = "ShortTextPat"; GString *command; const GList *node; assert_send_commands( cut_take_printf("table_create %s TABLE_PAT_KEY ShortText", table_name)); command = g_string_new(NULL); g_string_append_printf(command, "load --table %s\n", table_name); g_string_append(command, "[\n"); g_string_append(command, " [\"_key\"],\n"); for (node = texts; node; node = g_list_next(node)) { const gchar *text = node->data; g_string_append_printf(command, " [\"%s\"]", text); if (g_list_next(node)) { g_string_append(command, ","); } g_string_append(command, "\n"); } g_string_append(command, "]"); assert_send_commands(cut_take_string(g_string_free(command, FALSE))); table = grn_ctx_get(context, table_name, strlen(table_name)); }
static void header_list_inspect (GString *string, gconstpointer data, gpointer user_data) { const GList *header_list = data; g_string_append(string, cut_take_string(gcut_list_inspect_string(header_list))); }
void test_get_content_disposition_with_line_feed (void) { char *type = NULL, *filename = NULL, *charset = NULL; const char *content; unsigned int length; cut_take_string(type); cut_take_string(filename); content = mz_test_utils_load_data("attachment_content_disposition_with_line_feed", &length); cut_assert_not_null(content); cut_assert_true(mz_utils_get_content_disposition(content, length, &type, &charset, &filename)); cut_assert_equal_string("attachment", type); cut_assert_equal_string("t.png", filename); }
void test_get_content_disposition_mime_encoded_filename (void) { char *type = NULL, *filename = NULL, *charset = NULL; const char *content; unsigned int length; cut_take_string(type); cut_take_string(filename); content = mz_test_utils_load_data("attachment_filename_is_mime_encoded", &length); cut_assert_not_null(content); cut_assert_true(mz_utils_get_content_disposition(content, length, &type, &charset, &filename)); cut_assert_equal_string("attachment", type); cut_assert_equal_string("iso-2022-jp", charset); cut_assert_equal_string("\x1B\x24\x42\x46\x7C\x4B\x5C\x38\x6C\x1B\x28\x42\x2e\x74\x78\x74", /* 日本語.txt */ filename); }
static const gchar * take_sjis_to_utf8(const gchar *sjis) { gchar *utf8; GError *error = NULL; utf8 = sjis_to_utf8(sjis, &error); cut_assert_g_error(error); return cut_take_string(utf8); }
static const gchar * take_euc_jp_to_utf8(const gchar *euc_jp) { gchar *utf8; GError *error = NULL; utf8 = euc_jp_to_utf8(euc_jp, &error); cut_assert_g_error(error); return cut_take_string(utf8); }
static void add_groonga_bookmark(void) { gchar key[] = "groonga"; groonga_bookmark_id = grn_table_add(&context, bookmarks, &key, strlen(key), NULL); grn_test_assert_context(&context); cut_set_message("%s", cut_take_string(grn_collect_logger_to_string(logger))); grn_test_assert_not_nil(groonga_bookmark_id); }
static const gchar * build_uri (const gchar *fixture_data_component) { gchar *uri, *path; path = cut_build_fixture_data_path (fixture_data_component, NULL); uri = g_strconcat ("file://", path, NULL); g_free (path); return cut_take_string (uri); }
static const gchar * format_reply (void) { gchar *formatted_reply; formatted_reply = milter_client_context_format_reply(context); if (formatted_reply) return cut_take_string(formatted_reply); else return NULL; }
void test_get_rfc2311_filename (void) { char *type = NULL, *filename = NULL, *charset = NULL; const char *content; unsigned int length; cut_take_string(type); cut_take_string(filename); content = mz_test_utils_load_data("rfc2311", &length); cut_assert_not_null(content); cut_assert_true(mz_utils_get_content_disposition(content, length, &type, &charset, &filename)); cut_assert_equal_string("attachment", type); cut_assert_equal_string("ISO-2022-JP", charset); cut_assert_equal_string("\x1B\x24\x42\x3F\x37\x24\x37\x24\x24\x25\x46\x25\x2D\x25" /* 新しいテキスト ドキュメント.txt */ "\x39\x25\x48\x1B\x28\x42\x20\x1B\x24\x42\x25\x49\x25\x2D" "\x25\x65\x25\x61\x25\x73\x25\x48\x1B\x28\x42\x2E\x74\x78\x74", filename); }
void test_get_content_type (void) { char *content_type; const char *content; content = cut_get_fixture_data_string("attachment", NULL); cut_assert_not_null(content); content_type = mz_utils_get_content_type(content); cut_take_string(content_type); cut_assert_equal_string("image/png", content_type); }
const gchar * cut_take_replace_helper (const gchar *target, const gchar *pattern, const gchar *replacement, CutCallbackFunction callback) { gchar *replaced; GError *error = NULL; replaced = cut_utils_regex_replace(pattern, target, replacement, &error); gcut_assert_error_helper(error, "error"); if (callback) callback(); return cut_take_string(replaced); }
void test_get_content_transfer_encoding (void) { char *content_transfer_encoding; const char *content; content = cut_get_fixture_data_string("attachment", NULL); cut_assert_not_null(content); content_transfer_encoding = mz_utils_get_content_transfer_encoding(content); cut_take_string(content_transfer_encoding); cut_assert_equal_string("base64", content_transfer_encoding); }
static void add_count_column_to_bookmarks_table (void) { const gchar count_column_name[] = "count"; count_column = grn_column_create(&context, bookmarks, count_column_name, strlen(count_column_name), NULL, 0, LOOKUP("<int>")); grn_test_assert_context(&context); cut_set_message("%s", cut_take_string(grn_collect_logger_to_string(logger))); cut_assert_not_null(count_column); }
static void create_bookmarks_table(void) { const gchar bookmarks_table_name[] = "bookmarks"; bookmarks = grn_table_create(&context, bookmarks_table_name, strlen(bookmarks_table_name), NULL, GRN_OBJ_TABLE_HASH_KEY, LOOKUP("<shorttext>"), 1024); grn_test_assert_context(&context); cut_set_message("%s", cut_take_string(grn_collect_logger_to_string(logger))); cut_assert_not_null(bookmarks); }
const gchar * cut_take_convert_helper (const gchar *string, const gchar *to_code_set, const gchar *from_code_set, CutCallbackFunction callback) { gchar *converted; GError *error = NULL; converted = g_convert(string, -1, to_code_set, from_code_set, NULL, NULL, &error); gcut_assert_error_helper(error, "error"); if (callback) callback(); return cut_take_string(converted); }
void test_save_custom (void) { GError *error = NULL; gchar *custom_config_path; custom_config_path = g_build_filename(tmp_dir, CUSTOM_CONFIG_FILE_NAME, NULL); cut_take_string(custom_config_path); milter_manager_configuration_prepend_load_path(config, tmp_dir); cut_assert_path_not_exist(custom_config_path); milter_manager_configuration_save_custom(config, "XXX", -1, &error); gcut_assert_error(error); cut_assert_path_exist(custom_config_path); }
void test_new_from_data (void) { GError *error = NULL; gchar *data; gsize length; const gchar *path; path = cut_take_string (cut_build_fixture_data_path ("multi-pages.pdf", NULL)); g_file_get_contents (path, &data, &length, &error); gcut_assert_error (error); document = poppler_document_new_from_data (data, length, NULL, &error); g_free (data); gcut_assert_error (error); cut_assert_equal_int (3, poppler_document_get_n_pages (document)); }
static const gchar * mangle (const gchar *component, ...) { GString *mangled; va_list args; mangled = g_string_new("@YAXXZ"); va_start(args, component); while (component) { g_string_prepend(mangled, "@"); g_string_prepend(mangled, component); component = va_arg(args, gchar *); } va_end(args); g_string_prepend(mangled, "?"); return cut_take_string(g_string_free(mangled, FALSE)); }
static void soupcut_test_fail_null_message (SoupCutClient *client, const gchar *expression_client) { GString *message; const gchar *fail_message; const gchar *inspected_client; message = g_string_new(NULL); g_string_append_printf(message, "<latest_message(%s) != NULL>\n", expression_client); inspected_client = gcut_object_inspect(G_OBJECT(client)); g_string_append_printf(message, " client: <%s>", inspected_client); fail_message = cut_take_string(g_string_free(message, FALSE)); cut_test_fail(fail_message); }
void grn_test_assert_null_helper (grn_ctx *context, grn_obj *object, const gchar *expression) { if (!object) { cut_test_pass(); } else { GString *inspected; const gchar *taken_inspected; inspected = g_string_new(NULL); grn_test_object_inspect(inspected, context, object); taken_inspected = cut_take_string(inspected->str); cut_test_fail(cut_take_printf("expected: <%s> is NULL\n" " actual: <%s>", expression, taken_inspected)); } }
static const gchar * mangle (const gchar *component, ...) { GString *mangled; va_list args; mangled = g_string_new("_ZN"); va_start(args, component); while (component) { g_string_append_printf(mangled, "%" G_GSIZE_FORMAT "%s", strlen(component), component); component = va_arg(args, gchar *); } va_end(args); g_string_append(mangled, "Ev"); return cut_take_string(g_string_free(mangled, FALSE)); }
const gchar * soupcut_server_build_uri(SoupServer *server, const gchar *path) { SoupAddress *address; SoupURI *uri; const gchar *uri_string; g_object_get(server, SOUP_SERVER_INTERFACE, &address, NULL); uri = soup_uri_new(NULL); soup_uri_set_scheme(uri, SOUP_URI_SCHEME_HTTP); soup_uri_set_host(uri, "localhost"); soup_uri_set_port(uri, soup_address_get_port(address)); soup_uri_set_path(uri, path); uri_string = cut_take_string(soup_uri_to_string(uri, FALSE)); soup_uri_free(uri); return uri_string; }