int main_initialize( void ) { application_t application; memset( &application, 0, sizeof( application ) ); application.name = "Foundation library test suite"; application.short_name = "test_all"; application.config_dir = "test_all"; application.version = foundation_version(); application.flags = APPLICATION_UTILITY; application.dump_callback = test_crash_handler; log_set_suppress( 0, ERRORLEVEL_INFO ); #if ( FOUNDATION_PLATFORM_IOS || FOUNDATION_PLATFORM_ANDROID ) && BUILD_ENABLE_LOG log_set_callback( test_log_callback ); #endif #if !FOUNDATION_PLATFORM_IOS && !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_PNACL _test_should_start = true; #endif return foundation_initialize( memory_system_malloc(), application ); }
int main_initialize( void ) { application_t application = {0}; application.name = "Foundation library test suite"; application.short_name = "test_all"; application.config_dir = "test_all"; application.flags = APPLICATION_UTILITY; log_set_suppress( 0, ERRORLEVEL_DEBUG ); #if FOUNDATION_PLATFORM_IOS log_set_callback( test_log_callback ); #endif return foundation_initialize( memory_system_malloc(), application ); }
DECLARE_TEST(error, output) { #if BUILD_ENABLE_LOG error_callback_fn callback_error = error_callback(); log_callback_fn callback_log = log_callback(); string_const_t shortmsg = string_const(STRING_CONST("Short message with prefix")); string_const_t longmsg = string_const(STRING_CONST("Longer message which should be output without a prefix")); error_set_callback(ignore_error_handler); log_set_callback(log_verify_callback); log_enable_stdout(false); log_warn(HASH_TEST, WARNING_SUSPICIOUS, STRING_ARGS(shortmsg)); log_enable_stdout(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING); EXPECT_GE(_last_log_length, shortmsg.length); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [suspicious]"), 0), STRING_NPOS); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_stdout(false); log_warn(HASH_TEST, (warning_t)0x1000, STRING_ARGS(shortmsg)); log_enable_stdout(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING); EXPECT_GE(_last_log_length, shortmsg.length); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [4096]"), 0), STRING_NPOS); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_prefix(false); log_enable_stdout(false); log_warn(HASH_TEST, WARNING_SYSTEM_CALL_FAIL, STRING_ARGS(longmsg)); log_enable_stdout(true); log_enable_prefix(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_stdout(false); log_error(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg)); log_enable_stdout(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR); EXPECT_GE(_last_log_length, shortmsg.length); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [deprecated]"), 0), STRING_NPOS); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_stdout(false); log_error(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg)); log_enable_stdout(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR); EXPECT_GE(_last_log_length, shortmsg.length); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [4096]"), 0), STRING_NPOS); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_prefix(false); log_enable_stdout(false); log_error(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg)); log_enable_stdout(true); log_enable_prefix(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_stdout(false); log_panic(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg)); log_enable_stdout(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC); EXPECT_GE(_last_log_length, shortmsg.length); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [deprecated]"), 0), STRING_NPOS); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_stdout(false); log_panic(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg)); log_enable_stdout(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC); EXPECT_GE(_last_log_length, shortmsg.length); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [4096]"), 0), STRING_NPOS); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_prefix(false); log_enable_stdout(false); log_panic(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg)); log_enable_stdout(true); log_enable_prefix(true); EXPECT_EQ(_last_log_context, HASH_TEST); EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC); EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS); EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0); error_context_push(STRING_CONST("one"), STRING_CONST("dataone")); error_context_push(STRING_CONST("two"), STRING_CONST("datatwo")); error_context_push(STRING_CONST("three"), STRING_CONST("datathree")); _last_log_context = 0; _last_log_severity = ERRORLEVEL_NONE; _last_log_msg = nullptr; _last_log_length = 0; log_enable_stdout(false); log_error_context(HASH_TEST, ERRORLEVEL_INFO); log_enable_stdout(true); error_context_pop(); error_context_pop(); error_context_pop(); EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When one: dataone"), 0), STRING_NPOS); EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When two: datatwo"), 0), STRING_NPOS); EXPECT_SIZENE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When three: datathree"), 0), STRING_NPOS); log_set_callback(callback_log); error_set_callback(callback_error); #endif return 0; }