#include "Utilities/SharedMemory.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Go to the source code of this file.
|
| TEST (SharedMemory, MemoryAndSemaphore) |
|
TEST |
( |
SharedMemory |
, |
|
|
MemoryAndSemaphore |
|
|
) |
| |
Definition at line 22 of file test_sharedMemory.cpp.
References SharedMemoryObject< T >::attach(), SharedMemoryObject< T >::closeNew(), SharedMemoryObject< T >::createNew(), SharedMemorySemaphore::decrement(), SharedMemoryObject< T >::detach(), SharedMemoryObject< T >::get(), SharedMemorySemaphore::init(), SharedMemoryTestNamespace::TestType::semaphore, and SharedMemoryTestNamespace::TestType::value.
24 std::string memoryName =
"/shared-memory-test";
30 EXPECT_TRUE(sharedObject.
get());
34 EXPECT_FALSE(oldStaleSharedMemory.
createNew(memoryName,
false));
39 EXPECT_TRUE(sharedObject.
createNew(memoryName,
true));
43 EXPECT_FALSE(sharedObject.
createNew(memoryName,
false));
45 const u32 valueFromParent = 2;
46 const u32 valueFromChildSuccess = 3;
47 const u32 valueFromChildFailure = 4;
50 EXPECT_TRUE(0 == sharedObject.
get()->
value);
52 sharedObject.
get()->
value = valueFromParent;
60 childView.
attach(memoryName);
63 if (childView().value == valueFromParent) {
64 childView().value = valueFromChildSuccess;
67 childView().value = valueFromChildFailure;
71 childView().semaphore.increment();
79 EXPECT_TRUE(valueFromChildSuccess == sharedObject.
get()->
value);
81 }
SharedMemorySemaphore semaphore
void attach(const std::string &name)
void init(unsigned int value)
bool createNew(const std::string &name, bool allowOverwrite=false)