From 919fc7a8141ab3f3706083f099e3ab36bf84f798 Mon Sep 17 00:00:00 2001 From: Lenny Maiorani Date: Sat, 17 Oct 2020 09:07:44 -0400 Subject: [PATCH] CircularQueue: Ensure constructor does not construct any values Problem: - There is no test which guarantees the CircularQueue does not construct any objects of the value type. The goal is to have uninitialized memory which can be used. Solution: - Add a test requiring that the constructor of the value type is never called. --- AK/Tests/TestCircularQueue.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/AK/Tests/TestCircularQueue.cpp b/AK/Tests/TestCircularQueue.cpp index 65425aa1fb..53a7803b68 100644 --- a/AK/Tests/TestCircularQueue.cpp +++ b/AK/Tests/TestCircularQueue.cpp @@ -75,4 +75,16 @@ TEST_CASE(complex_type_clear) EXPECT_EQ(strings.size(), 0u); } +struct ConstructorCounter { + static unsigned s_num_constructor_calls; + ConstructorCounter() { ++s_num_constructor_calls; } +}; +unsigned ConstructorCounter::s_num_constructor_calls = 0; + +TEST_CASE(should_not_call_value_type_constructor_when_created) +{ + CircularQueue queue; + EXPECT_EQ(0u, ConstructorCounter::s_num_constructor_calls); +} + TEST_MAIN(CircularQueue)