~stolowski/unity-scopes-api/fix-user-agent-in-preview-rtm

« back to all changes in this revision

Viewing changes to test/gtest/scopes/internal/ThreadSafeQueue/ThreadSafeQueue_test.cpp

  • Committer: Pawel Stolowski
  • Date: 2014-11-04 14:33:07 UTC
  • mfrom: (241.1.20 unity-scopes-api)
  • Revision ID: pawel.stolowski@canonical.com-20141104143307-cs70gjyowjtwpk69
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
 
87
87
        try
88
88
        {
89
 
            q->push("fred");
 
89
            q->push("fred");    // Move push
 
90
            FAIL();
 
91
        }
 
92
        catch (std::runtime_error const& e)
 
93
        {
 
94
            EXPECT_STREQ("ThreadSafeQueue: cannot push onto destroyed queue", e.what());
 
95
        }
 
96
 
 
97
        try
 
98
        {
 
99
            string s = "fred";
 
100
            q->push(s);         // Copy push
90
101
            FAIL();
91
102
        }
92
103
        catch (std::runtime_error const& e)
210
221
    EXPECT_EQ("again", m.val());
211
222
 
212
223
    q.destroy();
 
224
 
213
225
    try
214
226
    {
215
227
        q.push(move(MoveOnly("no_push")));
220
232
        EXPECT_STREQ("ThreadSafeQueue: cannot push onto destroyed queue", e.what());
221
233
    }
222
234
}
 
235
 
 
236
TEST(ThreadSafeQueue, wait_until_empty)
 
237
{
 
238
    ThreadSafeQueue<int> q;
 
239
    q.push(99);
 
240
    auto fut = std::async(launch::async, [&q] {
 
241
        this_thread::sleep_for(chrono::milliseconds(300)); q.wait_and_pop(); q.destroy();
 
242
    });
 
243
    q.wait_until_empty();
 
244
    EXPECT_TRUE(q.empty());
 
245
    fut.wait();
 
246
}