예제 #1
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestQueueSize)
{
    AsyncQueue<int> q;

    ASSERT_EQ(0, q.size());
    q.push(1);
    ASSERT_EQ(1, q.size());
    q.push(2);
    ASSERT_EQ(2, q.size());
}
예제 #2
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestConsumeOneRemovesOne)
{
    AsyncQueue<int> q;

    q.push(1);
    q.push(2);	
    ASSERT_EQ(2, q.size());
    q.consumeOne( [](int i) {});
    ASSERT_EQ(1, q.size());
}
예제 #3
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestConsumeAllEmptiesQueue) 
{
    AsyncQueue<int> q;

    q.push(1);
    q.push(2);
    ASSERT_EQ(2, q.size());
    q.consumeAll( [](int i) {});
    EXPECT_EQ(0, q.size());
}
예제 #4
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestConsumeNRemovesCorrectNumberOfElements)
{
    AsyncQueue<int> q;

    q.push(1);
    q.push(2);
    q.push(3);

    ASSERT_EQ(3, q.size());
    q.consumeN(2, [](int){});
    ASSERT_EQ(1, q.size());

    q.consumeN(1, [](int){});
    ASSERT_EQ(0, q.size());
}
예제 #5
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestConsumeNConsumesAfterEmptyQueue)
{
    AsyncQueue<int> q;

    q.push(1);
    q.push(2);
    std::atomic<bool> threadDone = false;
    std::thread t1([&]() 
    {
        q.consumeN(3, [](int){});
        threadDone = true;
    });	
    std::this_thread::sleep_for(std::chrono::milliseconds(250));
    ASSERT_EQ(0, q.size());
    ASSERT_EQ(false, threadDone);

    q.push(1);
    std::this_thread::sleep_for(std::chrono::milliseconds(250));
    ASSERT_EQ(0, q.size());
    ASSERT_EQ(true, threadDone);
    t1.join();
}
예제 #6
0
파일: test.cpp 프로젝트: mlove-au/utils
TEST(AsyncQueue, TestEmptyQueueBlocksConsumeOneUntilPushed)
{
    AsyncQueue<int> q;

    // run a separate thread to count how many items are consumed from the queue.	
    std::atomic<int> calls = 0;	
    std::thread t1([&] ()
    {	
        q.consumeOne([&calls] (int i)
        { 
            calls++; 
        });
    });	
    std::this_thread::sleep_for(std::chrono::milliseconds(250));
    ASSERT_EQ(0, calls);	

    // push something onto the queue and wait for consumer t1 to complete.
    q.push(1);
    t1.join();
    ASSERT_EQ(1, calls);
    ASSERT_EQ(0, q.size());
}