diff --git a/include/internal/TestCPPAssertions.h b/include/internal/TestCPPAssertions.h index 8cdccce..5b3bc34 100644 --- a/include/internal/TestCPPAssertions.h +++ b/include/internal/TestCPPAssertions.h @@ -301,10 +301,9 @@ namespace TestCPP { const string& failureMessage ) { - static constexpr const char* nullAssertionMessage = "Null assertion failed!"; - bool null = ptr == nullptr; if (!null) { + static constexpr const char* nullAssertionMessage = "Null assertion failed!"; return logTestFailure( "", "", nullAssertionMessage, @@ -321,10 +320,9 @@ namespace TestCPP { const string& failureMessage ) { - static constexpr const char* notNullAssertionMessage = "Not Null assertion failed!"; - bool notNull = ptr != nullptr; if (!notNull) { + static constexpr const char* notNullAssertionMessage = "Not Null assertion failed!"; return logTestFailure( "", "", notNullAssertionMessage, diff --git a/include/internal/TestCPPTestCase.h b/include/internal/TestCPPTestCase.h index f092f33..2edfe26 100644 --- a/include/internal/TestCPPTestCase.h +++ b/include/internal/TestCPPTestCase.h @@ -143,7 +143,7 @@ namespace TestCPP { * TestCase. * @param o The test case from which to make a copy. */ - TestCase (TestCase& o); + TestCase (const TestCase& o); /** * @brief Construct a TestCase by moving all data from another @@ -157,7 +157,7 @@ namespace TestCPP { * @param rhs The test case to copy from. * @return A reference to the new TestCase copy. */ - TestCase& operator= (TestCase& rhs); + TestCase& operator= (const TestCase& rhs); /** * @brief Move a TestCase into another TestCase. @@ -289,7 +289,7 @@ namespace TestCPP { * @param out The stream to write the test failure reason to. * @param reason The test failure reason to write. */ - void logFailure (ostream& out, string& reason); + void logFailure (ostream& out, const string& reason); /** * @brief If a test encounters an error while running, this * function will be called to log the test error. diff --git a/src/TestCPPTestCase.cpp b/src/TestCPPTestCase.cpp index c4c3d43..c032288 100644 --- a/src/TestCPPTestCase.cpp +++ b/src/TestCPPTestCase.cpp @@ -142,7 +142,7 @@ namespace TestCPP { this->option = opt; } - TestCase::TestCase (TestCase& o) { + TestCase::TestCase (const TestCase& o) { this->outCompareOption(o.option); this->setNotifyPassed(o.notifyTestPassed); @@ -231,7 +231,7 @@ namespace TestCPP { } } - TestCase& TestCase::operator= (TestCase& rhs) { + TestCase& TestCase::operator= (const TestCase& rhs) { this->outCompareOption(rhs.option); this->setNotifyPassed(rhs.notifyTestPassed); @@ -289,7 +289,7 @@ namespace TestCPP { return this->lastRunTime; } - void TestCase::logFailure(ostream& out, string& reason) { + void TestCase::logFailure(ostream& out, const string& reason) { out << fixed; out << setprecision(TCPPNum::TIME_PRECISION); out << TCPPStr::TEST << this->testName << TCPPStr::FAIL diff --git a/test/include/TestCase/TestCaseSuite.h b/test/include/TestCase/TestCaseSuite.h index 18b1e5a..ba306ad 100644 --- a/test/include/TestCase/TestCaseSuite.h +++ b/test/include/TestCase/TestCaseSuite.h @@ -13,6 +13,14 @@ namespace TestCPP { "Case construction Test", function(TestCaseTests::TestConstructCase) ), + make_tuple( + "Case assignment Test", + function(TestCaseTests::TestAssignTestCase) + ), + make_tuple( + "Case move assignment Test", + function(TestCaseTests::TestMoveAssignTestCase) + ), make_tuple( "Case runner Test", function(TestCaseTests::TestTestCaseGo) diff --git a/test/include/TestCase/TestCaseTests.h b/test/include/TestCase/TestCaseTests.h index 35ca62a..9832a98 100644 --- a/test/include/TestCase/TestCaseTests.h +++ b/test/include/TestCase/TestCaseTests.h @@ -5,6 +5,8 @@ namespace TestCPP { namespace Testing { namespace TestCaseTests { void TestConstructCase (); + void TestAssignTestCase (); + void TestMoveAssignTestCase (); void TestTestCaseGo (); void TestTestCaseGoThrowStr (); void TestTestCaseGoThrowChr (); diff --git a/test/src/TestCase/TestCaseTests.cpp b/test/src/TestCase/TestCaseTests.cpp index e6fe31d..b880166 100644 --- a/test/src/TestCase/TestCaseTests.cpp +++ b/test/src/TestCase/TestCaseTests.cpp @@ -39,6 +39,59 @@ namespace TestCPP { parameterVariationTestChunks(); } + /** + * Targets various types of non-move assignments. + */ + void TestAssignTestCase() { + const auto test = unique_ptr(new TestCase( + "Assignment case Test - const TestCase", + function([]() {}) + )); + const auto test2 = unique_ptr(new TestCase( + "Assignment case Test 2 - const TestCase", + function([]() {}) + )); + + Assertions::assertTrue( + test->go(), + "Should have succeeded basic no-op test!" + ); + + const TestCase& testCopy = *test; + TestCase testCopy2 = *test2; + testCopy2 = testCopy; + + Assertions::assertTrue( + testCopy2.go(), + "Should have succeeded basic no-op test!" + ); + } + + void TestMoveAssignTestCase() { + auto test = unique_ptr(new TestCase( + "Move Assignment case Test - const TestCase", + function([]() {}) + )); + auto test2 = unique_ptr(new TestCase( + "Move Assignment case Test 2 - const TestCase", + function([]() {}) + )); + + Assertions::assertTrue( + test->go(), + "Should have succeeded basic no-op test!" + ); + + TestCase tempCpy = *test; + *test = std::move(*test2); + *test2 = std::move(tempCpy); + + Assertions::assertTrue( + test->go(), + "Should have succeeded basic no-op test!" + ); + } + void TestTestCaseGo () { auto test = unique_ptr(new TestCase( "SUB-TEST TestCaseGo case Test",