1 /***************************************************************************
2 * SPDX-FileCopyrightText: 2021 S. MANKOWSKI stephane@mankowski.fr
3 * SPDX-FileCopyrightText: 2021 G. DE BURE support@mankowski.fr
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 ***************************************************************************/
6 /** @file
7 * This file is a test script.
8 *
9 * @author Stephane MANKOWSKI / Guillaume DE BURE
10 */
11 #include "skgtestmacro.h"
12 #include "skgbankincludes.h"
13 #include "skgimportexportmanager.h"
14
15 /**
16 * The main function of the unit test
17 * @param argc the number of arguments
18 * @param argv the list of arguments
19 */
main(int argc,char ** argv)20 int main(int argc, char** argv)
21 {
22 Q_UNUSED(argc)
23 Q_UNUSED(argv)
24
25 // Init test
26 SKGINITTEST(true)
27
28 {
29 // Test import SKG
30 SKGDocumentBank document1;
31 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
32 SKGError err;
33 {
34 // Scope of the transaction
35 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err)
36 SKGImportExportManager impmissing(&document1, QUrl::fromLocalFile(QStringLiteral("missingfile.skg")));
37 SKGTESTERROR(QStringLiteral("imp1.importFile"), impmissing.importFile(), false)
38
39 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/all_types.skg"));
40 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true)
41 }
42
43 {
44 SKGAccountObject account(&document1);
45 SKGTESTERROR(QStringLiteral("SKG.setName"), account.setName(QStringLiteral("FRANC")), true)
46 SKGTESTERROR(QStringLiteral("SKG.load"), account.load(), true)
47 SKGTEST(QStringLiteral("SKG:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1.524490172"))
48 }
49 {
50 SKGAccountObject account(&document1);
51 SKGTESTERROR(QStringLiteral("SKG.setName"), account.setName(QStringLiteral("COURANT")), true)
52 SKGTESTERROR(QStringLiteral("SKG.load"), account.load(), true)
53 SKGTEST(QStringLiteral("SKG:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("-55"))
54 }
55 {
56 SKGAccountObject account(&document1);
57 SKGTESTERROR(QStringLiteral("SKG.setName"), account.setName(QStringLiteral("EPARGNE")), true)
58 SKGTESTERROR(QStringLiteral("SKG.load"), account.load(), true)
59 SKGTEST(QStringLiteral("SKG:getCurrentAmount"), SKGServices::doubleToString(account.getCurrentAmount()), QStringLiteral("1130.52449"))
60 }
61
62 // test multi import
63 {
64 // Scope of the transaction
65 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err)
66
67 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/all_types.skg"));
68 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true)
69 }
70
71 // Export xml
72 {
73 // Scope of the transaction
74 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_XML"), err)
75
76 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types.xml"));
77 SKGTESTERROR(QStringLiteral("SKG.exportFile"), imp1.exportFile(), true)
78 }
79
80 // Export json
81 {
82 // Scope of the transaction
83 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_JSON"), err)
84
85 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types.json"));
86 SKGTESTERROR(QStringLiteral("SKG.exportFile"), imp1.exportFile(), true)
87 }
88
89 // Export json
90 {
91 // Scope of the transaction
92 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_JSON"), err)
93
94 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types.json"));
95 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), false)
96 }
97 }
98 {
99 SKGDocumentBank document1;
100 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
101 SKGError err;
102 // Export skg from memory
103 {
104 // Scope of the transaction
105 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SKG"), err)
106
107 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_mem.skg"));
108 SKGTESTERROR(QStringLiteral("SKG.exportFile from memory"), imp1.exportFile(), true)
109 SKGTESTERROR(QStringLiteral("SKG.importFile from file"), imp1.importFile(), true)
110 }
111 SKGTESTERROR(QStringLiteral("SKG.saveAs"), document1.saveAs(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg", true), true)
112
113 // Export skg from file
114 SKGTESTERROR(QStringLiteral("SKG.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg"), true) {
115 // Scope of the transaction
116 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SKG"), err)
117
118 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_file.skg"));
119 SKGTESTERROR(QStringLiteral("SKG.exportFile from file"), imp1.exportFile(), true)
120 SKGTESTERROR(QStringLiteral("SKG.importFile from file"), imp1.importFile(), true)
121 }
122 }
123 {
124 SKGDocumentBank document1;
125 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
126 SKGError err;
127 // Export sqlite from memory
128 {
129 // Scope of the transaction
130 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLITE"), err)
131
132 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_mem.sqlite"));
133 SKGTESTERROR(QStringLiteral("SQLITE.exportFile from memory"), imp1.exportFile(), true)
134 SKGTESTERROR(QStringLiteral("SQLITE.importFile from file"), imp1.importFile(), true)
135 }
136
137 // Export skg from file
138 SKGTESTERROR(QStringLiteral("SKG.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg"), true) {
139 // Scope of the transaction
140 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLITE"), err)
141
142 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_file.sqlite"));
143 SKGTESTERROR(QStringLiteral("SQLITE.exportFile from file"), imp1.exportFile(), true)
144 SKGTESTERROR(QStringLiteral("SQLITE.importFile from file"), imp1.importFile(), true)
145 }
146 }
147 {
148 SKGDocumentBank document1;
149 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
150 SKGError err;
151 // Export sqlcipher from memory
152 {
153 // Scope of the transaction
154 SKGTESTERROR(QStringLiteral("SQLCIPHER.changePassword"), document1.changePassword(QStringLiteral("password")), true)
155
156 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLCIPHER"), err)
157 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_mem.sqlcipher"));
158 SKGTESTERROR(QStringLiteral("SQLCIPHER.exportFile from memory"), imp1.exportFile(), true)
159 QMap<QString, QString> parameters;
160 parameters[QStringLiteral("password")] = QStringLiteral("password");
161 imp1.setImportParameters(parameters);
162 SKGTESTERROR(QStringLiteral("SQLCIPHER.importFile from file"), imp1.importFile(), true)
163 }
164
165 // Export skg from file
166 SKGTESTERROR(QStringLiteral("SKG.load"), document1.load(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_save.skg"), true) {
167 // Scope of the transaction
168 SKGTESTERROR(QStringLiteral("SQLCIPHER.changePassword"), document1.changePassword(QStringLiteral("password")), true)
169
170 SKGBEGINTRANSACTION(document1, QStringLiteral("EXPORT_SQLCIPHER"), err)
171 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("OUT")) % "/skgtestimportskg/all_types_exp_from_file.sqlcipher"));
172 SKGTESTERROR(QStringLiteral("SQLCIPHER.exportFile from file"), imp1.exportFile(), true)
173 QMap<QString, QString> parameters;
174 parameters[QStringLiteral("password")] = QStringLiteral("password");
175 imp1.setImportParameters(parameters);
176 SKGTESTERROR(QStringLiteral("SQLCIPHER.importFile from file"), imp1.importFile(), true)
177 }
178 }
179 {
180 // Test import encrypted SKG
181 SKGDocumentBank document1;
182 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
183 SKGError err;
184 {
185 // Scope of the transaction
186 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err)
187
188 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/encrypted.skg"));
189 QMap<QString, QString> parameters;
190 parameters[QStringLiteral("password")] = QStringLiteral("password");
191 imp1.setImportParameters(parameters);
192 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true)
193 }
194 }
195
196 {
197 // Test import SKG
198 SKGDocumentBank document1;
199 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
200 SKGError err;
201 {
202 // Scope of the transaction
203 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err)
204 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/skgtestimportskg/euro_bitcoin_dollar.skg"));
205 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true)
206 }
207 }
208
209 {
210 // Test import SKG
211 SKGDocumentBank document1;
212 SKGTESTERROR(QStringLiteral("document1.initialize()"), document1.initialize(), true)
213 SKGError err;
214 {
215 // Scope of the transaction
216 SKGBEGINTRANSACTION(document1, QStringLiteral("IMPORT_SKG"), err)
217 SKGImportExportManager imp1(&document1, QUrl::fromLocalFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/advice.skg"));
218 SKGTESTERROR(QStringLiteral("SKG.importFile"), imp1.importFile(), true)
219 }
220 }
221 // End test
222 SKGENDTEST()
223 }
224