diff options
| author | Connor McLaughlin <stenzek@gmail.com> | 2019-10-01 23:42:16 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-01 23:42:16 +1000 |
| commit | b319f823bff0d64b46ccc399d3fdb93e9f3571bc (patch) | |
| tree | 622a47e9485fe8072be1cb7389e2654fafc6f341 /Source/UnitTests/Common/FixedSizeQueueTest.cpp | |
| parent | 66433cef6fd58d5de1a10e1ec99656f730d6ce16 (diff) | |
| parent | 6bfa4fa64306d2fc882282ea147f2b22afd4a9cb (diff) | |
Merge pull request #8337 from CookiePLMonster/log-widget-improvements
Log widget improvements
Diffstat (limited to 'Source/UnitTests/Common/FixedSizeQueueTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/FixedSizeQueueTest.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/FixedSizeQueueTest.cpp b/Source/UnitTests/Common/FixedSizeQueueTest.cpp index 1461ad672f..a6f6d7e833 100644 --- a/Source/UnitTests/Common/FixedSizeQueueTest.cpp +++ b/Source/UnitTests/Common/FixedSizeQueueTest.cpp @@ -31,3 +31,85 @@ TEST(FixedSizeQueue, Simple) EXPECT_EQ(0u, q.size()); } + +TEST(FixedSizeQueue, RingBuffer) +{ + // Testing if queue works when used as a ring buffer + FixedSizeQueue<int, 5> q; + + EXPECT_EQ(0u, q.size()); + + q.push(0); + q.push(1); + q.push(2); + q.push(3); + q.push(4); + q.push(5); + + EXPECT_EQ(5u, q.size()); + EXPECT_EQ(1, q.pop_front()); + + EXPECT_EQ(4u, q.size()); +} + +// Local classes cannot have static fields, +// therefore this has to be declared in global scope. +class NonTrivialTypeTestData +{ +public: + static inline int num_objects = 0; + static inline int total_constructed = 0; + static inline int default_constructed = 0; + static inline int total_destructed = 0; + + NonTrivialTypeTestData() + { + num_objects++; + total_constructed++; + default_constructed++; + } + + NonTrivialTypeTestData(int /*val*/) + { + num_objects++; + total_constructed++; + } + + ~NonTrivialTypeTestData() + { + num_objects--; + total_destructed++; + } +}; + +TEST(FixedSizeQueue, NonTrivialTypes) +{ + // Testing if construction/destruction of non-trivial types happens as expected + FixedSizeQueue<NonTrivialTypeTestData, 2> q; + + EXPECT_EQ(0u, q.size()); + + EXPECT_EQ(2, NonTrivialTypeTestData::num_objects); + EXPECT_EQ(2, NonTrivialTypeTestData::total_constructed); + EXPECT_EQ(2, NonTrivialTypeTestData::default_constructed); + EXPECT_EQ(0, NonTrivialTypeTestData::total_destructed); + + q.emplace(4); + q.emplace(6); + q.emplace(8); + + EXPECT_EQ(2, NonTrivialTypeTestData::num_objects); + EXPECT_EQ(2 + 3, NonTrivialTypeTestData::total_constructed); + EXPECT_EQ(2, NonTrivialTypeTestData::default_constructed); + EXPECT_EQ(3, NonTrivialTypeTestData::total_destructed); + EXPECT_EQ(2u, q.size()); + + q.pop(); + q.pop(); + + EXPECT_EQ(2, NonTrivialTypeTestData::num_objects); + EXPECT_EQ(2 + 3 + 2, NonTrivialTypeTestData::total_constructed); + EXPECT_EQ(2 + 2, NonTrivialTypeTestData::default_constructed); + EXPECT_EQ(3 + 2, NonTrivialTypeTestData::total_destructed); + EXPECT_EQ(0u, q.size()); +} |
