mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +00:00
Test Thread inheritance as well as callbacks.
This commit is contained in:
parent
93325df0c4
commit
b34afee979
1 changed files with 33 additions and 2 deletions
|
|
@ -24,7 +24,7 @@
|
|||
#include "testing/unitTesting.h"
|
||||
#include "platform/threads/thread.h"
|
||||
|
||||
TEST(Thread, BasicAPI)
|
||||
TEST(Thread, CallbackAPI)
|
||||
{
|
||||
#define VALUE_TO_SET 10
|
||||
|
||||
|
|
@ -51,6 +51,37 @@ TEST(Thread, BasicAPI)
|
|||
<< "Thread did not set expected value!";
|
||||
|
||||
#undef VALUE_TO_SET
|
||||
};
|
||||
}
|
||||
|
||||
TEST(Thread, InheritanceAPI)
|
||||
{
|
||||
#define VALUE_TO_SET 10
|
||||
|
||||
// This struct exists just so we can define run as a local function.
|
||||
struct thread : public Thread
|
||||
{
|
||||
U32* mPtr;
|
||||
thread(U32* ptr): mPtr(ptr) {}
|
||||
|
||||
// Do some work we can observe.
|
||||
virtual void run(void*)
|
||||
{
|
||||
*mPtr = VALUE_TO_SET;
|
||||
}
|
||||
};
|
||||
|
||||
// Test most basic Thread API functions.
|
||||
U32 value = ~VALUE_TO_SET;
|
||||
thread thread(&value);
|
||||
thread.start();
|
||||
EXPECT_TRUE(thread.isAlive());
|
||||
thread.join();
|
||||
EXPECT_FALSE(thread.isAlive());
|
||||
|
||||
EXPECT_EQ(value, VALUE_TO_SET)
|
||||
<< "Thread did not set expected value!";
|
||||
|
||||
#undef VALUE_TO_SET
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue