-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackedQueueTests.cpp
102 lines (88 loc) · 3.27 KB
/
backedQueueTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/// @brief Trivial tests for the various utilities for QEQueue.
/// @ingroup
/// @cond
///***************************************************************************
///
/// Copyright (C) 2022 Matthew Eshleman. All rights reserved.
///
/// This program is open source software: you can redistribute it and/or
/// modify it under the terms of the GNU General Public License as published
/// by the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// Alternatively, upon written permission from Matthew Eshleman, this program
/// may be distributed and modified under the terms of a Commercial
/// License. For further details, see the Contact Information below.
///
/// Contact Information:
/// Matthew Eshleman
/// https://covemountainsoftware.com
///***************************************************************************
/// @endcond
#include "CppUTest/TestHarness.h"
#include "cmsVectorBackedQEQueue.hpp"
#include "cmsArrayBackedQEQueue.hpp"
#include <memory>
using namespace cms;
TEST_GROUP(BackedQueueTests) {
void setup() final {}
void teardown() final {}
};
TEST(BackedQueueTests, can_create_vector_backed_qequeue)
{
auto underTest =
std::unique_ptr<VectorBackedQEQueue>(new VectorBackedQEQueue(10));
}
TEST(BackedQueueTests,
vector_backed_qequeue_reports_size_plus_one_same_as_qequeue)
{
constexpr uint16_t MaxStorageForEvents = 10;
auto underTest = std::unique_ptr<VectorBackedQEQueue>(
new VectorBackedQEQueue(MaxStorageForEvents));
// see QEQueue docs for reason of +1
CHECK_EQUAL(MaxStorageForEvents + 1, underTest->capacity());
}
TEST(BackedQueueTests, can_create_array_backed_qequeue)
{
auto underTest =
std::unique_ptr<ArrayBackedQEQueue<10>>(new ArrayBackedQEQueue<10>());
}
TEST(BackedQueueTests,
array_backed_qequeue_reports_size_plus_one_same_as_qequeue)
{
constexpr uint16_t MaxStorageForEvents = 10;
auto underTest = std::unique_ptr<ArrayBackedQEQueue<MaxStorageForEvents>>(
new ArrayBackedQEQueue<MaxStorageForEvents>());
// see QEQueue docs for reason of +1
CHECK_EQUAL(MaxStorageForEvents + 1, underTest->capacity());
}
TEST(BackedQueueTests, can_create_static_allocated_array_backed_qequeue)
{
constexpr uint16_t MaxStorageForEvents = 22;
using ArrayTestType = ArrayBackedQEQueue<MaxStorageForEvents>;
static ArrayTestType underTest;
// see QEQueue docs for reason of +1
CHECK_EQUAL(MaxStorageForEvents + 1, underTest.capacity());
}
TEST(BackedQueueTests, can_push_up_to_max_events)
{
constexpr uint16_t MaxStorageForEvents = 2;
using ArrayTestType = ArrayBackedQEQueue<MaxStorageForEvents>;
auto underTest = std::unique_ptr<ArrayTestType>(new ArrayTestType());
// fill up the queue
static QP::QEvt testEvent {5, 0, 0};
for (size_t i = 0; i < underTest->capacity(); ++i) {
underTest->post(&testEvent, QP::QF::NO_MARGIN, 0);
}
// confirm full
CHECK_FALSE(underTest->isEmpty());
CHECK_EQUAL(0, underTest->getNFree());
// empty the queue
for (size_t i = 0; i < underTest->capacity(); ++i) {
underTest->get(0);
}
// confirm empty
CHECK_TRUE(underTest->isEmpty());
CHECK_EQUAL(MaxStorageForEvents + 1, underTest->getNFree());
}