Ejemplo n.º 1
0
DECLARE_TEST(md5, reference) {
	md5_t* md5;
	char md5str[32];
	string_t digest;

	md5 = md5_allocate();
	md5_digest_finalize(md5);

	md5_digest(md5, "testing md5 implementation", 26);
	md5_digest_finalize(md5);

	digest = md5_get_digest(md5, md5str, sizeof(md5str));

	EXPECT_STRINGEQ(digest, string_const(STRING_CONST("4E24E37E5E06F23210FA1518E97A50C4")));

	md5_digest(md5, "testing md5 implementation", 26);
	md5_digest(md5, "", 0);
	md5_digest(md5, "further testing md5 implementation with long buffer > 32 bytes", 62);
	md5_digest_finalize(md5);
	digest = md5_get_digest(md5, md5str, sizeof(md5str));

	EXPECT_STRINGEQ(digest, string_const(STRING_CONST("BD870884942EA7B32A9CB2547B02B871")));

	md5_digest(md5, digest_test_string, 2000);
	md5_digest_finalize(md5);
	digest = md5_get_digest(md5, md5str, sizeof(md5str));

	EXPECT_STRINGEQ(digest, string_const(STRING_CONST("137D3C94230A0E230C4DDFC97EACCCD2")));

	md5_deallocate(md5);

	return 0;
}
Ejemplo n.º 2
0
DECLARE_TEST(md5, empty) {
	md5_t* md5;
	char md5str[32];
	string_t digest;

	md5 = md5_allocate();
	md5_digest_finalize(md5);
	digest = md5_get_digest(md5, md5str, sizeof(md5str));

	EXPECT_STRINGEQ(digest, string_const(STRING_CONST("D41D8CD98F00B204E9800998ECF8427E")));

	md5_initialize(md5);
	md5_digest_finalize(md5);
	digest = md5_get_digest(md5, md5str, sizeof(md5str));

	EXPECT_STRINGEQ(digest, string_const(STRING_CONST("D41D8CD98F00B204E9800998ECF8427E")));

	md5_deallocate(md5);

	return 0;
}
Ejemplo n.º 3
0
DECLARE_TEST(exception, error) {
    error_handler_fn handler;
    int ret;

    error();
    EXPECT_EQ(error(), ERROR_NONE);

    error_report(ERRORLEVEL_ERROR, ERROR_NONE);
    EXPECT_EQ(error(), ERROR_NONE);

    error_report(ERRORLEVEL_ERROR, ERROR_EXCEPTION);
    EXPECT_EQ(error(), ERROR_EXCEPTION);

    handler = error_handler();
    error_set_handler(_error_handler_test);

    ret = error_report(ERRORLEVEL_WARNING, ERROR_INVALID_VALUE);
    EXPECT_EQ(error(), ERROR_INVALID_VALUE);
    EXPECT_EQ(ret, 2);
    EXPECT_EQ(_error_level_test, ERRORLEVEL_WARNING);
    EXPECT_EQ(_error_test, ERROR_INVALID_VALUE);
    EXPECT_EQ(error_handler(), _error_handler_test);

    error_set_handler(handler);

    {
#if BUILD_ENABLE_ERROR_CONTEXT
        const char context_data[] = "another message";
#endif
        char context_buffer[512];
        string_t contextstr;
        error_context_clear();
        error_context_push(STRING_CONST("test context"), STRING_CONST("some message"));
        error_context_push(STRING_CONST("foo bar"), 0, 0);
        error_context_pop();
        error_context_pop();
        error_context_pop();
        error_context_push(STRING_CONST("test context"), STRING_CONST(context_data));

#if BUILD_ENABLE_ERROR_CONTEXT
        EXPECT_NE(error_context(), 0);
        EXPECT_EQ(error_context()->depth, 1);
        EXPECT_CONSTSTRINGEQ(error_context()->frame[0].name, string_const(STRING_CONST("test context")));
        EXPECT_EQ(error_context()->frame[0].data.str, context_data);
        EXPECT_EQ(error_context()->frame[0].data.length, sizeof(context_data) - 1);
#endif

        contextstr = error_context_buffer(context_buffer, 512);
#if BUILD_ENABLE_ERROR_CONTEXT
        EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(contextstr), STRING_CONST("test context"), 0),
                            STRING_NPOS, "context name 'test context' not found in buffer: %s", context_buffer);
        EXPECT_NE_MSGFORMAT(string_find_string(STRING_ARGS(contextstr), STRING_CONST(context_data), 0),
                            STRING_NPOS, "context data '%s' not found in buffer: %s", context_data, context_buffer);
#else
        EXPECT_EQ(contextstr.length, 0);
#endif

        error_context_clear();
        contextstr = error_context_buffer(context_buffer, 512);
#if BUILD_ENABLE_ERROR_CONTEXT
        EXPECT_STRINGEQ(contextstr, string_empty());
