Luna/tests/libc/TestGlobalCtors.cpp

43 lines
693 B
C++
Raw Permalink Normal View History

#include <stdio.h>
#include <string.h>
#include <test.h>
#include <time.h>
struct TestStruct
{
TestStruct(const char* name) : m_name(name)
{
// Just to make sure this constructor doesn't get optimized out
time_t t = time(NULL);
ctime(&t);
}
const char* name()
{
return m_name;
}
private:
const char* m_name;
};
TestStruct g_struct("Example Struct");
TestResult test_successful_global_constructor()
{
validate(g_struct.name());
validate(!strcmp(g_struct.name(), "Example Struct"));
test_success;
}
Result<void> test_main()
{
test_prelude;
run_test(test_successful_global_constructor);
return {};
}