Files
MuditaOS/module-bsp/tests/tests-bluetooth.cpp
Radoslaw Wicik a8573a404c Apply new style
2020-03-17 10:03:16 +01:00

55 lines
1.7 KiB
C++

#include "catch.hpp"
#include <stdint.h>
#include <algorithm>
#include <bsp/bluetooth/Bluetooth.hpp>
#include <cstdio>
#include <cstring>
#include <array>
using namespace bsp;
TEST_CASE("TC1")
{
SECTION("Generic")
{
auto bt = Bluetopia::getInstance();
REQUIRE(bt != nullptr);
// cast to char* to aviod warning
REQUIRE(bt->write_blocking((char *)"LOL", strlen("LOL")) > 0);
std::array<char, 120> test_array;
test_array.fill('u');
size_t ret = bt->write_blocking(test_array.data(), test_array.size());
printf("ret: %lu\n", ret);
REQUIRE(ret != 0);
REQUIRE(ret == test_array.size());
// put 1 element
REQUIRE(bt->in.push('a') == 0);
// pop 1 element
REQUIRE(bt->in.pop(test_array.data()) == 0);
// test popped element
REQUIRE(test_array[0] == 'a');
test_array[0] = 'z';
// pop from empty buffer
REQUIRE(bt->in.pop(test_array.data()) != 0);
// check pointer passed for valid value (not changed)
REQUIRE(test_array[0] == 'z');
// fill while buffer
const bool guard_met = false;
for (int i = 0; i < bt->in.size; ++i) {
REQUIRE(bt->in.push('a') == 0);
if (!guard_met && i >= bt->in.size - bt->in.threshold) {
bool guard_met = bt->in.threshold_guard();
}
}
// default threshold == 0
REQUIRE(guard_met == false);
bt->in.threshold = 1;
// now shall be met
REQUIRE(bt->in.threshold_guard() == true);
// buffer is full -> we shouldn't be able to push anymore!
REQUIRE(bt->in.push('a') != 0);
}
}