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
10 changes: 9 additions & 1 deletion kdwsdl2cpp/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ void Compiler::download()
}

// qDebug() << "parsing" << fileName;
QDomDocument doc;
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
QString errorMsg;
int errorLine, errorCol;
QDomDocument doc;
if (!doc.setContent(&file, false, &errorMsg, &errorLine, &errorCol)) {
qDebug("%s at (%d,%d)", qPrintable(errorMsg), errorLine, errorCol);
QCoreApplication::exit(2);
return;
}
#else
if (auto result = doc.setContent(&file); !result) {
qDebug("%s at (%lld,%lld)", qPrintable(result.errorMessage), result.errorLine, result.errorColumn);
QCoreApplication::exit(2);
return;
}
#endif

parse(doc.documentElement());

Expand Down
2 changes: 1 addition & 1 deletion kdwsdl2cpp/src/converter_clientstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ bool Converter::convertClientService()
// for each operation, create a job class
for (const Operation &operation : std::as_const(operations)) {
Operation::OperationType opType = operation.operationType();
if (opType != Operation::SolicitResponseOperation && opType != Operation::RequestResponseOperation) {
if (opType == Operation::NotificationOperation) {
continue;
}

Expand Down
7 changes: 7 additions & 0 deletions kdwsdl2cpp/wsdl/definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,20 @@ void Definitions::importDefinition(ParserContext *context, const QString &locati
}

QDomDocument doc(QLatin1String("kwsdl"));
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
QString errorMsg;
int errorLine, errorColumn;
bool ok = doc.setContent(&file, false, &errorMsg, &errorLine, &errorColumn);
if (!ok) {
qDebug("Error[%d:%d] %s", errorLine, errorColumn, qPrintable(errorMsg));
return;
}
#else
if (auto result = doc.setContent(&file); !result) {
qDebug("Error[%lld:%lld] %s", result.errorLine, result.errorColumn, qPrintable(result.errorMessage));
return;
}
#endif

// prepare the new context to avoid infinite recursion
QDomElement rootNode = doc.documentElement();
Expand Down
19 changes: 18 additions & 1 deletion src/KDSoapClient/KDDateTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "KDDateTime.h"
#include <QDebug>
#include <QSharedData>
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#include <QTimeZone>
#endif

class KDDateTimeData : public QSharedData
{
Expand Down Expand Up @@ -64,11 +67,21 @@ void KDDateTime::setTimeZone(const QString &timeZone)
// Just in case someone cares: set the time spec in QDateTime accordingly.
// We can't do this the other way round, there's no public API for the offset-from-utc case.
if (timeZone == QLatin1String("Z")) {
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
setTimeSpec(Qt::UTC);
#else
QDateTime::setTimeZone(QTimeZone(QTimeZone::UTC));
#endif
} else if (timeZone.isEmpty()) {
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
setTimeSpec(Qt::LocalTime);
#else
QDateTime::setTimeZone(QTimeZone(QTimeZone::LocalTime));
#endif
} else {
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
setTimeSpec(Qt::OffsetFromUTC);
#endif
const int pos = timeZone.indexOf(QLatin1Char(':'));
if (pos > 0) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand All @@ -79,8 +92,12 @@ void KDDateTime::setTimeZone(const QString &timeZone)
const int hours = timeZoneView.first(pos).toInt();
const int minutes = timeZoneView.sliced(pos + 1).toInt();
#endif
const int offset = hours * 3600 + minutes * 60;
const int offset = hours * 3600 + (hours >= 0 ? minutes : -minutes) * 60;
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
setOffsetFromUtc(offset);
#else
QDateTime::setTimeZone(QTimeZone::fromSecondsAheadOfUtc(offset));
#endif
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/KDSoapClient/KDSoapMessageAddressingProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ static void writeAddressField(QXmlStreamWriter &writer, const QString &addressin
static void writeKDSoapValueVariant(QXmlStreamWriter &writer, const KDSoapValue &value)
{
const QVariant valueToWrite = value.value();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (valueToWrite.canConvert(QVariant::String)) {
#else
if (valueToWrite.canConvert(QMetaType(QMetaType::QString))) {
#endif
writer.writeCharacters(valueToWrite.toString());
} else {
qWarning("Warning: KDSoapMessageAddressingProperties call to writeKDSoapValueVariant could not write the given KDSoapValue "
Expand Down
16 changes: 8 additions & 8 deletions src/KDSoapClient/KDSoapMessageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ static int xmlTypeToMetaType(const QString &xmlType)
{
const char *xml; // xsd: prefix assumed
const int metaTypeId;
} s_types[] = {{"string", QVariant::String}, // or QUrl
{"base64Binary", QVariant::ByteArray},
{"int", QVariant::Int}, // or long, or uint, or longlong
{"unsignedInt", QVariant::ULongLong},
{"boolean", QVariant::Bool},
} s_types[] = {{"string", QMetaType::QString}, // or QUrl
{"base64Binary", QMetaType::QByteArray},
{"int", QMetaType::Int}, // or long, or uint, or longlong
{"unsignedInt", QMetaType::ULongLong},
{"boolean", QMetaType::Bool},
{"float", QMetaType::Float},
{"double", QVariant::Double},
{"time", QVariant::Time},
{"date", QVariant::Date}};
{"double", QMetaType::Double},
{"time", QMetaType::QTime},
{"date", QMetaType::QDate}};
// Speed: could be sorted and then we could use qBinaryFind
for (const auto &type : s_types) {
if (xmlType == QLatin1String(type.xml)) {
Expand Down
54 changes: 27 additions & 27 deletions src/KDSoapClient/KDSoapValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ bool KDSoapValue::operator!=(const KDSoapValue &other) const
static QString variantToTextValue(const QVariant &value, const QString &typeNs, const QString &type)
{
switch (value.userType()) {
case QVariant::Char:
case QMetaType::QChar:
// fall-through
case QVariant::String:
case QMetaType::QString:
return value.toString();
case QVariant::Url:
case QMetaType::QUrl:
// xmlpatterns/data/qatomicvalue.cpp says to do this:
return value.toUrl().toString();
case QVariant::ByteArray: {
case QMetaType::QByteArray: {
const QByteArray data = value.toByteArray();
if (typeNs == KDSoapNamespaceManager::xmlSchema1999() || typeNs == KDSoapNamespaceManager::xmlSchema2001()) {
if (type == QLatin1String("hexBinary")) {
Expand All @@ -184,19 +184,19 @@ static QString variantToTextValue(const QVariant &value, const QString &typeNs,
const QByteArray b64 = value.toByteArray().toBase64();
return QString::fromLatin1(b64.constData(), b64.size());
}
case QVariant::Int:
case QMetaType::Int:
// fall-through
case QVariant::LongLong:
case QMetaType::LongLong:
// fall-through
case QVariant::UInt:
case QMetaType::UInt:
return QString::number(value.toLongLong());
case QVariant::ULongLong:
case QMetaType::ULongLong:
return QString::number(value.toULongLong());
case QVariant::Bool:
case QMetaType::Bool:
case QMetaType::Float:
case QVariant::Double:
case QMetaType::Double:
return value.toString();
case QVariant::Time: {
case QMetaType::QTime: {
const QTime time = value.toTime();
if (time.msec()) {
// include milli-seconds
Expand All @@ -205,11 +205,11 @@ static QString variantToTextValue(const QVariant &value, const QString &typeNs,
return time.toString(Qt::ISODate);
}
}
case QVariant::Date:
case QMetaType::QDate:
return value.toDate().toString(Qt::ISODate);
case QVariant::DateTime: // https://www.w3.org/TR/xmlschema-2/#dateTime
case QMetaType::QDateTime: // https://www.w3.org/TR/xmlschema-2/#dateTime
return KDDateTime(value.toDateTime()).toDateString();
case QVariant::Invalid:
case QMetaType::UnknownType:
qDebug() << "ERROR: Got invalid QVariant in a KDSoapValue";
return QString();
default:
Expand All @@ -232,33 +232,33 @@ static QString variantToTextValue(const QVariant &value, const QString &typeNs,
static QString variantToXMLType(const QVariant &value)
{
switch (value.userType()) {
case QVariant::Char:
case QMetaType::QChar:
// fall-through
case QVariant::String:
case QMetaType::QString:
// fall-through
case QVariant::Url:
case QMetaType::QUrl:
return QLatin1String("xsd:string");
case QVariant::ByteArray:
case QMetaType::QByteArray:
return QLatin1String("xsd:base64Binary");
case QVariant::Int:
case QMetaType::Int:
// fall-through
case QVariant::LongLong:
case QMetaType::LongLong:
// fall-through
case QVariant::UInt:
case QMetaType::UInt:
return QLatin1String("xsd:int");
case QVariant::ULongLong:
case QMetaType::ULongLong:
return QLatin1String("xsd:unsignedInt");
case QVariant::Bool:
case QMetaType::Bool:
return QLatin1String("xsd:boolean");
case QMetaType::Float:
return QLatin1String("xsd:float");
case QVariant::Double:
case QMetaType::Double:
return QLatin1String("xsd:double");
case QVariant::Time:
case QMetaType::QTime:
return QLatin1String("xsd:time"); // correct? xmlpatterns fallsback to datetime because of missing timezone
case QVariant::Date:
case QMetaType::QDate:
return QLatin1String("xsd:date");
case QVariant::DateTime:
case QMetaType::QDateTime:
return QLatin1String("xsd:dateTime");
default:
if (value.userType() == qMetaTypeId<float>()) {
Expand Down
4 changes: 4 additions & 0 deletions testtools/httpserver_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ static bool textBufferCompare(const QByteArray &source, const QByteArray &dest,

static void initHashSeed()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
qSetGlobalQHashSeed(0);
#else
QHashSeed::setDeterministicGlobalSeed();
#endif
}

Q_CONSTRUCTOR_FUNCTION(initHashSeed)
Expand Down
1 change: 1 addition & 0 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ add_subdirectory(ws_usernametoken_support)
add_subdirectory(empty_element_wsdl)
add_subdirectory(ws_discovery_wsdl)
add_subdirectory(soap_over_udp)
add_subdirectory(kdwsdl2cpp_jobs)

# These need internet access
add_subdirectory(webcalls)
Expand Down
58 changes: 58 additions & 0 deletions unittests/kddatetime/test_kddatetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "KDDateTime.h"
#include "KDSoapValue.h"
#include <QTest>
#include <QTimeZone>

class KDDateTimeTest : public QObject
{
Expand All @@ -35,6 +36,63 @@ private Q_SLOTS:
QCOMPARE(inputDateTime.timeZone(), outputDateTime.timeZone());
QCOMPARE(inputDateTime.toDateString(), outputDateTime.toDateString());
}

void testSetTimeZone_data()
Comment thread
dfaure-kdab marked this conversation as resolved.
{
QTest::addColumn<QString>("timeZone");
QTest::addColumn<QString>("expected");

// Example countries and their offsets.

QTest::newRow("empty") << "" << QDateTime({2020, 1, 1}, {0, 0}, QTimeZone::systemTimeZone()).timeZoneAbbreviation();
QTest::newRow("Z") << "Z" << "UTC";
QTest::newRow("US Minor outlying islands") << "-12:00" << "UTC-12:00";
QTest::newRow("New Zealand (Niue)") << "-11:00" << "UTC-11:00";
QTest::newRow("Hawaii") << "-10:00" << "UTC-10:00";
QTest::newRow("Marquesas Islands (French Polynesia)") << "-09:30" << "UTC-09:30";
QTest::newRow("Alaska") << "-09:00" << "UTC-09:00";
QTest::newRow("US Pacific") << "-08:00" << "UTC-08:00";
QTest::newRow("US Mountain") << "-07:00" << "UTC-07:00";
QTest::newRow("US Central") << "-06:00" << "UTC-06:00";
QTest::newRow("US Eastern") << "-05:00" << "UTC-05:00";
QTest::newRow("US Atlantic") << "-04:00" << "UTC-04:00";
QTest::newRow("Canada Newfoundland") << "-03:30" << "UTC-03:30";
QTest::newRow("Argentina") << "-03:00" << "UTC-03:00";
QTest::newRow("Greenland") << "-02:00" << "UTC-02:00";
QTest::newRow("Cape Verde") << "-01:00" << "UTC-01:00";
QTest::newRow("United Kingdom 1") << "+00:00" << "UTC";
QTest::newRow("United Kingdom 2") << "-00:00" << "UTC";
QTest::newRow("France (Metropolitan)") << "+01:00" << "UTC+01:00";
QTest::newRow("Greece") << "+02:00" << "UTC+02:00";
QTest::newRow("Turkey") << "+03:00" << "UTC+03:00";
QTest::newRow("Iran") << "+03:30" << "UTC+03:30";
QTest::newRow("Seychelles") << "+04:00" << "UTC+04:00";
QTest::newRow("Afghanistan") << "+04:30" << "UTC+04:30";
QTest::newRow("Kazakhstan") << "+05:00" << "UTC+05:00";
QTest::newRow("India") << "+05:30" << "UTC+05:30";
QTest::newRow("Bhutan") << "+06:00" << "UTC+06:00";
QTest::newRow("Myanmar") << "+06:30" << "UTC+06:30";
QTest::newRow("Cambodia") << "+07:00" << "UTC+07:00";
QTest::newRow("Western Australia") << "+08:00" << "UTC+08:00";
QTest::newRow("Western Australia (Eucla)") << "+08:45" << "UTC+08:45";
QTest::newRow("Japan") << "+09:00" << "UTC+09:00";
QTest::newRow("Australia (Adelaide)") << "+09:30" << "UTC+09:30";
QTest::newRow("Australia (Sydney)") << "+10:00" << "UTC+10:00";
QTest::newRow("Australia (Lord Howe Island)") << "+10:30" << "UTC+10:30";
QTest::newRow("Australia (Norfolk Island)") << "+11:00" << "UTC+11:00";
QTest::newRow("New Zealand") << "+12:00" << "UTC+12:00";
QTest::newRow("New Zealand (Chatham Islands)") << "+12:45" << "UTC+12:45";
QTest::newRow("Samoa") << "+13:00" << "UTC+13:00";
QTest::newRow("Kiribati (Line Islands)") << "+14:00" << "UTC+14:00";
}

void testSetTimeZone()
{
QFETCH(QString, timeZone);
QFETCH(QString, expected);

QCOMPARE(KDDateTime::fromDateString("2020-01-01T00:00" + timeZone).timeZoneAbbreviation(), expected);
}
};

QTEST_MAIN(KDDateTimeTest)
Expand Down
10 changes: 10 additions & 0 deletions unittests/kdwsdl2cpp_jobs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is part of the KD Soap project.
#
# SPDX-FileCopyrightText: 2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
#
# SPDX-License-Identifier: MIT
#

set(kdwsdl2cpp_jobs_SRCS test_jobs.cpp)
set(WSDL_FILES jobs.wsdl)
add_unittest(${kdwsdl2cpp_jobs_SRCS})
Loading
Loading