Improved PIBlockingDeque constructors
- resolve creation from constant (see test construct_from_constant_is_max_size_eq_capacity) - add tests for constructors
This commit is contained in:
@@ -41,7 +41,8 @@ public:
|
||||
/**
|
||||
* @brief Copy constructor. Initialize queue with copy of other container elements. Not thread-safe for other queue.
|
||||
*/
|
||||
template<typename Iterable>
|
||||
template<typename Iterable,
|
||||
typename std::enable_if<!std::is_arithmetic<Iterable>::value, int>::type = 0>
|
||||
explicit PIBlockingDequeue(const Iterable& other): PIBlockingDequeue() {
|
||||
mutex.lock();
|
||||
for (const T& t : other) data_queue.push_back(t);
|
||||
@@ -51,7 +52,7 @@ public:
|
||||
/**
|
||||
* @brief Thread-safe copy constructor. Initialize queue with copy of other queue elements.
|
||||
*/
|
||||
inline PIBlockingDequeue(PIBlockingDequeue<T>& other): PIBlockingDequeue() {
|
||||
explicit PIBlockingDequeue(PIBlockingDequeue<T>& other): PIBlockingDequeue() {
|
||||
other.mutex.lock();
|
||||
mutex.lock();
|
||||
max_size = other.max_size;
|
||||
|
||||
@@ -83,12 +83,14 @@ public:
|
||||
|
||||
explicit PIBlockingDequeuePrepare(size_t capacity = SIZE_MAX): SuperClass(capacity) { }
|
||||
|
||||
template<typename Iterable>
|
||||
template<typename Iterable,
|
||||
typename std::enable_if<!std::is_arithmetic<Iterable>::value, int>::type = 0>
|
||||
explicit PIBlockingDequeuePrepare(const Iterable& other): SuperClass(other) { }
|
||||
|
||||
MockConditionVar* getCondVarAdd() { return this->cond_var_add; }
|
||||
MockConditionVar* getCondVarRem() { return this->cond_var_rem; }
|
||||
MockDeque<QueueElement>& getQueue() { return this->data_queue; }
|
||||
size_t getMaxSize() { return max_size; }
|
||||
};
|
||||
|
||||
class BlockingDequeueUnitTest: public ::testing::Test {
|
||||
@@ -105,6 +107,27 @@ public:
|
||||
void take_is_wait_predicate(bool isEmpty);
|
||||
};
|
||||
|
||||
TEST_F(BlockingDequeueUnitTest, construct_default_is_max_size_eq_size_max) {
|
||||
PIBlockingDequeuePrepare dequeue;
|
||||
ASSERT_EQ(dequeue.getMaxSize(), SIZE_MAX);
|
||||
}
|
||||
|
||||
TEST_F(BlockingDequeueUnitTest, construct_from_constant_is_max_size_eq_capacity) {
|
||||
PIBlockingDequeuePrepare dequeue(2);
|
||||
ASSERT_EQ(dequeue.getMaxSize(), 2);
|
||||
}
|
||||
|
||||
TEST_F(BlockingDequeueUnitTest, construct_from_capacity_is_max_size_eq_capacity) {
|
||||
ASSERT_EQ(dequeue.getMaxSize(), capacity);
|
||||
}
|
||||
|
||||
TEST_F(BlockingDequeueUnitTest, construct_from_iterable) {
|
||||
std::vector<QueueElement> iterable;
|
||||
iterable.emplace_back(11);
|
||||
iterable.emplace_back(22);
|
||||
PIBlockingDequeuePrepare dequeue(iterable);
|
||||
}
|
||||
|
||||
void BlockingDequeueUnitTest::put_is_wait_predicate(bool isCapacityReach) {
|
||||
std::function<bool()> conditionVarPredicate;
|
||||
EXPECT_CALL(*dequeue.getCondVarRem(), wait(_, _))
|
||||
|
||||
Reference in New Issue
Block a user