#include "catch.hpp" #include #include #include #include #include #include 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 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); } }