Esempio n. 1
0
int
assert_report_formatted(hash_t context, const char* condition, size_t cond_length,
                        const char* file, size_t file_length, unsigned int line,
                        const char* msg, size_t msg_length, ...) {
	if (msg) {
		string_t buffer = { _assert_buffer, sizeof(_assert_buffer) };
		va_list ap;
		va_start(ap, msg_length);
		buffer = string_vformat(STRING_ARGS(buffer), msg, msg_length, ap);
		va_end(ap);
		msg = buffer.str;
		msg_length = buffer.length;
	}
	return assert_report(context, condition, cond_length,
	                     file, file_length, line, msg, msg_length);
}
Esempio n. 2
0
int assert_report_formatted( uint64_t context, const char* condition, const char* file, int line, const char* msg, ... )
{
	if( msg )
	{
		/*lint --e{438} Lint gets confused about assignment to ap */
		va_list ap;
		va_start( ap, msg );
		vsnprintf( _assert_buffer, (size_t)ASSERT_BUFFER_SIZE, msg, ap );
		va_end( ap );
	}
	else
	{
		_assert_buffer[0] = 0;
	}
	return assert_report( context, condition, file, line, _assert_buffer );
}
Esempio n. 3
0
int assert_report_formatted( const char* condition, const char* file, int line, const char* msg, ... )
{
	if( msg )
	{
		/*lint --e{438} */
		int ret;
		va_list ap;
		va_start( ap, msg );
		ret = vsnprintf( _assert_buffer, (size_t)ASSERT_BUFFER_SIZE, msg, ap );
		if( ( ret < 0 ) || ( ret >= ASSERT_BUFFER_SIZE ) )
			_assert_buffer[ASSERT_BUFFER_SIZE-1] = 0;
		va_end( ap );
	}
	else
	{
		_assert_buffer[0] = 0;
	}
	return assert_report( condition, file, line, _assert_buffer );
}
Esempio 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;
}