refactor concurrent module code
This commit is contained in:
51
tests/concurrent/MutexIntegrationTest.cpp
Normal file
51
tests/concurrent/MutexIntegrationTest.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "pithread.h"
|
||||
#include "testutil.h"
|
||||
|
||||
class Mutex : public ::testing::Test, public TestUtil {
|
||||
public:
|
||||
PIMutex* m = new PIMutex();
|
||||
};
|
||||
|
||||
TEST_F(Mutex, lock_is_protect) {
|
||||
m->lock();
|
||||
bool* isProtect = new bool(true);
|
||||
|
||||
createThread([&](){
|
||||
m->lock();
|
||||
*isProtect = false;
|
||||
});
|
||||
EXPECT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
ASSERT_TRUE(*isProtect);
|
||||
}
|
||||
|
||||
TEST_F(Mutex, unlock_is_release) {
|
||||
m->lock();
|
||||
bool* isReleased = new bool(false);
|
||||
m->unlock();
|
||||
|
||||
createThread([&](){
|
||||
m->lock();
|
||||
*isReleased = true;
|
||||
m->unlock();
|
||||
});
|
||||
ASSERT_TRUE(*isReleased);
|
||||
}
|
||||
|
||||
TEST_F(Mutex, tryLock_is_false_when_locked) {
|
||||
createThread([&](){
|
||||
m->lock();
|
||||
piMSleep(WAIT_THREAD_TIME_MS);
|
||||
});
|
||||
ASSERT_FALSE(m->tryLock());
|
||||
}
|
||||
|
||||
TEST_F(Mutex, tryLock_is_true_when_unlocked) {
|
||||
ASSERT_TRUE(m->tryLock());
|
||||
}
|
||||
|
||||
TEST_F(Mutex, tryLock_is_recursive_lock_enable) {
|
||||
m->lock();
|
||||
ASSERT_TRUE(m->tryLock());
|
||||
}
|
||||
Reference in New Issue
Block a user