diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,5 +1,3 @@ -remove_definitions(-DQT_NO_CAST_FROM_ASCII) - include(ECMAddTests) include(ConfigureChecks.cmake) #configure checks for QFileSystemWatcher diff --git a/autotests/desktoptojsontest.cpp b/autotests/desktoptojsontest.cpp --- a/autotests/desktoptojsontest.cpp +++ b/autotests/desktoptojsontest.cpp @@ -81,177 +81,179 @@ QJsonObject expectedResult; QJsonObject kpluginObj; QByteArray input = - // include an insignificant group - "[Some Group]\n" - "Foo=Bar\n" - "\n" - "[Desktop Entry]\n" - // only data inside [Desktop Entry] should be included - "Name=Example\n" - //empty lines - "\n" - " \n" - // make sure translations are included: - "Name[de_DE]=Beispiel\n" - // ignore comments: - "#Comment=Comment\n" - " #Comment=Comment\n" - "Categories=foo;bar;a\\;b\n" - // As the case is significant, the keys Name and NAME are not equivalent: - "CaseSensitive=ABC\n" - "CASESENSITIVE=abc\n" - // Space before and after the equals sign should be ignored: - "SpacesBeforeEq =foo\n" - "SpacesAfterEq= foo\n" - // Space before and after the equals sign should be ignored; the = sign is the actual delimiter. - // TODO: error in spec (spaces before and after the key??) - " SpacesBeforeKey=foo\n" - "SpacesAfterKey =foo\n" - // ignore trailing spaces - "TrailingSpaces=foo \n" - // However spaces in the value are significant: - "SpacesInValue=Hello, World!\n" - // The escape sequences \s, \n, \t, \r, and \\ are supported for values of - // type string and localestring, meaning ASCII space, newline, tab, - // carriage return, and backslash, respectively: - "EscapeSequences=So\\sme esc\\nap\\te se\\\\qu\\re\\\\nces\n" // make sure that the last n is a literal n not a newline! - // the standard keys that are used by plugins, make sure correct types are used: - "X-KDE-PluginInfo-Category=Examples\n" // string key - "X-KDE-PluginInfo-Version=1.0\n" - // The multiple values should be separated by a semicolon and the value of the key - // may be optionally terminated by a semicolon. Trailing empty strings must always - // be terminated with a semicolon. Semicolons in these values need to be escaped using \;. - "X-KDE-PluginInfo-Depends=foo,bar,esc\\,aped\n" // string list key - "X-KDE-ServiceTypes=\n" // empty string list - "X-KDE-PluginInfo-EnabledByDefault=true\n" // bool key - // now start a new group - "[New Group]\n" - "InWrongGroup=true\n"; + // include an insignificant group + "[Some Group]\n" + "Foo=Bar\n" + "\n" + "[Desktop Entry]\n" + // only data inside [Desktop Entry] should be included + "Name=Example\n" + //empty lines + "\n" + " \n" + // make sure translations are included: + "Name[de_DE]=Beispiel\n" + // ignore comments: + "#Comment=Comment\n" + " #Comment=Comment\n" + "Categories=foo;bar;a\\;b\n" + // As the case is significant, the keys Name and NAME are not equivalent: + "CaseSensitive=ABC\n" + "CASESENSITIVE=abc\n" + // Space before and after the equals sign should be ignored: + "SpacesBeforeEq =foo\n" + "SpacesAfterEq= foo\n" + // Space before and after the equals sign should be ignored; the = sign is the actual delimiter. + // TODO: error in spec (spaces before and after the key??) + " SpacesBeforeKey=foo\n" + "SpacesAfterKey =foo\n" + // ignore trailing spaces + "TrailingSpaces=foo \n" + // However spaces in the value are significant: + "SpacesInValue=Hello, World!\n" + // The escape sequences \s, \n, \t, \r, and \\ are supported for values of + // type string and localestring, meaning ASCII space, newline, tab, + // carriage return, and backslash, respectively: + "EscapeSequences=So\\sme esc\\nap\\te se\\\\qu\\re\\\\nces\n" // make sure that the last n is a literal n not a newline! + // the standard keys that are used by plugins, make sure correct types are used: + "X-KDE-PluginInfo-Category=Examples\n" // string key + "X-KDE-PluginInfo-Version=1.0\n" + // The multiple values should be separated by a semicolon and the value of the key + // may be optionally terminated by a semicolon. Trailing empty strings must always + // be terminated with a semicolon. Semicolons in these values need to be escaped using \;. + "X-KDE-PluginInfo-Depends=foo,bar,esc\\,aped\n" // string list key + "X-KDE-ServiceTypes=\n" // empty string list + "X-KDE-PluginInfo-EnabledByDefault=true\n" // bool key + // now start a new group + "[New Group]\n" + "InWrongGroup=true\n"; - expectedResult["Categories"] = QStringLiteral("foo;bar;a\\;b"); - expectedResult["CaseSensitive"] = QStringLiteral("ABC"); - expectedResult["CASESENSITIVE"] = QStringLiteral("abc"); - expectedResult["SpacesBeforeEq"] = QStringLiteral("foo"); - expectedResult["SpacesAfterEq"] = QStringLiteral("foo"); - expectedResult["SpacesBeforeKey"] = QStringLiteral("foo"); - expectedResult["SpacesAfterKey"] = QStringLiteral("foo"); - expectedResult["TrailingSpaces"] = QStringLiteral("foo"); - expectedResult["SpacesInValue"] = QStringLiteral("Hello, World!"); - expectedResult["EscapeSequences"] = QStringLiteral("So me esc\nap\te se\\qu\re\\nces"); - kpluginObj["Name"] = QStringLiteral("Example"); - kpluginObj["Name[de_DE]"] = QStringLiteral("Beispiel"); - kpluginObj["Category"] = QStringLiteral("Examples"); - kpluginObj["Dependencies"] = QJsonArray::fromStringList(QStringList() << "foo" << "bar" << "esc,aped"); - kpluginObj["ServiceTypes"] = QJsonArray::fromStringList(QStringList()); - kpluginObj["EnabledByDefault"] = true; - kpluginObj["Version"] = QStringLiteral("1.0"); + expectedResult[QStringLiteral("Categories")] = QStringLiteral("foo;bar;a\\;b"); + expectedResult[QStringLiteral("CaseSensitive")] = QStringLiteral("ABC"); + expectedResult[QStringLiteral("CASESENSITIVE")] = QStringLiteral("abc"); + expectedResult[QStringLiteral("SpacesBeforeEq")] = QStringLiteral("foo"); + expectedResult[QStringLiteral("SpacesAfterEq")] = QStringLiteral("foo"); + expectedResult[QStringLiteral("SpacesBeforeKey")] = QStringLiteral("foo"); + expectedResult[QStringLiteral("SpacesAfterKey")] = QStringLiteral("foo"); + expectedResult[QStringLiteral("TrailingSpaces")] = QStringLiteral("foo"); + expectedResult[QStringLiteral("SpacesInValue")] = QStringLiteral("Hello, World!"); + expectedResult[QStringLiteral("EscapeSequences")] = QStringLiteral("So me esc\nap\te se\\qu\re\\nces"); + kpluginObj[QStringLiteral("Name")] = QStringLiteral("Example"); + kpluginObj[QStringLiteral("Name[de_DE]")] = QStringLiteral("Beispiel"); + kpluginObj[QStringLiteral("Category")] = QStringLiteral("Examples"); + kpluginObj[QStringLiteral("Dependencies")] = QJsonArray::fromStringList + (QStringList() << QStringLiteral("foo") << QStringLiteral("bar") << QStringLiteral("esc,aped")); + kpluginObj[QStringLiteral("ServiceTypes")] = QJsonArray::fromStringList(QStringList()); + kpluginObj[QStringLiteral("EnabledByDefault")] = true; + kpluginObj[QStringLiteral("Version")] = QStringLiteral("1.0"); QJsonObject compatResult = expectedResult; - compatResult["Name"] = QStringLiteral("Example"); - compatResult["Name[de_DE]"] = QStringLiteral("Beispiel"); - compatResult["X-KDE-PluginInfo-Category"] = QStringLiteral("Examples"); - compatResult["X-KDE-PluginInfo-Version"] = QStringLiteral("1.0"); - compatResult["X-KDE-PluginInfo-Depends"] = QJsonArray::fromStringList(QStringList() << "foo" << "bar" << "esc,aped"); - compatResult["X-KDE-ServiceTypes"] = QJsonArray::fromStringList(QStringList()); - compatResult["X-KDE-PluginInfo-EnabledByDefault"] = true; + compatResult[QStringLiteral("Name")] = QStringLiteral("Example"); + compatResult[QStringLiteral("Name[de_DE]")] = QStringLiteral("Beispiel"); + compatResult[QStringLiteral("X-KDE-PluginInfo-Category")] = QStringLiteral("Examples"); + compatResult[QStringLiteral("X-KDE-PluginInfo-Version")] = QStringLiteral("1.0"); + compatResult[QStringLiteral("X-KDE-PluginInfo-Depends")] = QJsonArray::fromStringList + (QStringList() << QStringLiteral("foo") << QStringLiteral("bar") << QStringLiteral("esc,aped")); + compatResult[QStringLiteral("X-KDE-ServiceTypes")] = QJsonArray::fromStringList(QStringList()); + compatResult[QStringLiteral("X-KDE-PluginInfo-EnabledByDefault")] = true; - expectedResult["KPlugin"] = kpluginObj; + expectedResult[QStringLiteral("KPlugin")] = kpluginObj; QTest::newRow("newFormat") << input << expectedResult << false << QStringList(); QTest::newRow("compatFormat") << input << compatResult << true << QStringList(); // test conversion of a currently existing .desktop file (excluding most of the translations): QByteArray kdevInput = - "[Desktop Entry]\n" - "Type = Service\n" - "Icon=text-x-c++src\n" - "Exec=blubb\n" - "Comment=C/C++ Language Support\n" - "Comment[fr]=Prise en charge du langage C/C++\n" - "Comment[it]=Supporto al linguaggio C/C++\n" - "Name=C++ Support\n" - "Name[fi]=C++-tuki\n" - "Name[fr]=Prise en charge du C++\n" - "GenericName=Language Support\n" - "GenericName[sl]=Podpora jeziku\n" - "ServiceTypes=KDevelop/NonExistentPlugin\n" - "X-KDE-Library=kdevcpplanguagesupport\n" - "X-KDE-PluginInfo-Name=kdevcppsupport\n" - "X-KDE-PluginInfo-Category=Language Support\n" - "X-KDevelop-Version=1\n" - "X-KDevelop-Language=C++\n" - "X-KDevelop-Args=CPP\n" - "X-KDevelop-Interfaces=ILanguageSupport\n" - "X-KDevelop-SupportedMimeTypes=text/x-chdr,text/x-c++hdr,text/x-csrc,text/x-c++src\n" - "X-KDevelop-Mode=NoGUI\n" - "X-KDevelop-LoadMode=AlwaysOn"; + "[Desktop Entry]\n" + "Type = Service\n" + "Icon=text-x-c++src\n" + "Exec=blubb\n" + "Comment=C/C++ Language Support\n" + "Comment[fr]=Prise en charge du langage C/C++\n" + "Comment[it]=Supporto al linguaggio C/C++\n" + "Name=C++ Support\n" + "Name[fi]=C++-tuki\n" + "Name[fr]=Prise en charge du C++\n" + "GenericName=Language Support\n" + "GenericName[sl]=Podpora jeziku\n" + "ServiceTypes=KDevelop/NonExistentPlugin\n" + "X-KDE-Library=kdevcpplanguagesupport\n" + "X-KDE-PluginInfo-Name=kdevcppsupport\n" + "X-KDE-PluginInfo-Category=Language Support\n" + "X-KDevelop-Version=1\n" + "X-KDevelop-Language=C++\n" + "X-KDevelop-Args=CPP\n" + "X-KDevelop-Interfaces=ILanguageSupport\n" + "X-KDevelop-SupportedMimeTypes=text/x-chdr,text/x-c++hdr,text/x-csrc,text/x-c++src\n" + "X-KDevelop-Mode=NoGUI\n" + "X-KDevelop-LoadMode=AlwaysOn"; QJsonParseError e; QJsonObject kdevExpected = QJsonDocument::fromJson("{\n" - " \"GenericName\": \"Language Support\",\n" - " \"GenericName[sl]\": \"Podpora jeziku\",\n" - " \"KPlugin\": {\n" - " \"Category\": \"Language Support\",\n" - " \"Description\": \"C/C++ Language Support\",\n" - " \"Description[fr]\": \"Prise en charge du langage C/C++\",\n" - " \"Description[it]\": \"Supporto al linguaggio C/C++\",\n" - " \"Icon\": \"text-x-c++src\",\n" - " \"Id\": \"kdevcppsupport\",\n" - " \"Name\": \"C++ Support\",\n" - " \"Name[fi]\": \"C++-tuki\",\n" - " \"Name[fr]\": \"Prise en charge du C++\",\n" - " \"ServiceTypes\": [ \"KDevelop/NonExistentPlugin\" ]\n" - " },\n" - " \"X-KDevelop-Args\": \"CPP\",\n" - " \"X-KDevelop-Interfaces\": \"ILanguageSupport\",\n" - " \"X-KDevelop-Language\": \"C++\",\n" - " \"X-KDevelop-LoadMode\": \"AlwaysOn\",\n" - " \"X-KDevelop-Mode\": \"NoGUI\",\n" - " \"X-KDevelop-SupportedMimeTypes\": \"text/x-chdr,text/x-c++hdr,text/x-csrc,text/x-c++src\",\n" - " \"X-KDevelop-Version\": \"1\"\n" - "}\n", &e).object(); + " \"GenericName\": \"Language Support\",\n" + " \"GenericName[sl]\": \"Podpora jeziku\",\n" + " \"KPlugin\": {\n" + " \"Category\": \"Language Support\",\n" + " \"Description\": \"C/C++ Language Support\",\n" + " \"Description[fr]\": \"Prise en charge du langage C/C++\",\n" + " \"Description[it]\": \"Supporto al linguaggio C/C++\",\n" + " \"Icon\": \"text-x-c++src\",\n" + " \"Id\": \"kdevcppsupport\",\n" + " \"Name\": \"C++ Support\",\n" + " \"Name[fi]\": \"C++-tuki\",\n" + " \"Name[fr]\": \"Prise en charge du C++\",\n" + " \"ServiceTypes\": [ \"KDevelop/NonExistentPlugin\" ]\n" + " },\n" + " \"X-KDevelop-Args\": \"CPP\",\n" + " \"X-KDevelop-Interfaces\": \"ILanguageSupport\",\n" + " \"X-KDevelop-Language\": \"C++\",\n" + " \"X-KDevelop-LoadMode\": \"AlwaysOn\",\n" + " \"X-KDevelop-Mode\": \"NoGUI\",\n" + " \"X-KDevelop-SupportedMimeTypes\": \"text/x-chdr,text/x-c++hdr,text/x-csrc,text/x-c++src\",\n" + " \"X-KDevelop-Version\": \"1\"\n" + "}\n", &e).object(); QCOMPARE(e.error, QJsonParseError::NoError); QTest::newRow("kdevcpplanguagesupport no servicetype") << kdevInput << kdevExpected << false << QStringList(); QJsonObject kdevExpectedWithServiceType = QJsonDocument::fromJson("{\n" - " \"GenericName\": \"Language Support\",\n" - " \"GenericName[sl]\": \"Podpora jeziku\",\n" - " \"KPlugin\": {\n" - " \"Category\": \"Language Support\",\n" - " \"Description\": \"C/C++ Language Support\",\n" - " \"Description[fr]\": \"Prise en charge du langage C/C++\",\n" - " \"Description[it]\": \"Supporto al linguaggio C/C++\",\n" - " \"Icon\": \"text-x-c++src\",\n" - " \"Id\": \"kdevcppsupport\",\n" - " \"Name\": \"C++ Support\",\n" - " \"Name[fi]\": \"C++-tuki\",\n" - " \"Name[fr]\": \"Prise en charge du C++\",\n" - " \"ServiceTypes\": [ \"KDevelop/NonExistentPlugin\" ]\n" - " },\n" - " \"X-KDevelop-Args\": \"CPP\",\n" - " \"X-KDevelop-Interfaces\": [\"ILanguageSupport\"],\n" - " \"X-KDevelop-Language\": \"C++\",\n" - " \"X-KDevelop-LoadMode\": \"AlwaysOn\",\n" - " \"X-KDevelop-Mode\": \"NoGUI\",\n" - " \"X-KDevelop-SupportedMimeTypes\": [\"text/x-chdr\", \"text/x-c++hdr\", \"text/x-csrc\", \"text/x-c++src\"],\n" - " \"X-KDevelop-Version\": 1\n" - "}\n", &e).object(); + " \"GenericName\": \"Language Support\",\n" + " \"GenericName[sl]\": \"Podpora jeziku\",\n" + " \"KPlugin\": {\n" + " \"Category\": \"Language Support\",\n" + " \"Description\": \"C/C++ Language Support\",\n" + " \"Description[fr]\": \"Prise en charge du langage C/C++\",\n" + " \"Description[it]\": \"Supporto al linguaggio C/C++\",\n" + " \"Icon\": \"text-x-c++src\",\n" + " \"Id\": \"kdevcppsupport\",\n" + " \"Name\": \"C++ Support\",\n" + " \"Name[fi]\": \"C++-tuki\",\n" + " \"Name[fr]\": \"Prise en charge du C++\",\n" + " \"ServiceTypes\": [ \"KDevelop/NonExistentPlugin\" ]\n" + " },\n" + " \"X-KDevelop-Args\": \"CPP\",\n" + " \"X-KDevelop-Interfaces\": [\"ILanguageSupport\"],\n" + " \"X-KDevelop-Language\": \"C++\",\n" + " \"X-KDevelop-LoadMode\": \"AlwaysOn\",\n" + " \"X-KDevelop-Mode\": \"NoGUI\",\n" + " \"X-KDevelop-SupportedMimeTypes\": [\"text/x-chdr\", \"text/x-c++hdr\", \"text/x-csrc\", \"text/x-c++src\"],\n" + " \"X-KDevelop-Version\": 1\n" + "}\n", &e).object(); QCOMPARE(e.error, QJsonParseError::NoError); const QString kdevServiceTypePath = QFINDTESTDATA("data/servicetypes/fake-kdevelopplugin.desktop"); QVERIFY(!kdevServiceTypePath.isEmpty()); QTest::newRow("kdevcpplanguagesupport with servicetype") << kdevInput << kdevExpectedWithServiceType - << false << QStringList(kdevServiceTypePath); + << false << QStringList(kdevServiceTypePath); // test conversion of the X-KDE-PluginInfo-Author + X-KDE-PluginInfo-Email key: QByteArray authorInput = - "[Desktop Entry]\n" - "Type=Service\n" - "X-KDE-PluginInfo-Author=Foo Bar\n" - "X-KDE-PluginInfo-Email=foo.bar@baz.com\n"; + "[Desktop Entry]\n" + "Type=Service\n" + "X-KDE-PluginInfo-Author=Foo Bar\n" + "X-KDE-PluginInfo-Email=foo.bar@baz.com\n"; QJsonObject authorsExpected = QJsonDocument::fromJson("{\n" - " \"KPlugin\": {\n" - " \"Authors\": [ { \"Name\": \"Foo Bar\", \"Email\": \"foo.bar@baz.com\" } ]\n" - " }\n }\n", &e).object(); + " \"KPlugin\": {\n" + " \"Authors\": [ { \"Name\": \"Foo Bar\", \"Email\": \"foo.bar@baz.com\" } ]\n" + " }\n }\n", &e).object(); QCOMPARE(e.error, QJsonParseError::NoError); QTest::newRow("authors") << authorInput << authorsExpected << false << QStringList(); @@ -275,28 +277,28 @@ // test conversion of kcookiejar.desktop (for some reason the wrong boolean values were committed) QByteArray kcookiejarInput = - "[Desktop Entry]\n" - "Type= Service\n" - "Name=Cookie Jar\n" - "Comment=Stores network cookies\n" - "X-KDE-ServiceTypes=KDEDModule\n" - "X-KDE-Library=kf5/kded/kcookiejar\n" - "X-KDE-DBus-ModuleName=kcookiejar\n" - "X-KDE-Kded-autoload=false\n" - "X-KDE-Kded-load-on-demand=true\n"; + "[Desktop Entry]\n" + "Type= Service\n" + "Name=Cookie Jar\n" + "Comment=Stores network cookies\n" + "X-KDE-ServiceTypes=KDEDModule\n" + "X-KDE-Library=kf5/kded/kcookiejar\n" + "X-KDE-DBus-ModuleName=kcookiejar\n" + "X-KDE-Kded-autoload=false\n" + "X-KDE-Kded-load-on-demand=true\n"; auto kcookiejarResult = QJsonDocument::fromJson( - "{\n" - " \"KPlugin\": {\n" - " \"Description\": \"Stores network cookies\",\n" - " \"Name\": \"Cookie Jar\",\n" - " \"ServiceTypes\": [\n" - " \"KDEDModule\"\n" - " ]\n" - " },\n" - "\"X-KDE-DBus-ModuleName\": \"kcookiejar\",\n" - "\"X-KDE-Kded-autoload\": false,\n" - "\"X-KDE-Kded-load-on-demand\": true\n" - "}\n", &e).object(); + "{\n" + " \"KPlugin\": {\n" + " \"Description\": \"Stores network cookies\",\n" + " \"Name\": \"Cookie Jar\",\n" + " \"ServiceTypes\": [\n" + " \"KDEDModule\"\n" + " ]\n" + " },\n" + "\"X-KDE-DBus-ModuleName\": \"kcookiejar\",\n" + "\"X-KDE-Kded-autoload\": false,\n" + "\"X-KDE-Kded-load-on-demand\": true\n" + "}\n", &e).object(); const QString kdedmoduleServiceType = QFINDTESTDATA("data/servicetypes/fake-kdedmodule.desktop"); QVERIFY(!kdedmoduleServiceType.isEmpty()); QTest::newRow("kcookiejar") << kcookiejarInput << kcookiejarResult << false << QStringList(kdedmoduleServiceType); @@ -322,13 +324,13 @@ QProcess proc; - proc.setProgram(DESKTOP_TO_JSON_EXE); - QStringList arguments = QStringList() << "-i" << inputFile.fileName() << "-o" << output.fileName(); + proc.setProgram(QStringLiteral(DESKTOP_TO_JSON_EXE)); + QStringList arguments = QStringList() << QStringLiteral("-i") << inputFile.fileName() << QStringLiteral("-o") << output.fileName(); if (compatibilityMode) { - arguments << "-c"; + arguments << QStringLiteral("-c"); } foreach(const QString &s, serviceTypes) { - arguments << "-s" << s; + arguments << QStringLiteral("-s") << s; } proc.setArguments(arguments); proc.start(); diff --git a/autotests/kaboutdataapplicationdatatest.cpp b/autotests/kaboutdataapplicationdatatest.cpp --- a/autotests/kaboutdataapplicationdatatest.cpp +++ b/autotests/kaboutdataapplicationdatatest.cpp @@ -68,7 +68,7 @@ QCOMPARE(applicationAboutData.desktopFileName(), QLatin1String(DesktopFileName)); // now set some new KAboutData, with different values - KAboutData aboutData2(AppName2, QLatin1String(ProgramName2), Version2); + KAboutData aboutData2(QString::fromLatin1(AppName2), QString::fromLatin1(ProgramName2), QString::fromLatin1(Version2)); aboutData2.setOrganizationDomain(OrganizationDomain2); aboutData2.setDesktopFileName(QLatin1String(DesktopFileName2)); diff --git a/autotests/kaboutdatatest.cpp b/autotests/kaboutdatatest.cpp --- a/autotests/kaboutdatatest.cpp +++ b/autotests/kaboutdatatest.cpp @@ -24,6 +24,7 @@ #include #include #include +#include class KAboutDataTest : public QObject { @@ -61,13 +62,13 @@ void KAboutDataTest::testLongFormConstructorWithDefaults() { - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::Unknown); - QCOMPARE(aboutData.componentName(), QLatin1String(AppName)); - QCOMPARE(aboutData.productName(), QLatin1String(AppName)); + QCOMPARE(aboutData.componentName(), QString::fromLatin1(AppName)); + QCOMPARE(aboutData.productName(), QString::fromLatin1(AppName)); QCOMPARE(aboutData.displayName(), QLatin1String(ProgramName)); - QCOMPARE(aboutData.programIconName(), QLatin1String(AppName)); + QCOMPARE(aboutData.programIconName(), QString::fromLatin1(AppName)); QCOMPARE(aboutData.programLogo(), QVariant()); QCOMPARE(aboutData.organizationDomain(), QString::fromLatin1("kde.org")); QCOMPARE(aboutData.version(), QString::fromLatin1(Version)); @@ -78,15 +79,15 @@ QVERIFY(aboutData.translators().isEmpty()); QCOMPARE(aboutData.otherText(), QString()); QCOMPARE(aboutData.licenses().count(), 1); -// We don't know the default text, do we? -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); + // We don't know the default text, do we? + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::ShortName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::FullName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); QCOMPARE(aboutData.copyrightStatement(), QString()); - QCOMPARE(aboutData.shortDescription(), QLatin1String(ShortDescription)); + QCOMPARE(aboutData.shortDescription(), (QLatin1String(ShortDescription))); QCOMPARE(aboutData.customAuthorPlainText(), QString()); QCOMPARE(aboutData.customAuthorRichText(), QString()); QVERIFY(!aboutData.customAuthorTextEnabled()); @@ -96,10 +97,10 @@ void KAboutDataTest::testLongFormConstructor() { - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::Unknown, QLatin1String(CopyrightStatement), QLatin1String(Text), - HomePageAddress, BugsEmailAddress); + QString::fromLatin1(HomePageAddress), QString::fromLatin1(BugsEmailAddress)); QCOMPARE(aboutData.componentName(), QLatin1String(AppName)); QCOMPARE(aboutData.productName(), QLatin1String(AppName)); @@ -113,14 +114,14 @@ QVERIFY(aboutData.authors().isEmpty()); QVERIFY(aboutData.credits().isEmpty()); QVERIFY(aboutData.translators().isEmpty()); - QCOMPARE(aboutData.otherText(), QString::fromLatin1(Text)); + QCOMPARE(aboutData.otherText(), QLatin1String(Text)); QCOMPARE(aboutData.licenses().count(), 1); -// We don't know the default text, do we? -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); + // We don't know the default text, do we? + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::ShortName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::FullName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); QCOMPARE(aboutData.copyrightStatement(), QLatin1String(CopyrightStatement)); QCOMPARE(aboutData.shortDescription(), QLatin1String(ShortDescription)); @@ -132,24 +133,24 @@ // We support http and https protocols on the homepage address, ensure they // give the same org. domain and desktop file name. - KAboutData aboutDataSecure(AppName, QLatin1String(ProgramName), Version, - QLatin1String(ShortDescription), KAboutLicense::Unknown, - QLatin1String(CopyrightStatement), QLatin1String(Text), - HomePageSecure, BugsEmailAddress); + KAboutData aboutDataSecure(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), + QLatin1String(ShortDescription), KAboutLicense::Unknown, + QLatin1String(CopyrightStatement), QLatin1String(Text), + QString::fromLatin1(HomePageSecure), QString::fromLatin1(BugsEmailAddress)); QCOMPARE(aboutDataSecure.componentName(), QLatin1String(AppName)); QCOMPARE(aboutDataSecure.productName(), QLatin1String(AppName)); QCOMPARE(aboutDataSecure.organizationDomain(), QString::fromLatin1(OrganizationDomain)); QCOMPARE(aboutDataSecure.desktopFileName(), QStringLiteral("where.no.app")); } void KAboutDataTest::testShortFormConstructor() { - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version); + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version)); - QCOMPARE(aboutData.componentName(), QLatin1String(AppName)); - QCOMPARE(aboutData.productName(), QLatin1String(AppName)); + QCOMPARE(aboutData.componentName(), QString::fromLatin1(AppName)); + QCOMPARE(aboutData.productName(), QString::fromLatin1(AppName)); QCOMPARE(aboutData.displayName(), QLatin1String(ProgramName)); - QCOMPARE(aboutData.programIconName(), QLatin1String(AppName)); + QCOMPARE(aboutData.programIconName(), QString::fromLatin1(AppName)); QCOMPARE(aboutData.programLogo(), QVariant()); QCOMPARE(aboutData.organizationDomain(), QString::fromLatin1("kde.org")); QCOMPARE(aboutData.version(), QString::fromLatin1(Version)); @@ -160,12 +161,12 @@ QVERIFY(aboutData.translators().isEmpty()); QCOMPARE(aboutData.otherText(), QString()); QCOMPARE(aboutData.licenses().count(), 1); -// We don't know the default text, do we? -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); + // We don't know the default text, do we? + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::ShortName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::FullName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); QCOMPARE(aboutData.copyrightStatement(), QString()); QCOMPARE(aboutData.shortDescription(), QString()); @@ -178,17 +179,17 @@ void KAboutDataTest::testKAboutDataOrganizationDomain() { - KAboutData data("app", QLatin1String("program"), "version", + KAboutData data(QString::fromLatin1("app"), QLatin1String("program"), QString::fromLatin1("version"), QLatin1String("description"), KAboutLicense::LGPL, QLatin1String("copyright"), QLatin1String("hello world"), - "http://www.koffice.org"); + QStringLiteral("http://www.koffice.org")); QCOMPARE(data.organizationDomain(), QString::fromLatin1("koffice.org")); QCOMPARE(data.desktopFileName(), QStringLiteral("org.koffice.app")); - KAboutData data2("app", QLatin1String("program"), "version", + KAboutData data2(QString::fromLatin1("app"), QLatin1String("program"), QString::fromLatin1("version"), QLatin1String("description"), KAboutLicense::LGPL, - QLatin1String("copyright"), QLatin1String("hello world"), - "https://edu.kde.org/kig"); + QString::fromLatin1("copyright"), QLatin1String("hello world"), + QStringLiteral("app")); QCOMPARE(data2.organizationDomain(), QString::fromLatin1("kde.org")); QCOMPARE(data2.desktopFileName(), QStringLiteral("org.kde.app")); } @@ -199,77 +200,78 @@ QFile licenseFile(QString::fromLatin1(LicenseFileName)); licenseFile.open(QIODevice::WriteOnly); QTextStream licenseFileStream(&licenseFile); - licenseFileStream << QLatin1String(LicenseFileText); + licenseFileStream << LicenseFileText; licenseFile.close(); const QString copyrightStatement = QLatin1String(CopyrightStatement); const QString lineFeed = QString::fromLatin1("\n\n"); - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::Unknown, QLatin1String(CopyrightStatement), QLatin1String(Text), - HomePageAddress, BugsEmailAddress); + QString::fromLatin1(HomePageAddress), QString::fromLatin1(BugsEmailAddress)); // set to GPL2 aboutData.setLicense(KAboutLicense::GPL_V2); QCOMPARE(aboutData.licenses().count(), 1); QCOMPARE(aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString::fromLatin1("GPL v2")); QCOMPARE(aboutData.licenses().at(0).name(KAboutLicense::FullName), QString::fromLatin1("GNU General Public License Version 2")); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(GPL2Text) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(GPL2Text) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); // set to Unknown again aboutData.setLicense(KAboutLicense::Unknown); QCOMPARE(aboutData.licenses().count(), 1); -// We don't know the default text, do we? -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); + // We don't know the default text, do we? + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::ShortName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).name(KAboutLicense::FullName), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).name(KAboutLicense::FullName).isEmpty()); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(WarningText) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); // add GPL3 aboutData.addLicense(KAboutLicense::GPL_V3); QCOMPARE(aboutData.licenses().count(), 1); QCOMPARE(aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString::fromLatin1("GPL v3")); QCOMPARE(aboutData.licenses().at(0).name(KAboutLicense::FullName), QString::fromLatin1("GNU General Public License Version 3")); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(GPL3Text) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(GPL3Text) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); // add GPL2, Custom and File aboutData.addLicense(KAboutLicense::GPL_V2); aboutData.addLicenseText(QLatin1String(LicenseText)); - aboutData.addLicenseTextFile(QString::fromLatin1(LicenseFileName)); + aboutData.addLicenseTextFile(QLatin1String(LicenseFileName)); QCOMPARE(aboutData.licenses().count(), 4); QCOMPARE(aboutData.licenses().at(0).name(KAboutLicense::ShortName), QString::fromLatin1("GPL v3")); QCOMPARE(aboutData.licenses().at(0).name(KAboutLicense::FullName), QString::fromLatin1("GNU General Public License Version 3")); -// QCOMPARE( aboutData.licenses().at(0).text(), QString(GPL3Text) ); + // QCOMPARE( aboutData.licenses().at(0).text(), QString(GPL3Text) ); QVERIFY(!aboutData.licenses().at(0).text().isEmpty()); QCOMPARE(aboutData.licenses().at(1).name(KAboutLicense::ShortName), QString::fromLatin1("GPL v2")); QCOMPARE(aboutData.licenses().at(1).name(KAboutLicense::FullName), QString::fromLatin1("GNU General Public License Version 2")); -// QCOMPARE( aboutData.licenses().at(1).text(), QString(GPL2Text) ); + // QCOMPARE( aboutData.licenses().at(1).text(), QString(GPL2Text) ); QVERIFY(!aboutData.licenses().at(1).text().isEmpty()); QCOMPARE(aboutData.licenses().at(2).name(KAboutLicense::ShortName), QString::fromLatin1("Custom")); QCOMPARE(aboutData.licenses().at(2).name(KAboutLicense::FullName), QString::fromLatin1("Custom")); QCOMPARE(aboutData.licenses().at(2).text(), QLatin1String(LicenseText)); QCOMPARE(aboutData.licenses().at(3).name(KAboutLicense::ShortName), QString::fromLatin1("Custom")); QCOMPARE(aboutData.licenses().at(3).name(KAboutLicense::FullName), QString::fromLatin1("Custom")); - QCOMPARE(aboutData.licenses().at(3).text(), QString(copyrightStatement + lineFeed + QLatin1String(LicenseFileText))); + QCOMPARE(aboutData.licenses().at(3).text(), QString(copyrightStatement + lineFeed + + QLatin1String(LicenseFileText))); } void KAboutDataTest::testSetProgramIconName() { - const QLatin1String programIconName(ProgramIconName); + const QString programIconName(QString::fromLatin1(ProgramIconName)); - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::Unknown, QLatin1String(CopyrightStatement), QLatin1String(Text), - HomePageAddress, BugsEmailAddress); + QString::fromLatin1(HomePageAddress), QString::fromLatin1(BugsEmailAddress)); // Deprecated, still want to test this though. Silence GCC warnings. #pragma GCC diagnostic push @@ -282,11 +284,11 @@ void KAboutDataTest::testCopying() { - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::GPL_V2); { - KAboutData aboutData2(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData2(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::GPL_V3); aboutData2.addLicense(KAboutLicense::GPL_V2, KAboutLicense::OrLaterVersions); aboutData = aboutData2; @@ -305,7 +307,7 @@ void KAboutDataTest::testSetDesktopFileName() { - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::Unknown); QCOMPARE(aboutData.desktopFileName(), QStringLiteral("org.kde.app")); @@ -326,7 +328,7 @@ //we should be able to match by spdx too //create a KAboutLicense from enum, then make sure going to spdx and back gives the same enum for(int i = 1; i < KAboutLicense::LGPL_V2_1 ; i++) { /*current highest enum value*/ - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::GPL_V2); aboutData.setLicense(KAboutLicense::LicenseKey(i)); QVERIFY(aboutData.licenses().count() == 1); @@ -340,7 +342,7 @@ void KAboutDataTest::testLicenseOrLater() { // For kaboutdata we can replace the license with an orLater version. Or add a second one. - KAboutData aboutData(AppName, QLatin1String(ProgramName), Version, + KAboutData aboutData(QString::fromLatin1(AppName), QLatin1String(ProgramName), QString::fromLatin1(Version), QLatin1String(ShortDescription), KAboutLicense::GPL_V2); QCOMPARE(aboutData.licenses().at(0).spdx(), QStringLiteral("GPL-2.0")); aboutData.setLicense(KAboutLicense::GPL_V2, KAboutLicense::OrLaterVersions); diff --git a/autotests/kautosavefiletest.cpp b/autotests/kautosavefiletest.cpp --- a/autotests/kautosavefiletest.cpp +++ b/autotests/kautosavefiletest.cpp @@ -80,7 +80,7 @@ void KAutoSaveFileTest::test_fileStaleFiles() { - QUrl normalFile = QUrl::fromLocalFile(QDir::temp().absoluteFilePath("test directory/tîst me.txt")); + QUrl normalFile = QUrl::fromLocalFile(QDir::temp().absoluteFilePath(QStringLiteral("test directory/tîst me.txt"))); KAutoSaveFile saveFile(normalFile); QVERIFY(saveFile.open(QIODevice::ReadWrite)); diff --git a/autotests/kdelibs4migrationtest.cpp b/autotests/kdelibs4migrationtest.cpp --- a/autotests/kdelibs4migrationtest.cpp +++ b/autotests/kdelibs4migrationtest.cpp @@ -40,11 +40,10 @@ QString kdehome = kdehomeDir.path(); qputenv("KDEHOME", QFile::encodeName(kdehome)); - QString oldConfigDir = kdehome + "/share/config/"; + QString oldConfigDir = kdehome + QStringLiteral("/share/config/"); QVERIFY(QDir().mkpath(oldConfigDir)); - QString oldAppsDir = kdehome + "/share/apps/"; + QString oldAppsDir = kdehome + QStringLiteral("/share/apps/"); QVERIFY(QDir().mkpath(oldAppsDir)); - // Test Kdelibs4Migration migration; diff --git a/autotests/kdirwatch_unittest.cpp b/autotests/kdirwatch_unittest.cpp --- a/autotests/kdirwatch_unittest.cpp +++ b/autotests/kdirwatch_unittest.cpp @@ -182,7 +182,7 @@ const int numFiles = 10; for (int i = 0; i < numFiles; ++i) { - createFile(basePath + QLatin1Char('/') + s_filePrefix + QString::number(i)); + createFile(basePath + QLatin1Char('/') + QLatin1String(s_filePrefix) + QString::number(i)); ++filesCreated; } diff --git a/autotests/kformattest.cpp b/autotests/kformattest.cpp --- a/autotests/kformattest.cpp +++ b/autotests/kformattest.cpp @@ -33,60 +33,60 @@ locale.setNumberOptions(QLocale::DefaultNumberOptions); // Qt >= 5.6 sets QLocale::OmitGroupSeparator for the C locale KFormat format(locale); - QCOMPARE(format.formatByteSize(0), QString("0 B")); - QCOMPARE(format.formatByteSize(50), QString("50 B")); - QCOMPARE(format.formatByteSize(500), QString("500 B")); - QCOMPARE(format.formatByteSize(5000), QString("4.9 KiB")); - QCOMPARE(format.formatByteSize(50000), QString("48.8 KiB")); - QCOMPARE(format.formatByteSize(500000), QString("488.3 KiB")); - QCOMPARE(format.formatByteSize(5000000), QString("4.8 MiB")); - QCOMPARE(format.formatByteSize(50000000), QString("47.7 MiB")); - QCOMPARE(format.formatByteSize(500000000), QString("476.8 MiB")); + QCOMPARE(format.formatByteSize(0), QStringLiteral("0 B")); + QCOMPARE(format.formatByteSize(50), QStringLiteral("50 B")); + QCOMPARE(format.formatByteSize(500), QStringLiteral("500 B")); + QCOMPARE(format.formatByteSize(5000), QStringLiteral("4.9 KiB")); + QCOMPARE(format.formatByteSize(50000), QStringLiteral("48.8 KiB")); + QCOMPARE(format.formatByteSize(500000), QStringLiteral("488.3 KiB")); + QCOMPARE(format.formatByteSize(5000000), QStringLiteral("4.8 MiB")); + QCOMPARE(format.formatByteSize(50000000), QStringLiteral("47.7 MiB")); + QCOMPARE(format.formatByteSize(500000000), QStringLiteral("476.8 MiB")); #if (defined(__WORDSIZE) && (__WORDSIZE == 64)) || defined (_LP64) || defined(__LP64__) || defined(__ILP64__) - QCOMPARE(format.formatByteSize(5000000000), QString("4.7 GiB")); - QCOMPARE(format.formatByteSize(50000000000), QString("46.6 GiB")); - QCOMPARE(format.formatByteSize(500000000000), QString("465.7 GiB")); - QCOMPARE(format.formatByteSize(5000000000000), QString("4.5 TiB")); - QCOMPARE(format.formatByteSize(50000000000000), QString("45.5 TiB")); - QCOMPARE(format.formatByteSize(500000000000000), QString("454.7 TiB")); + QCOMPARE(format.formatByteSize(5000000000), QStringLiteral("4.7 GiB")); + QCOMPARE(format.formatByteSize(50000000000), QStringLiteral("46.6 GiB")); + QCOMPARE(format.formatByteSize(500000000000), QStringLiteral("465.7 GiB")); + QCOMPARE(format.formatByteSize(5000000000000), QStringLiteral("4.5 TiB")); + QCOMPARE(format.formatByteSize(50000000000000), QStringLiteral("45.5 TiB")); + QCOMPARE(format.formatByteSize(500000000000000), QStringLiteral("454.7 TiB")); #endif - QCOMPARE(format.formatByteSize(1024.0, 1, KFormat::IECBinaryDialect), QString("1.0 KiB")); - QCOMPARE(format.formatByteSize(1023.0, 1, KFormat::IECBinaryDialect), QString("1,023 B")); - QCOMPARE(format.formatByteSize(1163000.0, 1, KFormat::IECBinaryDialect), QString("1.1 MiB")); // 1.2 metric + QCOMPARE(format.formatByteSize(1024.0, 1, KFormat::IECBinaryDialect), QStringLiteral("1.0 KiB")); + QCOMPARE(format.formatByteSize(1023.0, 1, KFormat::IECBinaryDialect), QStringLiteral("1,023 B")); + QCOMPARE(format.formatByteSize(1163000.0, 1, KFormat::IECBinaryDialect), QStringLiteral("1.1 MiB")); // 1.2 metric - QCOMPARE(format.formatByteSize(-1024.0, 1, KFormat::IECBinaryDialect), QString("-1.0 KiB")); - QCOMPARE(format.formatByteSize(-1023.0, 1, KFormat::IECBinaryDialect), QString("-1,023 B")); - QCOMPARE(format.formatByteSize(-1163000.0, 1, KFormat::IECBinaryDialect), QString("-1.1 MiB")); // 1.2 metric + QCOMPARE(format.formatByteSize(-1024.0, 1, KFormat::IECBinaryDialect), QStringLiteral("-1.0 KiB")); + QCOMPARE(format.formatByteSize(-1023.0, 1, KFormat::IECBinaryDialect), QStringLiteral("-1,023 B")); + QCOMPARE(format.formatByteSize(-1163000.0, 1, KFormat::IECBinaryDialect), QStringLiteral("-1.1 MiB")); // 1.2 metric - QCOMPARE(format.formatByteSize(1024.0, 1, KFormat::JEDECBinaryDialect), QString("1.0 KB")); - QCOMPARE(format.formatByteSize(1023.0, 1, KFormat::JEDECBinaryDialect), QString("1,023 B")); - QCOMPARE(format.formatByteSize(1163000.0, 1, KFormat::JEDECBinaryDialect), QString("1.1 MB")); + QCOMPARE(format.formatByteSize(1024.0, 1, KFormat::JEDECBinaryDialect), QStringLiteral("1.0 KB")); + QCOMPARE(format.formatByteSize(1023.0, 1, KFormat::JEDECBinaryDialect), QStringLiteral("1,023 B")); + QCOMPARE(format.formatByteSize(1163000.0, 1, KFormat::JEDECBinaryDialect), QStringLiteral("1.1 MB")); - QCOMPARE(format.formatByteSize(-1024.0, 1, KFormat::JEDECBinaryDialect), QString("-1.0 KB")); - QCOMPARE(format.formatByteSize(-1023.0, 1, KFormat::JEDECBinaryDialect), QString("-1,023 B")); - QCOMPARE(format.formatByteSize(-1163000.0, 1, KFormat::JEDECBinaryDialect), QString("-1.1 MB")); + QCOMPARE(format.formatByteSize(-1024.0, 1, KFormat::JEDECBinaryDialect), QStringLiteral("-1.0 KB")); + QCOMPARE(format.formatByteSize(-1023.0, 1, KFormat::JEDECBinaryDialect), QStringLiteral("-1,023 B")); + QCOMPARE(format.formatByteSize(-1163000.0, 1, KFormat::JEDECBinaryDialect), QStringLiteral("-1.1 MB")); - QCOMPARE(format.formatByteSize(1024.0, 1, KFormat::MetricBinaryDialect), QString("1.0 kB")); - QCOMPARE(format.formatByteSize(1023.0, 1, KFormat::MetricBinaryDialect), QString("1.0 kB")); - QCOMPARE(format.formatByteSize(1163000.0, 1, KFormat::MetricBinaryDialect), QString("1.2 MB")); + QCOMPARE(format.formatByteSize(1024.0, 1, KFormat::MetricBinaryDialect), QStringLiteral("1.0 kB")); + QCOMPARE(format.formatByteSize(1023.0, 1, KFormat::MetricBinaryDialect), QStringLiteral("1.0 kB")); + QCOMPARE(format.formatByteSize(1163000.0, 1, KFormat::MetricBinaryDialect), QStringLiteral("1.2 MB")); - QCOMPARE(format.formatByteSize(-1024.0, 1, KFormat::MetricBinaryDialect), QString("-1.0 kB")); - QCOMPARE(format.formatByteSize(-1023.0, 1, KFormat::MetricBinaryDialect), QString("-1.0 kB")); - QCOMPARE(format.formatByteSize(-1163000.0, 1, KFormat::MetricBinaryDialect), QString("-1.2 MB")); + QCOMPARE(format.formatByteSize(-1024.0, 1, KFormat::MetricBinaryDialect), QStringLiteral("-1.0 kB")); + QCOMPARE(format.formatByteSize(-1023.0, 1, KFormat::MetricBinaryDialect), QStringLiteral("-1.0 kB")); + QCOMPARE(format.formatByteSize(-1163000.0, 1, KFormat::MetricBinaryDialect), QStringLiteral("-1.2 MB")); // Ensure all units are represented - QCOMPARE(format.formatByteSize(2.0e9, 1, KFormat::MetricBinaryDialect), QString("2.0 GB")); - QCOMPARE(format.formatByteSize(3.2e12, 1, KFormat::MetricBinaryDialect), QString("3.2 TB")); - QCOMPARE(format.formatByteSize(4.1e15, 1, KFormat::MetricBinaryDialect), QString("4.1 PB")); - QCOMPARE(format.formatByteSize(6.7e18, 2, KFormat::MetricBinaryDialect), QString("6.70 EB")); - QCOMPARE(format.formatByteSize(5.6e20, 2, KFormat::MetricBinaryDialect), QString("560.00 EB")); - QCOMPARE(format.formatByteSize(2.3e22, 2, KFormat::MetricBinaryDialect), QString("23.00 ZB")); - QCOMPARE(format.formatByteSize(1.0e27, 1, KFormat::MetricBinaryDialect), QString("1,000.0 YB")); + QCOMPARE(format.formatByteSize(2.0e9, 1, KFormat::MetricBinaryDialect), QStringLiteral("2.0 GB")); + QCOMPARE(format.formatByteSize(3.2e12, 1, KFormat::MetricBinaryDialect), QStringLiteral("3.2 TB")); + QCOMPARE(format.formatByteSize(4.1e15, 1, KFormat::MetricBinaryDialect), QStringLiteral("4.1 PB")); + QCOMPARE(format.formatByteSize(6.7e18, 2, KFormat::MetricBinaryDialect), QStringLiteral("6.70 EB")); + QCOMPARE(format.formatByteSize(5.6e20, 2, KFormat::MetricBinaryDialect), QStringLiteral("560.00 EB")); + QCOMPARE(format.formatByteSize(2.3e22, 2, KFormat::MetricBinaryDialect), QStringLiteral("23.00 ZB")); + QCOMPARE(format.formatByteSize(1.0e27, 1, KFormat::MetricBinaryDialect), QStringLiteral("1,000.0 YB")); // Spattering of specific units - QCOMPARE(format.formatByteSize(823000, 3, KFormat::IECBinaryDialect, KFormat::UnitMegaByte), QString("0.785 MiB")); - QCOMPARE(format.formatByteSize(1234034.0, 4, KFormat::JEDECBinaryDialect, KFormat::UnitByte), QString("1,234,034 B")); + QCOMPARE(format.formatByteSize(823000, 3, KFormat::IECBinaryDialect, KFormat::UnitMegaByte), QStringLiteral("0.785 MiB")); + QCOMPARE(format.formatByteSize(1234034.0, 4, KFormat::JEDECBinaryDialect, KFormat::UnitByte), QStringLiteral("1,234,034 B")); } enum TimeConstants { @@ -111,214 +111,214 @@ quint64 roundingIssues = 2* MSecsInHour + 59 * MSecsInMinute + 59 * MSecsInSecond + 900; // Default format - QCOMPARE(format.formatDuration(singleSecond), QString("0:00:04")); - QCOMPARE(format.formatDuration(doubleSecond), QString("0:00:34")); - QCOMPARE(format.formatDuration(singleMinute), QString("0:08:04")); - QCOMPARE(format.formatDuration(doubleMinute), QString("0:38:04")); - QCOMPARE(format.formatDuration(singleHour), QString("5:08:04")); - QCOMPARE(format.formatDuration(doubleHour), QString("15:08:04")); - QCOMPARE(format.formatDuration(singleDay), QString("29:08:04")); - QCOMPARE(format.formatDuration(doubleDay), QString("245:08:04")); - QCOMPARE(format.formatDuration(roundingIssues), QString("3:00:00")); + QCOMPARE(format.formatDuration(singleSecond), QStringLiteral("0:00:04")); + QCOMPARE(format.formatDuration(doubleSecond), QStringLiteral("0:00:34")); + QCOMPARE(format.formatDuration(singleMinute), QStringLiteral("0:08:04")); + QCOMPARE(format.formatDuration(doubleMinute), QStringLiteral("0:38:04")); + QCOMPARE(format.formatDuration(singleHour), QStringLiteral("5:08:04")); + QCOMPARE(format.formatDuration(doubleHour), QStringLiteral("15:08:04")); + QCOMPARE(format.formatDuration(singleDay), QStringLiteral("29:08:04")); + QCOMPARE(format.formatDuration(doubleDay), QStringLiteral("245:08:04")); + QCOMPARE(format.formatDuration(roundingIssues), QStringLiteral("3:00:00")); // ShowMilliseconds format KFormat::DurationFormatOptions options = KFormat::ShowMilliseconds; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0:00:03.700")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0:00:33.700")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("0:08:03.700")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("0:38:03.700")); - QCOMPARE(format.formatDuration(singleHour, options), QString("5:08:03.700")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("15:08:03.700")); - QCOMPARE(format.formatDuration(singleDay, options), QString("29:08:03.700")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("245:08:03.700")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("2:59:59.900")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0:00:03.700")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0:00:33.700")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("0:08:03.700")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("0:38:03.700")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("5:08:03.700")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("15:08:03.700")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("29:08:03.700")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("245:08:03.700")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("2:59:59.900")); // HideSeconds format options = KFormat::HideSeconds; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0:00")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0:01")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("0:08")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("0:38")); - QCOMPARE(format.formatDuration(singleHour, options), QString("5:08")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("15:08")); - QCOMPARE(format.formatDuration(singleDay, options), QString("29:08")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("245:08")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("3:00")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0:00")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0:01")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("0:08")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("0:38")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("5:08")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("15:08")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("29:08")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("245:08")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("3:00")); // FoldHours format options = KFormat::FoldHours; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0:04")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0:34")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("8:04")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("38:04")); - QCOMPARE(format.formatDuration(singleHour, options), QString("308:04")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("908:04")); - QCOMPARE(format.formatDuration(singleDay, options), QString("1748:04")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("14708:04")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("180:00")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0:04")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0:34")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("8:04")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("38:04")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("308:04")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("908:04")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("1748:04")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("14708:04")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("180:00")); // FoldHours ShowMilliseconds format options = KFormat::FoldHours; options = options | KFormat::ShowMilliseconds; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0:03.700")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0:33.700")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("8:03.700")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("38:03.700")); - QCOMPARE(format.formatDuration(singleHour, options), QString("308:03.700")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("908:03.700")); - QCOMPARE(format.formatDuration(singleDay, options), QString("1748:03.700")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("14708:03.700")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("179:59.900")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0:03.700")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0:33.700")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("8:03.700")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("38:03.700")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("308:03.700")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("908:03.700")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("1748:03.700")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("14708:03.700")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("179:59.900")); // InitialDuration format options = KFormat::InitialDuration; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0h00m04s")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0h00m34s")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("0h08m04s")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("0h38m04s")); - QCOMPARE(format.formatDuration(singleHour, options), QString("5h08m04s")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("15h08m04s")); - QCOMPARE(format.formatDuration(singleDay, options), QString("29h08m04s")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("245h08m04s")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("3h00m00s")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0h00m04s")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0h00m34s")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("0h08m04s")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("0h38m04s")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("5h08m04s")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("15h08m04s")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("29h08m04s")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("245h08m04s")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("3h00m00s")); // InitialDuration and ShowMilliseconds format options = KFormat::InitialDuration; options = options | KFormat::ShowMilliseconds; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0h00m03.700s")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0h00m33.700s")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("0h08m03.700s")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("0h38m03.700s")); - QCOMPARE(format.formatDuration(singleHour, options), QString("5h08m03.700s")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("15h08m03.700s")); - QCOMPARE(format.formatDuration(singleDay, options), QString("29h08m03.700s")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("245h08m03.700s")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("2h59m59.900s")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0h00m03.700s")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0h00m33.700s")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("0h08m03.700s")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("0h38m03.700s")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("5h08m03.700s")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("15h08m03.700s")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("29h08m03.700s")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("245h08m03.700s")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("2h59m59.900s")); // InitialDuration and HideSeconds format options = KFormat::InitialDuration; options = options | KFormat::HideSeconds; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0h00m")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0h01m")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("0h08m")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("0h38m")); - QCOMPARE(format.formatDuration(singleHour, options), QString("5h08m")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("15h08m")); - QCOMPARE(format.formatDuration(singleDay, options), QString("29h08m")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("245h08m")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("3h00m")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0h00m")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0h01m")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("0h08m")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("0h38m")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("5h08m")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("15h08m")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("29h08m")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("245h08m")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("3h00m")); // InitialDuration and FoldHours format options = KFormat::InitialDuration; options = options | KFormat::FoldHours; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0m04s")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0m34s")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("8m04s")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("38m04s")); - QCOMPARE(format.formatDuration(singleHour, options), QString("308m04s")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("908m04s")); - QCOMPARE(format.formatDuration(singleDay, options), QString("1748m04s")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("14708m04s")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("180m00s")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0m04s")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0m34s")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("8m04s")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("38m04s")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("308m04s")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("908m04s")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("1748m04s")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("14708m04s")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("180m00s")); // InitialDuration and FoldHours and ShowMilliseconds format options = KFormat::InitialDuration; options = options | KFormat::FoldHours | KFormat::ShowMilliseconds; - QCOMPARE(format.formatDuration(singleSecond, options), QString("0m03.700s")); - QCOMPARE(format.formatDuration(doubleSecond, options), QString("0m33.700s")); - QCOMPARE(format.formatDuration(singleMinute, options), QString("8m03.700s")); - QCOMPARE(format.formatDuration(doubleMinute, options), QString("38m03.700s")); - QCOMPARE(format.formatDuration(singleHour, options), QString("308m03.700s")); - QCOMPARE(format.formatDuration(doubleHour, options), QString("908m03.700s")); - QCOMPARE(format.formatDuration(singleDay, options), QString("1748m03.700s")); - QCOMPARE(format.formatDuration(doubleDay, options), QString("14708m03.700s")); - QCOMPARE(format.formatDuration(roundingIssues, options), QString("179m59.900s")); + QCOMPARE(format.formatDuration(singleSecond, options), QStringLiteral("0m03.700s")); + QCOMPARE(format.formatDuration(doubleSecond, options), QStringLiteral("0m33.700s")); + QCOMPARE(format.formatDuration(singleMinute, options), QStringLiteral("8m03.700s")); + QCOMPARE(format.formatDuration(doubleMinute, options), QStringLiteral("38m03.700s")); + QCOMPARE(format.formatDuration(singleHour, options), QStringLiteral("308m03.700s")); + QCOMPARE(format.formatDuration(doubleHour, options), QStringLiteral("908m03.700s")); + QCOMPARE(format.formatDuration(singleDay, options), QStringLiteral("1748m03.700s")); + QCOMPARE(format.formatDuration(doubleDay, options), QStringLiteral("14708m03.700s")); + QCOMPARE(format.formatDuration(roundingIssues, options), QStringLiteral("179m59.900s")); } void KFormatTest::formatDecimalDuration() { KFormat format(QLocale::c()); - QCOMPARE(format.formatDecimalDuration(10), QString("10 millisecond(s)")); - QCOMPARE(format.formatDecimalDuration(10, 3), QString("10 millisecond(s)")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInSecond + 10), QString("1.01 seconds")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInSecond + 1, 3), QString("1.001 seconds")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInMinute + 10 * MSecsInSecond), QString("1.17 minutes")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInMinute + 10 * MSecsInSecond, 3), QString("1.167 minutes")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInHour + 10 * MSecsInMinute), QString("1.17 hours")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInHour + 10 * MSecsInMinute, 3), QString("1.167 hours")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInDay + 10 * MSecsInHour), QString("1.42 days")); - QCOMPARE(format.formatDecimalDuration(1 * MSecsInDay + 10 * MSecsInHour, 3), QString("1.417 days")); + QCOMPARE(format.formatDecimalDuration(10), QStringLiteral("10 millisecond(s)")); + QCOMPARE(format.formatDecimalDuration(10, 3), QStringLiteral("10 millisecond(s)")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInSecond + 10), QStringLiteral("1.01 seconds")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInSecond + 1, 3), QStringLiteral("1.001 seconds")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInMinute + 10 * MSecsInSecond), QStringLiteral("1.17 minutes")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInMinute + 10 * MSecsInSecond, 3), QStringLiteral("1.167 minutes")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInHour + 10 * MSecsInMinute), QStringLiteral("1.17 hours")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInHour + 10 * MSecsInMinute, 3), QStringLiteral("1.167 hours")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInDay + 10 * MSecsInHour), QStringLiteral("1.42 days")); + QCOMPARE(format.formatDecimalDuration(1 * MSecsInDay + 10 * MSecsInHour, 3), QStringLiteral("1.417 days")); } void KFormatTest::formatSpelloutDuration() { KFormat format(QLocale::c()); - QCOMPARE(format.formatSpelloutDuration(1000), QString("1 second(s)")); - QCOMPARE(format.formatSpelloutDuration(5000), QString("5 second(s)")); - QCOMPARE(format.formatSpelloutDuration(60000), QString("1 minute(s)")); - QCOMPARE(format.formatSpelloutDuration(300000), QString("5 minute(s)")); - QCOMPARE(format.formatSpelloutDuration(3600000), QString("1 hour(s)")); - QCOMPARE(format.formatSpelloutDuration(18000000), QString("5 hour(s)")); - QCOMPARE(format.formatSpelloutDuration(75000), QString("1 minute(s) and 15 second(s)")); + QCOMPARE(format.formatSpelloutDuration(1000), QStringLiteral("1 second(s)")); + QCOMPARE(format.formatSpelloutDuration(5000), QStringLiteral("5 second(s)")); + QCOMPARE(format.formatSpelloutDuration(60000), QStringLiteral("1 minute(s)")); + QCOMPARE(format.formatSpelloutDuration(300000), QStringLiteral("5 minute(s)")); + QCOMPARE(format.formatSpelloutDuration(3600000), QStringLiteral("1 hour(s)")); + QCOMPARE(format.formatSpelloutDuration(18000000), QStringLiteral("5 hour(s)")); + QCOMPARE(format.formatSpelloutDuration(75000), QStringLiteral("1 minute(s) and 15 second(s)")); // Problematic case #1 (there is a reference to this case on kformat.cpp) - QCOMPARE(format.formatSpelloutDuration(119999), QString("2 minute(s)")); + QCOMPARE(format.formatSpelloutDuration(119999), QStringLiteral("2 minute(s)")); // This case is strictly 2 hours, 15 minutes and 59 seconds. However, since the range is // pretty high between hours and seconds, formatSpelloutDuration always omits seconds when there // are hours in scene. - QCOMPARE(format.formatSpelloutDuration(8159000), QString("2 hour(s) and 15 minute(s)")); + QCOMPARE(format.formatSpelloutDuration(8159000), QStringLiteral("2 hour(s) and 15 minute(s)")); // This case is strictly 1 hour and 10 seconds. For the same reason, formatSpelloutDuration // detects that 10 seconds is just garbage compared to 1 hour, and omits it on the result. - QCOMPARE(format.formatSpelloutDuration(3610000), QString("1 hour(s)")); + QCOMPARE(format.formatSpelloutDuration(3610000), QStringLiteral("1 hour(s)")); } void KFormatTest::formatRelativeDate() { KFormat format(QLocale::c()); QDate testDate = QDate::currentDate(); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QString("Today")); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QString("Today")); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QString("Today")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QStringLiteral("Today")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QStringLiteral("Today")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QStringLiteral("Today")); testDate = QDate::currentDate().addDays(1); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QString("Tomorrow")); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QString("Tomorrow")); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QString("Tomorrow")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QStringLiteral("Tomorrow")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QStringLiteral("Tomorrow")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QStringLiteral("Tomorrow")); testDate = QDate::currentDate().addDays(-1); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QString("Yesterday")); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QString("Yesterday")); - QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QString("Yesterday")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QStringLiteral("Yesterday")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), QStringLiteral("Yesterday")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), QStringLiteral("Yesterday")); // Relative dates within a week are up to translators but there's no // expectation that day names are shortened -- per the API docs, the date // format is only used when the date is outside the relative window testDate = QDate::currentDate().addDays(-7); QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), - QString("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + QStringLiteral("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), - QString("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + QStringLiteral("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), - QString("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + QStringLiteral("Last %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); testDate = QDate::currentDate().addDays(7); QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), - QString("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + QStringLiteral("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); QCOMPARE(format.formatRelativeDate(testDate, QLocale::ShortFormat), - QString("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + QStringLiteral("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); QCOMPARE(format.formatRelativeDate(testDate, QLocale::NarrowFormat), - QString("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); + QStringLiteral("Next %1").arg(QLocale::c().dayName(testDate.dayOfWeek(), QLocale::LongFormat))); testDate = QDate::currentDate().addDays(-8); QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), @@ -337,10 +337,10 @@ QLocale::c().toString(testDate, QLocale::NarrowFormat)); testDate = QDate(); // invalid date - QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QString("Invalid date")); + QCOMPARE(format.formatRelativeDate(testDate, QLocale::LongFormat), QStringLiteral("Invalid date")); QDateTime testDateTime = QDateTime(QDate::currentDate(), QTime(3, 0, 0)); - QCOMPARE(format.formatRelativeDateTime(testDateTime, QLocale::ShortFormat), QString("Today, 03:00:00")); + QCOMPARE(format.formatRelativeDateTime(testDateTime, QLocale::ShortFormat), QStringLiteral("Today, 03:00:00")); testDateTime = QDateTime(QDate::currentDate().addDays(8), QTime(3, 0, 0)); QCOMPARE(format.formatRelativeDateTime(testDateTime, QLocale::LongFormat), diff --git a/autotests/kpluginfactorytest.cpp b/autotests/kpluginfactorytest.cpp --- a/autotests/kpluginfactorytest.cpp +++ b/autotests/kpluginfactorytest.cpp @@ -31,11 +31,11 @@ private Q_SLOTS: void testCreate() { - KPluginLoader multiplugin("multiplugin"); + KPluginLoader multiplugin(QStringLiteral("multiplugin")); KPluginFactory *factory = multiplugin.factory(); QVERIFY(factory); QVariantList args; - args << "Some" << "args" << 5; + args << QStringLiteral("Some") << QStringLiteral("args") << 5; QObject *obj = factory->create(this, args); QVERIFY(obj); @@ -48,11 +48,11 @@ delete obj; delete obj2; - obj = factory->create("secondary", this, args); + obj = factory->create(QStringLiteral("secondary"), this, args); QVERIFY(obj); QCOMPARE(obj->objectName(), QString::fromLatin1("MultiPlugin2")); - obj2 = factory->create("secondary", this, args); + obj2 = factory->create(QStringLiteral("secondary"), this, args); QVERIFY(obj2); QCOMPARE(obj2->objectName(), QString::fromLatin1("MultiPlugin2")); QVERIFY(obj != obj2); diff --git a/autotests/kpluginloadertest.cpp b/autotests/kpluginloadertest.cpp --- a/autotests/kpluginloadertest.cpp +++ b/autotests/kpluginloadertest.cpp @@ -40,118 +40,118 @@ private Q_SLOTS: void testFindPlugin_missing() { - const QString location = KPluginLoader::findPlugin("idonotexist"); + const QString location = KPluginLoader::findPlugin(QStringLiteral("idonotexist")); QVERIFY2(location.isEmpty(), qPrintable(location)); } void testFindPlugin() { - const QString location = KPluginLoader::findPlugin("jsonplugin"); + const QString location = KPluginLoader::findPlugin(QStringLiteral("jsonplugin")); QVERIFY2(!location.isEmpty(), qPrintable(location)); } void testPluginVersion() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QCOMPARE(vplugin.pluginVersion(), quint32(5)); - KPluginLoader vplugin2("versionedplugin"); + KPluginLoader vplugin2(QStringLiteral("versionedplugin")); QCOMPARE(vplugin2.pluginVersion(), quint32(5)); - KPluginLoader uplugin("unversionedplugin"); + KPluginLoader uplugin(QStringLiteral("unversionedplugin")); QCOMPARE(uplugin.pluginVersion(), quint32(-1)); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QCOMPARE(jplugin.pluginVersion(), quint32(-1)); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QCOMPARE(eplugin.pluginVersion(), quint32(-1)); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QCOMPARE(noplugin.pluginVersion(), quint32(-1)); } void testPluginName() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QCOMPARE(vplugin.pluginName(), QString::fromLatin1("versionedplugin")); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QCOMPARE(jplugin.pluginName(), QString::fromLatin1("jsonplugin")); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY2(eplugin.pluginName().isEmpty(), qPrintable(eplugin.pluginName())); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QCOMPARE(noplugin.pluginName(), QString::fromLatin1("idonotexist")); } void testFactory() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QVERIFY(vplugin.factory()); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QVERIFY(jplugin.factory()); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY(!eplugin.factory()); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QVERIFY(!noplugin.factory()); } void testErrorString() { - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QCOMPARE(eplugin.errorString(), QString::fromLatin1("there was an error")); } void testFileName() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QCOMPARE(QFileInfo(vplugin.fileName()).canonicalFilePath(), QFileInfo(QStringLiteral(VERSIONEDPLUGIN_FILE)).canonicalFilePath()); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QCOMPARE(QFileInfo(jplugin.fileName()).canonicalFilePath(), QFileInfo(QStringLiteral(JSONPLUGIN_FILE)).canonicalFilePath()); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY2(eplugin.fileName().isEmpty(), qPrintable(eplugin.fileName())); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QVERIFY2(noplugin.fileName().isEmpty(), qPrintable(noplugin.fileName())); } void testInstance() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QVERIFY(vplugin.instance()); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QVERIFY(jplugin.instance()); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY(!eplugin.instance()); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QVERIFY(!noplugin.instance()); } void testIsLoaded() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QVERIFY(!vplugin.isLoaded()); QVERIFY(vplugin.load()); QVERIFY(vplugin.isLoaded()); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QVERIFY(!jplugin.isLoaded()); QVERIFY(jplugin.load()); QVERIFY(jplugin.isLoaded()); - KPluginLoader aplugin("alwaysunloadplugin"); + KPluginLoader aplugin(QStringLiteral("alwaysunloadplugin")); QVERIFY(!aplugin.isLoaded()); QVERIFY(aplugin.load()); QVERIFY(aplugin.isLoaded()); @@ -161,119 +161,119 @@ qDebug() << "Could not unload alwaysunloadplugin:" << aplugin.errorString(); } - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY(!eplugin.isLoaded()); QVERIFY(!eplugin.load()); QVERIFY(!eplugin.isLoaded()); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QVERIFY(!noplugin.isLoaded()); QVERIFY(!noplugin.load()); QVERIFY(!noplugin.isLoaded()); } void testLoad() { - KPluginLoader vplugin("versionedplugin"); + KPluginLoader vplugin(QStringLiteral("versionedplugin")); QVERIFY(vplugin.load()); - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QVERIFY(jplugin.load()); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY(!eplugin.load()); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QVERIFY(!noplugin.load()); } void testLoadHints() { - KPluginLoader aplugin("alwaysunloadplugin"); + KPluginLoader aplugin(QStringLiteral("alwaysunloadplugin")); aplugin.setLoadHints(QLibrary::ResolveAllSymbolsHint); QCOMPARE(aplugin.loadHints(), QLibrary::ResolveAllSymbolsHint); } void testMetaData() { - KPluginLoader aplugin("alwaysunloadplugin"); + KPluginLoader aplugin(QStringLiteral("alwaysunloadplugin")); QJsonObject ametadata = aplugin.metaData(); QVERIFY(!ametadata.isEmpty()); - QVERIFY(ametadata.keys().contains("IID")); - QJsonValue ametadata_metadata = ametadata.value("MetaData"); + QVERIFY(ametadata.keys().contains(QStringLiteral("IID"))); + QJsonValue ametadata_metadata = ametadata.value(QStringLiteral("MetaData")); QVERIFY(ametadata_metadata.toObject().isEmpty()); QVERIFY(!aplugin.isLoaded()); // didn't load anything - KPluginLoader jplugin(KPluginName("jsonplugin")); + KPluginLoader jplugin(KPluginName(QStringLiteral("jsonplugin"))); QJsonObject jmetadata = jplugin.metaData(); QVERIFY(!jmetadata.isEmpty()); - QJsonValue jmetadata_metadata = jmetadata.value("MetaData"); + QJsonValue jmetadata_metadata = jmetadata.value(QStringLiteral("MetaData")); QVERIFY(jmetadata_metadata.isObject()); QJsonObject jmetadata_obj = jmetadata_metadata.toObject(); QVERIFY(!jmetadata_obj.isEmpty()); - QJsonValue comment = jmetadata_obj.value("KPlugin").toObject().value("Description"); + QJsonValue comment = jmetadata_obj.value(QStringLiteral("KPlugin")).toObject().value(QStringLiteral("Description")); QVERIFY(comment.isString()); QCOMPARE(comment.toString(), QString::fromLatin1("This is a plugin")); - KPluginLoader eplugin(KPluginName::fromErrorString("there was an error")); + KPluginLoader eplugin(KPluginName::fromErrorString(QStringLiteral("there was an error"))); QVERIFY(eplugin.metaData().isEmpty()); - KPluginLoader noplugin("idonotexist"); + KPluginLoader noplugin(QStringLiteral("idonotexist")); QVERIFY(noplugin.metaData().isEmpty()); } void testUnload() { - KPluginLoader aplugin("alwaysunloadplugin"); + KPluginLoader aplugin(QStringLiteral("alwaysunloadplugin")); QVERIFY(aplugin.load()); // may need QEXPECT_FAIL on some platforms... QVERIFY(aplugin.unload()); } void testInstantiatePlugins() { - const QString plugin1Path = KPluginLoader::findPlugin("jsonplugin"); + const QString plugin1Path = KPluginLoader::findPlugin(QStringLiteral("jsonplugin")); QVERIFY2(!plugin1Path.isEmpty(), qPrintable(plugin1Path)); - const QString plugin2Path = KPluginLoader::findPlugin("unversionedplugin"); + const QString plugin2Path = KPluginLoader::findPlugin(QStringLiteral("unversionedplugin")); QVERIFY2(!plugin2Path.isEmpty(), qPrintable(plugin2Path)); - const QString plugin3Path = KPluginLoader::findPlugin("jsonplugin2"); + const QString plugin3Path = KPluginLoader::findPlugin(QStringLiteral("jsonplugin2")); QVERIFY2(!plugin3Path.isEmpty(), qPrintable(plugin3Path)); QTemporaryDir temp; QVERIFY(temp.isValid()); QDir dir(temp.path()); QVERIFY2(QFile::copy(plugin1Path, dir.absoluteFilePath(QFileInfo(plugin1Path).fileName())), - qPrintable(dir.absoluteFilePath(QFileInfo(plugin1Path).fileName()))); + qPrintable(dir.absoluteFilePath(QFileInfo(plugin1Path).fileName()))); QVERIFY2(QFile::copy(plugin2Path, dir.absoluteFilePath(QFileInfo(plugin2Path).fileName())), - qPrintable(dir.absoluteFilePath(QFileInfo(plugin2Path).fileName()))); + qPrintable(dir.absoluteFilePath(QFileInfo(plugin2Path).fileName()))); QVERIFY2(QFile::copy(plugin3Path, dir.absoluteFilePath(QFileInfo(plugin3Path).fileName())), - qPrintable(dir.absoluteFilePath(QFileInfo(plugin3Path).fileName()))); + qPrintable(dir.absoluteFilePath(QFileInfo(plugin3Path).fileName()))); // only jsonplugin, since unversionedplugin has no json metadata QList plugins = KPluginLoader::instantiatePlugins(temp.path()); QCOMPARE(plugins.size(), 2); - QStringList classNames = QStringList() << plugins[0]->metaObject()->className() - << plugins[1]->metaObject()->className(); + QStringList classNames = QStringList() << QString::fromLatin1(plugins[0]->metaObject()->className()) + << QString::fromLatin1(plugins[1]->metaObject()->className()); classNames.sort(); QCOMPARE(classNames[0], QStringLiteral("jsonplugin2")); QCOMPARE(classNames[1], QStringLiteral("jsonpluginfa")); qDeleteAll(plugins); //try filter plugins = KPluginLoader::instantiatePlugins(temp.path(), [](const KPluginMetaData & md) { - return md.pluginId() == "jsonplugin"; + return md.pluginId() == QStringLiteral("jsonplugin"); }); QCOMPARE(plugins.size(), 1); QCOMPARE(plugins[0]->metaObject()->className(), "jsonpluginfa"); qDeleteAll(plugins); plugins = KPluginLoader::instantiatePlugins(temp.path(), [](const KPluginMetaData & md) { - return md.pluginId() == "unversionedplugin"; + return md.pluginId() == QStringLiteral("unversionedplugin"); }); QCOMPARE(plugins.size(), 0); plugins = KPluginLoader::instantiatePlugins(temp.path(), [](const KPluginMetaData & md) { - return md.pluginId() == "foobar"; // ID does not match file name, is set in JSON + return md.pluginId() == QStringLiteral("foobar"); // ID does not match file name, is set in JSON }); QCOMPARE(plugins.size(), 1); QCOMPARE(plugins[0]->metaObject()->className(), "jsonplugin2"); @@ -295,76 +295,76 @@ QVERIFY(!QDir::isAbsolutePath(subDirName)); plugins = KPluginLoader::instantiatePlugins(subDirName); QCOMPARE(plugins.size(), 2); - classNames = QStringList() << plugins[0]->metaObject()->className() - << plugins[1]->metaObject()->className(); + classNames = QStringList() << QString::fromLatin1(plugins[0]->metaObject()->className()) + << QString::fromLatin1(plugins[1]->metaObject()->className()); classNames.sort(); QCOMPARE(classNames[0], QStringLiteral("jsonplugin2")); QCOMPARE(classNames[1], QStringLiteral("jsonpluginfa")); qDeleteAll(plugins); } void testFindPlugins() { - const QString plugin1Path = KPluginLoader::findPlugin("jsonplugin"); + const QString plugin1Path = KPluginLoader::findPlugin(QStringLiteral("jsonplugin")); QVERIFY2(!plugin1Path.isEmpty(), qPrintable(plugin1Path)); - const QString plugin2Path = KPluginLoader::findPlugin("unversionedplugin"); + const QString plugin2Path = KPluginLoader::findPlugin(QStringLiteral("unversionedplugin")); QVERIFY2(!plugin2Path.isEmpty(), qPrintable(plugin2Path)); - const QString plugin3Path = KPluginLoader::findPlugin("jsonplugin2"); + const QString plugin3Path = KPluginLoader::findPlugin(QStringLiteral("jsonplugin2")); QVERIFY2(!plugin3Path.isEmpty(), qPrintable(plugin3Path)); QTemporaryDir temp; QVERIFY(temp.isValid()); QDir dir(temp.path()); - QVERIFY(dir.mkdir("kpluginmetadatatest")); - QVERIFY(dir.cd("kpluginmetadatatest")); + QVERIFY(dir.mkdir(QStringLiteral("kpluginmetadatatest"))); + QVERIFY(dir.cd(QStringLiteral("kpluginmetadatatest"))); QVERIFY2(QFile::copy(plugin1Path, dir.absoluteFilePath(QFileInfo(plugin1Path).fileName())), - qPrintable(dir.absoluteFilePath(QFileInfo(plugin1Path).fileName()))); + qPrintable(dir.absoluteFilePath(QFileInfo(plugin1Path).fileName()))); QVERIFY2(QFile::copy(plugin2Path, dir.absoluteFilePath(QFileInfo(plugin2Path).fileName())), - qPrintable(dir.absoluteFilePath(QFileInfo(plugin2Path).fileName()))); + qPrintable(dir.absoluteFilePath(QFileInfo(plugin2Path).fileName()))); QVERIFY2(QFile::copy(plugin3Path, dir.absoluteFilePath(QFileInfo(plugin3Path).fileName())), - qPrintable(dir.absoluteFilePath(QFileInfo(plugin3Path).fileName()))); + qPrintable(dir.absoluteFilePath(QFileInfo(plugin3Path).fileName()))); LibraryPathRestorer restorer(QCoreApplication::libraryPaths()); // we only want plugins from our temporary dir QCoreApplication::setLibraryPaths(QStringList() << temp.path()); auto sortPlugins = [](const KPluginMetaData &a, const KPluginMetaData &b) { return a.pluginId() < b.pluginId(); }; // it should find jsonplugin and jsonplugin2 since unversionedplugin does not have any meta data - auto plugins = KPluginLoader::findPlugins("kpluginmetadatatest"); + auto plugins = KPluginLoader::findPlugins(QStringLiteral("kpluginmetadatatest")); std::sort(plugins.begin(), plugins.end(), sortPlugins); QCOMPARE(plugins.size(), 2); QCOMPARE(plugins[0].pluginId(), QStringLiteral("foobar")); // ID is not the filename, it is set in the JSON metadata QCOMPARE(plugins[0].description(), QStringLiteral("This is another plugin")); QCOMPARE(plugins[1].pluginId(), QStringLiteral("jsonplugin")); QCOMPARE(plugins[1].description(), QStringLiteral("This is a plugin")); // filter accepts none - plugins = KPluginLoader::findPlugins("kpluginmetadatatest", [](const KPluginMetaData &) { return false; }); + plugins = KPluginLoader::findPlugins(QStringLiteral("kpluginmetadatatest"), [](const KPluginMetaData &) { return false; }); std::sort(plugins.begin(), plugins.end(), sortPlugins); QCOMPARE(plugins.size(), 0); // filter accepts all - plugins = KPluginLoader::findPlugins("kpluginmetadatatest", [](const KPluginMetaData &) { return true; }); + plugins = KPluginLoader::findPlugins(QStringLiteral("kpluginmetadatatest"), [](const KPluginMetaData &) { return true; }); std::sort(plugins.begin(), plugins.end(), sortPlugins); QCOMPARE(plugins.size(), 2); QCOMPARE(plugins[0].description(), QStringLiteral("This is another plugin")); QCOMPARE(plugins[1].description(), QStringLiteral("This is a plugin")); // invalid std::function as filter - plugins = KPluginLoader::findPlugins("kpluginmetadatatest"); + plugins = KPluginLoader::findPlugins(QStringLiteral("kpluginmetadatatest")); std::sort(plugins.begin(), plugins.end(), sortPlugins); QCOMPARE(plugins.size(), 2); QCOMPARE(plugins[0].description(), QStringLiteral("This is another plugin")); QCOMPARE(plugins[1].description(), QStringLiteral("This is a plugin")); // by plugin id - plugins = KPluginLoader::findPluginsById(dir.absolutePath(), "foobar"); + plugins = KPluginLoader::findPluginsById(dir.absolutePath(), QStringLiteral("foobar")); QCOMPARE(plugins.size(), 1); QCOMPARE(plugins[0].description(), QStringLiteral("This is another plugin")); // by plugin invalid id - plugins = KPluginLoader::findPluginsById(dir.absolutePath(), "invalidid"); + plugins = KPluginLoader::findPluginsById(dir.absolutePath(), QStringLiteral("invalidid")); QCOMPARE(plugins.size(), 0); // absolute path, no filter @@ -377,28 +377,28 @@ void testForEachPlugin() { - const QString jsonPluginSrc = KPluginLoader::findPlugin("jsonplugin"); + const QString jsonPluginSrc = KPluginLoader::findPlugin(QStringLiteral("jsonplugin")); QVERIFY2(!jsonPluginSrc.isEmpty(), qPrintable(jsonPluginSrc)); - const QString unversionedPluginSrc = KPluginLoader::findPlugin("unversionedplugin"); + const QString unversionedPluginSrc = KPluginLoader::findPlugin(QStringLiteral("unversionedplugin")); QVERIFY2(!unversionedPluginSrc.isEmpty(), qPrintable(unversionedPluginSrc)); - const QString jsonPlugin2Src = KPluginLoader::findPlugin("jsonplugin2"); + const QString jsonPlugin2Src = KPluginLoader::findPlugin(QStringLiteral("jsonplugin2")); QVERIFY2(!jsonPlugin2Src.isEmpty(), qPrintable(jsonPlugin2Src)); QTemporaryDir temp; QVERIFY(temp.isValid()); QDir dir(temp.path()); - QVERIFY(dir.mkdir("for-each-plugin")); - QVERIFY(dir.cd("for-each-plugin")); + QVERIFY(dir.mkdir(QStringLiteral("for-each-plugin"))); + QVERIFY(dir.cd(QStringLiteral("for-each-plugin"))); const QString jsonPluginDest = dir.absoluteFilePath(QFileInfo(jsonPluginSrc).fileName()); QVERIFY2(QFile::copy(jsonPluginSrc, jsonPluginDest), qPrintable(jsonPluginDest)); const QString unversionedPluginDest = dir.absoluteFilePath(QFileInfo(unversionedPluginSrc).fileName()); QVERIFY2(QFile::copy(unversionedPluginSrc, unversionedPluginDest), qPrintable(unversionedPluginDest)); // copy jsonplugin2 to a "for-each-plugin" subdirectory in a different directory QTemporaryDir temp2; QVERIFY(temp2.isValid()); QDir dir2(temp2.path()); - QVERIFY(dir2.mkdir("for-each-plugin")); - QVERIFY(dir2.cd("for-each-plugin")); + QVERIFY(dir2.mkdir(QStringLiteral("for-each-plugin"))); + QVERIFY(dir2.cd(QStringLiteral("for-each-plugin"))); const QString jsonPlugin2Dest = dir2.absoluteFilePath(QFileInfo(jsonPlugin2Src).fileName()); QVERIFY2(QFile::copy(jsonPlugin2Src, jsonPlugin2Dest), qPrintable(jsonPlugin2Dest)); @@ -431,23 +431,23 @@ expectedPlugins = QStringList() << jsonPluginDest << unversionedPluginDest; expectedPlugins.sort(); foundPlugins.clear(); - KPluginLoader::forEachPlugin("for-each-plugin", addToFoundPlugins); + KPluginLoader::forEachPlugin(QStringLiteral("for-each-plugin"), addToFoundPlugins); foundPlugins.sort(); QCOMPARE(foundPlugins, expectedPlugins); QCoreApplication::setLibraryPaths(QStringList() << temp2.path()); expectedPlugins = QStringList() << jsonPlugin2Dest; expectedPlugins.sort(); foundPlugins.clear(); - KPluginLoader::forEachPlugin("for-each-plugin", addToFoundPlugins); + KPluginLoader::forEachPlugin(QStringLiteral("for-each-plugin"), addToFoundPlugins); foundPlugins.sort(); QCOMPARE(foundPlugins, expectedPlugins); QCoreApplication::setLibraryPaths(QStringList() << temp.path() << temp2.path()); expectedPlugins = QStringList() << jsonPluginDest << unversionedPluginDest << jsonPlugin2Dest; expectedPlugins.sort(); foundPlugins.clear(); - KPluginLoader::forEachPlugin("for-each-plugin", addToFoundPlugins); + KPluginLoader::forEachPlugin(QStringLiteral("for-each-plugin"), addToFoundPlugins); foundPlugins.sort(); QCOMPARE(foundPlugins, expectedPlugins); } diff --git a/autotests/kpluginmetadatatest.cpp b/autotests/kpluginmetadatatest.cpp --- a/autotests/kpluginmetadatatest.cpp +++ b/autotests/kpluginmetadatatest.cpp @@ -46,7 +46,7 @@ private Q_SLOTS: void testFromPluginLoader() { - QString location = KPluginLoader::findPlugin("jsonplugin"); + QString location = KPluginLoader::findPlugin(QStringLiteral("jsonplugin")); QVERIFY2(!location.isEmpty(),"Could not find jsonplugin"); // now that this file is translated we need to read it instead of hardcoding the contents here @@ -60,10 +60,10 @@ location = QFileInfo(location).absoluteFilePath(); - KPluginMetaData fromQPluginLoader(QPluginLoader("jsonplugin")); - KPluginMetaData fromKPluginLoader(KPluginLoader("jsonplugin")); + KPluginMetaData fromQPluginLoader(QPluginLoader(QStringLiteral("jsonplugin"))); + KPluginMetaData fromKPluginLoader(KPluginLoader(QStringLiteral("jsonplugin"))); KPluginMetaData fromFullPath(location); - KPluginMetaData fromRelativePath("jsonplugin"); + KPluginMetaData fromRelativePath(QStringLiteral("jsonplugin")); KPluginMetaData fromRawData(jsonDoc.object(), location); auto description = QStringLiteral("This is a plugin"); @@ -107,25 +107,25 @@ { QJsonParseError e; QJsonObject jo = QJsonDocument::fromJson("{\n" - " \"KPlugin\": {\n" - " \"Name\": \"Date and Time\",\n" - " \"Description\": \"Date and time by timezone\",\n" - " \"Icon\": \"preferences-system-time\",\n" - " \"Authors\": { \"Name\": \"Aaron Seigo\", \"Email\": \"aseigo@kde.org\" },\n" - " \"Translators\": { \"Name\": \"No One\", \"Email\": \"no.one@kde.org\" },\n" - " \"OtherContributors\": { \"Name\": \"No One\", \"Email\": \"no.one@kde.org\" },\n" - " \"Category\": \"Date and Time\",\n" - " \"Dependencies\": [ \"foo\", \"bar\"],\n" - " \"EnabledByDefault\": \"true\",\n" - " \"ExtraInformation\": \"Something else\",\n" - " \"License\": \"LGPL\",\n" - " \"Copyright\": \"(c) Alex Richardson 2015\",\n" - " \"Id\": \"time\",\n" - " \"Version\": \"1.0\",\n" - " \"Website\": \"https://plasma.kde.org/\",\n" - " \"MimeTypes\": [ \"image/png\" ],\n" - " \"ServiceTypes\": [\"Plasma/DataEngine\"]\n" - " }\n}\n", &e).object(); + " \"KPlugin\": {\n" + " \"Name\": \"Date and Time\",\n" + " \"Description\": \"Date and time by timezone\",\n" + " \"Icon\": \"preferences-system-time\",\n" + " \"Authors\": { \"Name\": \"Aaron Seigo\", \"Email\": \"aseigo@kde.org\" },\n" + " \"Translators\": { \"Name\": \"No One\", \"Email\": \"no.one@kde.org\" },\n" + " \"OtherContributors\": { \"Name\": \"No One\", \"Email\": \"no.one@kde.org\" },\n" + " \"Category\": \"Date and Time\",\n" + " \"Dependencies\": [ \"foo\", \"bar\"],\n" + " \"EnabledByDefault\": \"true\",\n" + " \"ExtraInformation\": \"Something else\",\n" + " \"License\": \"LGPL\",\n" + " \"Copyright\": \"(c) Alex Richardson 2015\",\n" + " \"Id\": \"time\",\n" + " \"Version\": \"1.0\",\n" + " \"Website\": \"https://plasma.kde.org/\",\n" + " \"MimeTypes\": [ \"image/png\" ],\n" + " \"ServiceTypes\": [\"Plasma/DataEngine\"]\n" + " }\n}\n", &e).object(); QCOMPARE(e.error, QJsonParseError::NoError); KPluginMetaData m(jo, QString()); QVERIFY(m.isValid()); @@ -135,7 +135,7 @@ QCOMPARE(m.extraInformation(), QStringLiteral("Something else")); QCOMPARE(m.iconName(), QStringLiteral("preferences-system-time")); QCOMPARE(m.category(), QStringLiteral("Date and Time")); - QCOMPARE(m.dependencies(), QStringList() << "foo" << "bar"); + QCOMPARE(m.dependencies(), QStringList() << QStringLiteral("foo") << QStringLiteral("bar")); QCOMPARE(m.authors().size(), 1); QCOMPARE(m.authors()[0].name(), QStringLiteral("Aaron Seigo")); QCOMPARE(m.authors()[0].emailAddress(), QStringLiteral("aseigo@kde.org")); @@ -158,71 +158,71 @@ { QJsonParseError e; QJsonObject jo = QJsonDocument::fromJson("{ \"KPlugin\": {\n" - "\"Name\": \"Name\",\n" - "\"Name[de]\": \"Name (de)\",\n" - "\"Name[de_DE]\": \"Name (de_DE)\",\n" - "\"Description\": \"Description\",\n" - "\"Description[de]\": \"Beschreibung (de)\",\n" - "\"Description[de_DE]\": \"Beschreibung (de_DE)\"\n" - "}\n}", &e).object(); + "\"Name\": \"Name\",\n" + "\"Name[de]\": \"Name (de)\",\n" + "\"Name[de_DE]\": \"Name (de_DE)\",\n" + "\"Description\": \"Description\",\n" + "\"Description[de]\": \"Beschreibung (de)\",\n" + "\"Description[de_DE]\": \"Beschreibung (de_DE)\"\n" + "}\n}", &e).object(); KPluginMetaData m(jo, QString()); QLocale::setDefault(QLocale::c()); QCOMPARE(m.name(), QStringLiteral("Name")); QCOMPARE(m.description(), QStringLiteral("Description")); - QLocale::setDefault(QLocale("de_DE")); + QLocale::setDefault(QLocale(QStringLiteral("de_DE"))); QCOMPARE(m.name(), QStringLiteral("Name (de_DE)")); QCOMPARE(m.description(), QStringLiteral("Beschreibung (de_DE)")); - QLocale::setDefault(QLocale("de_CH")); + QLocale::setDefault(QLocale(QStringLiteral("de_CH"))); QCOMPARE(m.name(), QStringLiteral("Name (de)")); QCOMPARE(m.description(), QStringLiteral("Beschreibung (de)")); - QLocale::setDefault(QLocale("fr_FR")); + QLocale::setDefault(QLocale(QStringLiteral("fr_FR"))); QCOMPARE(m.name(), QStringLiteral("Name")); QCOMPARE(m.description(), QStringLiteral("Description")); } void testReadStringList() { QJsonParseError e; QJsonObject jo = QJsonDocument::fromJson("{\n" - "\"String\": \"foo\",\n" - "\"OneArrayEntry\": [ \"foo\" ],\n" - "\"Bool\": true,\n" // make sure booleans are accepted - "\"QuotedBool\": \"true\",\n" // make sure booleans are accepted - "\"Number\": 12345,\n" // number should also work - "\"QuotedNumber\": \"12345\",\n" // number should also work - "\"EmptyArray\": [],\n" - "\"NumberArray\": [1, 2, 3],\n" - "\"BoolArray\": [true, false, true],\n" - "\"StringArray\": [\"foo\", \"bar\"],\n" - "\"Null\": null,\n" // should return empty list - "\"QuotedNull\": \"null\",\n" // this is okay, it is a string - "\"ArrayWithNull\": [ \"foo\", null, \"bar\"],\n" // TODO: null is converted to empty string, is this okay? - "\"Object\": { \"foo\": \"bar\" }\n" // should return empty list - "}", &e).object(); + "\"String\": \"foo\",\n" + "\"OneArrayEntry\": [ \"foo\" ],\n" + "\"Bool\": true,\n" // make sure booleans are accepted + "\"QuotedBool\": \"true\",\n" // make sure booleans are accepted + "\"Number\": 12345,\n" // number should also work + "\"QuotedNumber\": \"12345\",\n" // number should also work + "\"EmptyArray\": [],\n" + "\"NumberArray\": [1, 2, 3],\n" + "\"BoolArray\": [true, false, true],\n" + "\"StringArray\": [\"foo\", \"bar\"],\n" + "\"Null\": null,\n" // should return empty list + "\"QuotedNull\": \"null\",\n" // this is okay, it is a string + "\"ArrayWithNull\": [ \"foo\", null, \"bar\"],\n" // TODO: null is converted to empty string, is this okay? + "\"Object\": { \"foo\": \"bar\" }\n" // should return empty list + "}", &e).object(); QCOMPARE(e.error, QJsonParseError::NoError); QTest::ignoreMessage(QtWarningMsg, "Expected JSON property \"String\" to be a string list. Treating it as a list with a single entry: \"foo\" "); - QCOMPARE(KPluginMetaData::readStringList(jo, "String"), QStringList("foo")); - QCOMPARE(KPluginMetaData::readStringList(jo, "OneArrayEntry"), QStringList("foo")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("String")), QStringList(QStringLiteral("foo")));; + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("OneArrayEntry")), QStringList(QStringLiteral("foo"))); QTest::ignoreMessage(QtWarningMsg, "Expected JSON property \"Bool\" to be a string list. Treating it as a list with a single entry: \"true\" "); - QCOMPARE(KPluginMetaData::readStringList(jo, "Bool"), QStringList("true")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("Bool")), QStringList(QStringLiteral("true"))); QTest::ignoreMessage(QtWarningMsg, "Expected JSON property \"QuotedBool\" to be a string list. Treating it as a list with a single entry: \"true\" "); - QCOMPARE(KPluginMetaData::readStringList(jo, "QuotedBool"), QStringList("true")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("QuotedBool")), QStringList(QStringLiteral("true"))); QTest::ignoreMessage(QtWarningMsg, "Expected JSON property \"Number\" to be a string list. Treating it as a list with a single entry: \"12345\" "); - QCOMPARE(KPluginMetaData::readStringList(jo, "Number"), QStringList("12345")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("Number")), QStringList(QStringLiteral("12345"))); QTest::ignoreMessage(QtWarningMsg, "Expected JSON property \"QuotedNumber\" to be a string list. Treating it as a list with a single entry: \"12345\" "); - QCOMPARE(KPluginMetaData::readStringList(jo, "QuotedNumber"), QStringList("12345")); - QCOMPARE(KPluginMetaData::readStringList(jo, "EmptyArray"), QStringList()); - QCOMPARE(KPluginMetaData::readStringList(jo, "NumberArray"), QStringList() << "1" << "2" << "3"); - QCOMPARE(KPluginMetaData::readStringList(jo, "BoolArray"), QStringList() << "true" << "false" << "true"); - QCOMPARE(KPluginMetaData::readStringList(jo, "StringArray"), QStringList() << "foo" << "bar"); - QCOMPARE(KPluginMetaData::readStringList(jo, "Null"), QStringList()); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("QuotedNumber")), QStringList(QStringLiteral("12345"))); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("EmptyArray")), QStringList()); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("NumberArray")), QStringList() << QStringLiteral("1") << QStringLiteral("2") << QStringLiteral("3")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("BoolArray")), QStringList() << QStringLiteral("true") << QStringLiteral("false") << QStringLiteral("true")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("StringArray")), QStringList() << QStringLiteral("foo") << QStringLiteral("bar")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("Null")), QStringList()); QTest::ignoreMessage(QtWarningMsg, "Expected JSON property \"QuotedNull\" to be a string list. Treating it as a list with a single entry: \"null\" "); - QCOMPARE(KPluginMetaData::readStringList(jo, "QuotedNull"), QStringList("null")); - QCOMPARE(KPluginMetaData::readStringList(jo, "ArrayWithNull"), QStringList() << "foo" << "" << "bar"); - QCOMPARE(KPluginMetaData::readStringList(jo, "Object"), QStringList()); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("QuotedNull")), QStringList(QStringLiteral("null"))); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("ArrayWithNull")), QStringList() << QStringLiteral("foo") << QStringLiteral("") << QStringLiteral("bar")); + QCOMPARE(KPluginMetaData::readStringList(jo, QStringLiteral("Object")), QStringList()); } void testFromDesktopFile() @@ -240,13 +240,13 @@ QCOMPARE(md.version(), QStringLiteral("1.0")); QCOMPARE(md.dependencies(), QStringList()); QCOMPARE(md.isHidden(), false); - QCOMPARE(md.serviceTypes(), QStringList("KService/NSA")); - QCOMPARE(md.mimeTypes(), QStringList() << "image/png" << "application/pdf"); + QCOMPARE(md.serviceTypes(), QStringList(QStringLiteral("KService/NSA"))); + QCOMPARE(md.mimeTypes(), QStringList() << QStringLiteral("image/png") << QStringLiteral("application/pdf")); - auto kp = md.rawData()["KPlugin"].toObject(); + auto kp = md.rawData()[QStringLiteral("KPlugin")].toObject(); QStringList formFactors = KPluginMetaData::readStringList(kp, QStringLiteral("FormFactors")); - QCOMPARE(formFactors, QStringList() << "mediacenter" << "desktop"); - QCOMPARE(md.formFactors(), QStringList() << "mediacenter" << "desktop"); + QCOMPARE(formFactors, QStringList() << QStringLiteral("mediacenter") << QStringLiteral("desktop")); + QCOMPARE(md.formFactors(), QStringList() << QStringLiteral("mediacenter") << QStringLiteral("desktop")); const QString dfilehidden = QFINDTESTDATA("data/hiddenplugin.desktop"); KPluginMetaData mdhidden(dfilehidden); @@ -284,17 +284,17 @@ KPluginMetaData md = KPluginMetaData::fromDesktopFile(inputPath, QStringList() << typesPath); QVERIFY(md.isValid()); QCOMPARE(md.name(), QStringLiteral("Example")); - QCOMPARE(md.serviceTypes(), QStringList() << "foo/bar" << "bar/foo"); + QCOMPARE(md.serviceTypes(), QStringList() << QStringLiteral("foo/bar") << QStringLiteral("bar/foo")); // qDebug().noquote() << QJsonDocument(md.rawData()).toJson(); QCOMPARE(md.rawData().size(), 8); - QVERIFY(md.rawData().value("KPlugin").isObject()); - QCOMPARE(md.rawData().value("X-Test-Integer"), QJsonValue(42)); - QCOMPARE(md.rawData().value("X-Test-Bool"), QJsonValue(true)); - QCOMPARE(md.rawData().value("X-Test-Double"), QJsonValue(42.42)); - QCOMPARE(md.rawData().value("X-Test-String"), QJsonValue("foobar")); - QCOMPARE(md.rawData().value("X-Test-List"), QJsonValue(QJsonArray::fromStringList(QStringList() << "a" << "b" << "c" << "def"))); - QCOMPARE(md.rawData().value("X-Test-Size"), QJsonValue("10,20")); // QSize no longer supported (and also no longer used) - QCOMPARE(md.rawData().value("X-Test-Unknown"), QJsonValue("true")); // unknown property -> string + QVERIFY(md.rawData().value(QStringLiteral("KPlugin")).isObject()); + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-Integer")), QJsonValue(42)); + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-Bool")), QJsonValue(true)); + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-Double")), QJsonValue(42.42)); + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-String")), QJsonValue(QStringLiteral("foobar"))); + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-List")), QJsonValue(QJsonArray::fromStringList(QStringList() << QStringLiteral("a") << QStringLiteral("b") << QStringLiteral("c") << QStringLiteral("def")))); + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-Size")), QJsonValue(QStringLiteral("10,20"))); // QSize no longer supported (and also no longer used) + QCOMPARE(md.rawData().value(QStringLiteral("X-Test-Unknown")), QJsonValue(QStringLiteral("true"))); // unknown property -> string } @@ -308,29 +308,28 @@ QTest::ignoreMessage(QtWarningMsg, "Illegal .desktop group definition (does not end with ']'): \"[PropertyDef::\""); QTest::ignoreMessage(QtWarningMsg, "Illegal .desktop group definition (does not end with ']'): \"[\""); QTest::ignoreMessage(QtWarningMsg, "Read empty .desktop file group name! Invalid file?"); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Skipping invalid group \"\" in service type \".*/bad-groups-servicetype.desktop\"")); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Skipping invalid group \"DoesNotStartWithPropertyDef::SomeOtherProperty\" in service type \".+/data/servicetypes/bad-groups-servicetype.desktop\"")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(QStringLiteral("Skipping invalid group \"\" in service type \".*/bad-groups-servicetype.desktop\""))); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(QStringLiteral("Skipping invalid group \"DoesNotStartWithPropertyDef::SomeOtherProperty\" in service type \".+/data/servicetypes/bad-groups-servicetype.desktop\""))); QTest::ignoreMessage(QtWarningMsg, "Could not find Type= key in group \"PropertyDef::MissingType\""); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Property type \"integer\" is not a known QVariant type. Found while parsing property definition for \"InvalidType\" in \".+/data/servicetypes/bad-groups-servicetype.desktop\"")); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".+/data/servicetypes/bad-groups-input.desktop:\\d+: Key name is missing: \"=11\"")); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".+/data/servicetypes/bad-groups-input.desktop:\\d+: Key name is missing: \"=13\"")); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".+/data/servicetypes/bad-groups-input.desktop:\\d+: Key name is missing: \"=14\"")); - + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(QStringLiteral("Property type \"integer\" is not a known QVariant type. Found while parsing property definition for \"InvalidType\" in \".+/data/servicetypes/bad-groups-servicetype.desktop\""))); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(QStringLiteral(".+/data/servicetypes/bad-groups-input.desktop:\\d+: Key name is missing: \"=11\""))); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(QStringLiteral(".+/data/servicetypes/bad-groups-input.desktop:\\d+: Key name is missing: \"=13\""))); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(QStringLiteral(".+/data/servicetypes/bad-groups-input.desktop:\\d+: Key name is missing: \"=14\""))); KPluginMetaData md = KPluginMetaData::fromDesktopFile(inputPath, QStringList() << typesPath); QVERIFY(md.isValid()); QCOMPARE(md.name(), QStringLiteral("Bad Groups")); // qDebug().noquote() << QJsonDocument(md.rawData()).toJson(); QCOMPARE(md.rawData().size(), 8); - QCOMPARE(md.rawData().value("ThisIsOkay"), QJsonValue(10)); // integer + QCOMPARE(md.rawData().value(QStringLiteral("ThisIsOkay")), QJsonValue(10)); // integer // 11 is empty group - QCOMPARE(md.rawData().value("MissingTerminator"), QJsonValue(12)); // accept missing group terminator (for now) -> integer + QCOMPARE(md.rawData().value(QStringLiteral("MissingTerminator")), QJsonValue(12)); // accept missing group terminator (for now) -> integer // 13 is empty group name // 14 is empty group name - QCOMPARE(md.rawData().value("SomeOtherProperty"), QJsonValue("15")); // does not start with PropertyDef:: -> fall back to string - QCOMPARE(md.rawData().value("TrailingSpacesAreOkay"), QJsonValue(16)); // accept trailing spaces in group name -> integer - QCOMPARE(md.rawData().value("MissingType"), QJsonValue("17")); // Type= missing -> fall back to string - QCOMPARE(md.rawData().value("InvalidType"), QJsonValue("18")); // Type= is invalid -> fall back to string - QCOMPARE(md.rawData().value("ThisIsOkayAgain"), QJsonValue(19)); // valid defintion after invalid ones should still work -> integer + QCOMPARE(md.rawData().value(QStringLiteral("SomeOtherProperty")), QJsonValue(QStringLiteral("15"))); // does not start with PropertyDef:: -> fall back to string + QCOMPARE(md.rawData().value(QStringLiteral("TrailingSpacesAreOkay")), QJsonValue(16)); // accept trailing spaces in group name -> integer + QCOMPARE(md.rawData().value(QStringLiteral("MissingType")), QJsonValue(QStringLiteral("17"))); // Type= missing -> fall back to string + QCOMPARE(md.rawData().value(QStringLiteral("InvalidType")), QJsonValue(QStringLiteral("18"))); // Type= is invalid -> fall back to string + QCOMPARE(md.rawData().value(QStringLiteral("ThisIsOkayAgain")), QJsonValue(19)); // valid defintion after invalid ones should still work -> integer } void testJSONMetadata() @@ -340,10 +339,10 @@ QVERIFY(md.isValid()); QCOMPARE(md.name(), QStringLiteral("Test")); - QCOMPARE(md.value("X-Plasma-MainScript"), QStringLiteral("ui/main.qml")); + QCOMPARE(md.value(QStringLiteral("X-Plasma-MainScript")), QStringLiteral("ui/main.qml")); QJsonArray expected; expected.append(QStringLiteral("Export")); - QCOMPARE(md.rawData().value("X-Purpose-PluginTypes").toArray(), expected); + QCOMPARE(md.rawData().value(QStringLiteral("X-Purpose-PluginTypes")).toArray(), expected); } }; diff --git a/autotests/kprocesstest.cpp b/autotests/kprocesstest.cpp --- a/autotests/kprocesstest.cpp +++ b/autotests/kprocesstest.cpp @@ -44,9 +44,9 @@ { QProcess p; p.setProcessChannelMode(QProcess::MergedChannels); - p.start(gargv[0], QStringList() << QString::number(how) << QStringLiteral("--nocrashhandler")); + p.start(QString::fromLatin1(gargv[0]), QStringList() << QString::number(how) << QStringLiteral("--nocrashhandler")); p.waitForFinished(); - return p.readAllStandardOutput(); + return QString::fromLatin1(p.readAllStandardOutput()); } #define EOUT "foo - stdout" @@ -58,8 +58,8 @@ #define EO EOUT "\n" #define EE EERR "\n" #define TESTCHAN(me,ms,pout,rout,rerr) \ - e = "mode: " ms "\n" POUT pout ROUT rout RERR rerr; \ - a = "mode: " ms "\n" + recurse(KProcess::me); \ + e = QStringLiteral("mode: " ms "\n" POUT pout ROUT rout RERR rerr); \ + a = QStringLiteral("mode: " ms "\n") + recurse(KProcess::me); \ QCOMPARE(a, e) void KProcessTest::test_channels() @@ -79,26 +79,27 @@ void KProcessTest::test_setShellCommand() { -// Condition copied from kprocess.cpp + // Condition copied from kprocess.cpp #if !defined(__linux__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__) && !defined(__GNU__) QSKIP("This test needs a free UNIX system"); #else KProcess p; - p.setShellCommand("cat"); + p.setShellCommand(QStringLiteral("cat")); QCOMPARE(p.program().count(), 1); - QCOMPARE(p.program().at(0), QStandardPaths::findExecutable("cat")); - QVERIFY(p.program().at(0).endsWith("/bin/cat")); - p.setShellCommand("true || false"); - QCOMPARE(p.program(), QStringList() << "/bin/sh" << "-c" << "true || false"); + QCOMPARE(p.program().at(0), QStandardPaths::findExecutable(QStringLiteral("cat"))); + QVERIFY(p.program().at(0).endsWith(QStringLiteral("/bin/cat"))); + p.setShellCommand(QStringLiteral("true || false")); + QCOMPARE(p.program(), QStringList() << QStringLiteral("/bin/sh") << QStringLiteral("-c") + << QString::fromLatin1("true || false")); #endif } static void recursor(char **argv) { if (argv[1]) { KProcess p; - p.setShellCommand("echo " EOUT "; echo " EERR " >&2"); + p.setShellCommand(QString::fromLatin1("echo " EOUT "; echo " EERR " >&2")); p.setOutputChannelMode(static_cast(atoi(argv[1]))); fputs(POUT, stdout); fflush(stdout); diff --git a/autotests/krandomtest.cpp b/autotests/krandomtest.cpp --- a/autotests/krandomtest.cpp +++ b/autotests/krandomtest.cpp @@ -62,7 +62,7 @@ // Launch a separate process to generate random numbers to test first-time // seeding. - subtestProcess.start(binpath, QStringList() << QString::number(seq.count())); + subtestProcess.start(QLatin1String(binpath), QStringList() << QString::number(seq.count())); subtestProcess.waitForFinished(); QTextStream childStream(subtestProcess.readAllStandardOutput()); @@ -107,7 +107,7 @@ void KRandomTest::test_randomString() { const int desiredLength = 12; - const QRegExp outputFormat("[A-Za-z0-9]+"); + const QRegExp outputFormat(QStringLiteral("[A-Za-z0-9]+")); QString testString = KRandom::randomString(desiredLength); QCOMPARE(testString.length(), desiredLength); diff --git a/autotests/kshelltest.cpp b/autotests/kshelltest.cpp --- a/autotests/kshelltest.cpp +++ b/autotests/kshelltest.cpp @@ -55,14 +55,14 @@ KShellTest::tildeExpand() { QString me(KUser().loginName()); - QCOMPARE(KShell::tildeExpand("~"), QDir::homePath()); - QCOMPARE(KShell::tildeExpand("~/dir"), QString(QDir::homePath() + "/dir")); - QCOMPARE(KShell::tildeExpand('~' + me), myHomePath()); - QCOMPARE(KShell::tildeExpand('~' + me + "/dir"), QString(myHomePath() + "/dir")); + QCOMPARE(KShell::tildeExpand(QStringLiteral("~")), QDir::homePath()); + QCOMPARE(KShell::tildeExpand(QStringLiteral("~/dir")), QString(QDir::homePath() + QStringLiteral("/dir"))); + QCOMPARE(KShell::tildeExpand(QLatin1Char('~') + me), myHomePath()); + QCOMPARE(KShell::tildeExpand(QLatin1Char('~') + me + QStringLiteral("/dir")), QString(myHomePath() + QStringLiteral("/dir"))); #ifdef Q_OS_WIN QCOMPARE(KShell::tildeExpand("^~" + me), QString('~' + me)); #else - QCOMPARE(KShell::tildeExpand("\\~" + me), QString('~' + me)); + QCOMPARE(KShell::tildeExpand(QStringLiteral("\\~") + me), QString(QStringLiteral("~") + me)); #endif } @@ -81,16 +81,16 @@ QCOMPARE(KShell::quoteArg("foo bar\"\\\"bla"), QString("\"foo bar\"\\^\"\\\\\\^\"\"bla\"")); QCOMPARE(KShell::quoteArg("a % space"), QString("\"a %PERCENT_SIGN% space\"")); #else - QCOMPARE(KShell::quoteArg("a space"), QString("'a space'")); + QCOMPARE(KShell::quoteArg(QStringLiteral("a space")), QStringLiteral("'a space'")); #endif } void KShellTest::joinArgs() { QStringList list; - list << "this" << "is" << "a" << "test"; - QCOMPARE(KShell::joinArgs(list), QString("this is a test")); + list << QStringLiteral("this") << QStringLiteral("is") << QStringLiteral("a") << QStringLiteral("test"); + QCOMPARE(KShell::joinArgs(list), QStringLiteral("this is a test")); } static QString sj(const QString &str, KShell::Options flags, KShell::Errors *ret) @@ -136,37 +136,37 @@ QString("\\^\"\"just \"\\^\"\" fine\"\\^\"")); QVERIFY(err == KShell::NoError); #else - QCOMPARE(sj("\"~qU4rK\" 'text' 'jo'\"jo\" $'crap' $'\\\\\\'\\e\\x21' ha\\ lo \\a", KShell::NoOptions, &err), - QString("'~qU4rK' text jojo crap '\\'\\''\x1b!' 'ha lo' a")); + QCOMPARE(sj(QString::fromUtf8("\"~qU4rK\" 'text' 'jo'\"jo\" $'crap' $'\\\\\\'\\e\\x21' ha\\ lo \\a"), KShell::NoOptions, &err), + QString::fromUtf8("'~qU4rK' text jojo crap '\\'\\''\x1b!' 'ha lo' a")); QVERIFY(err == KShell::NoError); - QCOMPARE(sj("\"~qU4rK\" 'text'", KShell::TildeExpand, &err), - QString("'~qU4rK' text")); + QCOMPARE(sj(QStringLiteral("\"~qU4rK\" 'text'"), KShell::TildeExpand, &err), + QStringLiteral("'~qU4rK' text")); QVERIFY(err == KShell::NoError); - QCOMPARE(sj("~\"qU4rK\" 'text'", KShell::TildeExpand, &err), - QString("'~qU4rK' text")); + QCOMPARE(sj(QStringLiteral("~\"qU4rK\" 'text'"), KShell::TildeExpand, &err), + QStringLiteral("'~qU4rK' text")); QVERIFY(err == KShell::NoError); - QCOMPARE(sj("~/\"dir\" 'text'", KShell::TildeExpand, &err), - QString(QDir::homePath() + "/dir text")); + QCOMPARE(sj(QStringLiteral("~/\"dir\" 'text'"), KShell::TildeExpand, &err), + QString(QDir::homePath() + QStringLiteral("/dir text"))); QVERIFY(err == KShell::NoError); - QCOMPARE(sj("~ 'text' ~", KShell::TildeExpand, &err), - QString(QDir::homePath() + " text " + QDir::homePath())); + QCOMPARE(sj(QStringLiteral("~ 'text' ~"), KShell::TildeExpand, &err), + QString(QDir::homePath() + QStringLiteral(" text ") + QDir::homePath())); QVERIFY(err == KShell::NoError); - QCOMPARE(sj("\\~ blah", KShell::TildeExpand, &err), - QString("'~' blah")); + QCOMPARE(sj(QStringLiteral("\\~ blah"), KShell::TildeExpand, &err), + QStringLiteral("'~' blah")); QVERIFY(err == KShell::NoError); - QCOMPARE(sj("~qU4rK ~" + KUser().loginName(), KShell::TildeExpand, &err), - QString("'~qU4rK' " + myHomePath())); + QCOMPARE(sj(QStringLiteral("~qU4rK ~") + KUser().loginName(), KShell::TildeExpand, &err), + QString(QStringLiteral("'~qU4rK' ") + myHomePath())); QVERIFY(err == KShell::NoError); - const QString unicodeSpaceFileName = "test テスト.txt"; // #345140 + const QString unicodeSpaceFileName = QStringLiteral("test テスト.txt"); // #345140 QCOMPARE(sj(unicodeSpaceFileName, KShell::AbortOnMeta | KShell::TildeExpand, &err), - unicodeSpaceFileName); + unicodeSpaceFileName); QVERIFY(err == KShell::NoError); #endif } @@ -177,8 +177,8 @@ { QTest::addColumn("string"); - QTest::newRow("no space") << QString("hiho"); - QTest::newRow("regular space") << QString("hi there"); + QTest::newRow("no space") << QStringLiteral("hiho"); + QTest::newRow("regular space") << QStringLiteral("hi there"); QTest::newRow("special space") << QString::fromUtf8("如何定期清潔典型的電風扇 講義.pdf"); } @@ -197,17 +197,16 @@ { KShell::Errors err1 = KShell::NoError, err2 = KShell::NoError; - QCOMPARE(sj("text", KShell::AbortOnMeta, &err1), - QString("text")); + QCOMPARE(sj(QStringLiteral("text"), KShell::AbortOnMeta, &err1), + QStringLiteral("text")); QVERIFY(err1 == KShell::NoError); #ifdef Q_OS_WIN QVERIFY(KShell::splitArgs("BLA & asdf sdfess d", KShell::AbortOnMeta, &err1).isEmpty()); QVERIFY(err1 == KShell::FoundMeta); QVERIFY(KShell::splitArgs("foo %PATH% bar", KShell::AbortOnMeta, &err1).isEmpty()); QVERIFY(err1 == KShell::FoundMeta); - QCOMPARE(sj("foo %PERCENT_SIGN% bar", KShell::AbortOnMeta, &err1), QString("foo %PERCENT_SIGN% bar")); QVERIFY(err1 == KShell::NoError); @@ -228,25 +227,24 @@ QString("b-q me \"\\\\|\"\\\\\\^\"")); QVERIFY(err1 == KShell::NoError); #else - QCOMPARE(sj("say \" error", KShell::NoOptions, &err1), + QCOMPARE(sj(QStringLiteral("say \" error"), KShell::NoOptions, &err1), QString()); QVERIFY(err1 != KShell::NoError); - QCOMPARE(sj("say \" still error", KShell::AbortOnMeta, &err1), + QCOMPARE(sj(QStringLiteral("say \" still error"), KShell::AbortOnMeta, &err1), QString()); QVERIFY(err1 != KShell::NoError); - QVERIFY(sj("say `echo no error`", KShell::NoOptions, &err1) != - sj("say `echo no error`", KShell::AbortOnMeta, &err2)); + QVERIFY(sj(QStringLiteral("say `echo no error`"), KShell::NoOptions, &err1) != + sj(QStringLiteral("say `echo no error`"), KShell::AbortOnMeta, &err2)); QVERIFY(err1 != err2); - QVERIFY(sj("BLA=say echo meta", KShell::NoOptions, &err1) != - sj("BLA=say echo meta", KShell::AbortOnMeta, &err2)); + QVERIFY(sj(QStringLiteral("BLA=say echo meta"), KShell::NoOptions, &err1) != + sj(QStringLiteral("BLA=say echo meta"), KShell::AbortOnMeta, &err2)); QVERIFY(err1 != err2); - QVERIFY(sj("B\"L\"A=say FOO=bar echo meta", KShell::NoOptions, &err1) == - sj("B\"L\"A=say FOO=bar echo meta", KShell::AbortOnMeta, &err2)); - QVERIFY(err1 == err2); + QVERIFY(sj(QStringLiteral("B\"L\"A=say FOO=bar echo meta"), KShell::NoOptions, &err1) == + sj(QStringLiteral("B\"L\"A=say FOO=bar echo meta"), KShell::AbortOnMeta, &err2)); #endif } diff --git a/autotests/kstringhandlertest.cpp b/autotests/kstringhandlertest.cpp --- a/autotests/kstringhandlertest.cpp +++ b/autotests/kstringhandlertest.cpp @@ -7,23 +7,23 @@ #include "kstringhandler.h" -QString KStringHandlerTest::test = "The quick brown fox jumped over the lazy bridge. "; +QString KStringHandlerTest::test = QStringLiteral("The quick brown fox jumped over the lazy bridge. "); void KStringHandlerTest::capwords() { QCOMPARE(KStringHandler::capwords(test), - QString("The Quick Brown Fox Jumped Over The Lazy Bridge. ")); + QStringLiteral("The Quick Brown Fox Jumped Over The Lazy Bridge. ")); } void KStringHandlerTest::tagURLs() { - QString test = "Click on https://foo@bar:www.kde.org/yoyo/dyne.html#a1 for info."; + QString test = QStringLiteral("Click on https://foo@bar:www.kde.org/yoyo/dyne.html#a1 for info."); QCOMPARE(KStringHandler::tagUrls(test), - QString("Click on https://foo@bar:www.kde.org/yoyo/dyne.html#a1 for info.")); + QStringLiteral("Click on https://foo@bar:www.kde.org/yoyo/dyne.html#a1 for info.")); - test = "http://www.foo.org/story$806"; + test = QStringLiteral("http://www.foo.org/story$806"); QCOMPARE(KStringHandler::tagUrls(test), - QString("http://www.foo.org/story$806")); + QStringLiteral("http://www.foo.org/story$806")); #if 0 // XFAIL - i.e. this needs to be fixed, but has never been @@ -36,23 +36,26 @@ void KStringHandlerTest::perlSplit() { QStringList expected; - expected << "some" << "string" << "for" << "you__here"; - QCOMPARE(KStringHandler::perlSplit("__", "some__string__for__you__here", 4), expected); + expected << QStringLiteral("some") << QStringLiteral("string") << QStringLiteral("for") + << QStringLiteral("you__here"); + QCOMPARE(KStringHandler::perlSplit(QStringLiteral("__"), QStringLiteral("some__string__for__you__here"), 4), expected); expected.clear(); - expected << "kparts" << "reaches" << "the parts other parts can't"; - QCOMPARE(KStringHandler::perlSplit(' ', "kparts reaches the parts other parts can't", 3), expected); + expected << QStringLiteral("kparts") << QStringLiteral("reaches") << QStringLiteral("the parts other parts can't"); + QCOMPARE(KStringHandler::perlSplit(QLatin1Char(' '), + QStringLiteral("kparts reaches the parts other parts can't"), 3), expected); expected.clear(); - expected << "Split" << "me" << "up ! I'm bored ! OK ?"; - QCOMPARE(KStringHandler::perlSplit(QRegExp("[! ]"), "Split me up ! I'm bored ! OK ?", 3), expected); + expected << QStringLiteral("Split") << QStringLiteral("me") << QStringLiteral("up ! I'm bored ! OK ?"); + QCOMPARE(KStringHandler::perlSplit(QRegExp(QStringLiteral("[! ]")), + QStringLiteral("Split me up ! I'm bored ! OK ?"), 3), expected); } void KStringHandlerTest::obscure() { // See bug 167900, obscure() produced chars that could not properly be converted to and from // UTF8. The result was that storing passwords with '!' in them did not work. - QString test = "!TEST!"; + QString test = QStringLiteral("!TEST!"); QString obscured = KStringHandler::obscure(test); QByteArray obscuredBytes = obscured.toUtf8(); QCOMPARE(KStringHandler::obscure(QString::fromUtf8(obscuredBytes.constData())), test); @@ -70,19 +73,22 @@ // Should insert a ZWSP after each '_' QTest::newRow("underscores") << "foo_bar_baz" - << QString("foo_" + zwsp + "bar_" + zwsp + "baz"); + << QString(QStringLiteral("foo_") + zwsp + QStringLiteral("bar_") + zwsp + QStringLiteral("baz")); // Should insert a ZWSP after each '-' QTest::newRow("hyphens") << "foo-bar-baz" - << QString("foo-" + zwsp + "bar-" + zwsp + "baz"); + << QString(QStringLiteral("foo-") + zwsp + + QStringLiteral("bar-") + zwsp + QStringLiteral("baz")); // Should insert a ZWSP after each '.' QTest::newRow("periods") << "foo.bar.baz" - << QString("foo." + zwsp + "bar." + zwsp + "baz"); + << QString(QStringLiteral("foo.") + + zwsp + QStringLiteral("bar.") + zwsp + QStringLiteral("baz")); // Should insert a ZWSP after each ',' QTest::newRow("commas") << "foo,bar,baz" - << QString("foo," + zwsp + "bar," + zwsp + "baz"); + << QString(QStringLiteral("foo,") + zwsp + + QStringLiteral("bar,") + zwsp + QStringLiteral("baz")); // Should result in no additional breaks since the '_'s are followed by spaces QTest::newRow("mixed underscores and spaces") @@ -93,40 +99,45 @@ // Should insert a ZWSP before '(' and after ')' QTest::newRow("parens") << "foo(bar)baz" - << QString("foo" + zwsp + "(bar)" + zwsp + "baz"); + << QString(QStringLiteral("foo") + zwsp + + QStringLiteral("(bar)") + zwsp + QStringLiteral("baz")); // Should insert a ZWSP before '[' and after ']' QTest::newRow("brackets") << "foo[bar]baz" - << QString("foo" + zwsp + "[bar]" + zwsp + "baz"); + << QString(QStringLiteral("foo") + zwsp + + QStringLiteral("[bar]") + zwsp + QStringLiteral("baz")); // Should insert a ZWSP before '{' and after '}' QTest::newRow("curly braces") << "foo{bar}baz" - << QString("foo" + zwsp + "{bar}" + zwsp + "baz"); + << QString(QStringLiteral("foo") + zwsp + + QStringLiteral("{bar}") + zwsp + QStringLiteral("baz")); // Should insert a ZWSP before '(' but not after ')' since it's the last char QTest::newRow("ends with ')'") << "foo(bar)" - << QString("foo" + zwsp + "(bar)"); + << QString(QStringLiteral("foo") + zwsp + QStringLiteral("(bar)")); // Should insert a single ZWSP between the '_' and the '(' QTest::newRow("'_' followed by '('") << "foo_(bar)" - << QString("foo_" + zwsp + "(bar)"); + << QString(QStringLiteral("foo_") + zwsp + QStringLiteral("(bar)")); // Should insert ZWSP's between the '_' and the '[', between the double // '['s and the double ']'s, but not before and after 'bar' QTest::newRow("'_' before double brackets") << "foo_[[bar]]" - << QString("foo_" + zwsp + '[' + zwsp + "[bar]" + zwsp + ']'); + << QString(QStringLiteral("foo_") + zwsp + + QStringLiteral("[") + zwsp + QStringLiteral("[bar]") + zwsp + + QStringLiteral("]")); // Should only insert ZWSP's between the double '['s and the double ']'s QTest::newRow("space before double brackets") << "foo [[bar]]" - << QString("foo [" + zwsp + "[bar]" + zwsp + "]"); + << QString(QStringLiteral("foo [") + zwsp + QStringLiteral("[bar]") + zwsp + QStringLiteral("]")); // Shouldn't result in any additional breaks since the '(' is preceded // by a space, and the ')' is followed by a space. QTest::newRow("parens with spaces") << "foo (bar) baz" << "foo (bar) baz"; // Should insert a WJ (Word Joiner) before a single quote const QChar wj(0x2060); - QTest::newRow("single quote") << "foo'bar" << QString("foo" + wj + "'bar"); + QTest::newRow("single quote") << "foo'bar" << QString(QStringLiteral("foo") + QString(wj) + QStringLiteral("'bar")); } static QString replaceZwsp(const QString &string) @@ -136,7 +147,7 @@ QString result; for (int i = 0; i < string.length(); i++) if (string[i] == zwsp) { - result += ""; + result += QStringLiteral(""); } else { result += string[i]; } diff --git a/autotests/ktexttohtmltest.cpp b/autotests/ktexttohtmltest.cpp --- a/autotests/ktexttohtmltest.cpp +++ b/autotests/ktexttohtmltest.cpp @@ -62,12 +62,12 @@ KTextToHTMLHelper ll6(QStringLiteral(" @bar.baz"), 1); QVERIFY(ll6.getEmailAddress().isEmpty()); KTextToHTMLHelper ll7(QStringLiteral(".!#$%&'*+-/=?^_`{|}~@bar.baz"), - qstrlen(".!#$%&'*+-/=?^_`{|}~")); + qstrlen(".!#$%&'*+-/=?^_`{|}~")); QVERIFY(ll7.getEmailAddress().isEmpty()); // allowed special chars in local part of address KTextToHTMLHelper ll8(QStringLiteral("a.!#$%&'*+-/=?^_`{|}~@bar.baz"), - qstrlen("a.!#$%&'*+-/=?^_`{|}~")); + qstrlen("a.!#$%&'*+-/=?^_`{|}~")); QCOMPARE(ll8.getEmailAddress(), QStringLiteral("a.!#$%&'*+-/=?^_`{|}~@bar.baz")); // '@' in domain part @@ -157,7 +157,7 @@ urls << QStringLiteral("user:pass@www.kde.org:1234/sub/path:with:colon/special(123)?a=1#anchor[bla]"); urls << QStringLiteral("user:pass@www.kde.org:1234/\nsub/path:with:colon/\nspecial(123)?\na=1#anchor[bla]"); urls << QStringLiteral("user:pass@www.kde.org:1234/ \n sub/path:with:colon/ \n\t \t special(123)?") + - QStringLiteral("\n\t \n\t a=1#anchor[bla]"); + QStringLiteral("\n\t \n\t a=1#anchor[bla]"); foreach (const QString &schema, schemas) { foreach (QString url, urls) { //krazy:exclude=foreach @@ -202,7 +202,7 @@ urlsWithoutSchema << QStringLiteral(".kde.org:1234/sub/path:with:colon/special(123)?a=1#anchor[bla]"); urlsWithoutSchema << QStringLiteral(".kde.org:1234/\nsub/path:with:colon/\nspecial(123)?\na=1#anchor[bla]"); urlsWithoutSchema << QStringLiteral(".kde.org:1234/ \n sub/path:with:colon/ \n\t \t special(123)?") + - QStringLiteral("\n\t \n\t a=1#anchor[bla]"); + QStringLiteral("\n\t \n\t a=1#anchor[bla]"); QStringList starts; starts << QStringLiteral("www") << QStringLiteral("ftp") << QStringLiteral("news:www"); @@ -382,52 +382,52 @@ << KTextToHTML::Options(KTextToHTML::PreserveSpaces) << "bla (https://www.kde.org - section 5.2)"; - // Fix url as foo < > when we concatened them. - QTest::newRow("url-with-url") << "foo >" - << KTextToHTML::Options(KTextToHTML::PreserveSpaces) - << "foo <https://www.kde.org/ <https://www.kde.org/>>"; + // Fix url as foo < > when we concatened them. + QTest::newRow("url-with-url") << "foo >" + << KTextToHTML::Options(KTextToHTML::PreserveSpaces) + << "foo <https://www.kde.org/ <https://www.kde.org/>>"; - //Fix url exploit - QTest::newRow("url-exec-html") << "https://\">