extern_interface/tests/test_queue.cpp

35 lines
597 B
C++
Raw Normal View History

#include <thread>
#include <unistd.h>
2024-11-28 10:14:00 +00:00
#include "c_testcase.h"
#include "dataqueue.hpp"
TEST_CASE(init) {
DataQueue<int> q;
assert(q.Empty());
assert_eq(q.Size(), 0);
END_TEST;
}
TEST_CASE(push) {
DataQueue<int> q;
q.Push(10);
assert_eq(q.Size(), 1);
assert_eq(q.Pop(), 10);
END_TEST;
}
TEST_CASE(pop) {
DataQueue<int> 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;
}