- Lots of changes for migrating C code to C++ - Improved `Lockable` in several ways like adding `withLock()` (+ tests) - Improved `Semaphore` a bit for improved readability, and also added some tests - Upgrade Linux machine in GitHub Actions so that we can compile with a newer GCC - Simplification of WiFi connection - Updated funding options - (and more)
40 lines
930 B
C++
40 lines
930 B
C++
#include "Lockable.h"
|
|
#include "Semaphore.h"
|
|
#include "doctest.h"
|
|
#include <Mutex.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);
|
|
}
|