tests: Use QStringLiteral

This commit is contained in:
Jonas Kvinge
2024-04-21 19:37:39 +02:00
parent c3f596e64e
commit c1a49da385
10 changed files with 959 additions and 959 deletions

View File

@@ -38,21 +38,21 @@
TEST(UtilitiesTest, PrettyTimeDelta) {
ASSERT_EQ(Utilities::PrettyTimeDelta(60), "+1:00");
ASSERT_EQ(Utilities::PrettyTimeDelta(60), QStringLiteral("+1:00"));
ASSERT_EQ(Utilities::PrettyTimeDelta(3600), "+1:00:00");
ASSERT_EQ(Utilities::PrettyTimeDelta(3600), QStringLiteral("+1:00:00"));
ASSERT_EQ(Utilities::PrettyTimeDelta(9600), "+2:40:00");
ASSERT_EQ(Utilities::PrettyTimeDelta(9600), QStringLiteral("+2:40:00"));
}
TEST(UtilitiesTest, PrettyTime) {
ASSERT_EQ(Utilities::PrettyTime(60), "1:00");
ASSERT_EQ(Utilities::PrettyTime(60), QStringLiteral("1:00"));
ASSERT_EQ(Utilities::PrettyTime(3600), "1:00:00");
ASSERT_EQ(Utilities::PrettyTime(3600), QStringLiteral("1:00:00"));
ASSERT_EQ(Utilities::PrettyTime(9600), "2:40:00");
ASSERT_EQ(Utilities::PrettyTime(9600), QStringLiteral("2:40:00"));
}
@@ -60,7 +60,7 @@ TEST(UtilitiesTest, PrettyTimeNanosec) {}
TEST(UtilitiesTest, WordyTime) {
ASSERT_EQ(Utilities::WordyTime(787200), "9 days 2:40:00");
ASSERT_EQ(Utilities::WordyTime(787200), QStringLiteral("9 days 2:40:00"));
}
@@ -68,7 +68,7 @@ TEST(UtilitiesTest, WordyTimeNanosec) {}
TEST(UtilitiesTest, Ago) {
ASSERT_EQ(Utilities::Ago(QDateTime::currentDateTime().toSecsSinceEpoch() - 604800, QLocale()), "7 days ago");
ASSERT_EQ(Utilities::Ago(QDateTime::currentDateTime().toSecsSinceEpoch() - 604800, QLocale()), QStringLiteral("7 days ago"));
}
@@ -76,87 +76,87 @@ TEST(UtilitiesTest, PrettyFutureDate) {}
TEST(UtilitiesTest, PrettySize) {
ASSERT_EQ(Utilities::PrettySize(787200), "787.2 KB");
ASSERT_EQ(Utilities::PrettySize(787200), QStringLiteral("787.2 KB"));
}
TEST(UtilitiesTest, ColorToRgba) {
ASSERT_EQ(Utilities::ColorToRgba(QColor(33, 22, 128)), "rgba(33, 22, 128, 255)");
ASSERT_EQ(Utilities::ColorToRgba(QColor(33, 22, 128)), QStringLiteral("rgba(33, 22, 128, 255)"));
}
TEST(UtilitiesTest, HmacFunctions) {
QString key("key");
QString data("The quick brown fox jumps over the lazy dog");
QString key(QStringLiteral("key"));
QString data(QStringLiteral("The quick brown fox jumps over the lazy dog"));
// Test Hmac MD5
QString result_hash_md5 = Utilities::HmacMd5(key.toLocal8Bit(), data.toLocal8Bit()).toHex();
bool result_md5 = result_hash_md5 == QString("80070713463e7749b90c2dc24911e275");
QString result_hash_md5 = QString::fromLatin1(Utilities::HmacMd5(key.toLocal8Bit(), data.toLocal8Bit()).toHex());
bool result_md5 = result_hash_md5 == QStringLiteral("80070713463e7749b90c2dc24911e275");
EXPECT_TRUE(result_md5);
// Test Hmac SHA256
QString result_hash_sha256 = Utilities::HmacSha256(key.toLocal8Bit(), data.toLocal8Bit()).toHex();
bool result_sha256 = result_hash_sha256 == QString("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
QString result_hash_sha256 = QString::fromLatin1(Utilities::HmacSha256(key.toLocal8Bit(), data.toLocal8Bit()).toHex());
bool result_sha256 = result_hash_sha256 == QStringLiteral("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
EXPECT_TRUE(result_sha256);
}
TEST(UtilitiesTest, PrettySize2) {
ASSERT_EQ(Utilities::PrettySize(QSize(22, 32)), "22x32");
ASSERT_EQ(Utilities::PrettySize(QSize(22, 32)), QStringLiteral("22x32"));
}
TEST(UtilitiesTest, ParseRFC822DateTime) {
QDateTime result_DateTime = Utilities::ParseRFC822DateTime(QString("22 Feb 2008 00:16:17 GMT"));
QDateTime result_DateTime = Utilities::ParseRFC822DateTime(QStringLiteral("22 Feb 2008 00:16:17 GMT"));
EXPECT_TRUE(result_DateTime.isValid());
result_DateTime = Utilities::ParseRFC822DateTime(QString("Thu, 13 Dec 2012 13:27:52 +0000"));
result_DateTime = Utilities::ParseRFC822DateTime(QStringLiteral("Thu, 13 Dec 2012 13:27:52 +0000"));
EXPECT_TRUE(result_DateTime.isValid());
result_DateTime = Utilities::ParseRFC822DateTime(QString("Mon, 12 March 2012 20:00:00 +0100"));
result_DateTime = Utilities::ParseRFC822DateTime(QStringLiteral("Mon, 12 March 2012 20:00:00 +0100"));
EXPECT_TRUE(result_DateTime.isValid());
}
TEST(UtilitiesTest, DecodeHtmlEntities) {
ASSERT_EQ(Utilities::DecodeHtmlEntities("&"), "&");
ASSERT_EQ(Utilities::DecodeHtmlEntities("&"), "&");
ASSERT_EQ(Utilities::DecodeHtmlEntities("""), "\"");
ASSERT_EQ(Utilities::DecodeHtmlEntities("""), "\"");
ASSERT_EQ(Utilities::DecodeHtmlEntities("'"), "'");
ASSERT_EQ(Utilities::DecodeHtmlEntities("'"), "'");
ASSERT_EQ(Utilities::DecodeHtmlEntities("&lt;"), "<");
ASSERT_EQ(Utilities::DecodeHtmlEntities("&#60;"), "<");
ASSERT_EQ(Utilities::DecodeHtmlEntities("&gt;"), ">");
ASSERT_EQ(Utilities::DecodeHtmlEntities("&#62;"), ">");
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&amp;")), QStringLiteral("&"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&#38;")), QStringLiteral("&"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&quot;")), QStringLiteral("\""));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&#34;")), QStringLiteral("\""));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&apos;")), QStringLiteral("'"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&#39;")), QStringLiteral("'"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&lt;")), QStringLiteral("<"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&#60;")), QStringLiteral("<"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&gt;")), QStringLiteral(">"));
ASSERT_EQ(Utilities::DecodeHtmlEntities(QStringLiteral("&#62;")), QStringLiteral(">"));
}
TEST(UtilitiesTest, PathWithoutFilenameExtension) {
ASSERT_EQ(Utilities::PathWithoutFilenameExtension("/home/jonas/test/filename.txt"), "/home/jonas/test/filename");
ASSERT_EQ(Utilities::PathWithoutFilenameExtension(QStringLiteral("/home/jonas/test/filename.txt")), QStringLiteral("/home/jonas/test/filename"));
}
TEST(UtilitiesTest, FiddleFileExtension) {
ASSERT_EQ(Utilities::FiddleFileExtension("/home/jonas/test/filename.txt", "db"), "/home/jonas/test/filename.db");
ASSERT_EQ(Utilities::FiddleFileExtension(QStringLiteral("/home/jonas/test/filename.txt"), QStringLiteral("db")), QStringLiteral("/home/jonas/test/filename.db"));
}
TEST(UtilitiesTest, SetEnvGetEnv) {
QString var = "STRAWBERRY_UNIT_TEST_" + Utilities::GetRandomStringWithCharsAndNumbers(20);
QString value = "STRAWBERRY_UNIT_TEST_" + Utilities::GetRandomStringWithCharsAndNumbers(20);
QString var = QStringLiteral("STRAWBERRY_UNIT_TEST_") + Utilities::GetRandomStringWithCharsAndNumbers(20);
QString value = QStringLiteral("STRAWBERRY_UNIT_TEST_") + Utilities::GetRandomStringWithCharsAndNumbers(20);
Utilities::SetEnv(var.toUtf8().constData(), value);
ASSERT_EQ(Utilities::GetEnv(var), value);
Utilities::SetEnv(var.toUtf8().constData(), "");
Utilities::SetEnv(var.toUtf8().constData(), QLatin1String(""));
}
@@ -168,13 +168,13 @@ TEST(UtilitiesTest, Random) {
EXPECT_FALSE(Utilities::CryptographicRandomString(20) == Utilities::CryptographicRandomString(20));
EXPECT_FALSE(Utilities::GetRandomString(20, "&%XVBGQ") == Utilities::GetRandomString(20, "&%XVBGQ"));
EXPECT_FALSE(Utilities::GetRandomString(20, QStringLiteral("&%XVBGQ")) == Utilities::GetRandomString(20, QStringLiteral("&%XVBGQ")));
}
TEST(UtilitiesTest, Transliterate) {
ASSERT_EQ(Utilities::Transliterate("ÆØÅ"), "AEOA");
ASSERT_EQ(Utilities::Transliterate(QStringLiteral("ÆØÅ")), QStringLiteral("AEOA"));
}
@@ -194,29 +194,29 @@ TEST(UtilitiesTest, ReplaceVariable) {
song.set_performer(Utilities::GetRandomStringWithChars(8));
song.set_grouping(Utilities::GetRandomStringWithChars(8));
song.set_length_nanosec(900000000000);
song.set_url(QUrl("file:///home/jonas/Music/test_song.flac"));
song.set_url(QUrl(QStringLiteral("file:///home/jonas/Music/test_song.flac")));
song.set_skipcount(20);
song.set_playcount(90);
song.set_rating(1.0);
ASSERT_EQ(Utilities::ReplaceVariable("%title%", song, ""), song.title());
ASSERT_EQ(Utilities::ReplaceVariable("%album%", song, ""), song.album());
ASSERT_EQ(Utilities::ReplaceVariable("%artist%", song, ""), song.artist());
ASSERT_EQ(Utilities::ReplaceVariable("%albumartist%", song, ""), song.effective_albumartist());
ASSERT_EQ(Utilities::ReplaceVariable("%track%", song, ""), QString::number(song.track()));
ASSERT_EQ(Utilities::ReplaceVariable("%disc%", song, ""), QString::number(song.disc()));
ASSERT_EQ(Utilities::ReplaceVariable("%year%", song, ""), QString::number(song.year()));
ASSERT_EQ(Utilities::ReplaceVariable("%originalyear%", song, ""), QString::number(song.originalyear()));
ASSERT_EQ(Utilities::ReplaceVariable("%genre%", song, ""), song.genre());
ASSERT_EQ(Utilities::ReplaceVariable("%composer%", song, ""), song.composer());
ASSERT_EQ(Utilities::ReplaceVariable("%performer%", song, ""), song.performer());
ASSERT_EQ(Utilities::ReplaceVariable("%grouping%", song, ""), song.grouping());
ASSERT_EQ(Utilities::ReplaceVariable("%length%", song, ""), song.PrettyLength());
ASSERT_EQ(Utilities::ReplaceVariable("%filename%", song, ""), song.basefilename());
ASSERT_EQ(Utilities::ReplaceVariable("%url%", song, ""), song.url().toString());
ASSERT_EQ(Utilities::ReplaceVariable("%playcount%", song, ""), QString::number(song.playcount()));
ASSERT_EQ(Utilities::ReplaceVariable("%skipcount%", song, ""), QString::number(song.skipcount()));
ASSERT_EQ(Utilities::ReplaceVariable("%rating%", song, ""), song.PrettyRating());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%title%"), song, QLatin1String("")), song.title());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%album%"), song, QLatin1String("")), song.album());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%artist%"), song, QLatin1String("")), song.artist());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%albumartist%"), song, QLatin1String("")), song.effective_albumartist());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%track%"), song, QLatin1String("")), QString::number(song.track()));
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%disc%"), song, QLatin1String("")), QString::number(song.disc()));
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%year%"), song, QLatin1String("")), QString::number(song.year()));
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%originalyear%"), song, QLatin1String("")), QString::number(song.originalyear()));
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%genre%"), song, QLatin1String("")), song.genre());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%composer%"), song, QLatin1String("")), song.composer());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%performer%"), song, QLatin1String("")), song.performer());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%grouping%"), song, QLatin1String("")), song.grouping());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%length%"), song, QLatin1String("")), song.PrettyLength());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%filename%"), song, QLatin1String("")), song.basefilename());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%url%"), song, QLatin1String("")), song.url().toString());
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%playcount%"), song, QLatin1String("")), QString::number(song.playcount()));
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%skipcount%"), song, QLatin1String("")), QString::number(song.skipcount()));
ASSERT_EQ(Utilities::ReplaceVariable(QStringLiteral("%rating%"), song, QLatin1String("")), song.PrettyRating());
}
@@ -236,11 +236,11 @@ TEST(UtilitiesTest, ReplaceMessage) {
song.set_performer(Utilities::GetRandomStringWithChars(8));
song.set_grouping(Utilities::GetRandomStringWithChars(8));
song.set_length_nanosec(900000000000);
song.set_url(QUrl("file:///home/jonas/Music/test_song.flac"));
song.set_url(QUrl(QStringLiteral("file:///home/jonas/Music/test_song.flac")));
song.set_skipcount(20);
song.set_playcount(90);
song.set_rating(1.0);
ASSERT_EQ(Utilities::ReplaceMessage("%title% - %artist%", song, ""), song.title() + " - " + song.artist());
ASSERT_EQ(Utilities::ReplaceMessage(QStringLiteral("%title% - %artist%"), song, QLatin1String("")), song.title() + QStringLiteral(" - ") + song.artist());
}