/* * Copyright 2023, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #include "StringUtilsTest.h" #include #include #include #include "StringUtils.h" StringUtilsTest::StringUtilsTest() { } StringUtilsTest::~StringUtilsTest() { } void StringUtilsTest::TestStartInSituTrimSpaceAndControl() { BString string = "\t\n Tonic Water"; // ---------------------- StringUtils::InSituTrimSpaceAndControl(string); // ---------------------- const BString expected = "Tonic Water"; CPPUNIT_ASSERT_EQUAL(expected, string); } void StringUtilsTest::TestEndInSituTrimSpaceAndControl() { BString string = "Tonic Water \x05\t"; // ---------------------- StringUtils::InSituTrimSpaceAndControl(string); // ---------------------- const BString expected = "Tonic Water"; CPPUNIT_ASSERT_EQUAL(expected, string); } void StringUtilsTest::TestStartAndEndInSituTrimSpaceAndControl() { BString string = "\x01Tonic Water\x02"; // ---------------------- StringUtils::InSituTrimSpaceAndControl(string); // ---------------------- const BString expected = "Tonic Water"; CPPUNIT_ASSERT_EQUAL(expected, string); } void StringUtilsTest::TestNoTrimInSituTrimSpaceAndControl() { BString string = "Tonic Water"; // ---------------------- StringUtils::InSituTrimSpaceAndControl(string); // ---------------------- const BString expected = "Tonic Water"; CPPUNIT_ASSERT_EQUAL(expected, string); } void StringUtilsTest::TestInSituStripSpaceAndControl() { BString string = "\x01 To\tnic Wa\nter "; // ---------------------- StringUtils::InSituTrimSpaceAndControl(string); // ---------------------- const BString expected = "TonicWater"; // note intervening space also removed CPPUNIT_ASSERT_EQUAL(expected, string); } void StringUtilsTest::TestNoInSituStripSpaceAndControl() { BString string = "Tonic Water"; // ---------------------- StringUtils::InSituStripSpaceAndControl(string); // ---------------------- const BString expected = "Tonic Water"; CPPUNIT_ASSERT_EQUAL(expected, string); } /*static*/ void StringUtilsTest::AddTests(BTestSuite& parent) { CppUnit::TestSuite& suite = *new CppUnit::TestSuite("StringUtilsTest"); suite.addTest( new CppUnit::TestCaller( "StringUtilsTest::TestStartInSituTrimSpaceAndControl", &StringUtilsTest::TestStartInSituTrimSpaceAndControl)); suite.addTest( new CppUnit::TestCaller( "StringUtilsTest::TestEndInSituTrimSpaceAndControl", &StringUtilsTest::TestEndInSituTrimSpaceAndControl)); suite.addTest( new CppUnit::TestCaller( "StringUtilsTest::TestStartAndEndInSituTrimSpaceAndControl", &StringUtilsTest::TestStartAndEndInSituTrimSpaceAndControl)); suite.addTest( new CppUnit::TestCaller( "StringUtilsTest::TestNoTrimInSituTrimSpaceAndControl", &StringUtilsTest::TestNoTrimInSituTrimSpaceAndControl)); suite.addTest( new CppUnit::TestCaller( "StringUtilsTest::TestNoInSituStripSpaceAndControl", &StringUtilsTest::TestNoInSituStripSpaceAndControl)); suite.addTest( new CppUnit::TestCaller( "StringUtilsTest::TestInSituStripSpaceAndControl", &StringUtilsTest::TestInSituStripSpaceAndControl)); parent.addTest("StringUtilsTest", &suite); }