JD2022-TU1/main/unittests/core/system/Thread.cpp

47 lines
1 KiB
C++

#include "precompiled_unittests_core.h"
#include "core/system/Thread.h"
namespace ITF
{
namespace
{
u32 WINAPI toggleFunc(void* _param)
{
volatile bool& boolRef = *reinterpret_cast<volatile bool*>(_param);
boolRef = !boolRef;
return 0;
}
}
TEST(Thread, test_isOnMyStack)
{
EXPECT_FALSE(Thread::isOnMyStack(nullptr));
int staticVar;
EXPECT_TRUE(Thread::isOnMyStack(&staticVar));
std::unique_ptr<int> dynamicVar (new int(0));
EXPECT_FALSE(Thread::isOnMyStack(dynamicVar.get()));
}
TEST(Thread, test_create)
{
volatile bool isToggled = false;
{
ThreadPtr threadPtr = Thread::create(toggleFunc, const_cast<bool*>(&isToggled), ThreadSettings());
ITF_UNUSED(threadPtr);
// threadPtr->join() will implicitly be called here, by the thread destructor, since we hold the only reference to the thread object
}
EXPECT_TRUE(isToggled);
}
}