MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / testThread

Method testThread

Tests/Libraries/Threading/ThreadingTest.cpp:50–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48};
49
50void SC::ThreadingTest::testThread()
51{
52 bool threadCalled = false;
53 Thread defaultInit;
54 SC_TEST_EXPECT(not defaultInit.join());
55 SC_TEST_EXPECT(not defaultInit.detach());
56 Thread thread;
57 auto lambda = [&](Thread& thread)
58 {
59 thread.setThreadName(SC_NATIVE_STR("test thread"));
60 threadCalled = true;
61 };
62 SC_TEST_EXPECT(thread.start(lambda));
63 SC_TEST_EXPECT(thread.threadID() != 0);
64 SC_TEST_EXPECT(thread.join());
65 SC_TEST_EXPECT(thread.threadID() == 0);
66 SC_TEST_EXPECT(not thread.detach());
67 SC_TEST_EXPECT(threadCalled);
68
69 Atomic<int> atomicInt(0);
70
71 auto lambdaDetach = [&](Thread& thread)
72 {
73 thread.setThreadName(SC_NATIVE_STR("detach thread"));
74 atomicInt.exchange(1);
75 };
76 SC_TEST_EXPECT(thread.start(lambdaDetach));
77 SC_TEST_EXPECT(thread.detach());
78 SC_TEST_EXPECT(thread.threadID() == 0);
79 while (atomicInt.load() == 0)
80 {
81 Thread::Sleep(1);
82 }
83}
84
85void SC::ThreadingTest::testEventObject()
86{

Callers

nothing calls this directly

Calls 6

joinMethod · 0.45
detachMethod · 0.45
setThreadNameMethod · 0.45
startMethod · 0.45
exchangeMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected