Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions App/Server/clsAPIObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ void clsAPIObject::invokeMethod(const QVariantList& _arguments, QGenericReturnAr
else
InvokableMethod = this->LessArgumentMethods.at(this->ParamNames.size() - _arguments.size() - 1);

#ifdef QT_DEBUG
if (InvokableMethod.name().toStdString() == "apiPOSTfixtureCleanup")
{
int i = 0;

}
#endif

QVector<void*> ArgStorage(_arguments.size(), {});

try {
Expand Down
12 changes: 0 additions & 12 deletions Interfaces/API/intfSQLBasedModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,4 @@ bool intfSQLBasedModule::DeleteByPks(clsTable& _table, DELETE_METHOD_ARGS_IMPL_I
return query.execute(_userID, {}, _realDelete) > 0;
}

//#ifdef QT_DEBUG
//QVariant intfSQLBasedModule::apiPOSTfixtureSetup(TAPI::RemoteIP_t _REMOTE_IP)
//{
// return fixtureSetup(_REMOTE_IP);
//}

//QVariant intfSQLBasedModule::apiPOSTfixtureCleanup(TAPI::RemoteIP_t _REMOTE_IP)
//{
// return fixtureCleanup(_REMOTE_IP);
//}
//#endif

} // namespace Targoman::API::API
22 changes: 0 additions & 22 deletions Interfaces/API/intfSQLBasedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,6 @@ class intfSQLBasedModule : public intfPureModule, public clsTable
const QVariantMap& _extraFilters = {},
bool _realDelete = false
);

//#ifdef QT_DEBUG
//protected slots:
// QVariant REST_POST(
// fixtureSetup,
// (
// TAPI::RemoteIP_t _REMOTE_IP
// ),
// "Create sample data"
// )

// QVariant REST_POST(
// fixtureCleanup,
// (
// TAPI::RemoteIP_t _REMOTE_IP
// ),
// "Cleanup sample data"
// )
//protected:
// virtual QVariant fixtureSetup(TAPI::RemoteIP_t _REMOTE_IP) { Q_UNUSED(_REMOTE_IP); return QVariant(); }
// virtual QVariant fixtureCleanup(TAPI::RemoteIP_t _REMOTE_IP) { Q_UNUSED(_REMOTE_IP); return QVariant(); }
//#endif
};

} // namespace Targoman::API::API
Expand Down
122 changes: 117 additions & 5 deletions Interfaces/Common/QtTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Interfaces/Common/tmplNullable.hpp"
#include "Interfaces/Common/tmplAPIArg.h"
#include <QJsonValue>
#include <math.h>

/*****************************************************/
#define IGNORE_TYPE_Void ,
Expand Down Expand Up @@ -68,17 +69,128 @@ namespace TAPI { \
} \
}

//https://cpp.hotexamples.com/examples/-/QString/toLongLong/cpp-qstring-tolonglong-method-examples.html
inline QVariant readNumber(const QString& _str, bool *ok)
{
//m_settings->locale()
QString negativeSign = "-";
QString decimalSymbol = ".";
QString thousandsSeparator = "'";

bool isInt = false;
QString str = _str.trimmed();
bool neg = str.indexOf(negativeSign) == 0;
if (neg)
str.remove(0, negativeSign.length());

/* will hold the scientific notation portion of the number.
Example, with 2.34E+23, exponentialPart == "E+23"
*/
QString exponentialPart;
int EPos = str.indexOf('E', 0, Qt::CaseInsensitive);

if (EPos != -1) {
exponentialPart = str.mid(EPos);
str = str.left(EPos);
}

int pos;
int fracPos;
QString major;
QString minor;
if ((pos = str.indexOf(decimalSymbol)) != -1) {
major = str.left(pos);
minor = str.mid(pos + decimalSymbol.length());
isInt = false;
} else if (((pos = str.indexOf(' ')) != -1) &&
((fracPos = str.indexOf('/')) != -1)) {
// try to parse fractions of this form:
// [0-9]+ [0-9]+/[1-9][0-9]?
major = str.left(pos);
QString numerator = str.mid(pos + 1, (fracPos - pos - 1));
QString denominator = str.mid(fracPos + 1);
double minorVal = numerator.toDouble() / denominator.toDouble();
if (minorVal > 1) {
// assume major is just a plain number
double wholePart = floor(minorVal);
minorVal -= wholePart;
major = QString("%1").arg(major.toInt() + (int)wholePart);
}
minor = QString::number(minorVal, 'f').mid(2); // chop off the "0." part
// kDebug() <<"fraction:" << major <<"." << minor;
} else {
major = str;
isInt = (EPos == -1); // only, if no exponential part was found
}

// Remove thousand separators
int thlen = thousandsSeparator.length();
int lastpos = 0;
while ((pos = major.indexOf(thousandsSeparator)) > 0) {
// e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N
int fromEnd = major.length() - pos;
if (fromEnd % (3 + thlen) != 0 // Needs to be a multiple, otherwise it's an error
|| pos - lastpos > 3 // More than 3 digits between two separators -> error
|| pos == 0 // Can't start with a separator
|| (lastpos > 0 && pos - lastpos != 3)) { // Must have exactly 3 digits between two separators
if (ok) *ok = false;
return QVariant();
}

lastpos = pos;
major.remove(pos, thlen);
}
if (lastpos > 0 && major.length() - lastpos != 3) { // Must have exactly 3 digits after the last separator
if (ok) *ok = false;
return QVariant();
}

// log10(2^63) ~= 18
if (isInt && major.length() > 19) isInt = false;

QString tot;
if (neg) tot = '-';
tot += major;
if (!isInt) tot += '.' + minor + exponentialPart;

return isInt ? QVariant(tot.toLongLong(ok)) : QVariant(tot.toDouble(ok));
}

#define TAPI_SPECIAL_MAKE_GENERIC_ON_NUMERIC_TYPE(_numericType, _convertor) \
namespace Targoman::API::Common { \
template<> inline QGenericArgument tmplAPIArg<_numericType, COMPLEXITY_Integral, false, true>::makeGenericArgument(const QVariant& _val, const QByteArray& _paramName, void** _argStorage){ \
bool Result; *_argStorage = new _numericType; *(reinterpret_cast<_numericType*>(*_argStorage)) = static_cast<_numericType>(_val._convertor(&Result)); \
if (!Result) throw exHTTPBadRequest("Invalid value specified for parameter: " + _paramName); \
bool Result; \
*_argStorage = new _numericType; \
_numericType ConvertedVal; \
if (_val.userType() == QMetaType::QString) \
{ \
QString StrVal = _val.toString(); \
ConvertedVal = static_cast<_numericType>(readNumber(StrVal, &Result)._convertor(&Result)); \
} \
else \
ConvertedVal = static_cast<_numericType>(_val._convertor(&Result)); \
*(reinterpret_cast<_numericType*>(*_argStorage)) = ConvertedVal; \
if (!Result) \
throw exHTTPBadRequest("Invalid value specified for parameter: " + _paramName); \
return QGenericArgument(this->RealTypeName, *_argStorage); \
} \
template<> inline QGenericArgument tmplAPIArg<NULLABLE_TYPE(_numericType), COMPLEXITY_Integral, true>::makeGenericArgument(const QVariant& _val, const QByteArray& _paramName, void** _argStorage){ \
bool Result = true; *_argStorage = new NULLABLE_TYPE(_numericType); \
if(_val.isValid() && _val.isNull() == false) **(reinterpret_cast<NULLABLE_TYPE(_numericType)*>(*_argStorage)) = static_cast<_numericType>(_val._convertor(&Result)); \
if (!Result) throw exHTTPBadRequest("Invalid value specified for parameter:: " + _paramName); \
bool Result = true; \
*_argStorage = new NULLABLE_TYPE(_numericType); \
if (_val.isValid() && _val.isNull() == false) \
{ \
_numericType ConvertedVal; \
if (_val.userType() == QMetaType::QString) \
{ \
QString StrVal = _val.toString(); \
ConvertedVal = static_cast<_numericType>(readNumber(StrVal, &Result)._convertor(&Result)); \
} \
else \
ConvertedVal = static_cast<_numericType>(_val._convertor(&Result)); \
*(reinterpret_cast<NULLABLE_TYPE(_numericType)*>(*_argStorage)) = ConvertedVal; \
} \
if (!Result) \
throw exHTTPBadRequest("Invalid value specified for NULLABLE parameter: " + _paramName); \
return QGenericArgument(this->RealTypeName, *_argStorage); \
} \
} \
Expand Down
52 changes: 52 additions & 0 deletions Interfaces/Helpers/FixtureHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI 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 AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#include "FixtureHelper.h"

