diff --git a/application/argumentparser.cpp b/application/argumentparser.cpp index f2ba80d..da5f5ce 100644 --- a/application/argumentparser.cpp +++ b/application/argumentparser.cpp @@ -251,7 +251,7 @@ void ArgumentReader::read(ArgumentVector &args) ++index, ++argv, argDenotation = nullptr; break; case UnknownArgumentBehavior::Fail: - throw Failure("The specified argument \"" % string(*argv) + "\" is unknown and will be ignored."); + throw Failure("The specified argument \""s % *argv + "\" is unknown and will be ignored."s); } } } // if(!matchingArg) @@ -1123,10 +1123,10 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args) for(const Argument *arg : args) { const auto occurrences = arg->occurrences(); if(arg->isParentPresent() && occurrences > arg->maxOccurrences()) { - throw Failure("The argument \"" % string(arg->name()) % "\" mustn't be specified more than " % arg->maxOccurrences() + (arg->maxOccurrences() == 1 ? " time." : " times.")); + throw Failure("The argument \""s % arg->name() % "\" mustn't be specified more than "s % arg->maxOccurrences() + (arg->maxOccurrences() == 1 ? " time."s : " times."s)); } if(arg->isParentPresent() && occurrences < arg->minOccurrences()) { - throw Failure("The argument \"" % string(arg->name()) % "\" must be specified at least " % arg->minOccurrences() + (arg->minOccurrences() == 1 ? " time." : " times.")); + throw Failure("The argument \""s % arg->name() % "\" must be specified at least "s % arg->minOccurrences() + (arg->minOccurrences() == 1 ? " time."s : " times."s)); } Argument *conflictingArgument = nullptr; if(arg->isMainArgument()) { @@ -1137,7 +1137,7 @@ void ArgumentParser::checkConstraints(const ArgumentVector &args) conflictingArgument = arg->conflictsWithArgument(); } if(conflictingArgument) { - throw Failure("The argument \"" % string(conflictingArgument->name()) % "\" can not be combined with \"" + arg->name() + "\"."); + throw Failure("The argument \""s % conflictingArgument->name() % "\" can not be combined with \""s + arg->name() + "\"."s); } for(size_t i = 0; i != occurrences; ++i) { if(!arg->allRequiredValuesPresent(i)) { diff --git a/chrono/datetime.cpp b/chrono/datetime.cpp index 2f8f10b..a5cdce3 100644 --- a/chrono/datetime.cpp +++ b/chrono/datetime.cpp @@ -104,7 +104,7 @@ DateTime DateTime::fromString(const char *str) } else if(c == '\0') { break; } else { - throw ConversionException(string("unexpected ") + c); + throw ConversionException("unexpected "s + c); } } return DateTime::fromDateAndTime(values[0], values[1], *dayIndex, values[3], values[4], *secondsIndex, miliSeconds); @@ -169,7 +169,7 @@ std::pair DateTime::fromIsoString(const char *str) } else if(c == '\0') { break; } else { - throw ConversionException(string("unexpected \"") % c + '\"'); + throw ConversionException("unexpected \""s % c + '\"'); } } deltaNegative && (*deltaHourIndex = -*deltaHourIndex); diff --git a/tests/argumentparsertests.cpp b/tests/argumentparsertests.cpp index 214b5ac..194a166 100644 --- a/tests/argumentparsertests.cpp +++ b/tests/argumentparsertests.cpp @@ -185,11 +185,12 @@ void ArgumentParserTests::testParsing() throw; } cerr.rdbuf(regularCerrBuffer); - CPPUNIT_ASSERT(!strcmp(buffer.str().data(), "The specified argument \"album\" is unknown and will be ignored.\n" - "The specified argument \"title\" is unknown and will be ignored.\n" - "The specified argument \"diskpos\" is unknown and will be ignored.\n" - "The specified argument \"--files\" is unknown and will be ignored.\n" - "The specified argument \"somefile\" is unknown and will be ignored.\n")); + CPPUNIT_ASSERT_EQUAL("The specified argument \"album\" is unknown and will be ignored.\n"s + "The specified argument \"title\" is unknown and will be ignored.\n"s + "The specified argument \"diskpos\" is unknown and will be ignored.\n"s + "The specified argument \"--files\" is unknown and will be ignored.\n"s + "The specified argument \"somefile\" is unknown and will be ignored.\n"s, + buffer.str()); // none of the arguments should be present now CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent()); CPPUNIT_ASSERT(!displayFileInfoArg.isPresent()); @@ -422,7 +423,7 @@ void ArgumentParserTests::testBashCompletion() reader.read(); parser.printBashCompletion(1, argv1, 0, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=()\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=()\n"s, buffer.str()); // correct operation arg flags buffer.str(string()); @@ -431,7 +432,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv1, argv1 + 1).read(); parser.printBashCompletion(1, argv1, 0, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('set' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('set' )\n"s, buffer.str()); // argument at current cursor position already specified -> the completion should just return the argument const char *const argv2[] = {"set"}; @@ -441,7 +442,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv2, argv2 + 1).read(); parser.printBashCompletion(1, argv2, 0, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('set' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('set' )\n"s, buffer.str()); // advance the cursor position -> the completion should propose the next argument buffer.str(string()); @@ -450,7 +451,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv2, argv2 + 1).read(); parser.printBashCompletion(1, argv2, 1, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('--files' '--values' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('--files' '--values' )\n"s, buffer.str()); // specifying no args should propose all main arguments buffer.str(string()); @@ -459,7 +460,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(nullptr, nullptr).read(); parser.printBashCompletion(0, nullptr, 0, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n"s, buffer.str()); // pre-defined values const char *const argv3[] = {"get", "--fields"}; @@ -469,7 +470,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv3, argv3 + 2).read(); parser.printBashCompletion(2, argv3, 2, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n"s, buffer.str()); // pre-defined values with equation sign, one letter already present const char *const argv4[] = {"set", "--values", "a"}; @@ -479,7 +480,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv4, argv4 + 3).read(); parser.printBashCompletion(3, argv4, 2, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('album=' 'artist=' ); compopt -o nospace\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('album=' 'artist=' ); compopt -o nospace\n"s, buffer.str()); // file names string iniFilePath = TestUtilities::testFilePath("test.ini"); @@ -510,7 +511,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv6, argv6 + 2).read(); parser.printBashCompletion(2, argv6, 1, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('--files' '--values' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('--files' '--values' )\n"s, buffer.str()); // nested sub arguments const char *const argv7[] = {"-i", "--sub", "--"}; @@ -520,7 +521,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv7, argv7 + 3).read(); parser.printBashCompletion(3, argv7, 2, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('--files' '--nested-sub' '--verbose' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('--files' '--nested-sub' '--verbose' )\n"s, buffer.str()); // started pre-defined values with equation sign, one letter already present, last value matches const char *const argv8[] = {"set", "--values", "t"}; @@ -530,7 +531,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv8, argv8 + 3).read(); parser.printBashCompletion(3, argv8, 2, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n"s, buffer.str()); // combined abbreviations const char *const argv9[] = {"-gf"}; @@ -540,7 +541,7 @@ void ArgumentParserTests::testBashCompletion() reader.reset(argv9, argv9 + 1).read(); parser.printBashCompletion(1, argv9, 0, reader); cout.rdbuf(regularCoutBuffer); - CPPUNIT_ASSERT_EQUAL(string("COMPREPLY=('-gf' )\n"), buffer.str()); + CPPUNIT_ASSERT_EQUAL("COMPREPLY=('-gf' )\n"s, buffer.str()); buffer.str(string()); cout.rdbuf(buffer.rdbuf()); diff --git a/tests/chronotests.cpp b/tests/chronotests.cpp index 3972f84..6031230 100644 --- a/tests/chronotests.cpp +++ b/tests/chronotests.cpp @@ -53,11 +53,11 @@ void ChronoTests::testDateTime() CPPUNIT_ASSERT(test1.dayOfWeek() == DayOfWeek::Wednesday); CPPUNIT_ASSERT_EQUAL((31 + 29), test1.dayOfYear()); CPPUNIT_ASSERT(test1.isLeapYear()); - CPPUNIT_ASSERT_EQUAL(string("Wed 2012-02-29 15:34:20.033"), test1.toString(DateTimeOutputFormat::DateTimeAndShortWeekday)); + CPPUNIT_ASSERT_EQUAL("Wed 2012-02-29 15:34:20.033"s, test1.toString(DateTimeOutputFormat::DateTimeAndShortWeekday)); // test fromTimeStamp() const auto test2 = DateTime::fromTimeStampGmt(1453840331); - CPPUNIT_ASSERT(test2.toString(DateTimeOutputFormat::DateTimeAndShortWeekday) == "Tue 2016-01-26 20:32:11"); + CPPUNIT_ASSERT_EQUAL("Tue 2016-01-26 20:32:11"s, test2.toString(DateTimeOutputFormat::DateTimeAndShortWeekday)); // test whether ConversionException() is thrown when invalid values are specified CPPUNIT_ASSERT_THROW(DateTime::fromDateAndTime(2013, 2, 29, 15, 34, 20, 33), ConversionException); @@ -67,10 +67,10 @@ void ChronoTests::testDateTime() // test fromString()/toString() CPPUNIT_ASSERT_EQUAL(test1, DateTime::fromString("2012-02-29 15:34:20.033")); - CPPUNIT_ASSERT_EQUAL(string("2012-02-29 15:34:20.033"), test1.toString(DateTimeOutputFormat::DateAndTime, false)); + CPPUNIT_ASSERT_EQUAL("2012-02-29 15:34:20.033"s, test1.toString(DateTimeOutputFormat::DateAndTime, false)); CPPUNIT_ASSERT_THROW(TimeSpan::fromString("2012-02-29 15:34:34:20.033"), ConversionException); const auto test3 = DateTime::fromIsoString("2016-08-29T21:32:31.125+02:00"); - CPPUNIT_ASSERT_EQUAL(string("2016-08-29T21:32:31.125+02:00"), test3.first.toIsoString(test3.second)); + CPPUNIT_ASSERT_EQUAL("2016-08-29T21:32:31.125+02:00"s, test3.first.toIsoString(test3.second)); } /*! @@ -89,7 +89,7 @@ void ChronoTests::testTimeSpan() CPPUNIT_ASSERT(test1.totalDays() > 3.0 && test1.totalDays() < 4.0); CPPUNIT_ASSERT(test1.totalHours() > (2 * 24 + 34) && test1.totalHours() < (2 * 24 + 35)); CPPUNIT_ASSERT(test1.totalMinutes() > (2 * 24 * 60 + 34 * 60 + 53) && test1.totalHours() < (2 * 24 * 60 + 34 * 60 + 54)); - CPPUNIT_ASSERT(test1.toString(TimeSpanOutputFormat::WithMeasures, false) == "3 d 10 h 53 min 2 s 500 ms"); + CPPUNIT_ASSERT_EQUAL("3 d 10 h 53 min 2 s 500 ms"s, test1.toString(TimeSpanOutputFormat::WithMeasures, false)); // test whether ConversionException() is thrown when invalid values are specified CPPUNIT_ASSERT_THROW(TimeSpan::fromString("2:34a:53:32.5"), ConversionException); diff --git a/tests/conversiontests.cpp b/tests/conversiontests.cpp index b10ace2..2bc1849 100644 --- a/tests/conversiontests.cpp +++ b/tests/conversiontests.cpp @@ -263,19 +263,19 @@ void ConversionTests::testStringConversions() CPPUNIT_ASSERT(interpretIntegerAsString(0x54455354) == "TEST"); // splitString() / joinStrings() - auto splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s", ",", EmptyPartsTreat::Keep), " ", false, "(", ")"); - CPPUNIT_ASSERT(splitJoinTest == "() (a) () (ab) (ABC) (s)"); - splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s", ",", EmptyPartsTreat::Keep), " ", true, "(", ")"); - CPPUNIT_ASSERT(splitJoinTest == "(a) (ab) (ABC) (s)"); - splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s", ",", EmptyPartsTreat::Omit), " ", false, "(", ")"); - CPPUNIT_ASSERT(splitJoinTest == "(a) (ab) (ABC) (s)"); - splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s", ",", EmptyPartsTreat::Merge), " ", false, "(", ")"); - CPPUNIT_ASSERT(splitJoinTest == "(a,ab) (ABC) (s)"); + string splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Keep), " "s, false, "("s, ")"s); + CPPUNIT_ASSERT_EQUAL("() (a) () (ab) (ABC) (s)"s, splitJoinTest); + splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Keep), " "s, true, "("s, ")"s); + CPPUNIT_ASSERT_EQUAL("(a) (ab) (ABC) (s)"s, splitJoinTest); + splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Omit), " "s, false, "("s, ")"s); + CPPUNIT_ASSERT_EQUAL("(a) (ab) (ABC) (s)"s, splitJoinTest); + splitJoinTest = joinStrings(splitString >(",a,,ab,ABC,s"s, ","s, EmptyPartsTreat::Merge), " "s, false, "("s, ")"s); + CPPUNIT_ASSERT_EQUAL("(a,ab) (ABC) (s)"s, splitJoinTest); // findAndReplace() string findReplaceTest("findAndReplace()"); findAndReplace(findReplaceTest, "And", "Or"); - CPPUNIT_ASSERT(findReplaceTest == "findOrReplace()"); + CPPUNIT_ASSERT_EQUAL("findOrReplace()"s, findReplaceTest); // startsWith() CPPUNIT_ASSERT(!startsWith(findReplaceTest, "findAnd")); @@ -312,8 +312,8 @@ void ConversionTests::testStringBuilder() CPPUNIT_ASSERT_EQUAL(string("foobarfoo2bar2"), tupleToString(string("foo") % "bar" % string("foo2") % "bar2")); // construction of string-tuple and final conversion to string works - CPPUNIT_ASSERT_EQUAL_MESSAGE("result can be passed to any function taking a std::string", string("123456789"), functionTakingString("12" % string("34") % '5' % 67 + "89")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("result can be passed to any function taking a std::string"s, "123456789"s, functionTakingString("12" % string("34") % '5' % 67 + "89")); constexpr double velocityExample = 27.0; - CPPUNIT_ASSERT_EQUAL_MESSAGE("real-word example", string("velocity: 27 km/h (7.5 m/s)"), functionTakingString("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)")); - CPPUNIT_ASSERT_EQUAL_MESSAGE("regular + operator still works (no problems with ambiguity)", string("regular + still works"), string("regular") + " + still works"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("real-word example"s, "velocity: 27 km/h (7.5 m/s)"s, functionTakingString("velocity: " % numberToString(velocityExample) % " km/h (" % numberToString(velocityExample / 3.6) + " m/s)")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("regular + operator still works (no problems with ambiguity)"s, "regular + still works"s, "regular"s + " + still works"); } diff --git a/tests/iotests.cpp b/tests/iotests.cpp index d523239..0d9b990 100644 --- a/tests/iotests.cpp +++ b/tests/iotests.cpp @@ -229,8 +229,8 @@ void IoTests::testBitReader() */ void IoTests::testPathUtilities() { - CPPUNIT_ASSERT(fileName("/usr/lib/libc++utilities.so") == "libc++utilities.so"); - CPPUNIT_ASSERT(directory("/usr/lib/libc++utilities.so") == "/usr/lib/"); + CPPUNIT_ASSERT_EQUAL("libc++utilities.so"s, fileName("/usr/lib/libc++utilities.so")); + CPPUNIT_ASSERT_EQUAL("/usr/lib/"s, directory("/usr/lib/libc++utilities.so")); CPPUNIT_ASSERT(directory("libc++utilities.so").empty()); string invalidPath("lib/c++uti*lities.so?"); removeInvalidChars(invalidPath);