File indexing completed on 2024-05-12 05:17:28
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "text/addressparser.cpp" 0008 0009 #include <KItinerary/Place> 0010 0011 #include <QTest> 0012 0013 using namespace KItinerary; 0014 0015 #define s(x) QStringLiteral(x) 0016 0017 class AddressParserTest : public QObject 0018 { 0019 Q_OBJECT 0020 private Q_SLOTS: 0021 void testPostalCodeExtraction_data() 0022 { 0023 QTest::addColumn<QString>("input"); 0024 QTest::addColumn<QString>("city"); 0025 QTest::addColumn<QString>("postalCode"); 0026 QTest::addColumn<QString>("country"); 0027 0028 QTest::newRow("empty") << QString() << QString() << QString() << QString(); 0029 QTest::newRow("no code") << s("PARIS") << s("PARIS") << QString() << QString(); 0030 QTest::newRow("BE-valid") << s("1060 Brussels") << s("Brussels") << s("1060") << s("BE"); 0031 QTest::newRow("BE-invalid") << s("171060 Brussels") << s("171060 Brussels") << QString() << s("BE"); 0032 QTest::newRow("FR-valid") << s("75012 Paris Some Suffix") << s("Paris Some Suffix") << s("75012") << s("FR"); 0033 QTest::newRow("NZ-valid") << s("Palmerston North 4414") << s("Palmerston North") << s("4414") << s("NZ"); 0034 QTest::newRow("PT-valid") << s("1000-205 Lisboa") << s("Lisboa") << s("1000-205") << s("PT"); 0035 QTest::newRow("PT-wrong-country") << s("1000-205 Lisboa") << s("1000-205 Lisboa") << QString() << s("DE"); 0036 QTest::newRow("AR-short") << s("C1420 Buenos Aires") << s("Buenos Aires") << s("C1420") << s("AR"); 0037 QTest::newRow("AR-full") << s("C1420ABC Buenos Aires") << s("Buenos Aires") << s("C1420ABC") << s("AR"); 0038 } 0039 0040 void testPostalCodeExtraction() 0041 { 0042 QFETCH(QString, input); 0043 QFETCH(QString, city); 0044 QFETCH(QString, postalCode); 0045 QFETCH(QString, country); 0046 0047 PostalAddress a; 0048 a.setAddressLocality(input); 0049 a.setAddressCountry(country); 0050 0051 AddressParser p; 0052 p.setFallbackCountry(s("GB")); 0053 p.parse(a); 0054 const auto out = p.result(); 0055 QCOMPARE(out.addressLocality(), city); 0056 QCOMPARE(out.postalCode(), postalCode); 0057 0058 p.parse(out); 0059 const auto out2 = p.result(); 0060 QCOMPARE(out, out2); 0061 } 0062 }; 0063 0064 QTEST_GUILESS_MAIN(AddressParserTest) 0065 0066 #include "addressparsertest.moc"