File indexing completed on 2024-05-12 16:45:23
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 SKG 0030 SKGDocumentBank document1; 0031 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0032 SKGError err; 0033 { 0034 // Scope of the transaction 0035 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err) 0036 SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.skg"))); 0037 SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false) 0038 0039 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/all_types.skg")); 0040 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true) 0041 } 0042 0043 { 0044 SKGAccountObject account(&document1); 0045 SKGTESTERROR(QStringLiteral("SKG.setName"), account.setName(QStringLiteral("FRANC")), true) 0046 SKGTESTERROR(QStringLiteral("SKG.load"), account.load(), true) 0047 SKGTEST(QStringLiteral("SKG:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1.524490172")) 0048 } 0049 { 0050 SKGAccountObject account(&document1); 0051 SKGTESTERROR(QStringLiteral("SKG.setName"), account.setName(QStringLiteral("COURANT")), true) 0052 SKGTESTERROR(QStringLiteral("SKG.load"), account.load(), true) 0053 SKGTEST(QStringLiteral("SKG:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-14055")) 0054 0055 auto properties = account.getProperties(); 0056 SKGTEST(QStringLiteral("SKG:getProperties"), SKGServices::intToString(properties.length()), QStringLiteral("1")) 0057 0058 SKGPropertyObject p(account.getPropertyObject(properties.at(0))); 0059 SKGTEST(QStringLiteral("SKG:getPropertyBlob FALSE"), static_cast<unsigned int>(account.getPropertyBlob(properties.at(0)).isNull() || account.getPropertyBlob(properties.at(0)).toByteArray().length() == 0), static_cast<unsigned int>(true)) 0060 SKGTEST(QStringLiteral("SKG:getPropertyObject.value"), p.getValue(), "PROP_CPT") 0061 } 0062 { 0063 SKGAccountObject account(&document1); 0064 SKGTESTERROR(QStringLiteral("SKG.setName"), account.setName(QStringLiteral("EPARGNE")), true) 0065 SKGTESTERROR(QStringLiteral("SKG.load"), account.load(), true) 0066 SKGTEST(QStringLiteral("SKG:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("5622.224686")) 0067 } 0068 0069 // test multi import 0070 { 0071 // Scope of the transaction 0072 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err) 0073 0074 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/all_types.skg")); 0075 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true) 0076 } 0077 0078 // Export xml 0079 { 0080 // Scope of the transaction 0081 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_XML"), err) 0082 0083 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types.xml")); 0084 SKGTESTERROR(QStringLiteral("SKG.exportFile"), imp1.exportFile(), true) 0085 } 0086 0087 // Export json 0088 { 0089 // Scope of the transaction 0090 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_JSON"), err) 0091 0092 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types.json")); 0093 SKGTESTERROR(QStringLiteral("SKG.exportFile"), imp1.exportFile(), true) 0094 } 0095 0096 // Export json 0097 { 0098 // Scope of the transaction 0099 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_JSON"), err) 0100 0101 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types.json")); 0102 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), false) 0103 } 0104 } 0105 { 0106 SKGDocumentBank document1; 0107 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0108 SKGError err; 0109 // Export skg from memory 0110 { 0111 // Scope of the transaction 0112 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SKG"), err) 0113 0114 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_mem.skg")); 0115 SKGTESTERROR(QStringLiteral("SKG.exportFile from memory"), imp1.exportFile(), true) 0116 SKGTESTERROR(QStringLiteral("SKG.importFile from file"), imp1.importFile(), true) 0117 } 0118 SKGTESTERROR(QStringLiteral("SKG.saveAs"), document1.saveAs(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg", true), true) 0119 0120 // Export skg from file 0121 SKGTESTERROR(QStringLiteral("SKG.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg"), true) { 0122 // Scope of the transaction 0123 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SKG"), err) 0124 0125 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_file.skg")); 0126 SKGTESTERROR(QStringLiteral("SKG.exportFile from file"), imp1.exportFile(), true) 0127 SKGTESTERROR(QStringLiteral("SKG.importFile from file"), imp1.importFile(), true) 0128 } 0129 } 0130 { 0131 SKGDocumentBank document1; 0132 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0133 SKGError err; 0134 // Export sqlite from memory 0135 { 0136 // Scope of the transaction 0137 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLITE"), err) 0138 0139 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_mem.sqlite")); 0140 SKGTESTERROR(QStringLiteral("SQLITE.exportFile from memory"), imp1.exportFile(), true) 0141 SKGTESTERROR(QStringLiteral("SQLITE.importFile from file"), imp1.importFile(), true) 0142 } 0143 0144 // Export skg from file 0145 SKGTESTERROR(QStringLiteral("SKG.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg"), true) { 0146 // Scope of the transaction 0147 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLITE"), err) 0148 0149 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_file.sqlite")); 0150 SKGTESTERROR(QStringLiteral("SQLITE.exportFile from file"), imp1.exportFile(), true) 0151 SKGTESTERROR(QStringLiteral("SQLITE.importFile from file"), imp1.importFile(), true) 0152 } 0153 } 0154 { 0155 SKGDocumentBank document1; 0156 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0157 SKGError err; 0158 // Export sqlcipher from memory 0159 { 0160 // Scope of the transaction 0161 SKGTESTERROR(QStringLiteral("SQLCIPHER.changePassword"), document1.changePassword(QStringLiteral("password")), true) 0162 0163 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLCIPHER"), err) 0164 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_mem.sqlcipher")); 0165 SKGTESTERROR(QStringLiteral("SQLCIPHER.exportFile from memory"), imp1.exportFile(), true) 0166 QMap<QString, QString> parameters; 0167 parameters[QStringLiteral("password")] = QStringLiteral("password"); 0168 imp1.setImportParameters(parameters); 0169 SKGTESTERROR(QStringLiteral("SQLCIPHER.importFile from file"), imp1.importFile(), true) 0170 } 0171 0172 // Export skg from file 0173 SKGTESTERROR(QStringLiteral("SKG.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg"), true) { 0174 // Scope of the transaction 0175 SKGTESTERROR(QStringLiteral("SQLCIPHER.changePassword"), document1.changePassword(QStringLiteral("password")), true) 0176 0177 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLCIPHER"), err) 0178 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_file.sqlcipher")); 0179 SKGTESTERROR(QStringLiteral("SQLCIPHER.exportFile from file"), imp1.exportFile(), true) 0180 QMap<QString, QString> parameters; 0181 parameters[QStringLiteral("password")] = QStringLiteral("password"); 0182 imp1.setImportParameters(parameters); 0183 SKGTESTERROR(QStringLiteral("SQLCIPHER.importFile from file"), imp1.importFile(), true) 0184 } 0185 } 0186 { 0187 // Test import encrypted SKG 0188 SKGDocumentBank document1; 0189 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0190 SKGError err; 0191 { 0192 // Scope of the transaction 0193 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err) 0194 0195 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/encrypted.skg")); 0196 QMap<QString, QString> parameters; 0197 parameters[QStringLiteral("password")] = QStringLiteral("password"); 0198 imp1.setImportParameters(parameters); 0199 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true) 0200 } 0201 } 0202 0203 { 0204 // Test import SKG 0205 SKGDocumentBank document1; 0206 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0207 SKGError err; 0208 { 0209 // Scope of the transaction 0210 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err) 0211 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/euro_bitcoin_dollar.skg")); 0212 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true) 0213 } 0214 } 0215 0216 { 0217 // Test import SKG 0218 SKGDocumentBank document1; 0219 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true) 0220 SKGError err; 0221 { 0222 // Scope of the transaction 0223 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err) 0224 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/advice.skg")); 0225 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true) 0226 } 0227 } 0228 // End test 0229 SKGENDTEST() 0230 }