void grn_test_assert_error_helper (grn_rc expected_rc, const gchar *expected_message, grn_ctx *context, const gchar *expression) { if (!context) { cut_test_with_user_message( cut_assert_null_helper(context, expression), cut_message("context should not NULL")); } else if (context->rc == expected_rc && cut_equal_string(expected_message, context->errbuf)) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("<%s>\n" "expected: <%s>(%s)\n" " actual: <%s>(%s)\n" "%s:%d: %s():", expression, expected_message, grn_rc_to_string(expected_rc), context->errbuf, grn_rc_to_string(context->rc), context->errfile, context->errline, context->errfunc)); } }
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 milter_assert_equal_symbols_table_helper (GHashTable *expected, GHashTable *actual, const gchar *expression_expected, const gchar *expression_actual) { if (milter_test_equal_symbols_table(expected, actual)) { cut_test_pass(); } else { gchar *inspected_expected, *inspected_actual; const gchar *message; inspected_expected = milter_test_inspect_symbols_table(expected); inspected_actual = milter_test_inspect_symbols_table(actual); message = cut_take_printf("<%s> == <%s>\n" "expected: <%s>\n" " actual: <%s>", expression_expected, expression_actual, inspected_expected, inspected_actual); if (expected && actual) message = cut_append_diff(message, inspected_expected, inspected_actual); g_free(inspected_expected); g_free(inspected_actual); cut_test_fail(message); } }
void soupcut_client_assert_equal_body_helper (const gchar *expected, SoupCutClient *client, const gchar *expression_expected, const gchar *expression_client) { const gchar *body; SoupMessage *message; message = soupcut_client_get_latest_message(client); if (!message) { soupcut_test_fail_null_message(client, expression_client); } body = message->response_body->data; if (cut_utils_equal_string(expected, body)) { cut_test_pass(); } else { cut_set_expected(cut_take_inspect_string(expected)); cut_set_actual(cut_take_inspect_string(body)); cut_test_fail( cut_take_printf("<%s == latest_message(%s)[response][body]>", expression_expected, expression_client)); } }
void soupcut_client_assert_match_body_helper (const gchar *pattern, SoupCutClient *client, const gchar *expression_pattern, const gchar *expression_client) { const gchar *body; SoupMessage *message; message = soupcut_client_get_latest_message(client); if (!message) { soupcut_test_fail_null_message(client, expression_client); } body = message->response_body->data; if (cut_utils_regex_match(pattern, body)) { cut_test_pass(); } else { cut_set_actual(cut_take_inspect_string(body)); cut_test_fail( cut_take_printf("<%s> =~ <latest_message(%s)[response][body]>\n" " pattern: <%s>", expression_pattern, expression_client, cut_take_inspect_string(pattern))); } }
void milter_assert_equal_option_helper (MilterOption *expected, MilterOption *actual, const gchar *expression_expected, const gchar *expression_actual) { if (gcut_object_equal(G_OBJECT(expected), G_OBJECT(actual), (GEqualFunc)milter_option_equal)) { cut_test_pass(); } else { gchar *inspected_expected, *inspected_actual; const gchar *message; inspected_expected = gcut_object_inspect(G_OBJECT(expected)); inspected_actual = gcut_object_inspect(G_OBJECT(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 soupcut_client_assert_equal_content_type_helper (const gchar *expected, SoupCutClient *client, const gchar *expression_expected, const gchar *expression_client) { const gchar *content_type; SoupMessage *message; message = soupcut_client_get_latest_message(client); if (!message) { soupcut_test_fail_null_message(client, expression_client); } content_type = soupcut_message_get_content_type(message); if (cut_utils_equal_string(expected, content_type)) { cut_test_pass(); } else { cut_set_expected(cut_take_inspect_string(expected)); cut_set_actual(cut_take_inspect_string(content_type)); cut_test_fail( cut_take_printf("<%s == latest_message(%s)[response][content-type]>", expression_expected, expression_client)); } }
void grn_test_assert_not_nil_helper(grn_id id, const gchar *expression) { if (id != GRN_ID_NIL) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("<%s> != <GRN_ID_NIL>\n" "expected: <%u> is not <%u>", expression, id, GRN_ID_NIL)); } }
void grn_test_assert_not_null_helper (grn_ctx *context, grn_obj *object, const gchar *expression) { if (object) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("expected: <%s> is not NULL", expression)); } }
void grn_test_memcached_assert_helper(memcached_return rc, const gchar *expression) { if (rc == MEMCACHED_SUCCESS) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("expected: <%s> == MEMCACHED_SUCCESS\n" " but was: <%s>", expression, grn_memcached_rc_to_string(rc))); } }
void grn_test_assert_helper(grn_rc rc, const gchar *expression) { if (rc == GRN_SUCCESS) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("expected: <%s> == grn_success\n" " but was: <%s>", expression, grn_rc_to_string(rc))); } }
void grn_test_assert_nil_helper(grn_id id, const gchar *expression) { if (id == GRN_ID_NIL) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("<%s> == <GRN_ID_NIL>\n" "expected: <%u>\n" " but was: <%u>", expression, GRN_ID_NIL, id)); } }
void grn_test_assert_equal_rc_helper(grn_rc expected, grn_rc actual, const gchar *expression_expected, const gchar *expression_actual) { if (expected == actual) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("<%s> == <%s>\n" "expected: <%s>\n" " but was: <%s>", expression_expected, expression_actual, grn_rc_to_string(expected), grn_rc_to_string(actual))); } }
void soupcut_message_assert_equal_content_type_helper (const gchar *expected, SoupMessage *message, const gchar *expression_expected, const gchar *expression_message) { const gchar *content_type; content_type = soupcut_message_get_content_type(message); if (cut_utils_equal_string(expected, content_type)) { cut_test_pass(); } else { cut_set_expected(cut_take_inspect_string(expected)); cut_set_actual(cut_take_inspect_string(content_type)); cut_test_fail(cut_take_printf("<%s == %s[response][content-type]>", expression_expected, expression_message)); } }
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); }
CPPCUT_DECL void cut::assert_equal_reference<std::type_info>(const std::type_info& expected, const std::type_info& actual, const char *expression_expected, const char *expression_actual) { if (expected == actual) { cut_test_pass(); } else { std::ostringstream message; cut_set_expected(expected.name()); cut_set_actual(actual.name()); message << "<" << expression_expected << " == "; message << expression_actual << ">"; cut_test_fail(message.str().c_str()); } }
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)); } }
void grn_test_assert_context_helper (grn_ctx *context, const gchar *expression) { if (!context) { cut_set_message("context should not NULL"); cut_assert_null_helper(context, expression); } else if (context->rc == GRN_SUCCESS) { cut_test_pass(); } else { cut_test_fail(cut_take_printf("<(%s)->rc> != <GRN_SUCCESS>\n" "expected: <%s> is <%s>\n" "%s:%d: %s(): %s", expression, grn_rc_to_string(context->rc), grn_rc_to_string(GRN_SUCCESS), context->errfile, context->errline, context->errfunc, context->errbuf)); } }
void grn_test_assert_equal_id_helper(grn_ctx *context, grn_id expected, grn_id actual, const gchar *expression_context, const gchar *expression_expected, const gchar *expression_actual) { if (expected == actual) { cut_test_pass(); } else { grn_obj *expected_object, *actual_object; grn_obj inspected_expected_object, inspected_actual_object; expected_object = grn_ctx_at(context, expected); actual_object = grn_ctx_at(context, actual); GRN_TEXT_INIT(&inspected_expected_object, 0); GRN_TEXT_INIT(&inspected_actual_object, 0); grn_inspect(context, &inspected_expected_object, expected_object); grn_inspect(context, &inspected_actual_object, actual_object); cut_set_expected( cut_take_printf("%d: <%.*s>", expected, (int)GRN_TEXT_LEN(&inspected_expected_object), GRN_TEXT_VALUE(&inspected_expected_object))); cut_set_actual( cut_take_printf("%d: <%.*s>", actual, (int)GRN_TEXT_LEN(&inspected_actual_object), GRN_TEXT_VALUE(&inspected_actual_object))); grn_obj_unlink(context, &inspected_expected_object); grn_obj_unlink(context, &inspected_actual_object); grn_obj_unlink(context, expected_object); grn_obj_unlink(context, actual_object); cut_test_fail(cut_take_printf("<%s> == <%s> (%s)\n" " context: <%p>", expression_expected, expression_actual, expression_context, context)); } }
void grn_test_assert_send_command_error_helper (grn_ctx *context, grn_rc expected_rc, const gchar *expected_message, const gchar *command, const gchar *expected_rc_expression, const gchar *expected_message_expression, const gchar *command_expression) { const gchar **lines; lines = cut_take_string_array(g_strsplit(command, "\n", 0)); for (; *lines; lines++) { grn_ctx_send(context, *lines, strlen(*lines), 0); if (context->rc) { break; } } if (context->rc == expected_rc && cut_equal_string(expected_message, context->errbuf)) { gchar *command_result; unsigned int command_result_length; int flags = 0; cut_test_pass(); grn_ctx_recv(context, &command_result, &command_result_length, &flags); } else { cut_set_expected(cut_take_printf("<%s>(%s)", expected_message, grn_rc_to_string(expected_rc))); cut_set_actual(cut_take_printf("<%s>(%s)", context->errbuf, grn_rc_to_string(context->rc))); cut_test_fail(cut_take_printf("<send(\"%s\")>\n" "%s:%d: %s():", command_expression, context->errfile, context->errline, context->errfunc)); } }
void soupcut_client_assert_response_helper (SoupCutClient *client, const gchar *expression_client) { SoupMessage *message; message = soupcut_client_get_latest_message(client); if (!message) { soupcut_test_fail_null_message(client, expression_client); } if (200 <= message->status_code && message->status_code < 300) { cut_test_pass(); } else { cut_set_expected("2XX"); cut_set_actual(cut_take_printf("%u(%s)", message->status_code, message->reason_phrase)); cut_test_fail( cut_take_printf("<latest_message(%s)[response][status] == 2XX>", expression_client)); } }
void grn_test_assert_equal_type_helper(grn_ctx *context, unsigned char expected, unsigned char actual, const gchar *expression_context, const gchar *expression_expected, const gchar *expression_actual) { if (expected == actual) { cut_test_pass(); } else { grn_obj inspected_expected, inspected_actual; GRN_TEXT_INIT(&inspected_expected, 0); GRN_TEXT_INIT(&inspected_actual, 0); grn_inspect_type(context, &inspected_expected, expected); grn_inspect_type(context, &inspected_actual, actual); cut_set_expected( cut_take_printf("%x: <%.*s>", expected, (int)GRN_TEXT_LEN(&inspected_expected), GRN_TEXT_VALUE(&inspected_expected))); cut_set_actual( cut_take_printf("%x: <%.*s>", actual, (int)GRN_TEXT_LEN(&inspected_actual), GRN_TEXT_VALUE(&inspected_actual))); grn_obj_unlink(context, &inspected_expected); grn_obj_unlink(context, &inspected_actual); cut_test_fail(cut_take_printf("<%s> == <%s> (%s)\n" " context: <%p>", expression_expected, expression_actual, expression_context, context)); } }
void grn_test_assert_equal_record_id_helper(grn_ctx *context, grn_obj *table, grn_id expected, grn_id actual, const gchar *expression_context, const gchar *expression_table, const gchar *expression_expected, const gchar *expression_actual) { if (expected == actual) { cut_test_pass(); } else { gchar key[GRN_TABLE_MAX_KEY_SIZE]; int key_size; const gchar *message; grn_obj inspected_table; key_size = grn_table_get_key(context, table, expected, key, sizeof(key)); cut_set_expected(cut_take_printf("%d: <%.*s>", expected, key_size, key)); key_size = grn_table_get_key(context, table, actual, key, sizeof(key)); cut_set_actual(cut_take_printf("%d: <%.*s>", actual, key_size, key)); GRN_TEXT_INIT(&inspected_table, 0); grn_inspect(context, &inspected_table, table); message = cut_take_printf("<%s> == <%s> (context: <%s>, table: <%s>)\n" " context: <%p>\n" " table: <%.*s>", expression_expected, expression_actual, expression_context, expression_table, context, (int)GRN_TEXT_LEN(&inspected_table), GRN_TEXT_VALUE(&inspected_table)); grn_obj_unlink(context, &inspected_table); cut_test_fail(message); } }