File indexing completed on 2024-05-12 16:45:20
0001 /*************************************************************************** 0002 * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr 0003 * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 ***************************************************************************/ 0006 /** @file 0007 * This file is a test script. 0008 * 0009 * @author Stephane MANKOWSKI / Guillaume DE BURE 0010 */ 0011 #include "skgtestmacro.h" 0012 #include "skgbankincludes.h" 0013 #include "skgimportexportmanager.h" 0014 0015 /** 0016 * The main function of the unit test 0017 * @param argc the number of arguments 0018 * @param argv the list of arguments 0019 */ 0020 int main(int argc, char** argv) 0021 { 0022 Q_UNUSED(argc) 0023 Q_UNUSED(argv) 0024 0025 // Init test 0026 SKGINITTEST(true) 0027 0028 { 0029 // Test import AFB120 0030 SKGDocumentBank document1; 0031 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0032 SKGError err; 0033 { 0034 SKGTESTERROR(QStringLiteral("DOC:changePassword"), document1.changePassword(QStringLiteral("test")), true) 0035 0036 // Scope of the transaction 0037 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_AFB120"), err) 0038 0039 SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.cfo"))); 0040 SKGTESTERROR(QStringLiteral("AFB120.importFile"), impmissing.importFile(), false) 0041 0042 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportafb120/gs_01139_021239S.cfo")); 0043 SKGTESTERROR(QStringLiteral("AFB120.importFile"), imp1.importFile(), true) 0044 0045 document1.dump(DUMPOPERATION | DUMPACCOUNT); 0046 } 0047 0048 { 0049 SKGAccountObject account(&document1); 0050 SKGTESTERROR(QStringLiteral("AFB120.setName"), account.setName(QStringLiteral("0000021239S")), true) 0051 SKGTESTERROR(QStringLiteral("AFB120.load"), account.load(), true) 0052 SKGTEST(QStringLiteral("AFB120:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("2555.48")) 0053 } 0054 0055 { 0056 // Scope of the transaction 0057 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_AFB120"), err) 0058 0059 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportafb120/gs_01139_021239S.cfo")); 0060 SKGTESTERROR(QStringLiteral("AFB120.importFile"), imp1.importFile(), true) 0061 } 0062 0063 { 0064 SKGAccountObject account(&document1); 0065 SKGTESTERROR(QStringLiteral("AFB120.setName"), account.setName(QStringLiteral("0000021239S")), true) 0066 SKGTESTERROR(QStringLiteral("AFB120.load"), account.load(), true) 0067 SKGTEST(QStringLiteral("AFB120:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("2555.48")) 0068 } 0069 0070 QString fano; 0071 { 0072 QString f = SKGTest::getTestPath(QStringLiteral("OUT")) % QStringLiteral("/skgtestimportafb120/anonymize.skg"); 0073 QFile(f).remove(); 0074 SKGImportExportManager imp1(&document1); 0075 SKGTESTERROR(QStringLiteral("AFB120:anonymize"), imp1.anonymize(QLatin1String("")), false) 0076 SKGTESTERROR(QStringLiteral("AFB120.saveAs"), document1.saveAs(f), true) 0077 SKGTESTERROR(QStringLiteral("AFB120:anonymize"), imp1.anonymize(QLatin1String("")), true) 0078 fano = document1.getCurrentFileName(); 0079 SKGTEST(QStringLiteral("AFB120:getCurrentFileName"), static_cast<unsigned int>(fano != f), static_cast<unsigned int>(true)) 0080 0081 document1.close(); 0082 } 0083 0084 { 0085 // Load anonymized file 0086 SKGDocumentBank document2; 0087 SKGTESTERROR(QStringLiteral("DOC:load"), document2.load(fano), true) 0088 0089 SKGImportExportManager imp1(&document2); 0090 SKGTESTERROR(QStringLiteral("AFB120:anonymize"), imp1.anonymize(QStringLiteral("KEY")), true) 0091 } 0092 } 0093 // End test 0094 SKGENDTEST() 0095 }