test: Use standard mutex primitives in mocks
This commit is contained in:
parent
0a89b5abfe
commit
391c34d669
|
@ -23,6 +23,9 @@
|
||||||
|
|
||||||
#include "test/global/gmock.h"
|
#include "test/global/gmock.h"
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::Invoke;
|
using ::testing::Invoke;
|
||||||
|
|
||||||
|
@ -31,19 +34,9 @@ class IEventQueue;
|
||||||
class MockIpcServer : public IpcServer
|
class MockIpcServer : public IpcServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MockIpcServer() :
|
MockIpcServer() {}
|
||||||
m_sendCond(ARCH->newCondVar()),
|
|
||||||
m_sendMutex(ARCH->newMutex()) { }
|
|
||||||
|
|
||||||
~MockIpcServer() {
|
~MockIpcServer() {}
|
||||||
if (m_sendCond != NULL) {
|
|
||||||
ARCH->closeCondVar(m_sendCond);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_sendMutex != NULL) {
|
|
||||||
ARCH->closeMutex(m_sendMutex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MOCK_METHOD0(listen, void());
|
MOCK_METHOD0(listen, void());
|
||||||
MOCK_METHOD2(send, void(const IpcMessage&, EIpcClientType));
|
MOCK_METHOD2(send, void(const IpcMessage&, EIpcClientType));
|
||||||
|
@ -54,16 +47,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForSend() {
|
void waitForSend() {
|
||||||
ArchMutexLock lock{m_sendMutex, std::adopt_lock};
|
std::unique_lock<std::mutex> lock{send_mutex_};
|
||||||
ARCH->waitCondVar(m_sendCond, lock, 5);
|
ARCH->wait_cond_var(send_cv_, lock, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mockSend(const IpcMessage&, EIpcClientType) {
|
void mockSend(const IpcMessage&, EIpcClientType) {
|
||||||
ArchMutexLock lock(m_sendMutex);
|
std::lock_guard<std::mutex> lock(send_mutex_);
|
||||||
ARCH->broadcastCondVar(m_sendCond);
|
send_cv_.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
ArchCond m_sendCond;
|
std::condition_variable send_cv_;
|
||||||
ArchMutex m_sendMutex;
|
std::mutex send_mutex_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue