Loading system/gd/common/blocking_queue.h +2 −2 Original line number Diff line number Diff line Loading @@ -34,12 +34,12 @@ class BlockingQueue { } }; const T& take() { T take() { std::unique_lock<std::mutex> lock(mutex_); while (queue_.empty()) { not_empty_.wait(lock); } const T& data = queue_.front(); T data = queue_.front(); queue_.pop(); return data; }; Loading system/gd/common/blocking_queue_unittest.cc +22 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,28 @@ TEST_F(BlockingQueueTest, wait_for_non_empty_batch) { EXPECT_TRUE(queue_.empty()); } class VectorBlockingQueueTest : public ::testing::Test { protected: void SetUp() override { EXPECT_TRUE(queue_.empty()); } // Postcondition for each test case: clear the blocking queue void TearDown() override { EXPECT_TRUE(queue_.empty()); } BlockingQueue<std::vector<uint8_t>> queue_; }; TEST_F(VectorBlockingQueueTest, same_thread_push_and_pop) { std::vector<uint8_t> data = {1, 2, 3, 4, 5, 6}; queue_.push(data); EXPECT_FALSE(queue_.empty()); EXPECT_EQ(queue_.take(), data); EXPECT_TRUE(queue_.empty()); } } // namespace } // namespace common } // namespace bluetooth Loading
system/gd/common/blocking_queue.h +2 −2 Original line number Diff line number Diff line Loading @@ -34,12 +34,12 @@ class BlockingQueue { } }; const T& take() { T take() { std::unique_lock<std::mutex> lock(mutex_); while (queue_.empty()) { not_empty_.wait(lock); } const T& data = queue_.front(); T data = queue_.front(); queue_.pop(); return data; }; Loading
system/gd/common/blocking_queue_unittest.cc +22 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,28 @@ TEST_F(BlockingQueueTest, wait_for_non_empty_batch) { EXPECT_TRUE(queue_.empty()); } class VectorBlockingQueueTest : public ::testing::Test { protected: void SetUp() override { EXPECT_TRUE(queue_.empty()); } // Postcondition for each test case: clear the blocking queue void TearDown() override { EXPECT_TRUE(queue_.empty()); } BlockingQueue<std::vector<uint8_t>> queue_; }; TEST_F(VectorBlockingQueueTest, same_thread_push_and_pop) { std::vector<uint8_t> data = {1, 2, 3, 4, 5, 6}; queue_.push(data); EXPECT_FALSE(queue_.empty()); EXPECT_EQ(queue_.take(), data); EXPECT_TRUE(queue_.empty()); } } // namespace } // namespace common } // namespace bluetooth