diff --git a/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp b/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp
index 83da8b0d1..3bcd8565f 100644
--- a/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp
+++ b/plugins/import/skrooge_import_ledger/skgimportpluginledger.cpp
@@ -1,244 +1,225 @@
/***************************************************************************
* Copyright (C) 2017 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the impgnced warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
/** @file
* This file is Skrooge plugin for ledger import / export.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include "skgimportpluginledger.h"
-#if QT_VERSION < 0x050700
-#include
-#endif
#include
#include
#include
#include "skgtraces.h"
#include "skgdocumentbank.h"
#include "skgservices.h"
#include "skgbankincludes.h"
/**
* This plugin factory.
*/
K_PLUGIN_FACTORY(SKGImportPluginLedgerFactory, registerPlugin();)
SKGImportPluginLedger::SKGImportPluginLedger(QObject* iImporter, const QVariantList& iArg)
: SKGImportPlugin(iImporter)
{
SKGTRACEINFUNC(10);
Q_UNUSED(iArg);
}
SKGImportPluginLedger::~SKGImportPluginLedger()
= default;
bool SKGImportPluginLedger::isExportPossible()
{
SKGTRACEINFUNC(10);
return (!m_importer ? true : m_importer->getFileNameExtension() == QStringLiteral("LEDGER"));
}
SKGError SKGImportPluginLedger::exportFile()
{
SKGError err;
QSaveFile file(m_importer->getLocalFileName(false));
if (!file.open(QIODevice::WriteOnly)) {
err.setReturnCode(ERR_INVALIDARG).setMessage(i18nc("Error message", "Save file '%1' failed", m_importer->getFileName().toDisplayString()));
} else {
auto listUUIDs = SKGServices::splitCSVLine(m_exportParameters.value(QStringLiteral("uuid_of_selected_accounts_or_operations")));
QString wc;
for (const auto& uuid : listUUIDs) {
auto items = SKGServices::splitCSVLine(uuid, '-');
if (items.at(1) == QStringLiteral("operation")) {
if (!wc.isEmpty()) {
wc += QLatin1String(" AND ");
}
wc += " i_OPID=" + items.at(0);
} else if (items.at(1) == QStringLiteral("account")) {
if (!wc.isEmpty()) {
wc += QLatin1String(" AND ");
}
wc += " rd_account_id=" + items.at(0);
}
}
if (wc.isEmpty()) {
wc = QStringLiteral("1=1");
} else {
IFOKDO(err, m_importer->getDocument()->sendMessage(i18nc("An information message", "Only selected accounts and operations have been exported")))
}
-#if QT_VERSION < 0x050700
- KLocale en(QStringLiteral("en_EN"));
-#else
QLocale en(QStringLiteral("en_EN"));
-#endif
QTextStream stream(&file);
if (!m_importer->getCodec().isEmpty()) {
stream.setCodec(m_importer->getCodec().toLatin1().constData());
}
stream << "; -*- ledger file generated by Skrooge -*-" << endl;
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Export step", "Export %1 file", "ledger"), 2);
IFOK(err) {
auto punit = m_importer->getDocument()->getPrimaryUnit();
SKGObjectBase::SKGListSKGObjectBase units;
err = m_importer->getDocument()->getObjects(QStringLiteral("v_unit"), QStringLiteral("t_type NOT IN ('C', '1', '2')"), units);
int nb = units.count();
IFOK(err) {
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Export step", "Export units"), nb);
for (int i = 0; !err && i < nb; ++i) {
SKGUnitObject unit(units.at(i));
-#if QT_VERSION < 0x050700
- QString qs = en.formatMoney(SKGServices::stringToDouble(unit.getAttribute(QStringLiteral("f_CURRENTAMOUNT"))), punit.Symbol, punit.NbDecimal).trimmed();
-#else
QString qs = en.toCurrencyString(SKGServices::stringToDouble(unit.getAttribute(QStringLiteral("f_CURRENTAMOUNT"))), punit.Symbol, punit.NbDecimal);
-#endif
stream << "P " << SKGServices::dateToSqlString(QDate::currentDate()).replace('-', '/')
<< " \"" << unit.getSymbol() << '"'
<< " " << qs
<< endl;
stream << endl;
IFOKDO(err, m_importer->getDocument()->stepForward(i + 1))
}
SKGENDTRANSACTION(m_importer->getDocument(), err);
}
}
IFOKDO(err, m_importer->getDocument()->stepForward(1))
IFOK(err) {
SKGObjectBase::SKGListSKGObjectBase operations;
err = m_importer->getDocument()->getObjects(QStringLiteral("v_operation"), wc % QStringLiteral(" AND t_template='N' ORDER BY d_date"), operations);
int nb = operations.count();
IFOK(err) {
err = m_importer->getDocument()->beginTransaction("#INTERNAL#" % i18nc("Export step", "Export operations"), nb);
for (int i = 0; !err && i < nb; ++i) {
SKGOperationObject op(operations.at(i));
auto status = op.getStatus();
auto number = op.getNumber();
SKGPayeeObject payee;
op.getPayee(payee);
SKGUnitObject unit;
op.getUnit(unit);
bool isCurrency = unit.getType() == SKGUnitObject::CURRENCY || unit.getType() == SKGUnitObject::PRIMARY || unit.getType() == SKGUnitObject::SECONDARY;
auto payeeString = payee.getName();
if (payeeString.isEmpty()) {
payeeString = op.getComment();
}
auto nbDec = SKGServices::stringToInt(op.getAttribute(QStringLiteral("i_NBDEC")));
if (nbDec == 0) {
nbDec = 2;
}
QString symbol = unit.getSymbol();
if (symbol.contains(QStringLiteral(" "))) {
symbol = '"' + symbol + '"';
}
-#if QT_VERSION < 0x050700
- QString qs = en.formatMoney(SKGServices::stringToDouble(op.getAttribute(QStringLiteral("f_QUANTITY"))), QStringLiteral(" "), nbDec).trimmed();
-#else
QString qs = en.toCurrencyString(SKGServices::stringToDouble(op.getAttribute(QStringLiteral("f_QUANTITY"))), QStringLiteral(" "), nbDec);
-#endif
if (isCurrency) {
qs = symbol + qs;
} else {
qs = qs + ' ' + symbol;
}
stream << SKGServices::dateToSqlString(op.getDate()).replace('-', '/')
<< (status == SKGOperationObject::CHECKED ? " *" : status == SKGOperationObject::POINTED ? " !" : "")
<< (!number.isEmpty() ? QStringLiteral(" (") % number % ")" : QString())
<< QStringLiteral(" ") << payeeString
<< endl;
stream << " ; Skrooge ID: " << op.getID() << endl;
stream << " ; Import ID: " << op.getImportID() << endl;
auto properties = op.getProperties();
for (const auto& p : qAsConst(properties)) {
stream << " ; " << p << ": " << op.getProperty(p) << endl;
}
stream << " " << i18nc("The default category for the accounts for ledger export", "Account") << ':' << op.getAttribute(QStringLiteral("t_ACCOUNT"))
<< " " << qs
<< endl;
SKGObjectBase::SKGListSKGObjectBase suboperations;
IFOKDO(err, op.getSubOperations(suboperations))
int nbsuboperations = suboperations.count();
for (int j = 0; !err && j < nbsuboperations; ++j) {
SKGSubOperationObject sop(suboperations.at(j));
SKGCategoryObject cat;
sop.getCategory(cat);
auto catString = cat.getFullName().replace(OBJECTSEPARATOR, QLatin1String(":"));
if (catString.isEmpty()) {
catString = i18nc("Category not defined", "Not defined");
}
-#if QT_VERSION < 0x050700
- QString qs = en.formatMoney(-sop.getQuantity(), QStringLiteral(" "), nbDec).trimmed();
-#else
QString qs = en.toCurrencyString(-sop.getQuantity(), QStringLiteral(" "), nbDec);
-#endif
if (isCurrency) {
qs = unit.getSymbol() + qs;
} else {
qs = qs + ' ' + unit.getSymbol();
}
stream << " " << i18nc("The default category for the categories for ledger export", "Category") << ':' << catString
<< " " << qs;
if (sop.getDate() != op.getDate()) {
stream << " ; [=" << SKGServices::dateToSqlString(sop.getDate()).replace('-', '/') << "]";
}
auto comment = sop.getComment();
if (!comment.isEmpty()) {
stream << " ;comment=" << comment;
}
stream << " ; Skrooge ID: " << sop.getID();
stream << endl;
}
stream << endl;
IFOKDO(err, m_importer->getDocument()->stepForward(i + 1))
}
SKGENDTRANSACTION(m_importer->getDocument(), err);
}
}
IFOKDO(err, m_importer->getDocument()->stepForward(2))
SKGENDTRANSACTION(m_importer->getDocument(), err);
// Close file
file.commit();
}
return err;
}
QString SKGImportPluginLedger::getMimeTypeFilter() const
{
return "*.ledger|" % i18nc("A file format", "Ledger file");
}
#include
diff --git a/skgbasemodeler/skgdefine.h b/skgbasemodeler/skgdefine.h
index 9d5419a93..ce4d87ff4 100644
--- a/skgbasemodeler/skgdefine.h
+++ b/skgbasemodeler/skgdefine.h
@@ -1,273 +1,263 @@
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
#ifndef SKGDEFINE_H
#define SKGDEFINE_H
/** @file
* This file defines some macros.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include
#include
#include
#include "skgbasemodeler_export.h"
-template struct QAddConst {
- typedef const T Type;
-};
-
-#if QT_VERSION < 0x050700
-// this adds const to non-const objects (like std::as_const)
-template
-Q_DECL_CONSTEXPR typename QAddConst::Type& qAsConst(T& t) Q_DECL_NOTHROW { return t; }
-#endif
-
/**
* @var OBJECTSEPARATOR
* Define the separator between object and subobject
*/
#define OBJECTSEPARATOR QStringLiteral(" > ")
/**
* @var DUMPSQLITE
* To display SQLLITE internals (tables, views, indexes, ...)
* @see dump
*/
#define DUMPSQLITE (2 << 0)
/**
* @var DUMPPARAMETERS
* To display parameters
* @see dump
*/
#define DUMPPARAMETERS (2 << 1)
/**
* @var DUMPTRANSACTIONS
* To display transactions
* @see dump
*/
#define DUMPTRANSACTIONS (2 << 2)
/**
* @var DUMPNODES
* To display nodes
* @see dump
*/
#define DUMPNODES (2 << 3)
/**
* @var DUMPALL
* To display display all=@p DUMPSQLITE +@p DUMPPARAMETERS +@p DUMPTRANSACTIONS
* @see dump
*/
#define DUMPALL ((2 << 10) - 1)
/**
* @var SKG_UNDO_MAX_DEPTH
* Default value for the max depth for the undo / redo mechanism
*/
#define SKG_UNDO_MAX_DEPTH 50
/**
* @var ERR_NOTIMPL
* Error number
*/
#define ERR_NOTIMPL 1
/**
* @var ERR_NOINTERFACE
* Error number
*/
#define ERR_NOINTERFACE 2
/**
* @var ERR_POINTER
* Error number
*/
#define ERR_POINTER 3
/**
* @var ERR_ABORT
* Error number
*/
#define ERR_ABORT 4
/**
* @var ERR_FAIL
* Error number
*/
#define ERR_FAIL 5
/**
* @var ERR_HANDLE
* Error number
*/
#define ERR_HANDLE 6
/**
* @var ERR_OUTOFMEMORY
* Error number
*/
#define ERR_OUTOFMEMORY 7
/**
* @var ERR_INVALIDARG
* Error number
*/
#define ERR_INVALIDARG 8
/**
* @var ERR_UNEXPECTED
* Error number
*/
#define ERR_UNEXPECTED 9
/**
* @var ERR_WRITEACCESS
* Error number
*/
#define ERR_WRITEACCESS 10
/**
* @var ERR_FORCEABLE
* Error number
*/
#define ERR_FORCEABLE 11
/**
* @var ERR_ENCRYPTION
* Error number
*/
#define ERR_ENCRYPTION 12
/**
* @var ERR_INSTALL
* Error number
*/
#define ERR_INSTALL 13
/**
* @var ERR_CORRUPTION
* Error number
*/
#define ERR_CORRUPTION 14
/**
* @var ERR_READACCESS
* Error number
*/
#define ERR_READACCESS 15
/**
* @brief For a not modified field
**/
#define NOUPDATE QStringLiteral("-------")
/**
* @var EPSILON
* Epsilon (for comparison)
*/
#define EPSILON 0.00001
/**
* @def DELETECASCADE
* Define a standard trigger for cascaded delete
*/
#define DELETECASCADE(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
(QStringList() << QString()%"DROP TRIGGER IF EXISTS fkdc_"%(TABLEPARENT)%"_"%(TABLECHILD)%"_"%(ATTPARENT)%"_"%(ATTCHILD) \
<< QString()%"CREATE TRIGGER fkdc_"%(TABLEPARENT)%"_"%(TABLECHILD)%"_"%(ATTPARENT)%"_"%(ATTCHILD)%" "\
"BEFORE DELETE ON "%(TABLEPARENT)%" "\
"FOR EACH ROW BEGIN "\
" DELETE FROM "%(TABLECHILD)%" WHERE "%(TABLECHILD)%"."%(ATTCHILD)%" = OLD."%(ATTPARENT)%"; "\
"END")
/**
* @def INSERTUPDATECONSTRAINT
* Define a standard trigger for foreign constraint
*/
// Should these strings be translated ??? They look far too SQLish for that purpose
#define INSERTUPDATECONSTRAINT(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
(QStringList() << QString()%"DROP TRIGGER IF EXISTS fki_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT) \
<< QString()%"CREATE TRIGGER fki_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)%" "\
"BEFORE INSERT ON "%(TABLECHILD)%" "\
"FOR EACH ROW BEGIN "\
" SELECT RAISE(ABORT, '"%SKGServices::stringToSqlString(i18nc("Error message", "Impossible to insert object (%1 is used by %2).\nConstraint name: %3",TABLEPARENT, TABLECHILD, "fki_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)))%"') "\
" WHERE NEW."%(ATTCHILD)%"!=0 AND NEW."%(ATTCHILD)%"!='' AND (SELECT "%(ATTPARENT)%" FROM "%(TABLEPARENT)%" WHERE "%(ATTPARENT)%" = NEW."%(ATTCHILD)%") IS NULL; "\
"END"\
<< QString()%"DROP TRIGGER IF EXISTS fku_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT) \
<< QString()%"CREATE TRIGGER fku_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)%" "\
"BEFORE UPDATE ON "%(TABLECHILD)%" "\
"FOR EACH ROW BEGIN "\
" SELECT RAISE(ABORT, '"%SKGServices::stringToSqlString(i18nc("Error message", "Impossible to update object (%1 is used by %2).\nConstraint name: %3",TABLEPARENT, TABLECHILD, "fku_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)))%"') "\
" WHERE NEW."%(ATTCHILD)%"!=0 AND NEW."%(ATTCHILD)%"!='' AND (SELECT "%(ATTPARENT)%" FROM "%(TABLEPARENT)%" WHERE "%(ATTPARENT)%" = NEW."%(ATTCHILD)%") IS NULL; "\
"END")
/**
* @def FOREIGNCONSTRAINT
* Define a standard trigger for foreign constraint
*/
#define FOREIGNCONSTRAINT(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
(INSERTUPDATECONSTRAINT(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
<< QString()%"DROP TRIGGER IF EXISTS fkd_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT) \
<< QString()%"CREATE TRIGGER fkd_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)%" "\
"BEFORE DELETE ON "%(TABLEPARENT)%" "\
"FOR EACH ROW BEGIN "\
" SELECT RAISE(ABORT, '"%SKGServices::stringToSqlString(i18nc("Error message", "Impossible to delete used object (%1 is used by %2).\nConstraint name: %3",TABLEPARENT, TABLECHILD, "fkd_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)))%"') "\
" WHERE (SELECT "%(ATTCHILD)%" FROM "%(TABLECHILD)%" WHERE "%(ATTCHILD)%" = OLD."%(ATTPARENT)%") IS NOT NULL; "\
"END")
/**
* @def FOREIGNCONSTRAINTUPDATE
* Define a standard trigger for foreign constraint
*/
#define FOREIGNCONSTRAINTUPDATE(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
(INSERTUPDATECONSTRAINT(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
<< QString()%"DROP TRIGGER IF EXISTS fkd_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT) \
<< QString()%"CREATE TRIGGER fkd_"%(TABLECHILD)%"_"%(TABLEPARENT)%"_"%(ATTCHILD)%"_"%(ATTPARENT)%" "\
"BEFORE DELETE ON "%(TABLEPARENT)%" "\
"FOR EACH ROW BEGIN "\
" UPDATE "%(TABLECHILD)%" SET "%(ATTCHILD)%"=0 WHERE "%(ATTCHILD)%"=OLD."%(ATTPARENT)%"; "\
"END")
/**
* @def FOREIGNCONSTRAINTCASCADE
* Define a standard trigger for foreign constraint cascade delete
*/
#define FOREIGNCONSTRAINTCASCADE(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
INSERTUPDATECONSTRAINT(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)\
<< DELETECASCADE(TABLEPARENT,ATTPARENT,TABLECHILD,ATTCHILD)
/**
* @def DELETECASCADEPARAMETER
* Define a cascaded delete to delete parameters associated with an object
*/
#define DELETECASCADEPARAMETER(TABLE) \
(QStringList() << QString()%"DROP TRIGGER IF EXISTS fkdc_"%(TABLE)%"_parameters_uuid" \
<< QString()%"CREATE TRIGGER fkdc_"%(TABLE)%"_parameters_uuid "\
"BEFORE DELETE ON "%(TABLE)%" "\
"FOR EACH ROW BEGIN "\
" DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'"%(TABLE)%"'; "\
"END")
#endif
diff --git a/skgbasemodeler/skgservices.cpp b/skgbasemodeler/skgservices.cpp
index dd1fbd8ae..fbd2f3c42 100644
--- a/skgbasemodeler/skgservices.cpp
+++ b/skgbasemodeler/skgservices.cpp
@@ -1,2024 +1,2015 @@
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
/** @file
* This file implements classes SKGServices.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include "skgservices.h"
#include
#include
#include
#include
-#if QT_VERSION < 0x050700
-#include
-#endif
#ifndef Q_OS_WIN
#include
#endif
-#if QT_VERSION >= 0x050700
#include
-#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "skgtraces.h"
#include "skgdocument.h"
#define SQLCIPHERHEARDER "SQLCipher format"
int SKGServices::SKGSqlTraces = (SKGServices::getEnvVariable(QStringLiteral("SKGTRACESQL")).isEmpty() ? -1 : SKGServices::stringToInt(SKGServices::getEnvVariable(QStringLiteral("SKGTRACESQL"))));
SKGError SKGServices::m_lastCallbackError;
QString SKGServices::searchCriteriasToWhereClause(const SKGServices::SKGSearchCriteriaList& iSearchCriterias, const QStringList& iAttributes, const SKGDocument* iDocument, bool iForDisplay)
{
QString whereclause;
int nbCriterias = iSearchCriterias.count();
int nbAttributes = iAttributes.count();
for (int i = 0; i < nbCriterias; ++i) {
SKGSearchCriteria criteria = iSearchCriterias.at(i);
QString subWhereClause;
int nbWords = criteria.words.count();
for (int w = 0; w < nbWords; ++w) {
QString subWhereClause2;
QString word = criteria.words[w].toLower();
QString att;
QString op(':');
bool modeStartWith = true;
// Check if the word follows the format attribute:value
int pos = word.indexOf(QStringLiteral(":"));
int pos2 = word.indexOf(QStringLiteral("<="));
int pos3 = word.indexOf(QStringLiteral(">="));
int pos4 = word.indexOf(QStringLiteral("="));
int pos5 = word.indexOf(QStringLiteral("<"));
int pos6 = word.indexOf(QStringLiteral(">"));
int pos7 = word.indexOf(QStringLiteral("#"));
int opLength = 1;
if (pos2 != -1 && (pos2 < pos || pos == -1)) {
pos = pos2;
opLength = 2;
}
if (pos3 != -1 && (pos3 < pos || pos == -1)) {
pos = pos3;
opLength = 2;
}
if (pos4 != -1 && (pos4 < pos || pos == -1)) {
pos = pos4;
}
if (pos5 != -1 && (pos5 < pos || pos == -1)) {
pos = pos5;
}
if (pos6 != -1 && (pos6 < pos || pos == -1)) {
pos = pos6;
}
if (pos7 != -1 && (pos7 < pos || pos == -1)) {
pos = pos7;
}
if (pos != -1) {
att = word.left(pos);
if (att.endsWith(QStringLiteral("."))) {
modeStartWith = false;
att = att.left(att.count() - 1);
}
op = word.mid(pos, opLength);
word = word.right(word.count() - pos - op.count());
}
word = SKGServices::stringToSqlString(word);
for (int j = 0; j < nbAttributes; ++j) {
QString attDatabase = iAttributes.at(j);
QString attForComparison = (iDocument ? iDocument->getDisplay(attDatabase) : attDatabase).toLower();
if (att.isEmpty() ||
(modeStartWith && attForComparison.startsWith(att)) ||
(!modeStartWith && attForComparison.compare(att, Qt::CaseInsensitive) == 0)) {
if (iForDisplay) {
QString n = attForComparison + op + word;
if (subWhereClause2.isEmpty()) {
subWhereClause2 = n;
} else {
subWhereClause2 = i18nc("Logical condition", "%1 or %2", subWhereClause2, n);
}
} else {
if (!subWhereClause2.isEmpty()) {
subWhereClause2 = subWhereClause2 % " OR ";
}
if (attDatabase.startsWith(QLatin1String("p_"))) {
// Case property
QString propName = attDatabase.right(attDatabase.length() - 2);
if (op == QStringLiteral(":")) {
subWhereClause2 = subWhereClause2 % "i_PROPPNAME='" % SKGServices::stringToSqlString(propName) % "' AND (lower(i_PROPVALUE) LIKE '%" % word % "%')";
} else if (op == QStringLiteral("#")) {
subWhereClause2 = subWhereClause2 % "i_PROPPNAME='" % SKGServices::stringToSqlString(propName) % "' AND REGEXP('" % word % "',i_PROPVALUE)";
} else {
attDatabase = "i_PROPPNAME='" % SKGServices::stringToSqlString(propName) % "' AND i_PROPVALUE";
subWhereClause2 = subWhereClause2 % attDatabase % op % word;
}
} else {
// Case normal attribute
if (op == QStringLiteral(":")) {
subWhereClause2 = subWhereClause2 % "lower(" % attDatabase % ") LIKE '%" % word % "%'";
} else if (op == QStringLiteral("#")) {
subWhereClause2 = subWhereClause2 % "REGEXP('" % word % "'," % attDatabase % ")";
} else {
if (attDatabase.startsWith(QLatin1String("f_")) || attDatabase.startsWith(QLatin1String("i_"))) {
subWhereClause2 = subWhereClause2 % attDatabase % op % word;
} else {
subWhereClause2 = subWhereClause2 % "lower(" % attDatabase % ")" % op % "'" % word % "'";
}
}
}
}
}
}
if (iForDisplay) {
if (!subWhereClause2.isEmpty()) {
if (subWhereClause.isEmpty()) {
subWhereClause = subWhereClause2;
} else {
subWhereClause = i18nc("Logical condition", "(%1) and (%2)", subWhereClause, subWhereClause2);
}
}
} else {
if (!subWhereClause2.isEmpty()) {
if (!subWhereClause.isEmpty()) {
subWhereClause = subWhereClause % " AND ";
}
subWhereClause = subWhereClause % "(" % subWhereClause2 % ")";
} else {
subWhereClause = QStringLiteral("1=0");
}
}
}
if (iForDisplay) {
if (!subWhereClause.isEmpty()) {
if (criteria.mode == '+') {
if (whereclause.isEmpty()) {
whereclause = subWhereClause;
} else {
whereclause = i18nc("Logical condition", "(%1) and (%2)", whereclause, subWhereClause);
}
} else if (criteria.mode == '-') {
if (subWhereClause.isEmpty()) {
whereclause = i18nc("Logical condition", "not (%1)", subWhereClause);
} else {
whereclause = i18nc("Logical condition", "(%1) and not (%2)", whereclause, subWhereClause);
}
}
}
} else {
if (!subWhereClause.isEmpty()) {
if (criteria.mode == '+') {
if (!whereclause.isEmpty()) {
whereclause = whereclause % " OR ";
}
whereclause = whereclause % "(" % subWhereClause % ")";
} else if (criteria.mode == '-') {
if (!whereclause.isEmpty()) {
whereclause = whereclause % " AND NOT";
} else {
whereclause = QStringLiteral("NOT");
}
whereclause = whereclause % "(" % subWhereClause % ")";
}
}
}
}
return whereclause;
}
SKGServices::SKGSearchCriteriaList SKGServices::stringToSearchCriterias(const QString& iString)
{
SKGServices::SKGSearchCriteriaList output;
QStringList words = SKGServices::splitCSVLine(iString, ' ', true);
int nbwords = words.count();
output.reserve(nbwords);
SKGServices::SKGSearchCriteria criteria;
criteria.mode = '+';
bool atLeastOnePlus = false;
for (int i = 0; i < nbwords; ++i) {
QString word = words.at(i);
bool isWordStartingByPlus = word.startsWith(QLatin1String("+"));
bool isWordStartingByLess = word.startsWith(QLatin1String("-"));
if (isWordStartingByPlus || isWordStartingByLess) {
QChar nextChar;
if (word.count() > 1) {
nextChar = word[1];
}
if (nextChar < '0' || nextChar > '9') {
word = word.right(word.length() - 1);
if (Q_LIKELY(i != 0)) {
if (criteria.mode == '-') {
output.push_back(criteria);
} else {
output.push_front(criteria);
atLeastOnePlus = true;
}
}
criteria.words.clear();
criteria.mode = (isWordStartingByPlus ? '+' : '-');
}
}
criteria.words.push_back(word);
}
if (criteria.mode == '-') {
output.push_back(criteria);
} else {
output.push_front(criteria);
atLeastOnePlus = true;
}
if (!atLeastOnePlus) {
// Add a '+' always true
SKGServices::SKGSearchCriteria criteria2;
criteria2.mode = '+';
criteria2.words.push_back(QLatin1String(""));
output.push_front(criteria2);
}
return output;
}
QString SKGServices::getEnvVariable(const QString& iAttribute)
{
return QString::fromUtf8(qgetenv(iAttribute.toUtf8().constData()));
}
QString SKGServices::intToString(qlonglong iNumber)
{
QString output;
output.setNum(iNumber);
return output;
}
qlonglong SKGServices::stringToInt(const QString& iNumber)
{
if (Q_UNLIKELY(iNumber.isEmpty())) {
return 0;
}
bool ok;
qlonglong output = iNumber.toLongLong(&ok);
if (Q_LIKELY(!ok)) {
SKGTRACE << "WARNING: SKGServices::stringToInt(" << iNumber << ") failed" << endl;
}
return output;
}
QString SKGServices::stringToSqlString(const QString& iString)
{
QString output = iString;
output.replace('\'', QStringLiteral("''"));
return output;
}
QString SKGServices::stringToHtml(const QString& iString)
{
QString output = iString;
output.replace('&', QStringLiteral("&")); // Must be done first
output.replace('<', QStringLiteral("<"));
output.replace('>', QStringLiteral(">"));
output.replace('"', QStringLiteral("""));
return output;
}
QString SKGServices::htmlToString(const QString& iString)
{
QString output = iString;
output.replace(QStringLiteral("<"), QStringLiteral("<"));
output.replace(QStringLiteral(">"), QStringLiteral(">"));
output.replace(QStringLiteral("""), QStringLiteral("\""));
output.replace(QStringLiteral("&"), QStringLiteral("&"));
return output;
}
QString SKGServices::stringsToCsv(const QStringList& iList, const QChar iSeparator)
{
QString output;
int nb = iList.count();
for (int i = 0; i < nb; ++i) {
output.append(SKGServices::stringToCsv(iList.at(i)));
if (Q_LIKELY(i < nb - 1)) {
output.append(iSeparator);
}
}
return output;
}
QString SKGServices::stringToCsv(const QString& iNumber)
{
QString output = iNumber;
output.replace('"', QStringLiteral("#SKGDOUBLECOTE#"));
output.replace(QStringLiteral("#SKGDOUBLECOTE#"), QStringLiteral("\"\""));
output = '"' % output % '"';
return output;
}
double SKGServices::stringToDouble(const QString& iNumber)
{
if (Q_UNLIKELY(iNumber.isEmpty() || iNumber == QStringLiteral("nan"))) {
return 0;
} else if (Q_UNLIKELY(iNumber == QStringLiteral("inf"))) {
return 1e300;
} else if (Q_UNLIKELY(iNumber == QStringLiteral("-inf"))) {
return -1e300;
}
QString number = iNumber;
number.remove(QRegExp(QStringLiteral("[^0-9-+/eE,.]")));
if (number.contains(QStringLiteral("/"))) {
// Use script engine
QScriptEngine myEngine;
QScriptValue result = myEngine.evaluate(number);
if (result.isNumber()) {
return result.toNumber();
}
}
bool ok;
double output = number.toDouble(&ok);
if (Q_LIKELY(!ok)) {
QString tmp = number;
tmp.replace(',', '.');
if (tmp.count('.') > 1) {
tmp.remove(tmp.indexOf('.'), 1);
}
output = tmp.toDouble(&ok);
if (Q_LIKELY(!ok)) {
QString tmp2 = number;
tmp2.replace('.', ',');
if (tmp2.count(',') > 1) {
tmp2.remove(tmp2.indexOf(','), 1);
}
output = tmp2.toDouble(&ok);
if (!ok) {
QString tmp3 = number;
tmp3.remove(',');
output = tmp3.toDouble(&ok);
}
}
}
if (Q_LIKELY(!ok)) {
SKGTRACE << "WARNING: SKGServices::stringToDouble(" << iNumber << ") failed" << endl;
}
return output;
}
QString SKGServices::doubleToString(double iNumber)
{
QString output;
output.setNum(iNumber, 'g', 10);
return output;
}
QString SKGServices::getNextString(const QString& iString)
{
QString output = iString;
bool ok;
qlonglong val = output.toLongLong(&ok);
if (Q_LIKELY(ok)) {
// This is a int
output = SKGServices::intToString(val + 1);
} else {
// This is a string
output = QLatin1String("");
}
return output;
}
QString SKGServices::dateToPeriod(const QDate iDate, const QString& iPeriod)
{
QString period;
if (iPeriod == QStringLiteral("D")) {
// Day
period = iDate.toString(QStringLiteral("yyyy-MM-dd"));
} else if (iPeriod == QStringLiteral("W")) {
// Week
period = iDate.toString(QStringLiteral("yyyy-W")) % SKGServices::intToString(iDate.weekNumber()).rightJustified(2, '0');
} else if (iPeriod == QStringLiteral("M")) {
// Month
period = iDate.toString(QStringLiteral("yyyy-MM"));
} else if (iPeriod == QStringLiteral("Q")) {
// Quarter
period = iDate.toString(QStringLiteral("yyyy-Q")) % (iDate.month() <= 3 ? '1' : (iDate.month() <= 6 ? '2' : (iDate.month() <= 9 ? '3' : '4')));
} else if (iPeriod == QStringLiteral("S")) {
// Semester
period = iDate.toString(QStringLiteral("yyyy-S")) % (iDate.month() <= 6 ? '1' : '2');;
} else if (iPeriod == QStringLiteral("Y")) {
// Year
period = iDate.toString(QStringLiteral("yyyy"));
}
return period;
}
QString SKGServices::timeToString(const QDateTime& iDateTime)
{
QDateTime d = iDateTime;
if (Q_UNLIKELY(!d.isValid())) {
d = QDateTime::currentDateTime();
}
return d.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss"));
}
QString SKGServices::dateToSqlString(const QDate iDate)
{
return dateToSqlString(QDateTime(iDate));
}
QString SKGServices::dateToSqlString(const QDateTime& iDateTime)
{
QDateTime d = iDateTime;
if (Q_UNLIKELY(!d.isValid())) {
d = QDateTime::currentDateTime();
}
return d.toString(QStringLiteral("yyyy-MM-dd"));
}
int SKGServices::nbWorkingDays(const QDate iFrom, const QDate iTo)
{
int nb = 0;
QDate min = (iFrom < iTo ? iFrom : iTo);
QDate max = (iFrom < iTo ? iTo : iFrom);
while (min != max) {
if (min.dayOfWeek() <= 5) {
++nb;
}
min = min.addDays(1);
}
if (nb == 0) {
nb = 1;
}
return nb;
}
QDateTime SKGServices::stringToTime(const QString& iDateString)
{
QDateTime output = QDateTime::fromString(iDateString, QStringLiteral("yyyy-MM-dd HH:mm:ss"));
if (Q_UNLIKELY(!output.isValid())) {
output = QDateTime::fromString(iDateString, QStringLiteral("yyyy-MM-dd"));
}
return output;
}
QDate SKGServices::partialStringToDate(const QString& iDateString, bool iFixupBackward)
{
QDate result;
QStringList items = iDateString.split('/');
int size = items.count();
bool ok = false;
if (size == 1) {
int dayCount = items.at(0).toInt(&ok);
result = QDate::currentDate();
result = result.addDays(dayCount - result.day());
if (iFixupBackward) {
if (result > QDate::currentDate()) {
result = result.addMonths(-1);
}
} else {
if (result < QDate::currentDate()) {
result = result.addMonths(1);
}
}
} else if (size == 2) {
int dayCount = items.at(0).toInt(&ok);
int monthCount = items.at(1).toInt(&ok);
result = QDate::currentDate();
result = result.addDays(dayCount - result.day());
result = result.addMonths(monthCount - result.month());
if (iFixupBackward) {
if (result > QDate::currentDate()) {
result = result.addYears(-1);
}
} else {
if (result < QDate::currentDate()) {
result = result.addYears(1);
}
}
} else if (size == 3) {
int dayCount = items.at(0).toInt(&ok);
int monthCount = items.at(1).toInt(&ok);
int yearCount = items.at(2).toInt(&ok);
int lengthYear = items.at(2).count();
result = QDate::currentDate();
result = result.addDays(dayCount - result.day());
result = result.addMonths(monthCount - result.month());
if (lengthYear < 4) {
int y = static_cast(result.year() / qPow(10, lengthYear)) * qPow(10, lengthYear) + yearCount;
if (y > result.year() && iFixupBackward) {
y = y - qPow(10, lengthYear);
} else if (y < result.year() && !iFixupBackward) {
y = y + qPow(10, lengthYear);
}
result = result.addYears(y - result.year());
} else {
result = result.addYears(yearCount - result.year());
}
}
if (!ok) {
result = QDate();
}
return result;
}
QStringList SKGServices::splitCSVLine(const QString& iString, const QChar iSeparator, bool iCoteDefineBlock)
{
return splitCSVLine(iString, iSeparator, iCoteDefineBlock, nullptr);
}
QStringList SKGServices::splitCSVLine(const QString& iString, const QChar iSeparator, bool iCoteDefineBlock, QChar* oRealSeparator)
{
QStringList items;
QString item;
bool isInBlock = false;
QChar realSeparator = iSeparator;
QChar cote = ' '; // Not yet defined
int nb = iString.length();
items.reserve(nb);
for (int pos = 0; pos < nb; ++pos) {
QChar c = iString.at(pos);
if (isInBlock) {
if (c == cote) {
if (pos < nb - 1 && iString.at(pos + 1) == cote) {
++pos;
} else {
items.push_back(item);
item = QLatin1String("");
isInBlock = false;
// 320112 vvvv
// Reset the block character to autorize mix
cote = ' ';
// 320112 ^^^^
++pos; // To ignore next separator
if (pos < nb) {
realSeparator = iString.at(pos); // To get the real separator
}
}
}
if (isInBlock) {
item += c;
}
} else if ((c == '\"' || c == '\'') && item.isEmpty() && iCoteDefineBlock) {
if (cote == ' ') {
cote = c; // Set the real cote char
}
isInBlock = true;
} else if (QString(c) == realSeparator) {
items.push_back(item);
item = QLatin1String("");
isInBlock = false;
// 320112 vvvv
// Reset the block character to autorize mix
cote = ' ';
// 320112 ^^^^
} else {
item += c;
}
}
if (!item.isEmpty() || (nb > 0 && iString.at(nb - 1) == realSeparator)) {
items.push_back(item);
}
if (oRealSeparator) {
*oRealSeparator = realSeparator;
}
if (isInBlock) {
items.clear();
}
return items;
}
QString SKGServices::getDateFormat(const QStringList& iDates)
{
SKGTRACEINFUNC(2);
bool f_YYYY_MM_DD = true;
bool f_YYYYMMDD = true;
bool f_DDMMYYYY = true;
bool f_MMDDYYYY = true;
bool f_MM_DD_YY = true;
bool f_DD_MM_YY = true;
bool f_MM_DD_YYYY = true;
bool f_DD_MM_YYYY = true;
bool f_DDMMMYYYY = true;
bool f_DD_MMM_YY = true;
bool f_DD_MMM_YYYY = true;
// Build regexp
QRegExp rx(QStringLiteral("(.+)-(.+)-(.+)"));
// Check all dates
int nb = iDates.count();
for (int i = 0; i < nb; ++i) {
QString val = iDates.at(i).trimmed();
if (val.count() > 10) {
auto l = SKGServices::splitCSVLine(val, ' ');
val = l[0];
}
if (!val.isEmpty()) {
val = val.replace(' ', '0');
val = val.replace('\\', '-');
val = val.replace('/', '-');
val = val.replace('.', '-');
val = val.replace(QStringLiteral("'20"), QStringLiteral("-20"));
val = val.replace(QStringLiteral("' "), QStringLiteral("-200"));
val = val.replace('\'', QStringLiteral("-20"));
val = val.replace(QStringLiteral("-90"), QStringLiteral("-1990"));
val = val.replace(QStringLiteral("-91"), QStringLiteral("-1991"));
val = val.replace(QStringLiteral("-92"), QStringLiteral("-1992"));
val = val.replace(QStringLiteral("-93"), QStringLiteral("-1993"));
val = val.replace(QStringLiteral("-94"), QStringLiteral("-1994"));
val = val.replace(QStringLiteral("-95"), QStringLiteral("-1995"));
val = val.replace(QStringLiteral("-96"), QStringLiteral("-1996"));
val = val.replace(QStringLiteral("-97"), QStringLiteral("-1997"));
val = val.replace(QStringLiteral("-98"), QStringLiteral("-1998"));
val = val.replace(QStringLiteral("-99"), QStringLiteral("-1999"));
if (rx.indexIn(val) == -1) {
f_YYYY_MM_DD = false;
f_MM_DD_YY = false;
f_DD_MM_YY = false;
f_MM_DD_YYYY = false;
f_DD_MM_YYYY = false;
f_DD_MMM_YY = false;
f_DD_MMM_YYYY = false;
if (val.length() == 8) {
int left2 = SKGServices::stringToInt(val.left(2));
if (left2 > 12) {
f_MMDDYYYY = false;
}
if (left2 > 31) {
f_DDMMYYYY = false;
}
int mid2 = SKGServices::stringToInt(val.mid(2, 2));
if (mid2 > 12) {
f_DDMMYYYY = false;
}
if (mid2 > 31) {
f_MMDDYYYY = false;
}
int mid4 = SKGServices::stringToInt(val.mid(4, 2));
if (mid4 > 12) {
f_YYYYMMDD = false;
}
int right2 = SKGServices::stringToInt(val.right(2));
if (right2 > 31) {
f_YYYYMMDD = false;
}
f_DDMMMYYYY = false;
} else if (val.length() == 9) {
f_MMDDYYYY = false;
f_DDMMYYYY = false;
f_YYYYMMDD = false;
} else {
f_MMDDYYYY = false;
f_DDMMYYYY = false;
f_YYYYMMDD = false;
f_DDMMMYYYY = false;
}
} else {
f_YYYYMMDD = false;
f_DDMMYYYY = false;
f_MMDDYYYY = false;
f_DDMMMYYYY = false;
QString v1 = rx.cap(1);
QString v2 = rx.cap(2);
QString v3 = rx.cap(3);
if (SKGServices::stringToInt(v1) > 12) {
f_MM_DD_YY = false;
f_MM_DD_YYYY = false;
}
if (SKGServices::stringToInt(v2) > 12) {
f_DD_MM_YY = false;
f_DD_MM_YYYY = false;
}
if (v2.length() > 2) {
f_MM_DD_YY = false;
f_MM_DD_YYYY = false;
f_DD_MM_YY = false;
f_DD_MM_YYYY = false;
f_YYYY_MM_DD = false;
}
if (v2.length() != 3) {
f_DD_MMM_YYYY = false;
f_DD_MMM_YY = false;
}
if (SKGServices::stringToInt(v1) > 31 || SKGServices::stringToInt(v2) > 31) {
f_MM_DD_YY = false;
f_MM_DD_YYYY = false;
f_DD_MM_YY = false;
f_DD_MM_YYYY = false;
}
if (SKGServices::stringToInt(v3) > 31) {
f_YYYY_MM_DD = false;
}
if (v1.length() == 4) {
f_MM_DD_YY = false;
f_DD_MM_YY = false;
f_MM_DD_YYYY = false;
f_DD_MM_YYYY = false;
} else {
// To be more permissive and support mix of date: f_YYYY_MM_DD = false;
}
if (v3.length() == 4) {
f_YYYY_MM_DD = false;
f_MM_DD_YY = false;
f_DD_MM_YY = false;
} else {
// To be more permissive and support mix of date: f_MM_DD_YYYY = false;
// To be more permissive and support mix of date: f_DD_MM_YYYY = false;
}
}
}
}
if (f_YYYYMMDD) {
return QStringLiteral("YYYYMMDD");
} else if (f_MMDDYYYY) {
return QStringLiteral("MMDDYYYY");
} else if (f_DDMMYYYY) {
return QStringLiteral("DDMMYYYY");
} else if (f_DD_MM_YY && f_MM_DD_YY) {
QString sFormat = QLocale().dateFormat(QLocale::ShortFormat);
if (sFormat.startsWith(QLatin1String("%m")) || sFormat.startsWith(QLatin1String("%n"))) {
return QStringLiteral("MM-DD-YY");
}
return QStringLiteral("DD-MM-YY");
} else if (f_MM_DD_YY) {
return QStringLiteral("MM-DD-YY");
} else if (f_DD_MM_YY) {
return QStringLiteral("DD-MM-YY");
} else if (f_DD_MM_YYYY && f_MM_DD_YYYY) {
QString sFormat = QLocale().dateFormat(QLocale::ShortFormat);
if (sFormat.startsWith(QLatin1String("%m")) || sFormat.startsWith(QLatin1String("%n"))) {
return QStringLiteral("MM-DD-YYYY");
}
return QStringLiteral("DD-MM-YYYY");
} else if (f_MM_DD_YYYY) {
return QStringLiteral("MM-DD-YYYY");
} else if (f_DD_MM_YYYY) {
return QStringLiteral("DD-MM-YYYY");
} else if (f_YYYY_MM_DD) {
return QStringLiteral("YYYY-MM-DD");
} else if (f_DDMMMYYYY) {
return QStringLiteral("DDMMMYYYY");
} else if (f_DD_MMM_YY) {
return QStringLiteral("DD-MMM-YY");
} else if (f_DD_MMM_YYYY) {
return QStringLiteral("DD-MMM-YYYY");
}
return QLatin1String("");
}
QString SKGServices::toPercentageString(double iAmount, int iNbDecimal)
{
return toCurrencyString(iAmount, QString(), iNbDecimal) % " %";
}
QString SKGServices::toCurrencyString(double iAmount, const QString& iSymbol, int iNbDecimal)
{
if (iSymbol == QStringLiteral("%")) {
return toPercentageString(iAmount, iNbDecimal);
}
-#if QT_VERSION < 0x050700
- return KLocale::global()->formatMoney(iAmount, iSymbol.isEmpty() ? QStringLiteral(" ") : iSymbol, iNbDecimal).trimmed();
-#else
return QLocale::system().toCurrencyString(iAmount, iSymbol.isEmpty() ? QStringLiteral(" ") : iSymbol, iNbDecimal).trimmed();
-#endif
}
QString SKGServices::dateToSqlString(const QString& iDate, const QString& iFormat)
{
QString input = iDate;
if (input.count() > 10) {
auto l = SKGServices::splitCSVLine(input, ' ');
input = l[0];
}
QString format = QStringLiteral("yyyy-MM-dd");
QString YYYY = QStringLiteral("0000");
QString MM = QStringLiteral("00");
QString DD = QStringLiteral("00");
if (iFormat == QStringLiteral("YYYYMMDD")) {
YYYY = input.mid(0, 4);
MM = input.mid(4, 2);
DD = input.mid(6, 2);
} else if (iFormat == QStringLiteral("DDMMYYYY") || iFormat == QStringLiteral("DDMMYY")) {
YYYY = input.mid(4, 4);
MM = input.mid(2, 2);
DD = input.mid(0, 2);
} else if (iFormat == QStringLiteral("DDMMMYYYY") || iFormat == QStringLiteral("DDMMMYY")) {
YYYY = input.mid(5, 4);
MM = input.mid(2, 3);
DD = input.mid(0, 2);
format = QStringLiteral("yyyy-MMM-dd");
} else if (iFormat == QStringLiteral("MMDDYYYY") || iFormat == QStringLiteral("MMDDYY")) {
YYYY = input.mid(4, 4);
MM = input.mid(0, 2);
DD = input.mid(2, 2);
} else {
QString val = input;
val = val.replace(' ', '0');
val = val.replace('\\', '-');
val = val.replace('/', '-');
val = val.replace('.', '-');
val = val.replace(QStringLiteral("'20"), QStringLiteral("-20"));
val = val.replace(QStringLiteral("' "), QStringLiteral("-200"));
val = val.replace('\'', QStringLiteral("-20"));
val = val.replace(QStringLiteral("-90"), QStringLiteral("-1990"));
val = val.replace(QStringLiteral("-91"), QStringLiteral("-1991"));
val = val.replace(QStringLiteral("-92"), QStringLiteral("-1992"));
val = val.replace(QStringLiteral("-93"), QStringLiteral("-1993"));
val = val.replace(QStringLiteral("-94"), QStringLiteral("-1994"));
val = val.replace(QStringLiteral("-95"), QStringLiteral("-1995"));
val = val.replace(QStringLiteral("-96"), QStringLiteral("-1996"));
val = val.replace(QStringLiteral("-97"), QStringLiteral("-1997"));
val = val.replace(QStringLiteral("-98"), QStringLiteral("-1998"));
val = val.replace(QStringLiteral("-99"), QStringLiteral("-1999"));
QRegExp rx(QStringLiteral("(.+)-(.+)-(.+)"));
if (rx.indexIn(val) != -1) {
QString v1 = rx.cap(1);
QString v2 = rx.cap(2);
QString v3 = rx.cap(3);
if (iFormat == QStringLiteral("YYYY-MM-DD")) {
YYYY = v1;
MM = v2;
DD = v3;
} else if (iFormat == QStringLiteral("MM/DD/YY") || iFormat == QStringLiteral("MM-DD-YY") || iFormat == QStringLiteral("MM/DD/YYYY") || iFormat == QStringLiteral("MM-DD-YYYY")) {
MM = v1;
DD = v2;
YYYY = v3;
} else if (iFormat == QStringLiteral("DD/MM/YY") || iFormat == QStringLiteral("DD-MM-YY") || iFormat == QStringLiteral("DD/MM/YYYY") || iFormat == QStringLiteral("DD-MM-YYYY")) {
DD = v1;
MM = v2;
YYYY = v3;
} else if (iFormat == QStringLiteral("DD/MMM/YY") || iFormat == QStringLiteral("DD-MMM-YY") || iFormat == QStringLiteral("DD/MMM/YYYY") || iFormat == QStringLiteral("DD-MMM-YYYY")) {
DD = v1;
MM = v2;
YYYY = v3;
format = QStringLiteral("yyyy-MMM-dd");
}
}
}
if (MM.length() == 1) {
MM = '0' % MM;
}
if (DD.length() == 1) {
DD = '0' % DD;
}
if (YYYY.length() == 1) {
YYYY = '0' % YYYY;
}
if (YYYY.length() == 2) {
if (stringToInt(YYYY) > 70) {
YYYY = "19" % YYYY;
} else {
YYYY = "20" % YYYY;
}
}
QString date = YYYY % '-' % MM % '-' % DD;
date.replace(' ', '0');
return dateToSqlString(QDateTime::fromString(date, format));
}
QString SKGServices::getPeriodWhereClause(const QString& iPeriod, const QString& iDateAttribute)
{
QString output = QStringLiteral("1=0");
if (iPeriod == QStringLiteral("ALL")) {
output = QStringLiteral("1=1");
} else if (iPeriod.length() == 4) {
// 2014
output = "STRFTIME('%Y'," + SKGServices::stringToSqlString(iDateAttribute) + ")='" + SKGServices::stringToSqlString(iPeriod) + '\'';
} else if (iPeriod.length() == 7 && iPeriod[4] == '-') {
if (iPeriod[5] == 'S') {
// 2014-S1
output = "STRFTIME('%Y'," + SKGServices::stringToSqlString(iDateAttribute) + ")||'-S'||(CASE WHEN STRFTIME('%m'," + SKGServices::stringToSqlString(iDateAttribute) + ")<='06' THEN '1' ELSE '2' END)='" + SKGServices::stringToSqlString(iPeriod) + '\'';
} else if (iPeriod[5] == 'Q') {
// 2014-Q1
output = "STRFTIME('%Y'," + SKGServices::stringToSqlString(iDateAttribute) + ")||'-Q'||(CASE WHEN STRFTIME('%m'," + SKGServices::stringToSqlString(iDateAttribute) + ")<='03' THEN '1' WHEN STRFTIME('%m'," + SKGServices::stringToSqlString(iDateAttribute) + ")<='06' THEN '2' WHEN STRFTIME('%m'," + SKGServices::stringToSqlString(iDateAttribute) + ")<='09' THEN '3' ELSE '4' END)='" + SKGServices::stringToSqlString(iPeriod) + '\'';
} else {
// 2014-07
output = "STRFTIME('%Y-%m'," + SKGServices::stringToSqlString(iDateAttribute) + ")='" + SKGServices::stringToSqlString(iPeriod) + '\'';
}
}
return output;
}
QDate SKGServices::periodToDate(const QString& iPeriod)
{
QDate output;
if (iPeriod == QStringLiteral("ALL")) {
output = QDate::currentDate();
} else if (iPeriod.length() == 4) {
// 2014
output = QDate::fromString(iPeriod, QStringLiteral("yyyy")).addYears(1).addDays(-1);
} else if (iPeriod.length() == 7) {
if (iPeriod[5] == 'S') {
// 2014-S1
output = QDate::fromString(iPeriod, QStringLiteral("yyyy-SM"));
output = output.addMonths(output.month() * 6 - output.month()); // convert semester in month
output = output.addMonths(1).addDays(-1);
} else if (iPeriod[5] == 'Q') {
// 2014-Q1
output = QDate::fromString(iPeriod, QStringLiteral("yyyy-QM"));
output = output.addMonths(output.month() * 3 - output.month()); // convert quarter in month
output = output.addMonths(1).addDays(-1);
} else {
// 2014-07
output = QDate::fromString(iPeriod, QStringLiteral("yyyy-MM")).addMonths(1).addDays(-1);
}
}
return output;
}
QString SKGServices::getNeighboringPeriod(const QString& iPeriod, int iDelta)
{
QString output = QStringLiteral("1=0");
if (iPeriod.length() == 4) {
// 2014
QDate date = QDate::fromString(iPeriod, QStringLiteral("yyyy")).addYears(iDelta);
output = date.toString(QStringLiteral("yyyy"));
} else if (iPeriod.length() == 7) {
if (iPeriod[5] == 'S') {
// 2014-S1
QDate date2 = QDate::fromString(iPeriod, QStringLiteral("yyyy-SM"));
date2 = date2.addMonths(date2.month() * 6 - date2.month()); // convert semester in month
date2 = date2.addMonths(6 * iDelta);
output = date2.toString(QStringLiteral("yyyy-S")) % (date2.month() <= 6 ? '1' : '2');
} else if (iPeriod[5] == 'Q') {
// 2014-Q1
QDate date2 = QDate::fromString(iPeriod, QStringLiteral("yyyy-QM"));
date2 = date2.addMonths(date2.month() * 3 - date2.month()); // convert quarter in month
date2 = date2.addMonths(3 * iDelta);
output = date2.toString(QStringLiteral("yyyy-Q")) % (date2.month() <= 3 ? '1' : (date2.month() <= 6 ? '2' : (date2.month() <= 9 ? '3' : '4')));
} else {
// 2014-07
QDate date2 = QDate::fromString(iPeriod, QStringLiteral("yyyy-MM")).addMonths(iDelta);
output = date2.toString(QStringLiteral("yyyy-MM"));
}
}
return output;
}
QStringList SKGServices::tableToDump(const SKGStringListList& iTable, SKGServices::DumpMode iMode)
{
SKGTRACEINFUNC(10);
// initialisation
QStringList oResult;
// Compute max size of each column
int* maxSizes = nullptr;
int nbMaxSizes = 0;
if (iMode == DUMP_TEXT) {
int nb = iTable.count();
for (int i = 0; i < nb; ++i) {
QStringList line = iTable.at(i);
int nb2 = line.size();
if (maxSizes == nullptr) {
nbMaxSizes = nb2;
maxSizes = new int[nbMaxSizes];
for (int j = 0; j < nbMaxSizes; ++j) {
maxSizes[j] = 0;
}
}
for (int j = 0; j < nb2; ++j) {
QString s = line.at(j);
if (j < nbMaxSizes && s.length() > maxSizes[j]) {
maxSizes[j] = s.length();
}
}
}
}
// dump
int nb = iTable.count();
oResult.reserve(nb);
for (int i = 0; i < nb; ++i) {
QString lineFormated;
if (iMode == DUMP_TEXT) {
lineFormated = QStringLiteral("| ");
}
QStringList line = iTable.at(i);
int nb2 = line.size();
for (int j = 0; j < nb2; ++j) {
QString s = line.at(j);
s.remove('\n');
if (iMode == DUMP_CSV) {
if (j > 0) {
lineFormated += ';';
}
lineFormated += stringToCsv(s);
} else if (maxSizes) {
if (j < nbMaxSizes) {
s = s.leftJustified(maxSizes[j], ' ');
}
lineFormated += s % " | ";
}
}
oResult.push_back(lineFormated);
}
// delete
if (maxSizes) {
delete [] maxSizes;
maxSizes = nullptr;
}
return oResult;
}
QString SKGServices::getRealTable(const QString& iTable)
{
QString output = iTable;
if (output.length() > 2 && output.startsWith(QLatin1String("v_"))) {
output = output.mid(2, output.length() - 2);
int pos = output.indexOf(QStringLiteral("_"));
if (pos != -1) {
output = output.left(pos);
}
}
return output;
}
SKGError SKGServices::downloadToStream(const QUrl& iSourceUrl, QByteArray& oStream)
{
SKGError err;
SKGTRACEINFUNCRC(10, err);
QString tmpFile;
if (iSourceUrl.isLocalFile()) {
tmpFile = iSourceUrl.toLocalFile();
} else {
err = download(iSourceUrl, tmpFile);
}
IFOK(err) {
// Open file
QFile file(tmpFile);
if (Q_UNLIKELY(!file.open(QIODevice::ReadOnly))) {
err.setReturnCode(ERR_FAIL).setMessage(i18nc("An information message", "Open file '%1' failed", tmpFile));
} else {
oStream = file.readAll();
// close file
file.close();
}
if (!iSourceUrl.isLocalFile()) {
QFile(tmpFile).remove();
}
}
return err;
}
SKGError SKGServices::download(const QUrl& iSourceUrl, QString& oTemporaryFile)
{
SKGError err;
SKGTRACEINFUNCRC(10, err);
QTemporaryFile tmpFile;
tmpFile.setAutoRemove(false);
if (tmpFile.open()) {
err = upload(iSourceUrl, QUrl::fromLocalFile(tmpFile.fileName()));
IFOK(err) oTemporaryFile = tmpFile.fileName();
}
return err;
}
SKGError SKGServices::upload(const QUrl& iSourceUrl, const QUrl& iDescUrl)
{
SKGError err;
SKGTRACEINFUNCRC(10, err);
if (iDescUrl != iSourceUrl) {
if (iDescUrl.isLocalFile() && iSourceUrl.isLocalFile()) {
QFile(iDescUrl.toLocalFile()).remove();
if (!QFile::copy(iSourceUrl.toLocalFile(), iDescUrl.toLocalFile())) {
err = SKGError(ERR_ABORT, i18nc("Error message", "Impossible to copy '%1' to '%2'", iSourceUrl.toDisplayString(), iDescUrl.toDisplayString()));
}
} else {
KIO::FileCopyJob* getJob = KIO::file_copy(iSourceUrl, iDescUrl, -1, KIO::Overwrite | KIO::HideProgressInfo);
if (!getJob->exec()) {
err.setReturnCode(ERR_ABORT).setMessage(getJob->errorString());
err.addError(ERR_ABORT, i18nc("Error message", "Impossible to copy '%1' to '%2'", iSourceUrl.toDisplayString(), iDescUrl.toDisplayString()));
}
}
}
return err;
}
SKGError SKGServices::cryptFile(const QString& iFileSource, const QString& iFileTarget, const QString& iPassword, bool iEncrypt, const QString& iHeaderFile, bool& oModeSQLCipher)
{
SKGError err;
SKGTRACEINFUNCRC(10, err);
SKGTRACEL(10) << "Input parameter [iFileSource]=[" << iFileSource << ']' << endl;
SKGTRACEL(10) << "Input parameter [iFileTarget]=[" << iFileTarget << ']' << endl;
SKGTRACEL(10) << "Input parameter [iPassword] =[" << iPassword << ']' << endl;
SKGTRACEL(10) << "Input parameter [iHeaderFile]=[" << iHeaderFile << ']' << endl;
oModeSQLCipher = false;
// Read document
QByteArray input;
QByteArray uba;
err = downloadToStream(QUrl::fromUserInput(iFileSource), input);
IFOK(err) {
bool isFileEncrypted = (input.startsWith(QByteArray((iHeaderFile % "_ENCRYPT").toLatin1())));
bool sqliteMode = (input.left(15) == "SQLite format 3");
SKGTRACEL(10) << "isFileEncrypted=[" << static_cast(isFileEncrypted) << ']' << endl;
// !!!!! Remove Cipher encryption to remove security hole (thank you to Vincent P) !!!!!
// Only in sqlcipher mode. WARNING: in sqlite mode the issue is still there => add a message to push people to swith in sqlcipher mode
if (iEncrypt && !sqliteMode) {
// The input file is a sqlcipher file and we must save it
// We just have to add a new header to the input file
uba.reserve(input.length() + iHeaderFile.length() + 11);
uba.append(iHeaderFile.toLatin1());
uba.append(!iPassword.isEmpty() ? "_ENCRYPTE3-" : "_DECRYPTE3-");
uba.append(input);
oModeSQLCipher = true;
} else if (!iEncrypt && input.startsWith(QByteArray((iHeaderFile % "_ENCRYPTE3-").toLatin1()))) {
// This check is done to improve performances
if (iPassword.isEmpty() || iPassword == QStringLiteral("DEFAULTPASSWORD")) {
err = SKGError(ERR_ENCRYPTION, i18nc("Error message", "Wrong password"));
} else {
// The input file encrypter with the new mode
// We just have to remove the header
if (!iHeaderFile.isEmpty() && input.startsWith(iHeaderFile.toLatin1())) {
input = input.right(input.length() - iHeaderFile.length() - 11);
}
uba = input;
oModeSQLCipher = true;
}
} else {
// WARNING: This part is not really secured but is kept for compatibility
SKGTRACEL(10) << "Mode not secured" << endl;
QCA::Initializer init;
QCA::SymmetricKey key(QByteArray("skrooge"));
SKGTRACEL(10) << "QCA::Initializer done" << endl;
if (!iPassword.isEmpty() && !QCA::isSupported("aes128-ecb")) {
// Set error message
err.setReturnCode(ERR_INSTALL); // To avoid password request
err.setMessage(i18nc("An error message about encryption", "AES128 encryption is not supported (%1). Please install qca-ossl.", QCA::supportedFeatures().join(QStringLiteral(","))));
} else {
QCA::Cipher* cipher = nullptr;
QCA::InitializationVector iv(iPassword.toLatin1());
// Create a 128 bit AES cipher object using Cipher Block Chaining (CBC) mode
if ((isFileEncrypted || iEncrypt) && !iPassword.isEmpty()) {
cipher = new QCA::Cipher(QStringLiteral("aes128"), QCA::Cipher::CBC,
// use Default padding, which is equivalent to PKCS7 for CBC
QCA::Cipher::DefaultPadding,
iEncrypt ? QCA::Encode : QCA::Decode,
key, iv);
}
// BUG 249955 vvv
if (!cipher && isFileEncrypted) {
err = SKGError(ERR_ENCRYPTION, i18nc("Error message about encrypting a file", "Encryption failed"));
}
// BUG 249955 ^^^
// Suppress header
SKGTRACEL(10) << "input=[" << input.left(50) << "...]" << endl;
if (!iHeaderFile.isEmpty() && input.startsWith(iHeaderFile.toLatin1())) {
input = input.right(input.length() - iHeaderFile.length() - 11);
}
SKGTRACEL(10) << "input without header=[" << input.left(50) << "...]" << endl;
QCA::SecureArray u;
if (cipher) {
if (!err) {
// Process encryption or decryption
u = cipher->process(input);
// We need to check if that update() call worked.
if (!cipher->ok()) {
err = SKGError(ERR_UNEXPECTED, i18nc("Error message about encrypting a file", "Encryption failed"));
} else {
uba = u.toByteArray();
}
}
} else {
uba = input;
}
IFOK(err) {
// Check if decryption is OK
SKGTRACEL(10) << "output 1=[" << uba.left(50) << "...]" << endl;
if (!iEncrypt) {
if (!uba.startsWith(QByteArray("SQLite format 3"))) {
if (!uba.startsWith(SQLCIPHERHEARDER)) {
if (isFileEncrypted) {
err = SKGError(ERR_ENCRYPTION, i18nc("Error message", "Wrong password"));
} else {
oModeSQLCipher = true;
}
} else {
uba = uba.right(uba.length() - QStringLiteral(SQLCIPHERHEARDER).length());
oModeSQLCipher = true;
}
}
}
}
IFOK(err) {
// Add headers
if (iEncrypt && !iHeaderFile.isEmpty()) {
QByteArray h = (iHeaderFile % (cipher ? "_ENCRYPTED-" : "_DECRYPTED-")).toLatin1();
uba = uba.insert(0, h);
}
}
delete cipher;
cipher = nullptr;
}
}
SKGTRACEL(10) << "output 2=[" << uba.left(50) << "...]" << endl;
// output the results of that stage
IFOK(err) {
SKGTRACEIN(10, "SKGServices::cryptFile-save file");
QSaveFile fileOutput(iFileTarget);
if (!fileOutput.open(QIODevice::WriteOnly)) {
err = SKGError(ERR_WRITEACCESS, i18nc("Error message: writing a file failed", "Write file '%1' failed", iFileTarget));
} else {
// Write document
fileOutput.write(uba);
// Close the file
if (!fileOutput.commit()) {
IFOK(err) {
err = SKGError(ERR_WRITEACCESS, i18nc("Error message: writing a file failed", "Write file '%1' failed", iFileTarget));
}
}
}
}
}
SKGTRACEL(10) << "Output parameter [oModeSQLCipher]=[" << static_cast(oModeSQLCipher) << ']' << endl;
return err;
}
SKGError SKGServices::copySqliteDatabaseToXml(const QSqlDatabase& iDb, QDomDocument& oDocument)
{
SKGError err;
SKGTRACEINFUNCRC(10, err);
oDocument = QDomDocument(QStringLiteral("SKGML"));
QDomElement document = oDocument.createElement(QStringLiteral("document"));
oDocument.appendChild(document);
// Copy the tables
QStringList listTables = iDb.tables();
int nb = listTables.count();
for (int i = 0; !err && i < nb; ++i) {
QString tableName = listTables.at(i);
if (!tableName.startsWith(QLatin1String("sqlite_")) && !tableName.startsWith(QLatin1String("vm_"))) {
QDomElement table = oDocument.createElement(QStringLiteral("table"));
document.appendChild(table);
table.setAttribute(QStringLiteral("name"), tableName);
SKGStringListList listRows;
err = SKGServices::executeSelectSqliteOrder(iDb, "SELECT * FROM " % tableName, listRows);
int nbRows = listRows.count();
if (nbRows) {
QStringList titles = listRows.at(0);
for (int j = 1; !err && j < nbRows; ++j) { // Forget title
QStringList values = listRows.at(j);
QDomElement row = oDocument.createElement(QStringLiteral("row"));
table.appendChild(row);
int nbVals = values.count();
for (int k = 0; k < nbVals; ++k) {
row.setAttribute(titles.at(k), values.at(k));
}
}
}
}
}
return err;
}
SKGError SKGServices::copySqliteDatabase(const QSqlDatabase& iFileDb, const QSqlDatabase& iMemoryDb, bool iFromFileToMemory, const QString& iPassword)
{
SKGError err;
SKGTRACEINFUNCRC(10, err);
SKGTRACEL(20) << "Input parameter [iFileDb]=[" << iFileDb.databaseName() << ']' << endl;
SKGTRACEL(20) << "Input parameter [iMemoryDb]=[" << iMemoryDb.databaseName() << ']' << endl;
SKGTRACEL(10) << "Input parameter [iFromFileToMemory]=[" << (iFromFileToMemory ? "FILE->MEMORY" : "MEMORY->FILE") << ']' << endl;
QString dbFileName = iFileDb.databaseName();
// Copy the tables
SKGStringListList listTables;
int nb = 0;
IFOK(err) {
err = SKGServices::executeSelectSqliteOrder((iFromFileToMemory ? iFileDb : iMemoryDb),
QStringLiteral("SELECT sql, tbl_name FROM sqlite_master WHERE type='table' AND sql NOT NULL and name NOT LIKE 'sqlite_%'"),
listTables);
nb = listTables.count();
for (int i = 1; !err && i < nb; ++i) { // Forget header
QString val = listTables.at(i).at(0);
err = SKGServices::executeSqliteOrder((iFromFileToMemory ? iMemoryDb : iFileDb), val);
}
}
// Attach db
IFOK(err) {
QString add;
if (!iPassword.isEmpty()) {
add = " KEY '" % SKGServices::stringToSqlString(iPassword) % "'";
}
err = SKGServices::executeSqliteOrder(iMemoryDb, "ATTACH DATABASE '" % dbFileName % "' as source" % add);
}
// Copy records
IFOK(err) {
err = SKGServices::executeSqliteOrder(iMemoryDb, QStringLiteral("BEGIN"));
IFOK(err) {
for (int i = 1; !err && i < nb; ++i) { // Forget header
QString val = listTables.at(i).at(1);
if (iFromFileToMemory) {
err = SKGServices::executeSqliteOrder(iMemoryDb, "insert into main." % val % " select * from source." % val);
} else {
err = SKGServices::executeSqliteOrder(iMemoryDb, "insert into source." % val % " select * from main." % val);
}
}
}
SKGServices::executeSqliteOrder(iMemoryDb, QStringLiteral("COMMIT"));
}
// Detach
{
SKGError err2 = SKGServices::executeSqliteOrder(iMemoryDb, QStringLiteral("DETACH DATABASE source"));
if (!err && err2) {
err = err2;
}
}
// Optimization
IFOK(err) {
QStringList optimization;
optimization << QStringLiteral("PRAGMA case_sensitive_like=true")
<< QStringLiteral("PRAGMA journal_mode=MEMORY")
<< QStringLiteral("PRAGMA temp_store=MEMORY")
// << QStringLiteral("PRAGMA locking_mode=EXCLUSIVE")
<< QStringLiteral("PRAGMA synchronous = OFF")
<< QStringLiteral("PRAGMA recursive_triggers=true");
err = SKGServices::executeSqliteOrders(iFromFileToMemory ? iMemoryDb : iFileDb, optimization);
}
// Copy the indexes
IFOK(err) {
SKGStringListList listSqlOrder;
err = SKGServices::executeSelectSqliteOrder((iFromFileToMemory ? iFileDb : iMemoryDb),
QStringLiteral("SELECT sql FROM sqlite_master WHERE type='index' AND sql NOT NULL and name NOT LIKE 'sqlite_%'"),
listSqlOrder);
int nb2 = listSqlOrder.count();
for (int i = 1; !err && i < nb2; ++i) { // Forget header
QString val = listSqlOrder.at(i).at(0);
err = SKGServices::executeSqliteOrder((iFromFileToMemory ? iMemoryDb : iFileDb), val);
}
}
// Copy the views
IFOK(err) {
SKGStringListList listSqlOrder;
err = SKGServices::executeSelectSqliteOrder((iFromFileToMemory ? iFileDb : iMemoryDb),
QStringLiteral("SELECT sql FROM sqlite_master WHERE type='view' AND sql NOT NULL and name NOT LIKE 'sqlite_%'"),
listSqlOrder);
int nb2 = listSqlOrder.count();
for (int i = 1; !err && i < nb2; ++i) { // Forget header
QString val = listSqlOrder.at(i).at(0);
err = SKGServices::executeSqliteOrder((iFromFileToMemory ? iMemoryDb : iFileDb), val);
}
}
// Copy the triggers, must be done after the views
IFOK(err) {
SKGStringListList listSqlOrder;
err = SKGServices::executeSelectSqliteOrder((iFromFileToMemory ? iFileDb : iMemoryDb),
QStringLiteral("SELECT sql FROM sqlite_master WHERE type='trigger' AND sql NOT NULL and name NOT LIKE 'sqlite_%'"),
listSqlOrder);
int nb2 = listSqlOrder.count();
for (int i = 1; !err && i < nb2; ++i) { // Forget header
QString val = listSqlOrder.at(i).at(0);
err = SKGServices::executeSqliteOrder((iFromFileToMemory ? iMemoryDb : iFileDb), val);
}
}
// Check if created file exists
if (!err && !iFromFileToMemory && !QFile(dbFileName).exists()) {
err.setReturnCode(ERR_FAIL).setMessage(i18nc("An error message: creating a file failed", "Creation file '%1' failed", dbFileName));
}
IFKO(err) {
err.addError(SQLLITEERROR + ERR_FAIL, i18nc("Error message: something failed", "%1 failed", QStringLiteral("SKGServices::copySqliteDatabase()")));
}
return err;
}
SKGError SKGServices::executeSqliteOrders(const QSqlDatabase& iDb, const QStringList& iSqlOrders)
{
SKGError err;
_SKGTRACEINFUNCRC(10, err);
int nb = iSqlOrders.count();
for (int i = 0; !err && i < nb; ++i) {
err = executeSqliteOrder(iDb, iSqlOrders.at(i));
}
return err;
}
SKGError SKGServices::executeSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, const QMap& iBind, int* iLastId)
{
SKGError err;
_SKGTRACEINFUNCRC(10, err);
SKGTRACEL(20) << "Input parameter [iSqlOrder]=[" << iSqlOrder << ']' << endl;
QSqlQuery query(QString(), iDb);
query.setForwardOnly(true);
double elapse = 0;
if (SKGServices::SKGSqlTraces != -1) {
elapse = SKGServices::getMicroTime();
}
// Prepare sql order
bool prep = query.prepare(iSqlOrder);
// Bind values
QMapIterator i(iBind);
while (i.hasNext()) {
i.next();
query.bindValue(i.key(), i.value());
}
if (!prep || !query.exec()) {
QSqlError sqlError = query.lastError();
if (sqlError.number() != 19 /*SQLITE_CONSTRAINT*/ && iSqlOrder != QStringLiteral("SELECT count(*) FROM sqlite_master") /*Test password*/) {
SKGTRACE << "WARNING: " << iSqlOrder << endl;
SKGTRACE << " returns :" << sqlError.text() << endl;
}
err = SKGError(SQLLITEERROR + sqlError.number(), iSqlOrder);
err.addError(SQLLITEERROR + sqlError.number(), sqlError.text());
if (sqlError.number() == 19 && iSqlOrder.startsWith(QLatin1String("INSERT "))) {
err.addError(ERR_FAIL, i18nc("Error message", "Creation failed. The object already exists."));
}
} else {
if (iLastId) {
*iLastId = query.lastInsertId().toInt();
}
}
if (SKGServices::SKGSqlTraces != -1) {
elapse = SKGServices::getMicroTime() - elapse;
if (elapse >= SKGServices::SKGSqlTraces) {
SKGTRACE << "executeSqliteOrder :" << iSqlOrder << " TIME=" << elapse << " ms" << endl;
}
}
return err;
}
SKGError SKGServices::executeSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, int* iLastId)
{
return executeSqliteOrder(iDb, iSqlOrder, QMap< QString, QVariant >(), iLastId);
}
SKGError SKGServices::dumpSelectSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, SKGServices::DumpMode iMode)
{
return dumpSelectSqliteOrder(iDb, iSqlOrder, nullptr, iMode);
}
SKGError SKGServices::dumpSelectSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, QTextStream* oStream, SKGServices::DumpMode iMode)
{
SKGError err;
_SKGTRACEINFUNCRC(10, err);
SKGTRACEL(20) << "Input parameter [iSqlOrder]=[" << iSqlOrder << ']' << endl;
// initialisation
QStringList oResult;
err = SKGServices::dumpSelectSqliteOrder(iDb, iSqlOrder, oResult, iMode);
IFOK(err) {
// dump
int nb = oResult.size();
for (int i = 0; i < nb; ++i) {
if (oStream == nullptr) {
SKGTRACESUITE << oResult.at(i) << endl;
} else {
*oStream << oResult.at(i) << endl;
}
}
}
return err;
}
SKGError SKGServices::dumpSelectSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, QString& oResult, SKGServices::DumpMode iMode)
{
SKGError err;
_SKGTRACEINFUNCRC(10, err);
// initialisation
oResult = QLatin1String("");
QStringList oResultTmp;
err = SKGServices::dumpSelectSqliteOrder(iDb, iSqlOrder, oResultTmp, iMode);
IFOK(err) {
// dump
int nb = oResultTmp.size();
for (int i = 0; i < nb; ++i) {
oResult += oResultTmp.at(i) % '\n';
}
}
return err;
}
SKGError SKGServices::dumpSelectSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, QStringList& oResult, SKGServices::DumpMode iMode)
{
SKGError err;
_SKGTRACEINFUNCRC(10, err);
// Execution of sql order
SKGStringListList oResultTmp;
err = executeSelectSqliteOrder(iDb, iSqlOrder, oResultTmp);
IFOK(err) oResult = tableToDump(oResultTmp, iMode);
return err;
}
SKGError SKGServices::executeSingleSelectSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, QString& oResult)
{
SKGStringListList result;
SKGError err = executeSelectSqliteOrder(iDb, iSqlOrder, result);
oResult = result.value(1).value(0);
return err;
}
SKGError SKGServices::executeSelectSqliteOrder(const QSqlDatabase& iDb, const QString& iSqlOrder, SKGStringListList& oResult)
{
SKGError err;
_SKGTRACEINFUNCRC(10, err);
// initialisation
oResult.clear();
QSqlQuery query(QString(), iDb);
query.setForwardOnly(true);
double elapse = 0;
if (SKGServices::SKGSqlTraces != -1) {
elapse = SKGServices::getMicroTime();
}
if (!query.exec(iSqlOrder)) {
QSqlError sqlError = query.lastError();
if (qApp->thread() == QThread::currentThread()) {
SKGTRACE << "WARNING: " << iSqlOrder << endl;
SKGTRACE << " returns :" << sqlError.text() << endl;
}
err = SKGError(SQLLITEERROR + sqlError.number(), iSqlOrder);
err.addError(SQLLITEERROR + sqlError.number(), sqlError.text());
} else {
double elapse1 = 0;
if (SKGServices::SKGSqlTraces != -1) {
elapse1 = SKGServices::getMicroTime() - elapse;
}
// Addition of column names
QSqlRecord rec = query.record();
QStringList line;
int index = 0;
while (index != -1) {
QString val = rec.fieldName(index);
if (!val.isEmpty()) {
line.push_back(val);
++index;
} else {
index = -1;
}
}
oResult.push_back(line);
// Addition of rows
while (query.next()) {
QStringList line2;
int index2 = 0;
while (index2 != -1) {
QVariant val = query.value(index2);
if (val.isValid()) {
line2.push_back(val.toString());
++index2;
} else {
index2 = -1;
}
}
oResult.push_back(line2);
}
if (SKGServices::SKGSqlTraces != -1) {
double elapse2 = SKGServices::getMicroTime() - elapse;
if (elapse1 >= SKGServices::SKGSqlTraces) {
SKGTRACE << "executeSqliteOrder:" << iSqlOrder << " TIME=" << elapse1 << " ms, (with fetch):" << elapse2 << " ms" << endl;
}
}
}
return err;
}
SKGError SKGServices::readPropertyFile(const QString& iFileName, QHash< QString, QString >& oProperties)
{
SKGError err;
oProperties.clear();
// Open file
QFile file(iFileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
err = SKGError(ERR_FAIL, i18nc("An erro message", "Open file '%1' failed", iFileName));
} else {
// Read file
QTextStream stream(&file);
while (!stream.atEnd() && !err) {
// Read line
QString line = stream.readLine().trimmed();
if (!line.isEmpty() && !line.startsWith(QLatin1String("#"))) {
int pos = line.indexOf(QStringLiteral("="));
if (pos != -1) {
oProperties[line.left(pos).trimmed().toLower()] = line.right(line.count() - pos - 1);
}
}
}
// close file
file.close();
}
return err;
}
double SKGServices::getMicroTime()
{
#ifdef Q_OS_WIN
return static_cast(GetTickCount());
#else
struct timeval tv;
struct timezone tz;
// get time
gettimeofday(&tv, &tz);
// return time
return (static_cast(1000.0 * tv.tv_sec)) + (static_cast(tv.tv_usec / 1000));
#endif
}
SKGStringListList SKGServices::getBase100Table(const SKGStringListList& iTable)
{
SKGTRACEINFUNC(10);
// Build history
SKGStringListList output;
int nblines = iTable.count();
int nbCols = 0;
if (nblines) {
nbCols = iTable.at(0).count();
}
output.reserve(nblines + 1);
output.push_back(iTable.at(0));
// Create table
for (int i = 1; i < nblines; ++i) {
QStringList newLine;
newLine.reserve(nbCols + 1);
newLine.push_back(iTable.at(i).at(0));
double valInitial = 0;
for (int j = 1; j < nbCols; ++j) {
double val = SKGServices::stringToDouble(iTable.at(i).at(j));
if (j == 1) {
valInitial = val;
val = 100.0;
} else {
if (valInitial != 0.0) {
val = 100.0 * val / valInitial;
}
}
newLine.push_back(SKGServices::doubleToString(val));
}
output.push_back(newLine);
}
return output;
}
SKGStringListList SKGServices::getPercentTable(const SKGStringListList& iTable, bool iOfColumns, bool iAbsolute)
{
SKGTRACEINFUNC(10);
// Build history
SKGStringListList output;
int nblines = iTable.count();
int nbCols = 0;
if (nblines) {
nbCols = iTable.at(0).count();
}
output.reserve(nblines + 1);
output.push_back(iTable.at(0));
// Compute sums
QList sums;
if (iOfColumns) {
// Compute sum of columns
sums.reserve(nbCols);
for (int j = 1; j < nbCols; ++j) {
// Compute sum
double sum = 0;
for (int i = 1; i < nblines; ++i) {
double v = SKGServices::stringToDouble(iTable.at(i).at(j));
sum += (iAbsolute ? qAbs(v) : v);
}
sums.push_back(sum);
}
} else {
// Compute sum of lines
sums.reserve(nblines);
for (int j = 1; j < nblines; ++j) {
// Compute sum
double sum = 0;
for (int i = 1; i < nbCols; ++i) {
double v = SKGServices::stringToDouble(iTable.at(j).at(i));
sum += (iAbsolute ? qAbs(v) : v);
}
sums.push_back(sum);
}
}
// Create table
for (int i = 1; i < nblines; ++i) {
QStringList newLine;
newLine.reserve(nbCols + 1);
newLine.push_back(iTable.at(i).at(0));
for (int j = 1; j < nbCols; ++j) {
double val = SKGServices::stringToDouble(iTable.at(i).at(j));
val = (iAbsolute ? qAbs(val) : val);
double sum = (iOfColumns ? sums.at(j - 1) : sums.at(i - 1));
newLine.push_back(SKGServices::doubleToString(sum == 0.0 ? 0.0 : 100.0 * val / sum));
}
output.push_back(newLine);
}
return output;
}
SKGStringListList SKGServices::getHistorizedTable(const SKGStringListList& iTable)
{
SKGTRACEINFUNC(10);
// Build history
SKGStringListList output;
int nblines = iTable.count();
int nbCols = 0;
if (nblines) {
nbCols = iTable.at(0).count();
}
output.reserve(nblines + 1);
output.push_back(iTable.at(0));
for (int i = 1; i < nblines; ++i) {
QStringList newLine;
newLine.reserve(nbCols + 1);
newLine.push_back(iTable.at(i).at(0));
double sum = 0;
for (int j = 1; j < nbCols; ++j) {
sum += SKGServices::stringToDouble(iTable.at(i).at(j));
newLine.push_back(SKGServices::doubleToString(sum));
}
output.push_back(newLine);
}
return output;
}
QString SKGServices::encodeForUrl(const QString& iString)
{
return QUrl::toPercentEncoding(iString);
}
QIcon SKGServices::fromTheme(const QString& iName, const QStringList& iOverlays)
{
QIcon output;
if (!iOverlays.isEmpty()) {
output = KDE::icon(iName, iOverlays);
} else {
output = KDE::icon(iName);
}
if (output.isNull() && !iName.isEmpty()) {
static QHash alternatives;
if (alternatives.count() == 0) {
// Build alternatives
alternatives[QStringLiteral("arrow-down")] = QStringLiteral("go-down");
alternatives[QStringLiteral("arrow-right")] = QStringLiteral("go-next");
alternatives[QStringLiteral("arrow-up")] = QStringLiteral("go-up");
alternatives[QStringLiteral("arrow-down-double")] = QStringLiteral("go-down");
alternatives[QStringLiteral("arrow-up-double")] = QStringLiteral("go-up");
alternatives[QStringLiteral("bookmark")] = QStringLiteral("bookmark-new");
alternatives[QStringLiteral("bookmarks")] = QStringLiteral("bookmark-new");
alternatives[QStringLiteral("checkbox")] = QStringLiteral("emblem-symbolic-link");
alternatives[QStringLiteral("chronometer")] = QStringLiteral("appointment");
alternatives[QStringLiteral("configure")] = QStringLiteral("preferences-desktop");
alternatives[QStringLiteral("dashboard-show")] = QStringLiteral("user-desktop");
alternatives[QStringLiteral("dialog-cancel")] = QStringLiteral("process-stop");
alternatives[QStringLiteral("dialog-close")] = QStringLiteral("process-stop");
alternatives[QStringLiteral("dialog-ok")] = QLatin1String("");
alternatives[QStringLiteral("download-later")] = QStringLiteral("applications-internet");
alternatives[QStringLiteral("download")] = QStringLiteral("applications-internet");
alternatives[QStringLiteral("draw-freehand")] = QStringLiteral("accessories-text-editor");
alternatives[QStringLiteral("edit-guides")] = QStringLiteral("text-x-generic");
alternatives[QStringLiteral("edit-rename")] = QStringLiteral("accessories-text-editor");
alternatives[QStringLiteral("emblem-locked")] = QStringLiteral("lock");
alternatives[QStringLiteral("exchange-positions")] = QLatin1String("");
alternatives[QStringLiteral("format-fill-color")] = QLatin1String("");
alternatives[QStringLiteral("games-solve")] = QStringLiteral("application-certificate");
alternatives[QStringLiteral("get-hot-new-stuff")] = QStringLiteral("applications-other");
alternatives[QStringLiteral("irc-operator")] = QLatin1String("");
alternatives[QStringLiteral("ktip")] = QStringLiteral("dialog-information");
alternatives[QStringLiteral("labplot-xy-plot-two-axes-centered-origin")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("layer-visible-off")] = QLatin1String("");
alternatives[QStringLiteral("layer-visible-on")] = QLatin1String("");
alternatives[QStringLiteral("merge")] = QLatin1String("");
alternatives[QStringLiteral("office-chart-area")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-area-stacked")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-bar-percentage")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-bar")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-bar-stacked")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-line")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-line-stacked")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-pie")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-ring")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("map-flat")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("office-chart-scatter")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("preview")] = QStringLiteral("document-print-preview");
alternatives[QStringLiteral("quickopen")] = QStringLiteral("emblem-symbolic-link");
alternatives[QStringLiteral("run-build-configure")] = QStringLiteral("media-playback-start");
alternatives[QStringLiteral("run-build")] = QStringLiteral("media-playback-start");
alternatives[QStringLiteral("show-menu")] = QStringLiteral("applications-system");
alternatives[QStringLiteral("skrooge_category")] = QStringLiteral("folder-open");
alternatives[QStringLiteral("split")] = QStringLiteral("edit-cut");
alternatives[QStringLiteral("taxes-finances")] = QStringLiteral("fonts");
alternatives[QStringLiteral("tools-wizard")] = QStringLiteral("applications-other");
alternatives[QStringLiteral("user-group-properties")] = QStringLiteral("system-users");
alternatives[QStringLiteral("user-properties")] = QStringLiteral("document-properties");
alternatives[QStringLiteral("utilities-file-archiver")] = QStringLiteral("package-x-generic");
alternatives[QStringLiteral("vcs-conflicting")] = QStringLiteral("dialog-warning");
alternatives[QStringLiteral("vcs-normal")] = QStringLiteral("dialog-information");
alternatives[QStringLiteral("view-bank-account-checking")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-bank-account")] = QStringLiteral("x-office-address-book");
alternatives[QStringLiteral("view-bank-account-savings")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-bank")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-calendar-journal")] = QStringLiteral("x-office-calendar");
alternatives[QStringLiteral("view-calendar-month")] = QStringLiteral("x-office-calendar");
alternatives[QStringLiteral("view-calendar")] = QStringLiteral("x-office-calendar");
alternatives[QStringLiteral("view-calendar-week")] = QStringLiteral("x-office-calendar");
alternatives[QStringLiteral("view-calendar-whatsnext")] = QStringLiteral("x-office-calendar");
alternatives[QStringLiteral("view-categories")] = QStringLiteral("folder-open");
alternatives[QStringLiteral("view-categories-expenditures")] = QStringLiteral("face-sad");
alternatives[QStringLiteral("view-categories-incomes")] = QStringLiteral("face-smile");
alternatives[QStringLiteral("view-file-columns")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-financial-list")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-investment")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-list-details")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-list-text")] = QStringLiteral("go-home");
alternatives[QStringLiteral("view-pim-calendar")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("view-statistics")] = QStringLiteral("x-office-spreadsheet");
alternatives[QStringLiteral("window-duplicate")] = QStringLiteral("edit-copy");
alternatives[QStringLiteral("zoom-fit-width")] = QStringLiteral("media-playback-stop");
alternatives[QStringLiteral("smallclock")] = QLatin1String("");
alternatives[QStringLiteral("edit_undo")] = QStringLiteral("edit-undo");
}
bool alternativeEmpty = false;
if (alternatives.contains(iName)) {
auto alternative = alternatives.value(iName);
alternativeEmpty = (alternative.isEmpty());
if (!alternativeEmpty) {
if (!iOverlays.isEmpty()) {
output = KDE::icon(alternative, iOverlays);
} else {
output = KDE::icon(alternative);
}
}
}
if (output.isNull() && !alternativeEmpty) {
SKGTRACE << "WARNING: Icon [" << iName << "] not found" << endl;
output = KDE::icon(QStringLiteral("script-error"));
if (output.isNull()) {
output = KDE::icon(QStringLiteral("image-missing"));
}
}
}
return output;
}
QString SKGServices::getMajorVersion(const QString& iVersion)
{
QString output = iVersion;
int pos = output.indexOf('.');
if (pos != -1) {
pos = output.indexOf('.', pos + 1);
if (pos != -1) {
output = output.left(pos);
}
}
return output;
}
QString SKGServices::getFullPathCommandLine(const QString& iCommandLine)
{
QString output = iCommandLine;
if (!output.isEmpty()) {
auto pathWords = SKGServices::splitCSVLine(output, QLatin1Char(' '));
QString fullpath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, qApp->applicationName() % "/" % pathWords.at(0));
if (!fullpath.isEmpty()) {
pathWords[0] = fullpath;
output = pathWords.join(QLatin1Char(' '));
}
}
return output;
}
diff --git a/skgsqlcipher/skgsqlcipherdriverplugin.cpp b/skgsqlcipher/skgsqlcipherdriverplugin.cpp
index 5e829bbe0..4851f4c36 100644
--- a/skgsqlcipher/skgsqlcipherdriverplugin.cpp
+++ b/skgsqlcipher/skgsqlcipherdriverplugin.cpp
@@ -1,55 +1,51 @@
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
/** @file
* This file defines classes SKGSQLCipherDriverPlugin.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include
#include
-#if QT_VERSION < 0x050700
-#include "old-qsql_sqlite_p.h"
-#else
#include "qsql_sqlite_p.h"
-#endif
QT_BEGIN_NAMESPACE
class SKGSQLCipherDriverPlugin : public QSqlDriverPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "skgsqlcipherdriverplugin.json")
public:
SKGSQLCipherDriverPlugin() : QSqlDriverPlugin()
{}
QSqlDriver* create(const QString& iName) override
{
if (iName == QStringLiteral("SKGSQLCIPHER")) {
auto driver = new QSQLiteDriver();
return driver;
}
return nullptr;
}
};
QT_END_NAMESPACE
#include "skgsqlcipherdriverplugin.moc"
diff --git a/skrooge/main.cpp b/skrooge/main.cpp
index 2c1352a95..69ab60136 100644
--- a/skrooge/main.cpp
+++ b/skrooge/main.cpp
@@ -1,217 +1,215 @@
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
/** @file
* This file defines the main of skrooge.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include "skgmainpanel.h"
#include "skgdocumentbank.h"
#include "skgtraces.h"
#include
#include
#include
#include
#include
#include
#include
#include
/**
* To compute the version
*/
#define VER1_(x) #x
/**
* To compute the version
*/
#define VER_(x) VER1_(x)
/**
* To compute the version
*/
#define VER VER_(SKGVERSION)
void SKGMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
Q_UNUSED(context);
switch (type) {
case QtDebugMsg:
SKGTRACEL(1) << "DEBUG: " << msg << endl;
break;
case QtWarningMsg:
SKGTRACE << "WARNING: " << msg << endl;
break;
case QtCriticalMsg:
SKGTRACE << "CRITICAL: " << msg << endl;
break;
case QtFatalMsg:
SKGTRACE << "FATAL: " << msg << endl;
abort();
default:
SKGTRACE << "INFO: " << msg << endl;
break;
}
}
/**
* The main of the application
* @param argc number of arguments
* @param argv arguments
* @return return code
*/
int main(int argc, char** argv)
{
qInstallMessageHandler(SKGMessageOutput);
-#if QT_VERSION >= 0x050600
if (!SKGServices::getEnvVariable(QStringLiteral("SKGHIGHDPI")).isEmpty()) {
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
}
-#endif
QApplication app(argc, argv);
app.setWindowIcon(SKGServices::fromTheme(QStringLiteral("skrooge")));
// Migration kf4 => kf5
Kdelibs4ConfigMigrator migrate(QStringLiteral("skrooge"));
migrate.setConfigFiles(QStringList() << QStringLiteral("skroogerc"));
migrate.migrate();
// To use CPU instead CPU for QML (needed for printing)
qputenv("QMLSCENE_DEVICE", "softwarecontext");
#ifdef SKG_WEBENGINE
// DrKonqi
// https://www.dvratil.cz/2018/10/drkonqi-and-qtwebengine/
const auto chromiumFlags = qgetenv("QTWEBENGINE_CHROMIUM_FLAGS");
if (!chromiumFlags.contains("disable-in-process-stack-traces")) {
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", chromiumFlags + " --disable-in-process-stack-traces");
}
#endif
KLocalizedString::setApplicationDomain("skrooge");
KAboutData about(QStringLiteral("skrooge"),
i18nc("The name of the application", "Skrooge"),
QStringLiteral(VER),
i18nc("The description of the application", "Personal finances management made simple"),
KAboutLicense::GPL_V3,
i18nc("Fullname", "(c) 2007-%1 Stephane MANKOWSKI & Guillaume DE BURE", QDate::currentDate().toString(QStringLiteral("yyyy"))),
QLatin1String(""),
QStringLiteral("http://skrooge.org"));
about.addAuthor(i18nc("Fullname", "Stephane MANKOWSKI"), i18nc("A job description", "Architect & Developer"), QStringLiteral("stephane@mankowski.fr"), QLatin1String("")
, QStringLiteral("miraks")
);
about.addAuthor(i18nc("Fullname", "Guillaume DE BURE"), i18nc("A job description", "Developer"), QStringLiteral("guillaume.debure@gmail.com"), QLatin1String("")
, QStringLiteral("willy9")
);
about.addAuthor(i18nc("Fullname", "Siddharth SHARMA"), i18nc("A job description", "Developer - Google Summer Of Code 2010"), QStringLiteral("siddharth.kde@gmail.com"), QLatin1String("")
, QStringLiteral("h4xordood")
);
about.setOtherText(i18nc("The description of the application", "The application name is inspired by Charles Dicken's tale A Christmas Carol, where the main character, Ebenezer Scrooge, a grumpy old narrow man, gets visited by three ghosts who change the way he sees the world, in a good way."));
about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
about.setOrganizationDomain("kde.org");
about.addCredit(QStringLiteral("vicnet, noidea, rbruce, JesusM, schunka, SylvaiNN, Wolf, Hizoka, neutron68, blep0, BigaAl, ..."), i18nc("Reason of the about/credit", "Users helping us to improve this application"));
KAboutData::setApplicationData(about);
app.setApplicationName(about.componentName());
app.setOrganizationDomain(about.organizationDomain());
app.setApplicationVersion(about.version());
QCommandLineParser parser;
parser.addVersionOption();
parser.addHelpOption();
parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[URL]"), i18nc("Application argument", "Document to open")));
QCommandLineOption envOption(QStringList() << QStringLiteral("e") << QStringLiteral("env"), i18nc("Application argument", "Display environment variables used by this application."));
parser.addOption(envOption);
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
if (parser.isSet(envOption)) {
SKGTRACESUITE << parser.helpText() << endl;
SKGTRACESUITE << i18nc("Help", "Environment variables:") << endl;
SKGTRACESUITE << i18nc("Help, do not translate x", " %1: To enable traces. x is the level of traces expected. This enables the debug mode too.", "export SKGTRACE=x") << endl;
SKGTRACESUITE << i18nc("Help", " %1: To enable the profiling. This enables the debug mode too.", "export SKGTRACEPERFO=1") << endl;
SKGTRACESUITE << i18nc("Help do not translate x", " %1: To dump sql order taking more than x ms.", "export SKGTRACESQL=x") << endl;
SKGTRACESUITE << i18nc("Help", " %1: To enable the high DPI mode.", "export SKGHIGHDPI=1") << endl;
return 0;
}
// Manage unicity
KDBusService service(SKGServices::getEnvVariable(QStringLiteral("SKGNOTUNIQUE")).isEmpty() ? KDBusService::Unique : KDBusService::Multiple);
QObject::connect(&service, &KDBusService::activateRequested, &service, [ = ](const QStringList & arguments, const QString & workingDirectory) {
Q_UNUSED(workingDirectory);
SKGMainPanel::getMainPanel()->processArguments(arguments);
});
// Creating a main panel on a bank document
SKGDocumentBank doc;
if (!SKGServices::getEnvVariable(QStringLiteral("SKGTEST")).isEmpty()) {
QTimer::singleShot(5000, Qt::CoarseTimer, &app, &QApplication::quit);
}
// Build list of arguments
QStringList argument = parser.positionalArguments();
// Creation splash screen
QSplashScreen* m_splash = nullptr;
KConfigGroup pref = SKGMainPanel::getMainConfigGroup();
if (pref.readEntry("show_splash_screen", true)) {
QString splashPathRelativePath = KAboutData::applicationData().componentName() % "/images/splash.png";
QString splashPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, splashPathRelativePath.toLatin1());
if (!splashPath.isEmpty()) {
QPixmap pix(splashPath);
m_splash = new QSplashScreen(pix);
if (m_splash != nullptr) {
m_splash->setMask(pix.createMaskFromColor(Qt::blue));
m_splash->show();
m_splash->showMessage(i18nc("Splash screen message", "Loading ..."), Qt::AlignLeft, QColor(221, 130, 8)); // krazy:exclude=qmethods
}
} else {
SKGTRACE << "WARNING: Splash screen (" << splashPathRelativePath << ") not found !" << endl;
}
}
// First instance
QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true);
#ifdef SKG_WEBENGINE
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
#endif
auto m_widget = new SKGMainPanel(m_splash, &doc);
m_widget->processArguments(argument);
m_widget->setUnifiedTitleAndToolBarOnMac(true);
m_widget->show();
if (m_splash != nullptr) {
SKGTRACEINFUNC(1);
m_splash->clearMessage();
m_splash->finish(m_widget);
}
int rc = app.exec(); // krazy:exclude=crashy
delete m_splash;
SKGTraces::dumpProfilingStatistics();
return rc;
}
diff --git a/tests/skgbasemodelertest/skgtestbase.cpp b/tests/skgbasemodelertest/skgtestbase.cpp
index ac313cc66..5796a8835 100644
--- a/tests/skgbasemodelertest/skgtestbase.cpp
+++ b/tests/skgbasemodelertest/skgtestbase.cpp
@@ -1,730 +1,722 @@
/***************************************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
/** @file
* This file is a test script.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include "skgtestmacro.h"
-#if QT_VERSION < 0x050700
-#include
-#endif
/**
* The main function of the unit test
* @param argc the number of arguments
* @param argv the list of arguments
*/
void test_getPeriodWhereClause(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("2014")), QStringLiteral("STRFTIME('%Y',d_date)='2014'"));
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("2014-02")), QStringLiteral("STRFTIME('%Y-%m',d_date)='2014-02'"));
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("2014-10")), QStringLiteral("STRFTIME('%Y-%m',d_date)='2014-10'"));
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("2014-Q2")), QStringLiteral("STRFTIME('%Y',d_date)||'-Q'||(CASE WHEN STRFTIME('%m',d_date)<='03' THEN '1' WHEN STRFTIME('%m',d_date)<='06' THEN '2' WHEN STRFTIME('%m',d_date)<='09' THEN '3' ELSE '4' END)='2014-Q2'"));
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("2014-S2")), QStringLiteral("STRFTIME('%Y',d_date)||'-S'||(CASE WHEN STRFTIME('%m',d_date)<='06' THEN '1' ELSE '2' END)='2014-S2'"));
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("INVALID STRING")), QStringLiteral("1=0"));
SKGTEST(QStringLiteral("CONV:getPeriodWhereClause"), SKGServices::getPeriodWhereClause(QStringLiteral("ALL")), QStringLiteral("1=1"));
}
void test_getNeighboringPeriod(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014")), QStringLiteral("2013"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-10")), QStringLiteral("2014-09"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-01")), QStringLiteral("2013-12"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-Q2")), QStringLiteral("2014-Q1"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-Q1")), QStringLiteral("2013-Q4"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-S2")), QStringLiteral("2014-S1"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-S1")), QStringLiteral("2013-S2"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("INVALID STRING")), QStringLiteral("1=0"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod"), SKGServices::getNeighboringPeriod(QStringLiteral("ALL")), QStringLiteral("1=0"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014"), 1), QStringLiteral("2015"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-10"), 1), QStringLiteral("2014-11"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-01"), 1), QStringLiteral("2014-02"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-Q4"), 1), QStringLiteral("2015-Q1"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-Q2"), 1), QStringLiteral("2014-Q3"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-Q1"), 1), QStringLiteral("2014-Q2"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-S2"), 1), QStringLiteral("2015-S1"));
SKGTEST(QStringLiteral("CONV:getNeighboringPeriod +1"), SKGServices::getNeighboringPeriod(QStringLiteral("2014-S1"), 1), QStringLiteral("2014-S2"));
}
void test_periodToDate(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014")).toString(), QDate(2014, 12, 31).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-S1")).toString(), QDate(2014, 6, 30).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-S2")).toString(), QDate(2014, 12, 31).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-Q1")).toString(), QDate(2014, 3, 31).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-Q2")).toString(), QDate(2014, 6, 30).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-Q3")).toString(), QDate(2014, 9, 30).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-Q4")).toString(), QDate(2014, 12, 31).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-01")).toString(), QDate(2014, 1, 31).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("2014-07")).toString(), QDate(2014, 7, 31).toString());
SKGTEST(QStringLiteral("CONV:periodToDate"), SKGServices::periodToDate(QStringLiteral("ALL")).toString(), QDate::currentDate().toString());
}
void test_partialStringToDate(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("INVALID"), true).toString(), QLatin1String(""));
QDate currentMonth10 = QDate::currentDate();
currentMonth10 = currentMonth10.addDays(10 - QDate::currentDate().day());
QDate current0102(QDate::currentDate().year(), 2, 1);
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("10"), true).toString(), (currentMonth10 <= QDate::currentDate() ? currentMonth10 : currentMonth10.addMonths(-1)).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2"), true).toString(), (current0102 <= QDate::currentDate() ? current0102 : current0102.addYears(-1)).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/14"), true).toString(), QDate(2014, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/99"), true).toString(), QDate(1999, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/014"), true).toString(), QDate(2014, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/199"), true).toString(), QDate(1199, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/1014"), true).toString(), QDate(1014, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/2222"), true).toString(), QDate(2222, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("10"), false).toString(), (currentMonth10 >= QDate::currentDate() ? currentMonth10 : currentMonth10.addMonths(1)).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2"), false).toString(), (current0102 >= QDate::currentDate() ? current0102 : current0102.addYears(1)).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/14"), false).toString(), QDate(2114, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/99"), false).toString(), QDate(2099, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/014"), false).toString(), QDate(3014, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/199"), false).toString(), QDate(2199, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/1014"), false).toString(), QDate(1014, 2, 1).toString());
SKGTEST(QStringLiteral("CONV:partialStringToDate"), SKGServices::partialStringToDate(QStringLiteral("1/2/2222"), false).toString(), QDate(2222, 2, 1).toString());
}
void test_conversions(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 03, 05), QStringLiteral("D")), QStringLiteral("2013-03-05"));
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 01, 01), QStringLiteral("W")), QStringLiteral("2013-W01"));
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 03, 05), QStringLiteral("W")), QStringLiteral("2013-W10"));
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 03, 05), QStringLiteral("M")), QStringLiteral("2013-03"));
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 03, 05), QStringLiteral("Q")), QStringLiteral("2013-Q1"));
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 03, 05), QStringLiteral("S")), QStringLiteral("2013-S1"));
SKGTEST(QStringLiteral("CONV:dateToPeriod"), SKGServices::dateToPeriod(QDate(2013, 03, 05), QStringLiteral("Y")), QStringLiteral("2013"));
SKGTEST(QStringLiteral("CONV:intToString"), SKGServices::intToString(10), QStringLiteral("10"));
SKGTEST(QStringLiteral("CONV:intToString"), SKGServices::intToString(5490990004), QStringLiteral("5490990004"));
SKGTEST(QStringLiteral("CONV:stringToInt"), SKGServices::stringToInt(QStringLiteral("56")), 56);
SKGTEST(QStringLiteral("CONV:stringToInt"), SKGServices::stringToInt(QStringLiteral("HELLO")), 0);
SKGTEST(QStringLiteral("CONV:stringToInt"), SKGServices::stringToInt(QStringLiteral("5HELLO")), 0);
SKGTEST(QStringLiteral("CONV:stringToInt"), SKGServices::stringToInt(QStringLiteral("5490990004")), 5490990004);
SKGTEST(QStringLiteral("CONV:doubleToString"), SKGServices::doubleToString(10), QStringLiteral("10"));
SKGTEST(QStringLiteral("CONV:doubleToString"), SKGServices::doubleToString(5.3), QStringLiteral("5.3"));
SKGTEST(QStringLiteral("CONV:doubleToString"), SKGServices::doubleToString(11111115.33), QStringLiteral("11111115.33"));
SKGTEST(QStringLiteral("CONV:doubleToString"), SKGServices::doubleToString(119999.11), QStringLiteral("119999.11"));
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("10")) - 10, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("5.3")) - 5.3, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("11111115.33")) - 11111115.33, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("25,000.00")) - 25000.00, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("1.307,40")) - 1307.40, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("2 150,10")) - 2150.10, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("-$8.35")) + 8.35, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("8.35€")) - 8.35, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("1234.56e-02")) - 12.3456, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("31238/100")) - 312.38, 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("31238/abc")), 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("nan")), 0);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("inf")), 1e300);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("-inf")), -1e300);
SKGTEST(QStringLiteral("CONV:stringToDouble"), SKGServices::stringToDouble(QStringLiteral("00000000194065")), 194065);
SKGServices::timeToString(QDateTime());
SKGTEST(QStringLiteral("CONV:stringToTime"), SKGServices::timeToString(SKGServices::stringToTime(QStringLiteral("1970-07-16"))), QStringLiteral("1970-07-16 00:00:00"));
SKGTEST(QStringLiteral("CONV:stringToTime"), SKGServices::timeToString(SKGServices::stringToTime(QStringLiteral("2008-04-20"))), QStringLiteral("2008-04-20 00:00:00"));
SKGTEST(QStringLiteral("CONV:stringToTime"), SKGServices::dateToSqlString(SKGServices::stringToTime(QStringLiteral("1970-07-16"))), QStringLiteral("1970-07-16"));
SKGTEST(QStringLiteral("CONV:stringToTime"), SKGServices::dateToSqlString(SKGServices::stringToTime(QStringLiteral("2008-04-20"))), QStringLiteral("2008-04-20"));
SKGTESTBOOL("CONV:SKGServices::getMicroTime", (SKGServices::getMicroTime() > 0), true);
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("20080525"), QStringLiteral("YYYYMMDD")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("2008-05-25"), QStringLiteral("YYYY-MM-DD")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("2008-05-25 00:00:00"), QStringLiteral("YYYY-MM-DD")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("05/25/08"), QStringLiteral("MM/DD/YY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("05/25/78"), QStringLiteral("MM/DD/YY")), QStringLiteral("1978-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("05-25-08"), QStringLiteral("MM-DD-YY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("05-25-78"), QStringLiteral("MM-DD-YY")), QStringLiteral("1978-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5/25/08"), QStringLiteral("MM/DD/YY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5/25/78"), QStringLiteral("MM/DD/YY")), QStringLiteral("1978-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5-25-08"), QStringLiteral("MM-DD-YY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5-6-08"), QStringLiteral("MM-DD-YY")), QStringLiteral("2008-05-06"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5-25-78"), QStringLiteral("MM-DD-YY")), QStringLiteral("1978-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("25/05/08"), QStringLiteral("DD/MM/YY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("25/05/78"), QStringLiteral("DD/MM/YY")), QStringLiteral("1978-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("25-05-08"), QStringLiteral("DD-MM-YY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("25-05-78"), QStringLiteral("DD-MM-YY")), QStringLiteral("1978-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("25/05/2008"), QStringLiteral("DD/MM/YYYY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("25-05-2008"), QStringLiteral("DD-MM-YYYY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5/25/2008"), QStringLiteral("MM/DD/YYYY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5-25-2008"), QStringLiteral("MM-DD-YYYY")), QStringLiteral("2008-05-25"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5-6-2008"), QStringLiteral("MM-DD-YYYY")), QStringLiteral("2008-05-06"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("5-6-8"), QStringLiteral("MM-DD-YYYY")), QStringLiteral("2008-05-06"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("3.21.01"), QStringLiteral("MM-DD-YY")), QStringLiteral("2001-03-21"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("1/ 1' 6"), QStringLiteral("DD-MM-YY")), QStringLiteral("2006-01-01"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("6/ 1/94"), QStringLiteral("DD-MM-YY")), QStringLiteral("1994-01-06"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("21/12'2001"), QStringLiteral("DD-MM-YYYY")), QStringLiteral("2001-12-21"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("21122001"), QStringLiteral("DDMMYYYY")), QStringLiteral("2001-12-21"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("12212001"), QStringLiteral("MMDDYYYY")), QStringLiteral("2001-12-21"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("010203"), QStringLiteral("MMDDYY")), QStringLiteral("2003-01-02"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("010203"), QStringLiteral("DDMMYY")), QStringLiteral("2003-02-01"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("3/9/04"), QStringLiteral("DD-MM-YY")), QStringLiteral("2004-09-03"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31Dec2005"), QStringLiteral("DDMMMYYYY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31-Dec-2005"), QStringLiteral("DD-MMM-YYYY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31/Dec/2005"), QStringLiteral("DD/MMM/YYYY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31Dec05"), QStringLiteral("DDMMMYY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31-Dec-05"), QStringLiteral("DD-MMM-YY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31/Dec/05"), QStringLiteral("DD/MMM/YY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("31DEC2005"), QStringLiteral("DDMMMYYYY")), QStringLiteral("2005-12-31"));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("INVALIDDATE"), QStringLiteral("DD-MM-YY")), SKGServices::dateToSqlString(QDateTime::currentDateTime()));
SKGTEST(QStringLiteral("STR:dateToSqlString"), SKGServices::dateToSqlString(QStringLiteral("02.01.2015"), QStringLiteral("DD-MM-YYYY")), QStringLiteral("2015-01-02"));
}
void test_nbWorkingDays(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("SKGServices::nbWorkingDays"), SKGServices::nbWorkingDays(QDate(2010, 9, 3), QDate(2010, 9, 6)), 1);
SKGTEST(QStringLiteral("SKGServices::nbWorkingDays"), SKGServices::nbWorkingDays(QDate(2010, 9, 6), QDate(2010, 9, 3)), 1);
SKGTEST(QStringLiteral("SKGServices::nbWorkingDays"), SKGServices::nbWorkingDays(QDate(2010, 9, 3), QDate(2010, 9, 3)), 1);
SKGTEST(QStringLiteral("SKGServices::nbWorkingDays"), SKGServices::nbWorkingDays(QDate(2010, 9, 1), QDate(2010, 9, 3)), 2);
SKGTEST(QStringLiteral("SKGServices::nbWorkingDays"), SKGServices::nbWorkingDays(QDate(2010, 9, 1), QDate(2010, 9, 8)), 5);
}
void test_getnext(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("SKGServices::getNextString"), SKGServices::getNextString(QStringLiteral("12345")), QStringLiteral("12346"));
SKGTEST(QStringLiteral("SKGServices::getNextString"), SKGServices::getNextString(QStringLiteral("9")), QStringLiteral("10"));
}
void test_errors(int& nberror, int& nbcheck, bool showonlyfailures)
{
{
SKGTraces::cleanProfilingStatistics();
SKGError err;
SKGTEST(QStringLiteral("ERR:Default RC"), err.getReturnCode(), 0);
SKGTEST(QStringLiteral("ERR:Default RC"), err.getReturnCode(), 0);
SKGTESTBOOL("ERR:isWarning", err.isWarning(), false);
SKGTESTBOOL("ERR:isSucceeded", err.isSucceeded(), true);
SKGTESTBOOL("ERR:isFailed", err.isFailed(), false);
SKGTESTBOOL("ERR:!", !err, true);
SKGTESTBOOL("ERR:operator bool", err, false);
SKGTESTBOOL("ERR:getPreviousError", (err.getPreviousError() == nullptr), true);
SKGTEST(QStringLiteral("ERR:Default message"), err.getMessage(), QLatin1String(""));
err.setReturnCode(10);
err.setMessage(QStringLiteral("Invalid parameter"));
SKGTEST(QStringLiteral("ERR:getHistoricalSize"), err.getHistoricalSize(), 0);
SKGTEST(QStringLiteral("ERR:RC 10"), err.getReturnCode(), 10);
SKGTEST(QStringLiteral("ERR:MSG Invalid parameter"), err.getMessage(), QStringLiteral("Invalid parameter"));
err.addError(11, QStringLiteral("Message 11"));
SKGTESTBOOL("ERR:isWarning", err.isWarning(), false);
SKGTESTBOOL("ERR:isSucceeded", err.isSucceeded(), false);
SKGTESTBOOL("ERR:isFailed", err.isFailed(), true);
SKGTESTBOOL("ERR:!", !err, false);
SKGTESTBOOL("ERR:operator bool", err, true);
SKGTEST(QStringLiteral("ERR:getHistoricalSize"), err.getHistoricalSize(), 1);
err.addError(-12, QStringLiteral("Message 12"));
SKGTESTBOOL("ERR:isWarning", err.isWarning(), true);
SKGTESTBOOL("ERR:isSucceeded", err.isSucceeded(), true);
SKGTESTBOOL("ERR:isFailed", err.isFailed(), false);
SKGTESTBOOL("ERR:!", !err, true);
SKGTESTBOOL("ERR:operator bool", err, false);
SKGTEST(QStringLiteral("ERR:getHistoricalSize"), err.getHistoricalSize(), 2);
SKGTEST(QStringLiteral("ERR:getFullMessageWithHistorical"), err.getFullMessageWithHistorical(), QStringLiteral("[WAR--12]: Message 12\n[ERR-11]: Message 11\n[ERR-10]: Invalid parameter"));
}
{
SKGTraces::cleanProfilingStatistics();
SKGError err;
err.setReturnCode(10).setMessage(QStringLiteral("Invalid parameter")).addError(11, QStringLiteral("Message 11"));
SKGTEST(QStringLiteral("ERR:getHistoricalSize"), err.getHistoricalSize(), 1);
SKGTEST(QStringLiteral("ERR:RC 10"), err.getReturnCode(), 11);
SKGTEST(QStringLiteral("ERR:MSG Message 11"), err.getMessage(), QStringLiteral("Message 11"));
}
}
void test_getDateFormat(int& nberror, int& nbcheck, bool showonlyfailures)
{
{
QStringList dates;
dates << QStringLiteral("19/08/2008");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("20080819");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("YYYYMMDD"));
}
{
QStringList dates;
dates << QStringLiteral("10141989");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("MMDDYYYY"));
}
{
QStringList dates;
dates << QStringLiteral("14101989");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DDMMYYYY"));
}
{
QStringList dates;
dates << QStringLiteral("05/08/2008") << QStringLiteral("19/08/2008");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("19/ 1' 6");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("21/12'2001");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("6/ 1/94");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("10.29.07");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("MM-DD-YY"));
}
{
QStringList dates;
dates << QStringLiteral("10.05.07");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YY"));
}
{
QStringList dates;
dates << QStringLiteral("2001.10.25");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("YYYY-MM-DD"));
}
{
QStringList dates;
dates << QStringLiteral("45450116");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("YYYYMMDD"));
}
{
QStringList dates;
dates << QStringLiteral("7/14' 0") << QStringLiteral("11/30/99");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("MM-DD-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("10/ 8'10");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("7/8/06");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YY"));
}
{
QStringList dates;
dates << QStringLiteral("7/8/06") << QStringLiteral("11/30/99") << QStringLiteral("7/14' 0");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("MM-DD-YYYY"));
}
{
QStringList dates;
dates << QStringLiteral("3/9/04");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YY"));
}
{
QStringList dates;
dates << QStringLiteral("31Dec2005");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DDMMMYYYY"));
}
{
QStringList dates;
dates << QStringLiteral("31-Dec-05");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MMM-YY"));
}
{
QStringList dates;
dates << QStringLiteral("2008-05-25 00:00:00");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("YYYY-MM-DD"));
}
{
QStringList dates;
dates << QStringLiteral("2008-05-25 01:02:03");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("YYYY-MM-DD"));
}
{
QStringList dates;
QFile inputFile(SKGTest::getTestPath(QStringLiteral("IN")) % "/dates.txt");
if (inputFile.open(QIODevice::ReadOnly)) {
QTextStream in(&inputFile);
while (!in.atEnd()) {
QString l = in.readLine().trimmed();
if (!l.isEmpty()) {
dates << l;
}
}
inputFile.close();
}
SKGTEST(QStringLiteral("STR:dats.count"), dates.count(), 2364);
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("MM-DD-YY"));
}
{
QStringList dates;
dates << QStringLiteral(" 7/8/06 ") << QLatin1String("");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QStringLiteral("DD-MM-YY"));
}
{
QStringList dates;
dates << QStringLiteral("99999999") << QStringLiteral("9999999999");
SKGTEST(QStringLiteral("STR:getDateFormat"), SKGServices::getDateFormat(dates), QLatin1String(""));
}
}
void test_csv(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGTEST(QStringLiteral("STR:stringToCsv"), SKGServices::stringToCsv(QStringLiteral("ABC")), QStringLiteral("\"ABC\""));
SKGTEST(QStringLiteral("STR:stringToCsv"), SKGServices::stringToCsv(QStringLiteral("ABC;CDE")), QStringLiteral("\"ABC;CDE\""));
SKGTEST(QStringLiteral("STR:stringToCsv"), SKGServices::stringToCsv(QStringLiteral("AB \"C\" DE")), QStringLiteral("\"AB \"\"C\"\" DE\""));
SKGTEST(QStringLiteral("STR:stringToCsv"), SKGServices::stringToCsv(QStringLiteral("AB \"C\";DE")), QStringLiteral("\"AB \"\"C\"\";DE\""));
QStringList parameters = SKGServices::splitCSVLine(QStringLiteral("52.33,\"9/28/2010\",52.36,231803,52.33,0.00,+0.15,-,0.00,-,0.00,0.00,0.00,0.00,\"- - -\",\"-\",-,\"n\",N/A,0,+15.82,+43.33%,9,672,-1.08,-2.02%,-,-,\"51.76 - 52.57\",0.00,0.00,N/A,N/A,N/A,N/A,\"-\",51.91,52.18,-,\"+0.29%\",N/A,N/A,\"N/A\",N/A,\"N/A\",N/A,N/A,N/A,-,N/A,\"11:35am\",N/A,211524,-,\"36.51 - 53.41\",\"- - +0.29%\",\"Paris\",N/A,\"DASSAULT SYST.\""), ',');
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 59);
parameters = SKGServices::splitCSVLine(QStringLiteral("2013-04-02;transfer;\"a2\";'some text 2';-20,13"), ';', true);
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 5);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("2013-04-02"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("transfer"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[2], QStringLiteral("a2"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[3], QStringLiteral("some text 2"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[4], QStringLiteral("-20,13"));
parameters = SKGServices::splitCSVLine(QStringLiteral("\"A;'B\";'A;\"B'"), ';', true);
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A;'B"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("A;\"B"));
SKGTEST(QStringLiteral("STR:stringToHtml"), SKGServices::stringToHtml(QStringLiteral("&")), QStringLiteral("<hello>&<world>"));
SKGTEST(QStringLiteral("STR:htmlToString"), SKGServices::htmlToString(QStringLiteral("<hello>&<world>")), QStringLiteral("&"));
parameters = SKGServices::splitCSVLine(SKGServices::stringToCsv(QStringLiteral("Y")) % ';' % SKGServices::stringToCsv(QStringLiteral("A;B")));
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("Y"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("A;B"));
parameters = SKGServices::splitCSVLine(QStringLiteral("A;\"B;C\";D"));
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 3);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("B;C"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[2], QStringLiteral("D"));
parameters = SKGServices::splitCSVLine(QStringLiteral("'A';'B'"));
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("B"));
parameters = SKGServices::splitCSVLine(QStringLiteral("\"A ' B\",\"C\""));
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A ' B"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("C"));
parameters = SKGServices::splitCSVLine(QStringLiteral("'A \" B','C'"));
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A \" B"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("C"));
QChar realsep;
parameters = SKGServices::splitCSVLine(QStringLiteral("\"A\",18,\"B\""), ';', true, &realsep);
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 3);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("18"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[2], QStringLiteral("B"));
SKGTEST(QStringLiteral("STR:sep"), realsep, ',');
parameters = SKGServices::splitCSVLine(QStringLiteral("30/05/2008;RETRAIT ESPECES AGENCE; ; 100,00;DEBIT;"));
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 6);
parameters = SKGServices::splitCSVLine(QStringLiteral("A|\"B\";\"C\""), '|', false);
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("A"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("\"B\";\"C\""));
parameters = SKGServices::splitCSVLine(QStringLiteral("+123 \"-abc def\" \"e:f\" e:f"), ' ', true);
SKGTEST(QStringLiteral("STR:splitCSVLine count"), parameters.count(), 4);
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[0], QStringLiteral("+123"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[1], QStringLiteral("-abc def"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[2], QStringLiteral("e:f"));
SKGTEST(QStringLiteral("STR:splitCSVLine"), parameters[3], QStringLiteral("e:f"));
SKGTEST(QStringLiteral("STR:splitCSVLine words"), SKGServices::splitCSVLine(QStringLiteral("w1 w2"), ' ', true).count(), 2);
SKGTEST(QStringLiteral("STR:splitCSVLine words"), SKGServices::splitCSVLine(QStringLiteral("\"w1 w1\""), ' ', true).count(), 1);
SKGTEST(QStringLiteral("STR:splitCSVLine words"), SKGServices::splitCSVLine(QStringLiteral("\"w1 w1\" w2 \"w3 w3 w3\" w4"), ' ', true).count(), 4);
}
void test_stringToSearchCriterias(int& nberror, int& nbcheck, bool showonlyfailures)
{
SKGServices::SKGSearchCriteriaList criterias = SKGServices::stringToSearchCriterias(QStringLiteral("abc +def +ghi"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 3);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QStringLiteral("ghi"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[1].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[1].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[1].words[0], QStringLiteral("def"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[2].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[2].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[2].words[0], QStringLiteral("abc"));
criterias = SKGServices::stringToSearchCriterias(QStringLiteral("-abc +def ghi"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 2);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 2);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QStringLiteral("def"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[1], QStringLiteral("ghi"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[1].mode, '-');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[1].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[1].words[0], QStringLiteral("abc"));
criterias = SKGServices::stringToSearchCriterias(QStringLiteral("-abc +def ghi -10"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 2);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 3);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QStringLiteral("def"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[1], QStringLiteral("ghi"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[2], QStringLiteral("-10"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[1].mode, '-');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[1].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[1].words[0], QStringLiteral("abc"));
criterias = SKGServices::stringToSearchCriterias(QStringLiteral("-10"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QStringLiteral("-10"));
criterias = SKGServices::stringToSearchCriterias(QStringLiteral("-abc"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 2);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QLatin1String(""));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[1].mode, '-');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[1].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[1].words[0], QStringLiteral("abc"));
criterias = SKGServices::stringToSearchCriterias(QStringLiteral("\"abc def ghi\" \"123 456\""));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 2);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QStringLiteral("abc def ghi"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[1], QStringLiteral("123 456"));
criterias = SKGServices::stringToSearchCriterias(QStringLiteral("\"-payee:abc def : ghi\" +amount:25"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias count"), criterias.count(), 2);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[0].mode, '+');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[0].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[0].words[0], QStringLiteral("amount:25"));
SKGTEST(QStringLiteral("STR:stringToSearchCriterias mode"), criterias[1].mode, '-');
SKGTEST(QStringLiteral("STR:stringToSearchCriterias words count"), criterias[1].words.count(), 1);
SKGTEST(QStringLiteral("STR:stringToSearchCriterias word"), criterias[1].words[0], QStringLiteral("payee:abc def : ghi"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(d_DATEOP) LIKE '%toto%' OR lower(i_number) LIKE '%toto%' OR lower(t_PAYEE) LIKE '%toto%' OR lower(t_bookmarked) LIKE '%toto%'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("i_num:ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(i_number) LIKE '%toto%'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("i_num=1234")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((i_number=1234))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_PAYEE>ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(t_PAYEE)>'toto'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_PAYEE=ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(t_PAYEE)>='toto'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_PAYEE<=ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(t_PAYEE)<='toto'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_PAYEE=ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(t_PAYEE)='toto'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_PAYEE#^t[o|a]to$")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((REGEXP('^t[o|a]to$',t_PAYEE)))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("+i_number<20 +i_number>30")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((i_number>30)) OR ((i_number<20))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("d_DATEOP>2015-05-04")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("((lower(d_DATEOP)>'2015-05-04'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("notfound:ToTo")),
QStringList() << QStringLiteral("d_DATEOP") << QStringLiteral("i_number") << QStringLiteral("t_PAYEE") << QStringLiteral("t_bookmarked"), nullptr),
QStringLiteral("(1=0)"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("v1 v2 +v3 -v4 -v5")),
QStringList() << QStringLiteral("t_comment"), nullptr),
QStringLiteral("((lower(t_comment) LIKE '%v3%')) OR ((lower(t_comment) LIKE '%v1%') AND (lower(t_comment) LIKE '%v2%')) AND NOT((lower(t_comment) LIKE '%v4%')) AND NOT((lower(t_comment) LIKE '%v5%'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("v1 v2 +v3 -v4 -v5")),
QStringList() << QStringLiteral("t_comment"), nullptr, true),
QStringLiteral("(((t_comment:v3) and ((t_comment:v1) and (t_comment:v2))) and not (t_comment:v4)) and not (t_comment:v5)"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("-v5")),
QStringList() << QStringLiteral("t_comment"), nullptr),
QStringLiteral("((lower(t_comment) LIKE '%%')) AND NOT((lower(t_comment) LIKE '%v5%'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("a'b")),
QStringList() << QStringLiteral("t_comment"), nullptr),
QStringLiteral("((lower(t_comment) LIKE '%a''b%'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("-v5")),
QStringList() << QStringLiteral("t_comment"), nullptr, true),
QStringLiteral("(t_comment:) and not (t_comment:v5)"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral(":ToTo")),
QStringList() << QStringLiteral("p_prop1") << QStringLiteral("p_prop2"), nullptr),
QStringLiteral("((i_PROPPNAME='prop1' AND (lower(i_PROPVALUE) LIKE '%toto%') OR i_PROPPNAME='prop2' AND (lower(i_PROPVALUE) LIKE '%toto%')))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral(":ToTo")),
QStringList() << QStringLiteral("p_prop1") << QStringLiteral("p_prop2"), nullptr, true),
QStringLiteral("p_prop1:toto or p_prop2:toto"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("#ToTo")),
QStringList() << QStringLiteral("p_prop1") << QStringLiteral("p_prop2"), nullptr),
QStringLiteral("((i_PROPPNAME='prop1' AND REGEXP('toto',i_PROPVALUE) OR i_PROPPNAME='prop2' AND REGEXP('toto',i_PROPVALUE)))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_att>10")),
QStringList() << QStringLiteral("t_att") << QStringLiteral("t_att1"), nullptr),
QStringLiteral("((lower(t_att)>'10' OR lower(t_att1)>'10'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_att.>10")),
QStringList() << QStringLiteral("t_att") << QStringLiteral("t_att1"), nullptr),
QStringLiteral("((lower(t_att)>'10'))"));
SKGTEST(QStringLiteral("STR:searchCriteriasToWhereClause"),
SKGServices::searchCriteriasToWhereClause(SKGServices::stringToSearchCriterias(QStringLiteral("t_att.>10")),
QStringList() << QStringLiteral("t_att") << QStringLiteral("t_att1"), nullptr, true),
QStringLiteral("t_att>10"));
}
int main(int argc, char** argv)
{
Q_UNUSED(argc);
Q_UNUSED(argv);
-#if QT_VERSION < 0x050700
- KLocale::global()->setNegativePrefixCurrencySymbol(false);
- KLocale::global()->setPositivePrefixCurrencySymbol(false);
-#endif
-
// Init test
SKGINITTEST(true);
// Test class SKGError
test_errors(nberror, nbcheck, showonlyfailures);
// SKGServices
{
test_getPeriodWhereClause(nberror, nbcheck, showonlyfailures);
test_getNeighboringPeriod(nberror, nbcheck, showonlyfailures);
test_periodToDate(nberror, nbcheck, showonlyfailures);
test_partialStringToDate(nberror, nbcheck, showonlyfailures);
test_conversions(nberror, nbcheck, showonlyfailures);
test_nbWorkingDays(nberror, nbcheck, showonlyfailures);
test_getDateFormat(nberror, nbcheck, showonlyfailures);
test_csv(nberror, nbcheck, showonlyfailures);
test_stringToSearchCriterias(nberror, nbcheck, showonlyfailures);
test_getnext(nberror, nbcheck, showonlyfailures);
// Various test
SKGStringListList table;
table.push_back(QStringList() << QStringLiteral("Person") << QStringLiteral("Salary") << QStringLiteral("Age"));
table.push_back(QStringList() << QStringLiteral("John") << QStringLiteral("58000") << QStringLiteral("33"));
table.push_back(QStringList() << QStringLiteral("Paul") << QStringLiteral("42000") << QStringLiteral("25"));
table.push_back(QStringList() << QStringLiteral("Alan") << QStringLiteral("65000") << QStringLiteral("41"));
SKGServices::getBase100Table(table);
SKGServices::getPercentTable(table, true, false);
SKGServices::getPercentTable(table, false, true);
SKGServices::getHistorizedTable(table);
SKGTEST(QStringLiteral("STR:encodeForUrl"), SKGServices::encodeForUrl(QStringLiteral("abc")), QStringLiteral("abc"));
SKGTEST(QStringLiteral("STR:getMajorVersion"), SKGServices::getMajorVersion(QStringLiteral("4.3.12.3")), QStringLiteral("4.3"));
SKGTEST(QStringLiteral("STR:getMajorVersion"), SKGServices::getMajorVersion(QStringLiteral("4.3.12")), QStringLiteral("4.3"));
SKGTEST(QStringLiteral("STR:getMajorVersion"), SKGServices::getMajorVersion(QStringLiteral("4.3")), QStringLiteral("4.3"));
SKGTEST(QStringLiteral("STR:getMajorVersion"), SKGServices::getMajorVersion(QStringLiteral("4")), QStringLiteral("4"));
SKGTEST(QStringLiteral("STR:toCurrencyString"), SKGServices::toCurrencyString(5.12341234, QStringLiteral("F"), 2).remove(' '), QStringLiteral("5.12F"));
SKGTEST(QStringLiteral("STR:toCurrencyString"), SKGServices::toCurrencyString(-5.12341234, QStringLiteral("F"), 4).remove(' '), QStringLiteral("-5.1234F"));
SKGTEST(QStringLiteral("STR:toPercentageString"), SKGServices::toPercentageString(5.12341234, 2), QStringLiteral("5.12 %"));
SKGTEST(QStringLiteral("STR:toPercentageString"), SKGServices::toPercentageString(5.12341234, 4), QStringLiteral("5.1234 %"));
QByteArray tmp;
SKGTESTERROR(QStringLiteral("STR:downloadToStream"), SKGServices::downloadToStream(QUrl::fromLocalFile(QStringLiteral("notfound")), tmp), false);
SKGTEST(QStringLiteral("STR:getFullPathCommandLine"), SKGServices::getFullPathCommandLine(QStringLiteral("skrooge-release.py --help")), QStringLiteral("skrooge-release.py --help"));
}
// End test
SKGENDTEST();
}
diff --git a/tests/skgbasemodelertest/skgtestmultidocument.cpp b/tests/skgbasemodelertest/skgtestmultidocument.cpp
index 511834d78..b9daf7dfb 100644
--- a/tests/skgbasemodelertest/skgtestmultidocument.cpp
+++ b/tests/skgbasemodelertest/skgtestmultidocument.cpp
@@ -1,311 +1,303 @@
/**********************"*****************************************************
* Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see *
***************************************************************************/
/** @file
* This file is a test script.
*
* @author Stephane MANKOWSKI / Guillaume DE BURE
*/
#include "skgtestmacro.h"
-#if QT_VERSION < 0x050700
-#include
-#endif
#include
#include
#include
void dumpConnections()
{
const auto conNames = QSqlDatabase::connectionNames();
for (const auto& conName : conNames) {
SKGTRACE << "### " << conName << " ###" << endl;
auto con = QSqlDatabase::database(conName, false);
SKGTRACE << " connectionName=" << con.connectionName() << endl;
SKGTRACE << " connectOptions=" << con.connectOptions() << endl;
SKGTRACE << " isOpen=" << (con.isOpen() ? "Y" : "N") << endl;
}
}
/**
* The main function of the unit test
* @param argc the number of arguments
* @param argv the list of arguments
*/
int main(int argc, char** argv)
{
Q_UNUSED(argc);
Q_UNUSED(argv);
-#if QT_VERSION < 0x050700
- KLocale::global()->setNegativePrefixCurrencySymbol(false);
- KLocale::global()->setPositivePrefixCurrencySymbol(false);
-#endif
-
// Init test
SKGINITTEST(true);
// test class SKGDocument / PARAMETERS
SKGDocument document1;
SKGTESTERROR(QStringLiteral("PARAM:initialize"), document1.initialize(), true);
SKGTESTERROR(QStringLiteral("PARAM:close"), document1.close(), true);
SKGTESTERROR(QStringLiteral("PARAM:initialize"), document1.initialize(), true);
SKGTESTERROR(QStringLiteral("PARAM:beginTransaction"), document1.beginTransaction(QStringLiteral("t1")), true);
SKGTESTERROR(QStringLiteral("PARAM:setParameter"), document1.setParameter(QStringLiteral("ATT1"), QStringLiteral("VAL1")), true);
SKGTESTERROR(QStringLiteral("PARAM:endTransaction"), document1.endTransaction(true), true);
SKGTEST(QStringLiteral("PARAM:getCachedValue"), document1.getCachedValue(QStringLiteral("NOTFOUND")), QLatin1String(""));
SKGDocument document2;
SKGTESTERROR(QStringLiteral("PARAM:initialize"), document2.initialize(), true);
SKGTESTERROR(QStringLiteral("PARAM:beginTransaction"), document2.beginTransaction(QStringLiteral("t2")), true);
SKGTESTERROR(QStringLiteral("PARAM:setParameter"), document2.setParameter(QStringLiteral("ATT2"), QStringLiteral("VAL2")), true);
SKGTESTERROR(QStringLiteral("PARAM:setParameter"), document2.setParameter(QStringLiteral("ATT3"), QStringLiteral("dates.txt"), SKGTest::getTestPath(QStringLiteral("IN")) % "/dates.txt"), true);
SKGTESTERROR(QStringLiteral("PARAM:endTransaction"), document2.endTransaction(true), true);
SKGTEST(QStringLiteral("PARAM:getParameter"), document1.getParameter(QStringLiteral("ATT1")), QStringLiteral("VAL1"));
SKGTEST(QStringLiteral("PARAM:getParameter"), document2.getParameter(QStringLiteral("ATT2")), QStringLiteral("VAL2"));
SKGTEST(QStringLiteral("PARAM:getFileExtension"), document2.getFileExtension(), QStringLiteral("skgc"));
document1.formatPercentage(1.1, true);
document1.formatPercentage(1.1, false);
SKGTEST(QStringLiteral("PARAM:getRealAttribute"), document2.getRealAttribute(QStringLiteral("t_ATT")), QLatin1String(""));
SKGTEST(QStringLiteral("PARAM:getRealAttribute"), document2.getRealAttribute(QStringLiteral("t_att")), QStringLiteral("t_att"));
document1.getDatabaseIdentifier();
document1.getParameters(QStringLiteral("document"), QStringLiteral("t_name like 'ATT%'"));
// Special SQL command
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSqliteOrder(QStringLiteral("SELECT * FROM (SELECT CAPITALIZE(LOWER(UPPER(WORD('Abc Def', 2)))) AS V) WHERE REGEXP('D.*', V) AND WILDCARD('D*', V)")), true);
QString result;
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT TODATE('07162013', 'MMDDYYYY')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-TODATE"), result, QStringLiteral("2013-07-16"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT TOFORMATTEDDATE('2013-07-16', 'dd-MM-yyyy')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-TODATE"), result, QStringLiteral("16-07-2013"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT TOFORMATTEDDATE('2013-07-16', 'd M yy')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-TODATE"), result, QStringLiteral("16 7 13"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT TODATE('ABCDEFGHIJ', 'MMDDYYYY')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-TODATE"), result, SKGServices::dateToSqlString(QDate::currentDate()));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', 0)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Abc"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', 1)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Abc"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', 2)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Def"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', 3)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Ghi"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', 99)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Ghi"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', -99)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Abc"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', -3)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Abc"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', -2)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Def"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('Abc Def Ghi', -1)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Ghi"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD(' Abc Def Ghi ', 1)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Abc"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD(' Abc Def Ghi ', 2)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Def"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD(' Abc Def Ghi ', 3)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("Ghi"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('N:1234', 1)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("N"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT WORD('N:1234', 2)"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-WORD"), result, QStringLiteral("1234"));
QMap map;
map[QStringLiteral(":2")] = "20";
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSqliteOrder(QStringLiteral("SELECT WORD('Abc Def', :2)"), map, nullptr), true);
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT TOCURRENCY(1234, 'F')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-1234 F"), result.remove(' '), QStringLiteral("1,234.00F"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT TOCURRENCY(-1234, (SELECT 'F'))"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-1234 F"), result.remove(' '), QStringLiteral("-1,234.00F"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD((SELECT '2013-03-05'), (SELECT 'D'))"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD D"), result, QStringLiteral("2013-03-05"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2013-03-05', 'W')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD W"), result, QStringLiteral("2013-W10"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2013-03-05', 'M')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD M"), result, QStringLiteral("2013-03"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2013-03-05', 'Q')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD Q"), result, QStringLiteral("2013-Q1"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2013-03-05', 'S')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD S"), result, QStringLiteral("2013-S1"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2013-03-05', 'Y')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD Y"), result, QStringLiteral("2013"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2014-07-16', 'D')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD D"), result, QStringLiteral("2014-07-16"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2014-07-16', 'W')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD W"), result, QStringLiteral("2014-W29"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2014-07-16', 'M')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD M"), result, QStringLiteral("2014-07"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2014-07-16', 'Q')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD Q"), result, QStringLiteral("2014-Q3"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2014-07-16', 'S')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD S"), result, QStringLiteral("2014-S2"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT PERIOD('2014-07-16', 'Y')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-PERIOD Y"), result, QStringLiteral("2014"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT NEXT('12345')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-NEXT"), result, QStringLiteral("12346"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT NEXT('9')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-NEXT"), result, QStringLiteral("10"));
SKGTESTERROR(QStringLiteral("PARAM:executeSqliteOrder"), document1.executeSingleSelectSqliteOrder(QStringLiteral("SELECT NEXT('ABC')"), result), true);
SKGTEST(QStringLiteral("PARAM:executeSqliteOrder-NEXT"), result, QLatin1String(""));
SKGTRACE << "####### Before concurrent calls" << endl;
dumpConnections();
int nb = 5;
{
SKGTRACE << ">> executeSelectSqliteOrder same order" << endl;
QString output;
double elapse = SKGServices::getMicroTime();
for (int i = 0; i < nb; ++i) {
SKGStringListList oResult;
IFOK(document1.executeSelectSqliteOrder(QStringLiteral("SELECT SLEEP(1)"), oResult)) {
output = output + SKGServices::intToString(oResult.count());
}
}
double time = SKGServices::getMicroTime() - elapse;
SKGTRACE << nb << " x executeSelectSqliteOrder:" << output << " " << time << " ms" << endl;
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO >=1000"), static_cast(time >= 1000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO <2000"), static_cast(time < 2000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder"), output, QStringLiteral("22222"));
}
{
SKGTRACE << ">> concurrentExecuteSelectSqliteOrder same order" << endl;
QString output;
double elapse = SKGServices::getMicroTime();
for (int i = 0; i < nb; ++i) {
document1.concurrentExecuteSelectSqliteOrder(QStringLiteral("SELECT SLEEP(1), 2"),
[ &output ](const SKGStringListList & iResult) {
output = output + SKGServices::intToString(iResult.count());
});
}
double time = SKGServices::getMicroTime() - elapse;
SKGTRACE << nb << " x concurrentExecuteSelectSqliteOrder:" << output << " " << (SKGServices::getMicroTime() - elapse) << " ms" << endl;
qApp->processEvents(QEventLoop::AllEvents, 500);
for (int i = 1; i < 100; ++i) {
QThread::msleep(100);
qApp->processEvents(QEventLoop::AllEvents, 500);
time = SKGServices::getMicroTime() - elapse;
if (output == QStringLiteral("22222")) {
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO >=1000"), static_cast(time >= 1000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO <3500"), static_cast(time < 3500), static_cast(true));
break;
}
}
SKGTRACE << nb << " x concurrentExecuteSelectSqliteOrder:" << output << " " << time << " ms" << endl;
SKGTEST(QStringLiteral("PARAM:concurrentExecuteSelectSqliteOrder"), output, QStringLiteral("22222"));
}
{
SKGTRACE << ">> executeSelectSqliteOrder different orders" << endl;
QString output;
double elapse = SKGServices::getMicroTime();
for (int i = 0; i < nb; ++i) {
SKGStringListList oResult;
IFOK(document1.executeSelectSqliteOrder(QStringLiteral("SELECT SLEEP(1), ") + SKGServices::intToString(1000 + i), oResult)) {
output = output + SKGServices::intToString(oResult.count());
}
}
double time = SKGServices::getMicroTime() - elapse;
SKGTRACE << nb << " x executeSelectSqliteOrder:" << output << " " << time << " ms" << endl;
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO >5000"), static_cast(time > 5000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO <6000"), static_cast(time < 6000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder"), output, QStringLiteral("22222"));
}
{
SKGTRACE << ">> concurrentExecuteSelectSqliteOrder different orders" << endl;
QString output;
double elapse = SKGServices::getMicroTime();
for (int i = 0; i < nb; ++i) {
document1.concurrentExecuteSelectSqliteOrder(QStringLiteral("SELECT SLEEP(1), ") + SKGServices::intToString(2000 + i),
[ &output ](const SKGStringListList & iResult) {
output = output + SKGServices::intToString(iResult.count());
});
}
double time = SKGServices::getMicroTime() - elapse;
SKGTRACE << nb << " x concurrentExecuteSelectSqliteOrder:" << output << " " << (SKGServices::getMicroTime() - elapse) << " ms" << endl;
qApp->processEvents(QEventLoop::AllEvents, 500);
for (int i = 1; i < 100; ++i) {
QThread::msleep(100);
qApp->processEvents(QEventLoop::AllEvents, 500);
time = SKGServices::getMicroTime() - elapse;
if (output == QStringLiteral("22222")) {
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO >=1000"), static_cast(time >= 1000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO <3500"), static_cast(time < 3500), static_cast(true));
break;
}
}
SKGTRACE << nb << " x concurrentExecuteSelectSqliteOrder:" << output << " " << time << " ms" << endl;
SKGTEST(QStringLiteral("PARAM:concurrentExecuteSelectSqliteOrder"), output, QStringLiteral("22222"));
}
SKGTRACE << "####### Before close" << endl;
dumpConnections();
SKGTESTERROR(QStringLiteral("PARAM:close"), document1.close(), true);
SKGTRACE << "####### Before initialize" << endl;
dumpConnections();
SKGTESTERROR(QStringLiteral("PARAM:initialize"), document1.initialize(), true);
SKGTRACE << "####### Before concurrent calls" << endl;
dumpConnections();
{
SKGTRACE << ">> concurrentExecuteSelectSqliteOrder different orders (in other thread)" << endl;
QString output;
double elapse = SKGServices::getMicroTime();
for (int i = 0; i < nb; ++i) {
document1.concurrentExecuteSelectSqliteOrder(QStringLiteral("SELECT SLEEP(1), ") + SKGServices::intToString(3000 + i),
[ &output ](const SKGStringListList & iResult) {
QMutex mutex;
mutex.lock();
output = output + SKGServices::intToString(iResult.count());
mutex.unlock();
}, false);
}
double time = SKGServices::getMicroTime() - elapse;
SKGTRACE << nb << " x concurrentExecuteSelectSqliteOrder:" << output << " " << (SKGServices::getMicroTime() - elapse) << " ms" << endl;
for (int i = 1; i < 100; ++i) {
QThread::msleep(100);
time = SKGServices::getMicroTime() - elapse;
if (output == QStringLiteral("22222")) {
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO >=1000"), static_cast(time >= 1000), static_cast(true));
SKGTEST(QStringLiteral("PARAM:executeSelectSqliteOrder-PERFO <3500"), static_cast(time < 3500), static_cast(true));
break;
}
}
SKGTRACE << nb << " x concurrentExecuteSelectSqliteOrder:" << output << " " << time << " ms" << endl;
SKGTEST(QStringLiteral("PARAM:concurrentExecuteSelectSqliteOrder"), output, QStringLiteral("22222"));
}
SKGTRACE << "####### End" << endl;
dumpConnections();
// End test
SKGENDTEST();
}