#ifdef QT_DEBUG

namespace Targoman::API::Helpers {

QString FixtureHelper::MakeRandomizeName(
const QString &_random,
const QString &_sep,
const QString &_prefix,
const QString &_suffix
)
{
QStringList List;

List.append(_prefix);

if (_random.isEmpty() == false)
List.append(_random);

if (_suffix.isEmpty() == false)
List.append(_suffix);

return List.join(_sep);
};

} //namespace Targoman::API::Helpers

#endif
49 changes: 49 additions & 0 deletions Interfaces/Helpers/FixtureHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/******************************************************************************
# TargomanAPI: REST API for Targoman
#
# Copyright 2014-2020 by Targoman Intelligent Processing <http://tip.co.ir>
#
# TargomanAPI is free software: you can redistribute it and/or modify
# it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# TargomanAPI 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 AFFERO GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
# along with Targoman. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* @author S. Mehran M. Ziabary <ziabary@targoman.com>
* @author Kambiz Zandi <kambizzandi@gmail.com>
*/

#ifndef TARGOMAN_API_FIXTUREHELPER_H
#define TARGOMAN_API_FIXTUREHELPER_H

#include <QString>
#include "Interfaces/Common/APIArgHelperMacros.hpp"

#ifdef QT_DEBUG

namespace Targoman::API::Helpers {

class FixtureHelper
{
public:
static QString MakeRandomizeName(
const QString &_random,
const QString &_sep,
const QString &_prefix,
const QString &_suffix={}
);
};

} //namespace Targoman::API::Helpers

#endif

#endif // TARGOMAN_API_FIXTUREHELPER_H
2 changes: 2 additions & 0 deletions Interfaces/Interfaces.pro
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ HEADERS += \
Common/base.h \
Common/tmplNullable.hpp \
Common/APIArgHelperMacrosPrivate.h \
Helpers/FixtureHelper.h \
Helpers/ObjectStorageHelper.h \
Helpers/RESTClientHelper.h \
Helpers/SecurityHelper.h \
Expand All @@ -58,6 +59,7 @@ SOURCES += \
Common/base.cpp \
Common/GenericTypes.cpp \
Common/intfAPIArgManipulator.cpp \
Helpers/FixtureHelper.cpp \
Helpers/ObjectStorageHelper.cpp \
Helpers/PhoneHelper.cpp \
Helpers/RESTClientHelper.cpp \
Expand Down
3 changes: 2 additions & 1 deletion Modules/Account/functionalTest/functionalTest.pro
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ HEADERS += \
ORM/service.hpp \
ORM/roles.hpp \
ORM/tokens.hpp \
testAccount.hpp
testAccount.hpp \
testAccountFixture.hpp

SOURCES += \
$$BASE_PROJECT_PATH/3rdParty/QtCurl/libsrc/QtCUrl.cpp \
Expand Down
Loading