#include #include #include "c_testcase.h" #include "dataqueue.hpp" TEST_CASE(test_init) { DataQueue q; assert(q.Empty()); assert_eq(q.Size(), 0); END_TEST; } TEST_CASE(test_push) { DataQueue q; q.Push(10); assert_eq(q.Size(), 1); assert_eq(q.Pop(), 10); END_TEST; } TEST_CASE(test_pop) { DataQueue q; std::thread t([&]() { for (int i = 0; i < 10; i++) { q.Push(i); usleep(100); } }); for (int i = 0; i < 10; i++) { assert_eq(q.Pop(), i); } t.join(); END_TEST; } TEST_CASE(test_clear) { DataQueue q; q.Push(10); q.Clear(); assert(q.Empty()); std::thread t([&]() { try { q.Pop(); } catch (const QueueException&) { return; } throw std::runtime_error("QueueException not thrown"); }); std::this_thread::sleep_for(std::chrono::milliseconds(10)); q.Clear(); t.join(); END_TEST; }