C++ conversions (#111)
* Remove version from artifact name * Target C++ 20 and higher * Use cpp string * Better crash implementation * String utils in cpp style * Replace parameter methods with start() method * MutexType to Mutex::Type * Kernel c to cpp style * Cleanup event flag * More cpp conversions * Test fixes * Updated ideas docs
This commit is contained in:
committed by
GitHub
parent
d52fe52d96
commit
42e843b463
@@ -14,7 +14,7 @@ void increment_callback(TT_UNUSED std::shared_ptr<void> context) {
|
||||
void value_checker(std::shared_ptr<void> context) {
|
||||
auto value = std::static_pointer_cast<uint32_t>(context);
|
||||
if (*value != value_chacker_expected) {
|
||||
tt_crash_implementation();
|
||||
tt_crash("Test error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ TEST_CASE("dispatcher should not call callback if consume isn't called") {
|
||||
|
||||
auto context = std::make_shared<uint32_t>();
|
||||
dispatcher.dispatch(&increment_callback, std::move(context));
|
||||
delay_ticks(10);
|
||||
kernel::delayTicks(10);
|
||||
|
||||
CHECK_EQ(counter, 0);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ static int thread_with_mutex_parameter(void* parameter) {
|
||||
}
|
||||
|
||||
TEST_CASE("a mutex can block a thread") {
|
||||
auto* mutex = tt_mutex_alloc(MutexTypeNormal);
|
||||
auto* mutex = tt_mutex_alloc(Mutex::TypeNormal);
|
||||
tt_mutex_acquire(mutex, TtWaitForever);
|
||||
|
||||
Thread* thread = new Thread(
|
||||
@@ -22,12 +22,12 @@ TEST_CASE("a mutex can block a thread") {
|
||||
);
|
||||
thread->start();
|
||||
|
||||
delay_ms(5);
|
||||
kernel::delayMillis(5);
|
||||
CHECK_EQ(thread->getState(), Thread::StateRunning);
|
||||
|
||||
tt_mutex_release(mutex);
|
||||
|
||||
delay_ms(5);
|
||||
kernel::delayMillis(5);
|
||||
CHECK_EQ(thread->getState(), Thread::StateStopped);
|
||||
|
||||
thread->join();
|
||||
|
||||
@@ -1,66 +1,63 @@
|
||||
#include "doctest.h"
|
||||
#include "StringUtils.h"
|
||||
|
||||
using namespace tt;
|
||||
using namespace std;
|
||||
|
||||
// region string_split
|
||||
// region split
|
||||
|
||||
TEST_CASE("splitting an empty string results in an empty vector") {
|
||||
auto result = string_split("", ".");
|
||||
auto result = tt::string::split("", ".");
|
||||
CHECK_EQ(result.empty(), true);
|
||||
}
|
||||
|
||||
TEST_CASE("splitting a string with a single token results in a vector with that token") {
|
||||
auto result = string_split("token", ".");
|
||||
auto result = tt::string::split("token", ".");
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.front(), "token");
|
||||
}
|
||||
|
||||
TEST_CASE("splitting a string with multiple tokens results in a vector with those tokens") {
|
||||
auto result = string_split("token1;token2;token3;", ";");
|
||||
auto result = tt::string::split("token1;token2;token3;", ";");
|
||||
CHECK_EQ(result.size(), 3);
|
||||
CHECK_EQ(result[0], "token1");
|
||||
CHECK_EQ(result[1], "token2");
|
||||
CHECK_EQ(result[2], "token3");
|
||||
}
|
||||
|
||||
// endregion string_split
|
||||
// endregion split
|
||||
|
||||
// region string_join
|
||||
// region join
|
||||
|
||||
TEST_CASE("joining an empty vector results in an empty string") {
|
||||
vector<string> tokens = {};
|
||||
auto result = string_join(tokens, ".");
|
||||
std::vector<std::string> tokens = {};
|
||||
auto result = tt::string::join(tokens, ".");
|
||||
CHECK_EQ(result, "");
|
||||
}
|
||||
|
||||
TEST_CASE("joining a single token results in a string with that value") {
|
||||
vector<string> tokens = {
|
||||
std::vector<std::string> tokens = {
|
||||
"token"
|
||||
};
|
||||
auto result = string_join(tokens, ".");
|
||||
auto result = tt::string::join(tokens, ".");
|
||||
CHECK_EQ(result, "token");
|
||||
}
|
||||
|
||||
TEST_CASE("joining multiple tokens results in a string with all the tokens and the delimiter") {
|
||||
vector<string> tokens = {
|
||||
std::vector<std::string> tokens = {
|
||||
"token1",
|
||||
"token2",
|
||||
"token3",
|
||||
};
|
||||
auto result = string_join(tokens, ".");
|
||||
auto result = tt::string::join(tokens, ".");
|
||||
CHECK_EQ(result, "token1.token2.token3");
|
||||
}
|
||||
|
||||
TEST_CASE("joining with empty tokens leads to an extra delimiter") {
|
||||
vector<string> tokens = {
|
||||
std::vector<std::string> tokens = {
|
||||
"token1",
|
||||
"",
|
||||
"token2",
|
||||
};
|
||||
auto result = string_join(tokens, ".");
|
||||
auto result = tt::string::join(tokens, ".");
|
||||
CHECK_EQ(result, "token1..token2");
|
||||
}
|
||||
|
||||
// endregion string_join
|
||||
// endregion join
|
||||
|
||||
@@ -7,7 +7,7 @@ using namespace tt;
|
||||
static int interruptable_thread(void* parameter) {
|
||||
bool* interrupted = (bool*)parameter;
|
||||
while (!*interrupted) {
|
||||
delay_ms(5);
|
||||
kernel::delayMillis(5);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ TEST_CASE("a timer passes the context correctly") {
|
||||
auto foo = std::make_shared<int>(1);
|
||||
auto* timer = new Timer(Timer::TypeOnce, &timer_callback_with_context, foo);
|
||||
timer->start(1);
|
||||
delay_ticks(10);
|
||||
kernel::delayTicks(10);
|
||||
timer->stop();
|
||||
delete timer;
|
||||
|
||||
@@ -31,10 +31,10 @@ TEST_CASE("TimerTypePeriodic timers can be stopped and restarted") {
|
||||
auto counter = std::make_shared<int>(0);
|
||||
auto* timer = new Timer(Timer::TypePeriodic, &timer_callback_with_counter, counter);
|
||||
timer->start(1);
|
||||
delay_ticks(10);
|
||||
kernel::delayTicks(10);
|
||||
timer->stop();
|
||||
timer->start(1);
|
||||
delay_ticks(10);
|
||||
kernel::delayTicks(10);
|
||||
timer->stop();
|
||||
delete timer;
|
||||
|
||||
@@ -46,7 +46,7 @@ TEST_CASE("TimerTypePeriodic calls the callback periodically") {
|
||||
int ticks_to_run = 10;
|
||||
auto* timer = new Timer(Timer::TypePeriodic, &timer_callback_with_counter, counter);
|
||||
timer->start(1);
|
||||
delay_ticks(ticks_to_run);
|
||||
kernel::delayTicks(ticks_to_run);
|
||||
timer->stop();
|
||||
delete timer;
|
||||
|
||||
@@ -57,10 +57,10 @@ TEST_CASE("restarting TimerTypeOnce timers calls the callback again") {
|
||||
auto counter = std::make_shared<int>(0);
|
||||
auto* timer = new Timer(Timer::TypeOnce, &timer_callback_with_counter, counter);
|
||||
timer->start(1);
|
||||
delay_ticks(10);
|
||||
kernel::delayTicks(10);
|
||||
timer->stop();
|
||||
timer->start(1);
|
||||
delay_ticks(10);
|
||||
kernel::delayTicks(10);
|
||||
timer->stop();
|
||||
delete timer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user