File indexing completed on 2025-01-05 03:58:09

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-05-12
0007  * Description : Test parsing rg data.
0008  *
0009  * SPDX-FileCopyrightText: 2010 by Michael G. Hansen <mike at mghansen dot de>
0010  * SPDX-FileCopyrightText: 2010 by Gabriel Voicu <ping dot gabi at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "rgparsing_utest.h"
0017 
0018 // Qt includes
0019 
0020 #include <QDateTime>
0021 #include <QUrl>
0022 
0023 // local includes
0024 
0025 #include "backend-rg.h"
0026 #include "parsetagstring.h"
0027 
0028 using namespace Digikam;
0029 
0030 /**
0031  * @brief Dummy test that does nothing
0032  */
0033 void TestRGParsing::testNoOp()
0034 {
0035 }
0036 
0037 void TestRGParsing::testVerifyRG()
0038 {
0039     {
0040         // testing tag parsing
0041         RGInfo info;
0042         QString country = QString::fromUtf8("France");
0043         QString city = QString::fromUtf8("Paris");
0044 
0045         const QString howToFormat = QLatin1String("My Tags/{Country}/{City}");
0046 
0047         info.rgData[QLatin1String("country")] = country;
0048         info.rgData[QLatin1String("city")]    = city;
0049 
0050         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QLatin1String("My Tags/France/Paris"));
0051     }
0052 
0053     {
0054         // german special characters
0055         RGInfo info;
0056         QString country = QString::fromUtf8("Germany");
0057         QString city    = QString::fromUtf8("Düsseldorf");
0058 
0059         const QString howToFormat = QLatin1String("My Tags/{Country}/{City}");
0060 
0061         info.rgData[QLatin1String("country")] = country;
0062         info.rgData[QLatin1String("city")]    = city;
0063 
0064         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags/Germany/Düsseldorf") );
0065     }
0066 
0067     {
0068         // chinese special characters
0069         RGInfo info;
0070         QString country = QString::fromUtf8("中国");
0071         QString city    = QString::fromUtf8("北京市");
0072 
0073         const QString howToFormat = QLatin1String("My Tags/{Country}/{City}");
0074 
0075         info.rgData[QLatin1String("country")] = country;
0076         info.rgData[QLatin1String("city")]    = city;
0077 
0078         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags/中国/北京市") );
0079     }
0080 
0081     {
0082         // romanian special characters
0083         RGInfo info;
0084         QString country = QString::fromUtf8("România");
0085         QString city    = QString::fromUtf8("București");
0086 
0087         const QString howToFormat = QLatin1String("My Tags/{Country}/{City}");
0088 
0089         info.rgData[QLatin1String("country")] = country;
0090         info.rgData[QLatin1String("city")]    = city;
0091 
0092         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags/România/București"));
0093     }
0094 
0095     {
0096         // No {Country}
0097         RGInfo info;
0098         QString country = QString::fromUtf8("România");
0099         QString city    = QString::fromUtf8("București");
0100 
0101         const QString howToFormat = QLatin1String("My Tags/{City}");
0102 
0103         info.rgData[QLatin1String("country")] = country;
0104         info.rgData[QLatin1String("city")]    = city;
0105 
0106         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags/București"));
0107     }
0108 
0109     {
0110         // No {City}
0111         RGInfo info;
0112         QString country = QString::fromUtf8("România");
0113         QString city    = QString::fromUtf8("");
0114 
0115         const QString howToFormat = QLatin1String("My Tags/{Country}/{City}");
0116 
0117         info.rgData[QLatin1String("country")] = country;
0118         info.rgData[QLatin1String("city")]    = city;
0119 
0120         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags/România"));
0121     }
0122 
0123     {
0124         // {Ctonury} instead of {Country} -> parsing is aborted
0125         RGInfo info;
0126         QString country = QString::fromUtf8("România");
0127         QString city    = QString::fromUtf8("București");
0128 
0129         const QString howToFormat = QLatin1String("My Tags/{Ctonury}/{City}");
0130 
0131         info.rgData[QLatin1String("country")] = country;
0132         info.rgData[QLatin1String("city")]    = city;
0133 
0134         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags/"));
0135     }
0136 
0137     {
0138         // no retrieved data
0139         RGInfo info;
0140         QString country = QString::fromUtf8("");
0141         QString city    = QString::fromUtf8("");
0142 
0143         const QString howToFormat = QLatin1String("My Tags/{Country}/{City}");
0144 
0145         info.rgData[QLatin1String("country")] = country;
0146         info.rgData[QLatin1String("city")]    = city;
0147 
0148         QCOMPARE( makeTagString(info, howToFormat, QLatin1String("OSM")).last(), QString::fromUtf8("My Tags"));
0149     }
0150 
0151     // TODO:
0152     // - some fields are missing (no country)
0153     // * simply deletes {Country}
0154     // - invalid field names
0155     // * if we have {Country} or {bla} it deletes the etiquette
0156     // - how do we handle these cases in the UI?
0157     // * now that we have makeTagString separate, these are handled same in tests and UI
0158 }
0159 
0160 QTEST_GUILESS_MAIN(TestRGParsing)
0161 
0162 #include "moc_rgparsing_utest.cpp"