MCPcopy Create free account
hub / github.com/cameron314/concurrentqueue / exceptions

Method exceptions

tests/unittests/unittests.cpp:2526–3095  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2524 }
2525
2526 bool exceptions()
2527 {
2528 typedef TestTraits<4, 2> Traits;
2529
2530 {
2531 // Explicit, basic
2532 // enqueue
2533 ConcurrentQueue<ThrowingMovable, Traits> q;
2534 ProducerToken tok(q);
2535
2536 ThrowingMovable::reset();
2537
2538 bool threw = false;
2539 try {
2540 q.enqueue(tok, ThrowingMovable(1, true));
2541 }
2542 catch (ThrowingMovable* m) {
2543 threw = true;
2544 ASSERT_OR_FAIL(m->id == 1);
2545 ASSERT_OR_FAIL(m->moved);
2546 }
2547 ASSERT_OR_FAIL(threw);
2548 ASSERT_OR_FAIL(q.size_approx() == 0);
2549
2550 ASSERT_OR_FAIL(q.enqueue(tok, ThrowingMovable(2)));
2551 ThrowingMovable result(-1);
2552 ASSERT_OR_FAIL(q.try_dequeue(result));
2553 ASSERT_OR_FAIL(result.id == 2);
2554 ASSERT_OR_FAIL(result.moved);
2555 ASSERT_OR_FAIL(!q.try_dequeue(result));
2556
2557 ASSERT_OR_FAIL(ThrowingMovable::destroyCount() == 3);
2558
2559 // dequeue
2560 ThrowingMovable::reset();
2561 q.enqueue(tok, ThrowingMovable(10));
2562 q.enqueue(tok, ThrowingMovable(11, false, true));
2563 q.enqueue(tok, ThrowingMovable(12));
2564 ASSERT_OR_FAIL(q.size_approx() == 3);
2565
2566 ASSERT_OR_FAIL(q.try_dequeue(result));
2567 ASSERT_OR_FAIL(result.id == 10);
2568 threw = false;
2569 try {
2570 q.try_dequeue(result);
2571 }
2572 catch (ThrowingMovable* m) {
2573 ASSERT_OR_FAIL(m->id == 11);
2574 threw = true;
2575 }
2576 ASSERT_OR_FAIL(threw);
2577 ASSERT_OR_FAIL(q.size_approx() == 1);
2578
2579 ASSERT_OR_FAIL(q.try_dequeue(result));
2580 ASSERT_OR_FAIL(result.id == 12);
2581 ASSERT_OR_FAIL(result.moved);
2582
2583 ASSERT_OR_FAIL(!q.try_dequeue(result));

Callers

nothing calls this directly

Calls 14

ThrowingMovableClass · 0.85
SimpleThreadClass · 0.85
enqueueMethod · 0.45
size_approxMethod · 0.45
try_dequeueMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
backMethod · 0.45
enqueue_bulkMethod · 0.45
beginMethod · 0.45
try_dequeue_bulkMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected