void test_swap_aquires_both_locks() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<>> queue { 5 }, other { 4 }; reset_counters(); queue.swap(other); ASSERT_EQUAL(2, single_threaded_test_mutex::lock_count + single_threaded_test_mutex::try_lock_count); }
void test_full_aquires_lock() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<0, 0>> queue { 5 }; reset_counters(); queue.full(); ASSERT_EQUAL(1, single_threaded_test_mutex::lock_count); }
void test_push_rvalue_aquires_lock() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<1, 1>> queue { 5 }; reset_counters(); queue.push(1); ASSERT_EQUAL(1, single_threaded_test_mutex::lock_count); }
void test_swap_aquires_tries_multiple_times_to_try_lock() { BoundedQueue<int, single_threaded_count_down_mutex<3>, single_threaded_condition_variable<>> queue { 5 }, other { 4 }; reset_counters(); queue.swap(other); ASSERT_EQUAL(4, single_threaded_test_mutex::try_lock_count); }
void test_try_push_rvalue_releases_lock() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<0, 1>> queue { 5 }; reset_counters(); queue.try_push(1); ASSERT_EQUAL(1, single_threaded_test_mutex::unlock_count); }
OSTHREAD_FUNC test6_enqueuer(void *data){ BoundedQueue<int> *queue = (BoundedQueue<int> *) data; int i; for (i=0; i < TEST6_NOPS; ++i){ queue->enqueue(i); } return 0; }
void test_size_releases_lock() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<>> queue { 5 }; reset_counters(); queue.size(); ASSERT_EQUAL(1, single_threaded_test_mutex::unlock_count); }
void test_swap_releases_two_locks() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<>> queue { 5 }, other { 4 }; reset_counters(); queue.swap(other); ASSERT_EQUAL(2, single_threaded_test_mutex::unlock_count); }
void test_pop_releases_lock() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<1, 1>> queue { 5 }; queue.push(1); reset_counters(); queue.pop(); ASSERT_EQUAL(1, single_threaded_test_mutex::unlock_count); }
OSTHREAD_FUNC test6_dequeuer(void *data){ BoundedQueue<int> *queue = (BoundedQueue<int> *) data; int i, item; for (i=0; i < TEST6_NOPS; ++i){ item = queue->dequeue(); assert(item==i); } return 0; }
void test_try_push_for_releases_lock_on_full_queue() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<1, 0>> queue { 1 }; queue.push(1); reset_counters(); queue.try_push_for(1, std::chrono::milliseconds { 1 }); ASSERT_EQUAL(2, single_threaded_test_mutex::unlock_count); }
void test_try_push_for_aquires_lock_on_empty_queue() { int i { 1 }; BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<1, 1>> queue { 5 }; reset_counters(); queue.try_push_for(i, std::chrono::milliseconds { 1 }); ASSERT_EQUAL(1, single_threaded_test_mutex::lock_count); }
void test_try_pop_for_releases_lock_on_empty_queue() { int result { }; BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<1, 0>> queue { 5 }; reset_counters(); queue.try_pop_for(result, std::chrono::milliseconds { 1 }); ASSERT_EQUAL(2, single_threaded_test_mutex::unlock_count); }
void test_try_push_lvalue_aquires_lock() { int i { 1 }; BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<0, 1>> queue { 5 }; reset_counters(); queue.try_push(i); ASSERT_EQUAL(1, single_threaded_test_mutex::lock_count); }
void test_swap_successful_after_delayed_lock() { BoundedQueue<int, single_threaded_count_down_mutex<1>, single_threaded_condition_variable<1, 1>> queue { 5 }, other { 4 }; other.push(17); reset_counters(); queue.swap(other); ASSERT_EQUAL(17, queue.pop()); }
void test_try_pop_aquires_lock() { BoundedQueue<int, single_threaded_test_mutex, single_threaded_condition_variable<0, 1>> queue { 5 }; queue.push(1); int result { }; reset_counters(); queue.try_pop(result); ASSERT_EQUAL(1, single_threaded_test_mutex::lock_count); }
void test_capacity_is_copied_in_ctor() { //given BoundedQueue<MemoryOperationCounter> queue{4}; queue.push(MemoryOperationCounter{}); queue.push(MemoryOperationCounter{}); //when BoundedQueue<MemoryOperationCounter> copy {queue}; copy.push(MemoryOperationCounter{}); copy.push(MemoryOperationCounter{}); //then ASSERT(copy.full()); }
void test_queue_push_moves_element() { BoundedQueue<MemoryOperationCounter> queue { 1 }; MemoryOperationCounter counter { }, expected { 2, 0, true }; queue.push(std::move(counter)); ASSERT_EQUAL(expected, queue.pop()); }
void test_int_queue_of_capacity_thousand_is_empty() { BoundedQueue<int> const queue{1000}; ASSERTM("New queue should be empty", queue.empty()); }
void test_const_int_queue_of_capacity_thousand_is_not_full() { BoundedQueue<int> const queue{1000}; ASSERTM("New queue should not be full", !queue.full()); }
void test_queue_push_copies_element() { BoundedQueue<MemoryOperationCounter> queue { 1 }; MemoryOperationCounter counter { }, expected { 1 , 1, true }; queue.push(counter); ASSERT_EQUAL(expected, queue.pop()); // pop moves }
void test_int_queue_of_capacity_thousand_has_size_zero() { BoundedQueue<int> const queue{1000}; ASSERT_EQUALM("New queue should be empty", 0, queue.size()); }