#endif
    }

    return 0;
}
Ejemplo n.º 4
0
DECLARE_TEST(exception, assert_handler) {
    EXPECT_EQ(assert_handler(), 0);

    assert_set_handler(handle_assert);
    EXPECT_EQ(assert_handler(), handle_assert);

    log_enable_stdout(false);
    EXPECT_EQ(assert_report(1, STRING_CONST("condition"), STRING_CONST("file"), 2, STRING_CONST("msg")),
              1234);
    log_enable_stdout(true);
    EXPECT_EQ(assert_handler(), handle_assert);
    EXPECT_EQ(handled_context, 1);
    EXPECT_STRINGEQ(string(handled_condition, string_length(handled_condition)), string_const(STRING_CONST("condition")));
    EXPECT_STRINGEQ(string(handled_file, string_length(handled_file)), string_const(STRING_CONST("file")));
    EXPECT_EQ(handled_line, 2);
    EXPECT_STRINGEQ(string(handled_msg, string_length(handled_msg)), string_const(STRING_CONST("msg")));

    assert_set_handler(0);
    EXPECT_EQ(assert_handler(), 0);

#if BUILD_ENABLE_LOG
    _global_log_handler = log_handler();
    log_set_handler(handle_log);
#endif
    log_enable_stdout(false);
    EXPECT_EQ(assert_report_formatted(1, STRING_CONST("assert_report_formatted"), STRING_CONST("file"),
                                      2, STRING_CONST("%.*s"), 3, "msg"), 1);
    log_enable_stdout(true);
    EXPECT_EQ(error(), ERROR_ASSERT);
#if BUILD_ENABLE_LOG
    EXPECT_TRUE(string_find_string(handled_log, string_length(handled_log),
                                   STRING_CONST("assert_report_formatted"), 0) != STRING_NPOS);
    EXPECT_TRUE(string_find_string(handled_log, string_length(handled_log), STRING_CONST("msg"),
                                   0) != STRING_NPOS);

    log_enable_stdout(false);
    log_set_suppress(HASH_TEST, ERRORLEVEL_NONE);
#if BUILD_ENABLE_DEBUG_LOG
    log_debugf(HASH_TEST, STRING_CONST("%s"),
#else
    log_infof(HASH_TEST, STRING_CONST("%s"),
#endif
               "To test log handler and memory handling this test will print "
               "a really long log line with complete nonsense. Log handlers only occur for non-suppressed "
               "log levels, which is why this will be visible. However, it will not be printed to stdout. "
               "Lorem ipsum dolor sit amet, an quas vivendum sed, in est summo conclusionemque, an est nulla nonumy option. "
               "Malorum invidunt et mel, mei et hinc adolescens, eu velit deleniti urbanitas cum. Ei pericula omittantur duo, "
               "eam ei malis pertinacia, eum hinc dictas et. Duo et velit dolorem explicari, an tacimates abhorreant qui, "
               "esse possit intellegat ad vis. Eros populo numquam pro ea. Eius altera volumus duo ex, offendit comprehensam "
               "sit te. Ea facete nostrum fabellas sea. Vel ea rebum ridens quodsi, etiam urbanitas mea an. Ornatus commune et his, "
               "quo habeo denique an, id his amet diceret. Eam ei essent denique, cu quaestio perpetua vim. Mei utamur maluisset ex, "
               "iriure tritani eu per. Pro at rebum maluisset, nec ei eirmod scaevola consulatu, ius in meis patrioque. Vis at summo "
               "ancillae omnesque, inani moderatius delicatissimi qui an. Et illum vocibus eum, aliquando intellegat ex ius. Ius at "
               "tation veritus. Scripta reprehendunt at sed. Hinc idque mollis in cum, at elit habemus civibus eam, sea et modus "
               "eripuit. Alii ipsum electram id vel, mei alterum percipitur cu. Pro cu minim erant graecis, no vis tation nominavi "
               "imperdiet, mei affert probatus ut. Quo veri modus ad, solet nostrud atomorum ius ea. Everti aliquid ne usu, populo "
               "sapientem pro te. Persecuti definitionem qui ei, dicit dicunt ea quo. Sed minimum copiosae ei, pri dicat possit "
               "urbanitas eu. Tritani interesset theophrastus id sit, phaedrum facilisis his eu. Dictas accusam eu quo. Ea democritum "
               "consetetur vel. Iudicabit definitionem est eu, oportere temporibus at nec."
              );
    log_set_suppress(HASH_TEST, ERRORLEVEL_DEBUG);
    log_enable_stdout(true);
    EXPECT_TRUE(string_find_string(handled_log, string_length(handled_log), STRING_CONST("Lorem ipsum"),
                                   0) != STRING_NPOS);

    log_set_handler(_global_log_handler);
#endif

    return 0;
}