Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions include/internal/TestCPPAssertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions include/internal/TestCPPTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/TestCPPTestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/include/TestCase/TestCaseSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ namespace TestCPP {
"Case construction Test",
function<void()>(TestCaseTests::TestConstructCase)
),
make_tuple(
"Case assignment Test",
function<void()>(TestCaseTests::TestAssignTestCase)
),
make_tuple(
"Case move assignment Test",
function<void()>(TestCaseTests::TestMoveAssignTestCase)
),
make_tuple(
"Case runner Test",
function<void()>(TestCaseTests::TestTestCaseGo)
Expand Down
2 changes: 2 additions & 0 deletions test/include/TestCase/TestCaseTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace TestCPP {
namespace Testing {
namespace TestCaseTests {
void TestConstructCase ();
void TestAssignTestCase ();
void TestMoveAssignTestCase ();
void TestTestCaseGo ();
void TestTestCaseGoThrowStr ();
void TestTestCaseGoThrowChr ();
Expand Down
53 changes: 53 additions & 0 deletions test/src/TestCase/TestCaseTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,59 @@ namespace TestCPP {
parameterVariationTestChunks();
}

/**
* Targets various types of non-move assignments.
*/
void TestAssignTestCase() {
const auto test = unique_ptr<TestCase>(new TestCase(
"Assignment case Test - const TestCase",
function<void()>([]() {})
));
const auto test2 = unique_ptr<TestCase>(new TestCase(
"Assignment case Test 2 - const TestCase",
function<void()>([]() {})
));

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<TestCase>(new TestCase(
"Move Assignment case Test - const TestCase",
function<void()>([]() {})
));
auto test2 = unique_ptr<TestCase>(new TestCase(
"Move Assignment case Test 2 - const TestCase",
function<void()>([]() {})
));

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<TestCase>(new TestCase(
"SUB-TEST TestCaseGo case Test",
Expand Down