File indexing completed on 2024-06-16 04:46:15

0001 /*
0002     SPDX-FileCopyrightText: 2014 Christian Dávid <christian-david@web.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "internationalaccountidentifier-test.h"
0007 #include "payeeidentifier/ibanbic/ibanbic.h"
0008 #include "plugins/ibanbicdata/ibanbicdata.h"
0009 
0010 #include <QTest>
0011 
0012 QTEST_GUILESS_MAIN(internationalAccountIdentifierTest);
0013 
0014 bool internationalAccountIdentifierTest::dataInstalled(const QString& countryCode)
0015 {
0016     // Not really implemented yet
0017     Q_UNUSED(countryCode);
0018     return false;
0019 }
0020 
0021 void internationalAccountIdentifierTest::initTestCase()
0022 {
0023     // Called before the first testfunction is executed
0024 }
0025 
0026 void internationalAccountIdentifierTest::cleanupTestCase()
0027 {
0028     // Called after the last testfunction was executed
0029 }
0030 
0031 void internationalAccountIdentifierTest::init()
0032 {
0033     // Called before each testfunction is executed
0034 }
0035 
0036 void internationalAccountIdentifierTest::cleanup()
0037 {
0038     // Called after every testfunction
0039 }
0040 
0041 void internationalAccountIdentifierTest::comparison()
0042 {
0043 
0044 }
0045 
0046 void internationalAccountIdentifierTest::ibanChecksum_data()
0047 {
0048     QTest::addColumn<QString>("iban");
0049     QTest::addColumn<bool>("testResult");
0050 
0051     QTest::newRow("KDE e.V.") << "DE82200700240066644600" << true;
0052     QTest::newRow("Invalid iban") << "DE82200700240066644601" << false;
0053     QTest::newRow("IBAN with letters") << "BH82AEHI21601643513576" << true;
0054 }
0055 
0056 void internationalAccountIdentifierTest::ibanChecksum()
0057 {
0058     QFETCH(QString, iban);
0059     QFETCH(bool, testResult);
0060 
0061     QCOMPARE(payeeIdentifiers::ibanBic::validateIbanChecksum(iban), testResult);
0062 }
0063 
0064 void internationalAccountIdentifierTest::paperformatIban_data()
0065 {
0066     QTest::addColumn<QString>("iban");
0067     QTest::addColumn<QString>("paperformat");
0068 
0069     /** Random ibans generated using https://www.mobilefish.com/services/random_iban_generator/random_iban_generator.php */
0070     QTest::newRow("AL55359338525014419438694535") << "AL55359338525014419438694535" << "AL55 3593 3852 5014 4194 3869 4535";
0071     QTest::newRow("AD6507599863323512292387")     << "AD6507599863323512292387"     << "AD65 0759 9863 3235 1229 2387";
0072     QTest::newRow("AT550611200130969602")         << "AT550611200130969602"         << "AT55 0611 2001 3096 9602";
0073     QTest::newRow("AZ45YKNN50322618666505570288") << "AZ45YKNN50322618666505570288" << "AZ45 YKNN 5032 2618 6665 0557 0288";
0074     QTest::newRow("BH82AEHI21601643513576")       << "BH82AEHI21601643513576"       << "BH82 AEHI 2160 1643 5135 76";
0075     QTest::newRow("FR1767089178626632115068411")  << "FR1767089178626632115068411"  << "FR17 6708 9178 6266 3211 5068 411";
0076     QTest::newRow("GE87UH3052380574220575")       << "GE87UH3052380574220575"       << "GE87 UH30 5238 0574 2205 75";
0077     QTest::newRow("DE88476823289460743695")       << "DE88476823289460743695"       << "DE88 4768 2328 9460 7436 95";
0078     QTest::newRow("it81K2055156417927233643224")  << "it81K2055156417927233643224"  << "IT81 K205 5156 4179 2723 3643 224";
0079 
0080     // Unfinished ibans
0081     QTest::newRow("PK")                           << "PK"                           << "PK";
0082     QTest::newRow("NO5194556")                    << "NO5194556"                    << "NO51 9455 6";
0083 
0084     // Non canonical ibans
0085     QTest::newRow("VG33 NRCC 0371 8957 2076 3593") << "VG33 NRCC 0371 8957 2076 3593" << "VG33 NRCC 0371 8957 2076 3593";
0086     QTest::newRow(" SI 4523 946 27 23 327 14 9  ") << " SI 4523 946 27 23 327 14 9  " << "SI45 2394 6272 3327 149";
0087     QTest::newRow("MK 3-27/3287/612--98207//26")  << "MK 3-27/3287/612--98207//26"  << "MK32 7328 7612 9820 726";
0088 }
0089 
0090 void internationalAccountIdentifierTest::paperformatIban()
0091 {
0092     QFETCH(QString, iban);
0093     QFETCH(QString, paperformat);
0094 
0095     QCOMPARE(payeeIdentifiers::ibanBic::ibanToPaperformat(iban), paperformat);
0096 }
0097 
0098 void internationalAccountIdentifierTest::electronicformatIban_data()
0099 {
0100     QTest::addColumn<QString>("iban");
0101     QTest::addColumn<QString>("electronic");
0102 
0103     QTest::newRow("AL89 5112 2491 7164 1236 8777 7047") << "AL89 5112 2491 7164 1236 8777 7047" << "AL89511224917164123687777047";
0104     QTest::newRow("AZ11 BIAH 1276 1568 9842 3064 6155") << "AZ11 BIAH 1276 1568 9842 3064 6155" << "AZ11BIAH12761568984230646155";
0105     QTest::newRow("AZ73  WMRx 62 73 6   823 2803 9705") << "AZ73  WMRx 62 73 6   823 2803 9705" << "AZ73WMRX6273682328039705";
0106     QTest::newRow("AZ55/MKDW-9866$8070(4022)5306 7865") << "AZ55/MKDW-9866$8070(4022)5306 7865" << "AZ55MKDW98668070402253067865";
0107     QTest::newRow("AZ 57                             ") << "AZ 57                             " << "AZ57";
0108     QTest::newRow("dk3958515811555611")                 << "dk3958515811555611"                 << "DK3958515811555611";
0109 }
0110 
0111 void internationalAccountIdentifierTest::electronicformatIban()
0112 {
0113     QFETCH(QString, iban);
0114     QFETCH(QString, electronic);
0115     QCOMPARE(payeeIdentifiers::ibanBic::ibanToElectronic(iban), electronic);
0116 }
0117 
0118 void internationalAccountIdentifierTest::setIban_data()
0119 {
0120     QTest::addColumn<QString>("iban");
0121     QTest::addColumn<QString>("electronic");
0122     QTest::addColumn<QString>("paperformat");
0123 
0124     QTest::newRow("AL89 5112 2491 7164 1236 8777 7047") << "AL89 5112 2491 7164 1236 8777 7047" << "AL89511224917164123687777047" << "AL89 5112 2491 7164 1236 8777 7047" ;
0125     QTest::newRow("AZ73  WMRX 62 73 6   823 2803 9705") << "AZ73  WMRX 62 73 6   823 2803 9705" << "AZ73WMRX6273682328039705"     << "AZ73 WMRX 6273 6823 2803 9705";
0126     QTest::newRow("AZ55/MKDW-9866$8070(4022)5306 7865") << "AZ55/MKDW-9866$8070(4022)5306 7865" << "AZ55MKDW98668070402253067865" << "AZ55 MKDW 9866 8070 4022 5306 7865";
0127     QTest::newRow("AZ 57                             ") << "AZ 57                             " << "AZ57"                         << "AZ57";
0128     QTest::newRow("DK3958515811555611")                 << "DK3958515811555611"                 << "DK3958515811555611"           << "DK39 5851 5811 5556 11";
0129 }
0130 
0131 void internationalAccountIdentifierTest::setIban()
0132 {
0133     QFETCH(QString, iban);
0134     QFETCH(QString, electronic);
0135     QFETCH(QString, paperformat);
0136 
0137     payeeIdentifiers::ibanBic ident;
0138     ident.setIban(iban);
0139     QCOMPARE(ident.electronicIban(), electronic);
0140     QCOMPARE(ident.paperformatIban(), paperformat);
0141 }
0142 
0143 void internationalAccountIdentifierTest::setBic_data()
0144 {
0145     QTest::addColumn<QString>("input");
0146     QTest::addColumn<QString>("normalized");
0147     QTest::addColumn<QString>("full");
0148 
0149     QTest::newRow("Lower case")     << "chasgb2lxXx" << "CHASGB2L"    << "CHASGB2LXXX";
0150     QTest::newRow("Arbitrary case") << "RZtIaT22263" << "RZTIAT22263" << "RZTIAT22263";
0151     QTest::newRow("Without XXX")    << "MARKDEFF"    << "MARKDEFF"    << "MARKDEFFXXX";
0152     QTest::newRow("With XXX")       << "MARKDEFFXXX" << "MARKDEFF"    << "MARKDEFFXXX";
0153     QTest::newRow("Arbitrary bic")  << "GENODEF1JEV" << "GENODEF1JEV" << "GENODEF1JEV";
0154 }
0155 
0156 void internationalAccountIdentifierTest::setBic()
0157 {
0158     QFETCH(QString, input);
0159     QFETCH(QString, normalized);
0160     QFETCH(QString, full);
0161 
0162     payeeIdentifiers::ibanBic ident;
0163     ident.setBic(input);
0164     QCOMPARE(ident.bic(), normalized);
0165     QCOMPARE(ident.fullBic(), full);
0166 }
0167 
0168 void internationalAccountIdentifierTest::equalOperator_data()
0169 {
0170     QTest::addColumn<QString>("bic1");
0171     QTest::addColumn<QString>("iban1");
0172     QTest::addColumn<QString>("bic2");
0173     QTest::addColumn<QString>("iban2");
0174     QTest::addColumn<bool>("equals");
0175 
0176     QTest::newRow("equal") << "MARKDEFFXXX" << "DE88476823289460743695" << "MARKDEFF" << "        DE88 4768 2328 9460 7436 95" << true;
0177     QTest::newRow("BIC unequal") << "MARKDEFF001" << "DE884768  23289460743695" << "MARKDEFF" << "DE88 4768 2328 9460 7436 95" << false;
0178     QTest::newRow("IBAN unequal") << "MARKDEFFXXX" << "DE88476823289460743695" << "MARKDEFF" << "GE87UH3052380574220575" << false;
0179 }
0180 
0181 void internationalAccountIdentifierTest::equalOperator()
0182 {
0183     QFETCH(QString, bic1);
0184     QFETCH(QString, iban1);
0185     QFETCH(QString, bic2);
0186     QFETCH(QString, iban2);
0187     QFETCH(bool, equals);
0188 
0189     payeeIdentifiers::ibanBic ident1;
0190     ident1.setBic(bic1);
0191     ident1.setIban(iban1);
0192 
0193     payeeIdentifiers::ibanBic ident2;
0194     ident2.setBic(bic2);
0195     ident2.setIban(iban2);
0196 
0197     if (equals)
0198         QCOMPARE(ident1, ident2);
0199     else
0200         QVERIFY(!(ident1 == ident2));
0201 }
0202 
0203 void internationalAccountIdentifierTest::uneqalOperator_data()
0204 {
0205     equalOperator_data();
0206 }
0207 
0208 void internationalAccountIdentifierTest::uneqalOperator()
0209 {
0210     QFETCH(QString, bic1);
0211     QFETCH(QString, iban1);
0212     QFETCH(QString, bic2);
0213     QFETCH(QString, iban2);
0214     QFETCH(bool, equals);
0215 
0216     payeeIdentifiers::ibanBic ident1;
0217     ident1.setBic(bic1);
0218     ident1.setIban(iban1);
0219 
0220     payeeIdentifiers::ibanBic ident2;
0221     ident2.setBic(bic2);
0222     ident2.setIban(iban2);
0223 
0224     if (equals)
0225         QVERIFY(!(ident1 != ident2));
0226     else
0227         QVERIFY(ident1 != ident2);
0228 }
0229 
0230 void internationalAccountIdentifierTest::getProperties_data()
0231 {
0232     QTest::addColumn<QString>("countryCode");
0233     QTest::addColumn<int>("bbanLength");
0234     QTest::addColumn<int>("bankIdentifierLength");
0235 
0236     QTest::newRow("Germany")     << "DE" << 18 << 8;
0237     QTest::newRow("France")      << "FR" << 23 << 10;
0238     QTest::newRow("Switzerland") << "CH" << 17 << 5;
0239 }
0240 
0241 void internationalAccountIdentifierTest::getProperties()
0242 {
0243     QFETCH(QString, countryCode);
0244     QFETCH(int, bbanLength);
0245 
0246     if (!dataInstalled(countryCode))
0247         QSKIP(qPrintable(QString("Could not find ibanBicData service for this country (was looking for \"%1\"). Did you install the services?").arg(countryCode)), SkipSingle);
0248 
0249     QCOMPARE(payeeIdentifiers::ibanBic::ibanLengthByCountry(countryCode), bbanLength + 4);
0250 }
0251 
0252 void internationalAccountIdentifierTest::iban2bic_data()
0253 {
0254     QTest::addColumn<QString>("iban");
0255     QTest::addColumn<QString>("bic");
0256 
0257     QTest::newRow("Germany (Unicef Germany)")   << "DE57370205000000300000" << "BFSWDE33XXX";
0258     QTest::newRow("Switzerland (Unicef Swiss)") << "CH8809000000800072119"  << "POFICHBEXXX";
0259 }
0260 
0261 void internationalAccountIdentifierTest::iban2bic()
0262 {
0263     QFETCH(QString, iban);
0264     QFETCH(QString, bic);
0265 
0266     if (!dataInstalled(iban.left(2)))
0267         QSKIP(qPrintable(QString("Could not find ibanBicData service for this country (was looking for \"%1\"). Did you install the services?").arg(iban)), SkipSingle);
0268 
0269     QCOMPARE(payeeIdentifiers::ibanBic::bicByIban(iban), bic);
0270 }
0271 
0272 void internationalAccountIdentifierTest::nameByBic_data()
0273 {
0274     QTest::addColumn<QString>("bic");
0275     QTest::addColumn<QString>("name");
0276 
0277     QTest::newRow("Germany (Bundesbank)") << "MARKDEF1100" << "Bundesbank";
0278 }
0279 
0280 void internationalAccountIdentifierTest::nameByBic()
0281 {
0282     QFETCH(QString, bic);
0283     QFETCH(QString, name);
0284 
0285     if (!dataInstalled(bic.mid(4, 2)))
0286         QSKIP(qPrintable(QString("Could not find ibanBicData service for this country (was looking for \"%1\"). Did you install the services?").arg(bic)), SkipSingle);
0287 
0288     QCOMPARE(payeeIdentifiers::ibanBic::institutionNameByBic(bic), name);
0289 }
0290 
0291 void internationalAccountIdentifierTest::bicAndNameByIban_data()
0292 {
0293     QTest::addColumn<QString>("iban");
0294     QTest::addColumn<QString>("bic");
0295     QTest::addColumn<QString>("name");
0296 
0297     QTest::newRow("Germany (Unicef Germany)")   << "DE57370205000000300000" << "BFSWDE33XXX" << "";
0298 }
0299 
0300 void internationalAccountIdentifierTest::bicAndNameByIban()
0301 {
0302     QTest::addColumn<QString>("iban");
0303     QTest::addColumn<QString>("bic");
0304     QTest::addColumn<QString>("name");
0305 
0306     QSKIP("Test not implemented", SkipAll);
0307     //QPair<QString, QString> pair = internationalAccountIdentifier::;
0308 }
0309 
0310 void internationalAccountIdentifierTest::qStringNullAndEmpty()
0311 {
0312     const QString nullStr1;
0313     QVERIFY(nullStr1.isNull());
0314     QVERIFY(nullStr1.isEmpty());
0315 
0316     const QString nullStr2 = QString();
0317     QVERIFY(nullStr2.isEmpty());
0318     QVERIFY(nullStr2.isNull());
0319 
0320     const QString empty = QString("");
0321     QVERIFY(empty.isEmpty());
0322     QVERIFY(!empty.isNull());
0323 }
0324 
0325 Q_DECLARE_METATYPE(payeeIdentifiers::ibanBic::bicAllocationStatus);
0326 
0327 void internationalAccountIdentifierTest::bicAllocated_data()
0328 {
0329     QTest::addColumn<QString>("bic");
0330     QTest::addColumn<payeeIdentifiers::ibanBic::bicAllocationStatus>("allocated");
0331 
0332     QTest::newRow("Bundesbank")   << "MARKDEFFXXX" << payeeIdentifiers::ibanBic::bicAllocated;
0333     QTest::newRow("Not existing") << "DOOFDE12NOT" << payeeIdentifiers::ibanBic::bicNotAllocated;
0334     QTest::newRow("Unknown")      << "NODAFRTAFOR" << payeeIdentifiers::ibanBic::bicAllocationUncertain;
0335 }
0336 
0337 void internationalAccountIdentifierTest::bicAllocated()
0338 {
0339     QFETCH(QString, bic);
0340     QFETCH(payeeIdentifiers::ibanBic::bicAllocationStatus, allocated);
0341 
0342     if (!dataInstalled(bic.mid(4, 2)))
0343         QSKIP(qPrintable(QString("Could not find ibanBicData service for this country (was looking for \"%1\"). Did you install the services?").arg(bic)), SkipSingle);
0344 
0345     QCOMPARE(payeeIdentifiers::ibanBic::isBicAllocated(bic), allocated);
0346 }