Added inter thread communication lib
git-svn-id: svn://db.shs.com.ru/pip@858 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
65
src_concurrent/test/ConditionLockIntegrationTest.cpp
Normal file
65
src_concurrent/test/ConditionLockIntegrationTest.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Created by fomenko on 26.09.2019.
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
#include "piconditionvar.h"
|
||||
#include <pithread.h>
|
||||
#include "testutil.h"
|
||||
|
||||
class ConditionLock : public ::testing::Test, public TestUtil {
|
||||
protected:
|
||||
void TearDown() override {
|
||||
if (adapter != nullptr) delete adapter;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ConditionLock, lock_is_protect) {
|
||||
PIConditionLock m;
|
||||
m.lock();
|
||||
bool isProtect = true;
|
||||
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
isProtect = false;
|
||||
});
|
||||
ASSERT_TRUE(isProtect);
|
||||
}
|
||||
|
||||
TEST_F(ConditionLock, unlock_is_release) {
|
||||
PIConditionLock m;
|
||||
m.lock();
|
||||
volatile bool isReleased = false;
|
||||
m.unlock();
|
||||
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
isReleased = true;
|
||||
m.unlock();
|
||||
});
|
||||
EXPECT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
|
||||
ASSERT_TRUE(isReleased);
|
||||
}
|
||||
|
||||
TEST_F(ConditionLock, tryLock_is_false_when_locked) {
|
||||
PIConditionLock m;
|
||||
|
||||
createThread([&](){
|
||||
m.lock();
|
||||
piMSleep(WAIT_THREAD_TIME_MS);
|
||||
});
|
||||
ASSERT_FALSE(m.tryLock());
|
||||
}
|
||||
|
||||
TEST_F(ConditionLock, tryLock_is_true_when_unlocked) {
|
||||
PIConditionLock m;
|
||||
ASSERT_TRUE(m.tryLock());
|
||||
}
|
||||
|
||||
TEST_F(ConditionLock, tryLock_is_recursive_lock_enable) {
|
||||
PIConditionLock m;
|
||||
m.lock();
|
||||
ASSERT_TRUE(m.tryLock());
|
||||
}
|
||||
Reference in New Issue
Block a user