diff --git a/docs/CONFIGINI.md b/docs/CONFIGINI.md index 75d455a2..a1af8a77 100644 --- a/docs/CONFIGINI.md +++ b/docs/CONFIGINI.md @@ -173,7 +173,7 @@ Read more about the artwork compositing [here](ARTWORK.md). !!! note - If this is set in the `[main]` or `[]` section it will automatically add `/` to the end of the path. If you want better control consider adding it to a `[]` section instead where it will be used as is. + If this is set in the `[main]` or `[]` section it will automatically add `/` to the end of the path. If you want better control consider adding it to a `[]` section instead where it will be used as is. Default value: `/home//RetroPie/roms//media` Allowed in sections: `[main]`, `[]`, `[]` @@ -201,7 +201,7 @@ Sets a non-default location for the storing and loading of cached game resources !!! note - If this is set in the `[main]` section (recommended) it will automatically add `/` to the end of the path. If you want better control consider adding it to a `[]` section instead where it will be used as is. + If this is set in the `[main]` section (recommended) it will automatically add `/` to the end of the path. If you want better control consider adding it to a `[]` section instead where it will be used as is. Default value: `/home//.skyscraper/cache/` Allowed in sections: `[main]`, `[]` diff --git a/src/nametools.cpp b/src/nametools.cpp index 0e9e468b..c56155eb 100644 --- a/src/nametools.cpp +++ b/src/nametools.cpp @@ -294,9 +294,10 @@ QString NameTools::getSqrNotes(QString baseName) { QMapIterator i(replacements); while (i.hasNext()) { i.next(); + sqrNotes= sqrNotes.replace(QRegularExpression("\\["+i.value(),QRegularExpression::CaseInsensitiveOption), "["+i.value()); if (QRegularExpression(i.key()).match(baseName).hasMatch() && - /* avoid NTSC-U being replicated to NTSC on psx */ - !sqrNotes.contains("[" + i.value(), Qt::CaseInsensitive)) { + /* avoid duplicates */ + !sqrNotes.contains("[" + i.value())) { sqrNotes.append("[" % i.value() % "]"); } } diff --git a/src/strtools.cpp b/src/strtools.cpp index 096ec41c..7b5163d8 100644 --- a/src/strtools.cpp +++ b/src/strtools.cpp @@ -27,64 +27,40 @@ #include #include +#include #include #include +inline void issueParseWarning(QString msg, QString v) { + qWarning() << msg << v; + qWarning() + << "Please report an issue at https://github.com/Gemba/skyscraper"; + qWarning() << "Use the first line of this warning message as issue title, " + "no further details needed. Thank you!"; +} + QString StrTools::xmlUnescape(QString str) { - str = str.replace("&", "&") - .replace("<", "<") - .replace(">", ">") - .replace(""", "\"") - .replace("'", "'") - .replace("©", "(c)") - .replace(" ", " ") - .replace("!", "!") - .replace(""", "\"") - .replace("#", "#") - .replace("$", "$") - .replace("%", "%") - .replace("&", "&") - .replace("'", "'") - .replace("(", "(") - .replace(")", ")") - .replace("*", "*") - .replace("+", "+") - .replace(",", ",") - .replace("-", "-") - .replace(".", ".") - .replace("/", "/") - .replace(" ", " ") - .replace("!", "!") - .replace(""", "\"") - .replace("#", "#") - .replace("$", "$") - .replace("%", "%") - .replace("&", "&") - .replace("'", "'") - .replace("(", "(") - .replace(")", ")") - .replace("*", "*") - .replace("+", "+") - .replace(",", ",") - .replace("-", "-") - .replace(".", ".") - .replace("/", "/") - .replace(" ", " ") - .replace("³", "3") - .replace("–", "-") - .replace("’", "'") - .replace("ô", "o") - .replace("ã", "a") - .replace("ä", "ae") - .replace("á", "a") - .replace("é", "e") - .replace("í", "i") - .replace("ū", "uu") - .replace(""", "\"") - .replace("&", "&") - .replace("'", "'") - .replace("³", "3") - .replace("ō", "o"); + QMap xmlMap = { + {"&", "&"}, {"<", "<"}, {">", ">"}, {""", "\""}, + {"'", "'"}, {"©", "(c)"}, {" ", " "}, {"!", "!"}, + {""", "\""}, {"#", "#"}, {"$", "$"}, {"%", "%"}, + {"&", "&"}, {"'", "'"}, {"(", "("}, {")", ")"}, + {"*", "*"}, {"+", "+"}, {",", ","}, {"-", "-"}, + {".", "."}, {"/", "/"}, {" ", " "}, {"!", "!"}, + {""", "\""}, {"#", "#"}, {"$", "$"}, {"%", "%"}, + {"&", "&"}, {"'", "'"}, {"(", "("}, {")", ")"}, + {"*", "*"}, {"+", "+"}, {",", ","}, {"-", "-"}, + {".", "."}, {"/", "/"}, {" ", " "}, {"³", "3"}, + {"–", "-"}, {"’", "'"}, {"ô", "o"}, {"ã", "a"}, + {"ä", "ae"}, {"á", "a"}, {"é", "e"}, {"í", "i"}, + {"ū", "uu"}, {""", "\""}, {"&", "&"}, {"'", "'"}, + {"³", "3"}, {"ō", "o"}}; + + QMapIterator i(xmlMap); + while (i.hasNext()) { + i.next(); + str = str.replace(i.key(), i.value()); + } while (str.contains("&") && str.contains(";") && str.indexOf("&") < str.indexOf(";") && @@ -92,13 +68,11 @@ QString StrTools::xmlUnescape(QString str) { str = str.remove(str.indexOf("&"), str.indexOf(";") + 1 - str.indexOf("&")); } - return str; } QString StrTools::xmlEscape(QString str) { str = xmlUnescape(str); - return str.replace("&", "&") .replace("<", "<") .replace(">", ">") @@ -126,9 +100,7 @@ QByteArray StrTools::magic(const QByteArray str) { thingie.append(QString::number(strChars[a] += magicChars[a]).toUtf8() % ";"); } - thingie.chop(1); - return thingie; } @@ -151,171 +123,124 @@ QByteArray StrTools::unMagic(const QByteArray str) { for (int a = 0; a < length; ++a) { thingie.append(QString(QChar(strChars[a] -= magicChars[a])).toUtf8()); } - return thingie; } -QString StrTools::conformPlayers(const QString str) { - if (QRegularExpression("^1 Player").match(str).hasMatch()) - return "1"; - - if (QRegularExpression("^1 Only").match(str).hasMatch()) - return "1"; +QString StrTools::conformPlayers(const QString playerString) { + QString str = playerString.simplified(); + QStringList patterns = {"^(\\d) Player", "^(\\d) Only", "^1 or (\\d)", + "^\\d\\s?(?:-|to)\\s?(\\d\\d?)", "^(\\d)\\+"}; + QRegularExpression re; + re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch m; + for (auto const &p : patterns) { + re.setPattern(p); + m = re.match(str); + if (m.hasMatch()) + return m.captured(1); + } - if (QRegularExpression("^single player").match(str).hasMatch()) + // number as text + re.setPattern("^single player"); + if (re.match(str).hasMatch()) return "1"; - if (QRegularExpression("^1 or 2").match(str).hasMatch()) - return "2"; - - if (QRegularExpression("^\\d-\\d\\d").match(str).hasMatch()) - return str.mid(2, 2); - - if (QRegularExpression("^\\d-\\d").match(str).hasMatch()) - return str.mid(2, 1); - - if (QRegularExpression("^\\d - \\d\\d").match(str).hasMatch()) - return str.mid(4, 2); - - if (QRegularExpression("^\\d - \\d").match(str).hasMatch()) - return str.mid(4, 1); - - // A faulty Openretro entry is necessary as it marks "1 - 6" as "1 -6" - if (QRegularExpression("^\\d -\\d\\d").match(str).hasMatch()) - return str.mid(3, 2); - - if (QRegularExpression("^\\d -\\d").match(str).hasMatch()) - return str.mid(3, 1); - - if (QRegularExpression("^\\d to \\d\\d").match(str).hasMatch()) - return str.mid(5, 2); - - if (QRegularExpression("^\\d to \\d").match(str).hasMatch()) - return str.mid(5, 1); - - if (QRegularExpression("^\\d\\+").match(str).hasMatch()) - return str.mid(0, 1); + bool ok; + str.toInt(&ok); + if (ok) + return str; + issueParseWarning("Player count not replaced to number for scraper input", + str); return str; } QString StrTools::conformAges(QString str) { - if (str == "0 (ohne Altersbeschränkung)") { - str = "1"; - } else if (str == "U") { - str = "1"; - } else if (str == "E") { - str = "1"; - } else if (str == "E - Everyone") { - str = "1"; - } else if (str == "Everyone") { - str = "1"; - } else if (str == "GA") { - str = "1"; - } else if (str == "EC") { - str = "3"; - } else if (str == "Early Childhood") { - str = "3"; - } else if (str == "3+") { - str = "3"; - } else if (str == "G") { - str = "3"; - } else if (str == "KA") { - str = "6"; - } else if (str == "Kids to Adults") { - str = "6"; - } else if (str == "G8+") { - str = "8"; - } else if (str == "E10+") { - str = "10"; - } else if (str == "E10+ - Everyone 10+") { - str = "10"; - } else if (str == "Everyone 10+") { - str = "10"; - } else if (str == "11+") { - str = "11"; - } else if (str == "12+") { - str = "11"; - } else if (str == "MA-13") { - str = "13"; - } else if (str == "T") { - str = "13"; - } else if (str == "T - Teen") { - str = "13"; - } else if (str == "Teen") { - str = "13"; - } else if (str == "M") { - str = "15"; - } else if (str == "M15+") { - str = "15"; - } else if (str == "MA 15+") { - str = "15"; - } else if (str == "MA15+") { - str = "15"; - } else if (str == "PG") { - str = "15"; - } else if (str == "15+") { - str = "15"; - } else if (str == "MA-17") { - str = "17"; - } else if (str == "M") { - str = "17"; - } else if (str == "18+") { - str = "18"; - } else if (str == "R18+") { - str = "18"; - } else if (str == "18 (keine Jugendfreigabe)") { - str = "18"; - } else if (str == "A") { - str = "18"; - } else if (str == "AO") { - str = "18"; - } else if (str == "AO - Adults Only") { - str = "18"; - } else if (str == "Adults Only") { - str = "18"; - } else if (str == "M - Mature") { - str = "18"; - } else if (str == "Mature") { - str = "18"; + QMap ageMap = {{"0 (ohne Altersbeschränkung)", "1"}, + {"U", "1"}, + {"E", "1"}, + {"E - Everyone", "1"}, + {"Everyone", "1"}, + {"GA", "1"}, + {"EC", "3"}, + {"Early Childhood", "3"}, + {"3+", "3"}, + {"G", "3"}, + {"KA", "6"}, + {"Kids to Adults", "6"}, + {"G8+", "8"}, + {"E10+", "10"}, + {"E10+ - Everyone 10+", "10"}, + {"Everyone 10+", "10"}, + {"11+", "11"}, + {"12+", "11"}, + {"MA-13", "13"}, + {"T", "13"}, + {"T - Teen", "13"}, + {"Teen", "13"}, + {"M", "15"}, + {"M15+", "15"}, + {"MA 15+", "15"}, + {"MA15+", "15"}, + {"PG", "15"}, + {"15+", "15"}, + {"MA-17", "17"}, + {"18+", "18"}, + {"R18+", "18"}, + {"18 (keine Jugendfreigabe)", "18"}, + {"A", "18"}, + {"AO", "18"}, + {"AO - Adults Only", "18"}, + {"Adults Only", "18"}, + {"M - Mature", "18"}, + {"Mature", "18"}}; + + QMapIterator i(ageMap); + while (i.hasNext()) { + i.next(); + if (str == i.key()) + return i.value(); } + bool ok; + str.toInt(&ok); + if (ok) + return str; + issueParseWarning("Age rating not replaced to number for scraper input", + str); return str; } QString StrTools::conformReleaseDate(QString str) { - if (QRegularExpression("^\\d{4}$").match(str).hasMatch()) { - str = QDate::fromString(str, "yyyy").toString("yyyyMMdd"); - } else if (QRegularExpression("^\\d{4}-[0-1]{1}\\d{1}$") - .match(str) - .hasMatch()) { - str = QDate::fromString(str, "yyyy-MM").toString("yyyyMMdd"); - } else if (QRegularExpression("^\\d{4}-[0-1]{1}\\d{1}-[0-3]{1}\\d{1}$") - .match(str) - .hasMatch()) { - str = QDate::fromString(str, "yyyy-MM-dd").toString("yyyyMMdd"); - } else if (QRegularExpression("^[0-1]{1}\\d{1}/[0-3]{1}\\d{1}/\\d{4}$") - .match(str) - .hasMatch()) { - str = QDate::fromString(str, "MM/dd/yyyy").toString("yyyyMMdd"); - } else if (QRegularExpression("^\\d{4}-[a-zA-Z]{3}-[0-3]{1}\\d{1}$") - .match(str) - .hasMatch()) { - str = QDate::fromString(str, "yyyy-MMM-dd").toString("yyyyMMdd"); - } else if (QRegularExpression("^[a-zA-z]{3}, \\d{4}$") - .match(str) - .hasMatch()) { - str = QDate::fromString(str, "MMM, yyyy").toString("yyyyMMdd"); - } else if (QRegularExpression("^[a-zA-z]{3} [0-3]{1}\\d{1}, \\d{4}$") - .match(str) - .hasMatch()) { - str = QDate::fromString(str, "MMM dd, yyyy").toString("yyyyMMdd"); - } else if (QRegularExpression("^[12]{1}[019]{1}[0-9]{2}[0-1]{1}[0-9]{1}[0-" - "3]{1}[0-9]{1}T[0-9]{6}$") - .match(str) - .hasMatch()) { - str = str.left(8); + // cut of time if present + str = str.replace(QRegularExpression("T\\d{6}$"), ""); + QMap dateFormats = { + // clang-format off + {"^\\d{4}$", "yyyy"}, + {"^\\d{4}-[0-1]{1}\\d{1}$", "yyyy-MM"}, + {"^\\d{4}-[0-1]{1}\\d{1}-[0-3]{1}\\d{1}$", "yyyy-MM-dd"}, + {"^[0-1]{1}\\d{1}/[0-3]{1}\\d{1}/\\d{4}$", "MM/dd/yyyy"}, + {"^\\d{4}-[a-zA-Z]{3}-[0-3]{1}\\d{1}$", "yyyy-MMM-dd"}, + {"^[a-zA-z]{3}, \\d{4}$", "MMM, yyyy"}, + {"^[a-zA-z]{3} [0-3]{1}\\d{1}, \\d{4}$", "MMM dd, yyyy"}, + {"^[12]{1}[012349]{1}[0-9]{2}[0-1]{1}[0-9]{1}[0-3]{1}[0-9]{1}$", "yyyyMMdd"} + // clang-format on + }; + QRegularExpression re; + re.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch m; + + QMapIterator i(dateFormats); + while (i.hasNext()) { + i.next(); + re.setPattern(i.key()); + m = re.match(str); + if (m.hasMatch()) + return QLocale::c().toDate(str, i.value()).toString("yyyyMMdd"); } + + issueParseWarning( + "Release date string is not parsable as date for scraper input", str); return str; } diff --git a/test/abstractscraper/test_abstractscraper.pro b/test/abstractscraper/test_abstractscraper.pro index a97dea33..27d0f758 100644 --- a/test/abstractscraper/test_abstractscraper.pro +++ b/test/abstractscraper/test_abstractscraper.pro @@ -8,12 +8,15 @@ QT += core network xml QMAKE_CXXFLAGS += -std=c++17 CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT +PREFIX = /usr/local +DEFINES+=PREFIX=\\\"$$PREFIX\\\" include(../../VERSION) DEFINES+=TESTING DEFINES+=VERSION=\\\"$$VERSION\\\" HEADERS += ../../src/abstractscraper.h \ + ../../src/config.h \ ../../src/gameentry.h \ ../../src/nametools.h \ ../../src/netcomm.h \ @@ -23,6 +26,7 @@ HEADERS += ../../src/abstractscraper.h \ SOURCES += test_abstractscraper.cpp \ ../../src/abstractscraper.cpp \ + ../../src/config.cpp \ ../../src/gameentry.cpp \ ../../src/nametools.cpp \ ../../src/netcomm.cpp \ diff --git a/test/getsearchnames/test_getsearchnames.pro b/test/getsearchnames/test_getsearchnames.pro index 9a8fc1ee..48971614 100644 --- a/test/getsearchnames/test_getsearchnames.pro +++ b/test/getsearchnames/test_getsearchnames.pro @@ -7,6 +7,8 @@ CONFIG += debug QMAKE_CXXFLAGS += -std=c++17 CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT +PREFIX = /usr/local +DEFINES+=PREFIX=\\\"$$PREFIX\\\" include(../../VERSION) DEFINES+=VERSION=\\\"$$VERSION\\\" @@ -16,7 +18,9 @@ DEFINES+=VERSION=\\\"$$VERSION\\\" HEADERS += ../../src/abstractscraper.h \ ../../src/arcadedb.h \ + ../../src/cache.h \ ../../src/cli.h \ + ../../src/config.h \ ../../src/crc32.h \ ../../src/esgamelist.h \ ../../src/gameentry.h \ @@ -27,6 +31,7 @@ HEADERS += ../../src/abstractscraper.h \ ../../src/netmanager.h \ ../../src/openretro.h \ ../../src/platform.h \ + ../../src/queue.h \ ../../src/screenscraper.h \ ../../src/settings.h \ ../../src/strtools.h @@ -34,7 +39,9 @@ HEADERS += ../../src/abstractscraper.h \ SOURCES += test_getsearchnames.cpp \ ../../src/abstractscraper.cpp \ ../../src/arcadedb.cpp \ + ../../src/cache.cpp \ ../../src/cli.cpp \ + ../../src/config.cpp \ ../../src/crc32.cpp \ ../../src/esgamelist.cpp \ ../../src/gameentry.cpp \ @@ -45,6 +52,7 @@ SOURCES += test_getsearchnames.cpp \ ../../src/netmanager.cpp \ ../../src/openretro.cpp \ ../../src/platform.cpp \ + ../../src/queue.cpp \ ../../src/screenscraper.cpp \ ../../src/settings.cpp \ ../../src/strtools.cpp diff --git a/test/nametools/test_nametools.cpp b/test/nametools/test_nametools.cpp index cb7b787b..8f0b0db8 100644 --- a/test/nametools/test_nametools.cpp +++ b/test/nametools/test_nametools.cpp @@ -74,9 +74,10 @@ private slots: "Blarf _Aga_ text _Cd32_Ntsc texttext [any] end"), "[any][AGA][CD32][NTSC]"); QCOMPARE(NameTools::getSqrNotes( - "Blarf _Aga_ text _Cd32 [Aga] texttext [any] end"), - "[Aga][any][AGA][CD32]"); + "Blarf _AGa_ text _Cd32 [Aga] texttext [any] end"), + "[AGA][any][CD32]"); QCOMPARE(NameTools::getSqrNotes("Blarf end"), ""); + QCOMPARE(NameTools::getSqrNotes("Text [NTSC-U] Text"), "[NTSC-U]"); } void testGetParNotes() { diff --git a/test/settings/.gitignore b/test/settings/.gitignore index cfa612c4..0ca4d7b3 100644 --- a/test/settings/.gitignore +++ b/test/settings/.gitignore @@ -1,5 +1,5 @@ Makefile *.o -settings_test +test_settings peas.json platforms_idmap.csv diff --git a/test/settings/config_test.ini b/test/settings/config_test.ini index cb0ba834..bf152a7d 100644 --- a/test/settings/config_test.ini +++ b/test/settings/config_test.ini @@ -1,6 +1,6 @@ [main] addExtensions="*.zst *.test" -artworkXml="test_artwork.xml" +artworkXml="/tmp/test_artwork.xml" brackets="false" cacheCovers="false" cacheFolder="/home/pi/.skyscraper/cache/test/" @@ -64,7 +64,7 @@ videoSizeLimit="11" ; The following is an example of configs that only affect the 'snes' platform. [amiga] addExtensions="*.zst *.test" -artworkXml="test_artwork.xml" +artworkXml="/tmp/test_amiga_artwork.xml" brackets="false" cacheCovers="false" cacheFolder="/home/pi/.skyscraper/cache/test/" @@ -116,7 +116,7 @@ manuals="true" ; The following is an example of configs that only affect the 'pegasus' frontend. [pegasus] -artworkXml="pega_artwork.xml" +artworkXml="/tmp/test_pegasus_artwork.xml" brackets="true" cropBlack="1" emulator="emulator__pegasus_test" @@ -124,11 +124,11 @@ endAt="filename" excludePattern="*[BIOS]*" forceFilename="true" gameListBackup="true" -gameListFolder="/home/pi/RetroPie/roms/foobar" +gameListFolder="/home/fred/roms/foobar" includePattern="Super*" launch="launch__pegasus_test" maxLength="10000" -mediaFolder="/home/pi/RetroPie/roms/amiga/media" +mediaFolder="/home/fred/media" mediaFolderHidden="1" skipped="true" startAt="filename" @@ -154,7 +154,8 @@ cacheWheels="true" cacheMarquees="true" cacheTextures="true" cacheRefresh="1" -manuals="true" +; not applicable in [] +;manuals="true" videos="true" videoSizeLimit="42" videoConvertCommand="ffmpeg -i %i -y -pix_fmt yuv420p -t 00:00:10 -c:v libx264 -crf 23 -c:a aac -b:a 64k -vf scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2,setsar=1 %o" diff --git a/test/settings/settings_test.pro b/test/settings/settings_test.pro deleted file mode 100644 index b6f28243..00000000 --- a/test/settings/settings_test.pro +++ /dev/null @@ -1,22 +0,0 @@ -QT += core network xml testlib -TEMPLATE = app -TARGET = settings_test -INCLUDEPATH += ../.. - -include(../../VERSION) -DEFINES+=VERSION=\\\"$$VERSION\\\" - -QMAKE_POST_LINK += cp -f $$shell_quote($$shell_path($${PWD}/../../peas.json)) .; -QMAKE_POST_LINK += cp -f $$shell_quote($$shell_path($${PWD}/../../platforms_idmap.csv)) .; - -# Input -HEADERS += settings_test.h \ - ../../src/settings.h \ - ../../src/strtools.h \ - ../../src/platform.h \ - ../../src/cli.h -SOURCES += settings_test.cpp \ - ../../src/settings.cpp \ - ../../src/strtools.cpp \ - ../../src/platform.cpp \ - ../../src/cli.cpp diff --git a/test/settings/settings_test.cpp b/test/settings/test_settings.cpp similarity index 98% rename from test/settings/settings_test.cpp rename to test/settings/test_settings.cpp index 03d6f259..8481fdc0 100644 --- a/test/settings/settings_test.cpp +++ b/test/settings/test_settings.cpp @@ -1,4 +1,4 @@ -#include "settings_test.h" +#include "test_settings.h" #include "src/cli.h" #include "src/platform.h" @@ -6,7 +6,7 @@ #include #include -void TestSettings::configIniMain() { +void TestSettings::testConfigIniMain() { QString currentDir = QDir::currentPath(); Settings config; if (!Platform::get().loadConfig()) { @@ -165,7 +165,7 @@ void TestSettings::configIniMain() { settings.endGroup(); } -void TestSettings::configIniPlatform() { +void TestSettings::testConfigIniPlatform() { QString currentDir = QDir::currentPath(); Settings config; if (!Platform::get().loadConfig()) { @@ -308,7 +308,7 @@ void TestSettings::configIniPlatform() { settings.endGroup(); } -void TestSettings::configIniFrontend() { +void TestSettings::testConfigIniFrontend() { QString currentDir = QDir::currentPath(); Settings config; if (!Platform::get().loadConfig()) { @@ -368,13 +368,15 @@ void TestSettings::configIniFrontend() { exp = settings.value("gameListBackup"); QCOMPARE(config.gameListBackup, exp); exp = settings.value("gameListFolder"); - QCOMPARE(config.gameListFolder, exp); + // #88 + QCOMPARE(config.gameListFolder, exp.toString() + "/amiga"); exp = settings.value("includePattern"); QCOMPARE(config.includePattern, exp); exp = settings.value("maxLength"); QCOMPARE(config.maxLength, exp); exp = settings.value("mediaFolder"); - QCOMPARE(config.mediaFolder, exp); + // #88 + QCOMPARE(config.mediaFolder, exp.toString() + "/amiga"); exp = settings.value("mediaFolderHidden"); QCOMPARE(config.mediaFolderHidden, exp.toBool()); exp = settings.value("skipped"); @@ -397,7 +399,7 @@ void TestSettings::configIniFrontend() { settings.endGroup(); } -void TestSettings::configIniScraper() { +void TestSettings::testConfigIniScraper() { QString currentDir = QDir::currentPath(); Settings config; if (!Platform::get().loadConfig()) { diff --git a/test/settings/settings_test.h b/test/settings/test_settings.h similarity index 57% rename from test/settings/settings_test.h rename to test/settings/test_settings.h index 5ce00042..b0a45b63 100644 --- a/test/settings/settings_test.h +++ b/test/settings/test_settings.h @@ -8,8 +8,8 @@ class TestSettings : public QObject { TestSettings() {} ~TestSettings() {} private slots: - void configIniMain(); - void configIniPlatform(); - void configIniFrontend(); - void configIniScraper(); + void testConfigIniMain(); + void testConfigIniPlatform(); + void testConfigIniFrontend(); + void testConfigIniScraper(); }; diff --git a/test/settings/test_settings.pro b/test/settings/test_settings.pro new file mode 100644 index 00000000..a2dc7329 --- /dev/null +++ b/test/settings/test_settings.pro @@ -0,0 +1,35 @@ +QT += core network xml testlib +TEMPLATE = app +TARGET = test_settings +INCLUDEPATH += ../.. + +PREFIX = /usr/local +DEFINES+=PREFIX=\\\"$$PREFIX\\\" + +include(../../VERSION) +DEFINES+=VERSION=\\\"$$VERSION\\\" + +QMAKE_POST_LINK += cp -f $$shell_quote($$shell_path($${PWD}/../../peas.json)) .; +QMAKE_POST_LINK += cp -f $$shell_quote($$shell_path($${PWD}/../../platforms_idmap.csv)) .; + +# Input +HEADERS += test_settings.h \ + ../../src/cache.h \ + ../../src/cli.h \ + ../../src/config.h \ + ../../src/gameentry.h \ + ../../src/nametools.h \ + ../../src/platform.h \ + ../../src/queue.h \ + ../../src/settings.h \ + ../../src/strtools.h +SOURCES += test_settings.cpp \ + ../../src/cache.cpp \ + ../../src/cli.cpp \ + ../../src/config.cpp \ + ../../src/gameentry.cpp \ + ../../src/nametools.cpp \ + ../../src/platform.cpp \ + ../../src/queue.cpp \ + ../../src/settings.cpp \ + ../../src/strtools.cpp \ No newline at end of file diff --git a/test/strtools/.gitignore b/test/strtools/.gitignore index 2257f372..0cb1321e 100644 --- a/test/strtools/.gitignore +++ b/test/strtools/.gitignore @@ -1,3 +1,3 @@ Makefile *.o -strtools_test +test_strtools diff --git a/test/strtools/strtools_test b/test/strtools/strtools_test new file mode 100644 index 00000000..0d9cdf8e Binary files /dev/null and b/test/strtools/strtools_test differ diff --git a/test/strtools/strtools_test.cpp b/test/strtools/strtools_test.cpp deleted file mode 100644 index fe11b73c..00000000 --- a/test/strtools/strtools_test.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "strtools.h" - -#include - -int main() { - - QMap> tests = { - {"do not multbang", - QPair("I am sentence one!! I am sentence two.\nI " - "am sentence three!!!!!!!!!", - "I am sentence one!! I am sentence two.\nI am " - "sentence three!!!!!!!!!")}, - {"itemize bullet", - QPair( - "bla bla\n ● item 1\n* item2\nfoo bar baz\n* item 1b\n● item " - "2b", - "bla bla\n- item 1\n- item2\nfoo bar baz\n- item 1b\n- item 2b")}, - {"itemize star 2", QPair( - "bla bla\n * item 1\n* item2\nfoo bar baz\n* " - "item 1b\n* item 2b\n * item 3b \n\n\nbaz", - "bla bla\n- item 1\n- item2\nfoo bar baz\n- " - "item 1b\n- item 2b\n- item 3b\n\n\nbaz")}, - {"itemize star", - QPair( - "bla bla\n * item 1\n* item2\nfoo bar baz\n* item 1b\n* item " - "2b", - "bla bla\n- item 1\n- item2\nfoo bar baz\n- item 1b\n- item 2b")}, - {"multbang", - QPair( - "I am sentence one!! I am sentence two.\nI am sentence " - "three!!!!!!!!!", - "I am sentence one! I am sentence two.\nI am sentence three!")}, - {"multispaces", QPair("bla bla! \n\n\nblubb", - "bla bla!\n\n\nblubb")}, - {"replace ellipsis", - QPair("bla …bla \n …efefef efefef…\n \n ", - "bla ...bla\n...efefef efefef...\n\n")}, - {"sentence spacing", - QPair( - "I am sentence one. I am sentence two.\nI am sentence three.", - "I am sentence one. I am sentence two.\nI am sentence three.")}, - {"single star 2", - QPair("bla bla \n * efefef efefef\nefef", - "bla bla\n* efefef efefef\nefef")}, - {"single star", QPair("bla bla \n * efefef efefef", - "bla bla\n* efefef efefef")}, - {"trim lines", - QPair("bla bla \n efefef efefef\n \n ", - "bla bla\nefefef efefef\n\n")}, - }; - - qInfo() << ""; - int pass = 0; - for (auto t : tests.keys()) { - QString input = tests.value(t).first; - QString exp = tests.value(t).second; - QString out = - StrTools::tidyText(input, t == "do not multbang" ? true : false); - if (out == exp) { - qInfo() << " Pass: " << t; - pass++; - } else { - qWarning() << "Failed: " << t << "\nExp: " << exp - << "\nGot: " << out << "\n"; - } - } - qInfo() << "\nTests passed: " << pass << "/" << tests.keys().size(); -} \ No newline at end of file diff --git a/test/strtools/test_strtools.cpp b/test/strtools/test_strtools.cpp new file mode 100644 index 00000000..c1670ec3 --- /dev/null +++ b/test/strtools/test_strtools.cpp @@ -0,0 +1,196 @@ +#include "strtools.h" + +#include +#include + +class TestStrTools : public QObject { + Q_OBJECT + +private: + QMap> tidyDescData; + QMap xmlMap; + QMap ageMap; + QMap playerMap; + QMap rdMap; + +private slots: + void initTestCase() { + + tidyDescData = { + {"do not multbang", + QPair( + "I am sentence one!! I am sentence two.\nI " + "am sentence three!!!!!!!!!", + "I am sentence one!! I am sentence two.\nI am " + "sentence three!!!!!!!!!")}, + {"itemize bullet", + QPair("bla bla\n ● item 1\n* item2\nfoo " + "bar baz\n* item 1b\n● item " + "2b", + "bla bla\n- item 1\n- item2\nfoo bar " + "baz\n- item 1b\n- item 2b")}, + {"itemize star 2", + QPair( + "bla bla\n * item 1\n* item2\nfoo bar baz\n* " + "item 1b\n* item 2b\n * item 3b \n\n\nbaz", + "bla bla\n- item 1\n- item2\nfoo bar baz\n- " + "item 1b\n- item 2b\n- item 3b\n\n\nbaz")}, + {"itemize star", + QPair("bla bla\n * item 1\n* item2\nfoo " + "bar baz\n* item 1b\n* item " + "2b", + "bla bla\n- item 1\n- item2\nfoo bar " + "baz\n- item 1b\n- item 2b")}, + {"multbang", + QPair( + "I am sentence one!! I am sentence two.\nI am sentence " + "three!!!!!!!!!", + "I am sentence one! I am sentence two.\nI am sentence " + "three!")}, + {"multispaces", QPair("bla bla! \n\n\nblubb", + "bla bla!\n\n\nblubb")}, + {"replace ellipsis", + QPair("bla …bla \n …efefef efefef…\n \n ", + "bla ...bla\n...efefef efefef...\n\n")}, + {"sentence spacing", + QPair("I am sentence one. I am sentence " + "two.\nI am sentence three.", + "I am sentence one. I am sentence " + "two.\nI am sentence three.")}, + {"single star 2", + QPair("bla bla \n * efefef efefef\nefef", + "bla bla\n* efefef efefef\nefef")}, + {"single star", + QPair("bla bla \n * efefef efefef", + "bla bla\n* efefef efefef")}, + {"trim lines", + QPair("bla bla \n efefef efefef\n \n ", + "bla bla\nefefef efefef\n\n")}, + }; + } + + void testXmlUnescape() { + xmlMap = {{"&", "&"}, {"<", "<"}, {">", ">"}, + {""", "\""}, {"'", "'"}, {"©", "(c)"}, + {" ", " "}, {"!", "!"}, {""", "\""}, + {"#", "#"}, {"$", "$"}, {"%", "%"}, + {"&", "&"}, {"'", "'"}, {"(", "("}, + {")", ")"}, {"*", "*"}, {"+", "+"}, + {",", ","}, {"-", "-"}, {".", "."}, + {"/", "/"}, {" ", " "}, {"!", "!"}, + {""", "\""}, {"#", "#"}, {"$", "$"}, + {"%", "%"}, {"&", "&"}, {"'", "'"}, + {"(", "("}, {")", ")"}, {"*", "*"}, + {"+", "+"}, {",", ","}, {"-", "-"}, + {".", "."}, {"/", "/"}, {" ", " "}, + {"³", "3"}, {"–", "-"}, {"’", "'"}, + {"ô", "o"}, {"ã", "a"}, {"ä", "ae"}, + {"á", "a"}, {"é", "e"}, {"í", "i"}, + {"ū", "uu"}, {""", "\""}, {"&", "&"}, + {"'", "'"}, {"³", "3"}, {"ō", "o"}}; + QMapIterator i(xmlMap); + while (i.hasNext()) { + i.next(); + QString xmlIn = i.key(); + QString in = "Pre '" % xmlIn % "' Post"; + QString exp = "Pre '" % i.value() % "' Post"; + QCOMPARE(StrTools::xmlUnescape(in), exp); + } + QCOMPARE(StrTools::xmlUnescape("bla &ent; baz"), "bla baz"); + QCOMPARE(StrTools::xmlUnescape("bla &verylongentity; baz"), + "bla &verylongentity; baz"); + } + + void testConformAges() { + ageMap = {{"0 (ohne Altersbeschränkung)", "1"}, + {"U", "1"}, + {"E", "1"}, + {"E - Everyone", "1"}, + {"Everyone", "1"}, + {"GA", "1"}, + {"EC", "3"}, + {"Early Childhood", "3"}, + {"3+", "3"}, + {"G", "3"}, + {"KA", "6"}, + {"Kids to Adults", "6"}, + {"G8+", "8"}, + {"E10+", "10"}, + {"E10+ - Everyone 10+", "10"}, + {"Everyone 10+", "10"}, + {"11+", "11"}, + {"12+", "11"}, + {"MA-13", "13"}, + {"T", "13"}, + {"T - Teen", "13"}, + {"Teen", "13"}, + {"M", "15"}, + {"M15+", "15"}, + {"MA 15+", "15"}, + {"MA15+", "15"}, + {"PG", "15"}, + {"15+", "15"}, + {"MA-17", "17"}, + //{"M","17"}, /* dupe */ + {"18+", "18"}, + {"R18+", "18"}, + {"18 (keine Jugendfreigabe)", "18"}, + {"A", "18"}, + {"AO", "18"}, + {"AO - Adults Only", "18"}, + {"Adults Only", "18"}, + {"M - Mature", "18"}, + {"Mature", "18"}}; + QMapIterator i(ageMap); + while (i.hasNext()) { + i.next(); + QCOMPARE(StrTools::conformAges(i.key()), i.value()); + } + QCOMPARE(StrTools::conformAges("23"), "23"); + } + + void testConformPlayers() { + playerMap = { + {"1 Player", "1"}, {"1 Only", "1"}, {"single player", "1"}, + {"1 or 2", "2"}, {"1-33", "33"}, {"0-5", "5"}, + {"2 - 44", "44"}, {"3 - 7", "7"}, {"4 -99", "99"}, + {"5 -9", "9"}, {"1 to 66", "66"}, {"1 to 8", "8"}, + {"4+", "4"}, {"235", "235"}, + }; + QMapIterator i(playerMap); + while (i.hasNext()) { + i.next(); + QCOMPARE(StrTools::conformPlayers(i.key()), i.value()); + } + } + + void testConformReleaseDate() { + rdMap = {{"1972", "19720101"}, {"1972-11", "19721101"}, + {"1972-11-29", "19721129"}, {"11/29/1972", "19721129"}, + {"1972-Nov-29", "19721129"}, {"Nov, 1972", "19721101"}, + {"Nov 29, 1972", "19721129"}, {"19721129", "19721129"}, + {"19721129T204933", "19721129"}}; + QMapIterator i(rdMap); + while (i.hasNext()) { + i.next(); + qDebug() << "Input: " << i.key(); + QCOMPARE(StrTools::conformReleaseDate(i.key()), i.value()); + } + } + + void testTidyDesc() { + QMapIterator> i(tidyDescData); + while (i.hasNext()) { + i.next(); + QString testName = i.key(); + QString input = i.value().first; + QString exp = i.value().second; + QString out = StrTools::tidyText( + input, testName == "do not multbang" ? true : false); + QCOMPARE(out, exp); + } + } +}; + +QTEST_MAIN(TestStrTools) +#include "test_strtools.moc" \ No newline at end of file diff --git a/test/strtools/strtools_test.pro b/test/strtools/test_strtools.pro similarity index 69% rename from test/strtools/strtools_test.pro rename to test/strtools/test_strtools.pro index 31c54307..44fd3b0d 100644 --- a/test/strtools/strtools_test.pro +++ b/test/strtools/test_strtools.pro @@ -1,10 +1,10 @@ TEMPLATE = app -TARGET = strtools_test +TARGET = test_strtools DEPENDPATH += . INCLUDEPATH += ../../src CONFIG += debug -QT += core network xml -QMAKE_CXXFLAGS += -std=c++11 +QT += core network xml testlib +QMAKE_CXXFLAGS += -std=c++17 CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT @@ -13,6 +13,6 @@ DEFINES+=VERSION=\\\"$$VERSION\\\" HEADERS += ../../src/strtools.h -SOURCES += strtools_test.cpp \ +SOURCES += test_strtools.cpp \ ../../src/strtools.cpp