- Create `Include/` folder for all main projects - Fix some issues here and there (found while moving things) - All includes are now in `Tactility/` subfolder and must be included with that prefix. This fixes issues with clashing POSIX headers (e.g. `<semaphore.h>` versus Tactility's `Semaphore.h`)
40 lines
960 B
C++
40 lines
960 B
C++
#include "doctest.h"
|
|
#include <Tactility/Lockable.h>
|
|
#include <Tactility/Mutex.h>
|
|
#include <Tactility/Semaphore.h>
|
|
|
|
using namespace tt;
|
|
|
|
TEST_CASE("withLock() locks correctly on Semaphore") {
|
|
auto semaphore = std::make_shared<Semaphore>(2U);
|
|
semaphore->withLock([semaphore](){
|
|
CHECK_EQ(semaphore->getAvailable(), 1);
|
|
});
|
|
}
|
|
|
|
TEST_CASE("withLock() unlocks correctly on Semaphore") {
|
|
auto semaphore = std::make_shared<Semaphore>(2U);
|
|
semaphore->withLock([=](){
|
|
// NO-OP
|
|
});
|
|
|
|
CHECK_EQ(semaphore->getAvailable(), 2);
|
|
}
|
|
|
|
TEST_CASE("withLock() locks correctly on Mutex") {
|
|
auto mutex = std::make_shared<Mutex>();
|
|
mutex->withLock([mutex](){
|
|
CHECK_EQ(mutex->lock(1), false);
|
|
});
|
|
}
|
|
|
|
TEST_CASE("withLock() unlocks correctly on Mutex") {
|
|
auto mutex = std::make_shared<Mutex>();
|
|
mutex->withLock([=](){
|
|
// NO-OP
|
|
});
|
|
|
|
CHECK_EQ(mutex->lock(1), true);
|
|
CHECK_EQ(mutex->unlock(), true);
|
|
}
|