diff --git a/kdwsdl2cpp/src/converter.cpp b/kdwsdl2cpp/src/converter.cpp index c49dde2ff..18c6bdc5a 100644 --- a/kdwsdl2cpp/src/converter.cpp +++ b/kdwsdl2cpp/src/converter.cpp @@ -65,7 +65,9 @@ void Converter::setWSDL(const WSDL &wsdl) mTypeMap.setNSManager(&mNSManager); - cleanupUnusedTypes(); + if (!Settings::self()->keepUnusedTypes()) { + cleanupUnusedTypes(); + } // set the xsd types mTypeMap.addSchemaTypes(mWSDL.definitions().type().types(), Settings::self()->nameSpace()); diff --git a/kdwsdl2cpp/src/main.cpp b/kdwsdl2cpp/src/main.cpp index 306a2690f..7f331fd99 100644 --- a/kdwsdl2cpp/src/main.cpp +++ b/kdwsdl2cpp/src/main.cpp @@ -45,6 +45,7 @@ static void showHelp(const char *appName) " -optional-element-type \n" " use as the getter return value for optional elements.\n" " can be either raw-pointer or boost-optional\n" + " -keep-unused-types keep the wsdl unused types to the cpp generation step\n" "\n", appName); } @@ -61,6 +62,7 @@ int main(int argc, char **argv) QString exportMacro; QString nameSpace; Settings::OptionalElementType optionalElementType = Settings::ENone; + bool keepUnusedTypes = false; int arg = 1; while (arg < argc) { @@ -121,6 +123,8 @@ int main(int argc, char **argv) } else if (optType == QLatin1String("boost-optional")) { optionalElementType = Settings::EBoostOptional; } + } else if (opt == QLatin1String("-keep-unused-types")) { + keepUnusedTypes = true; } else if (!fileName) { fileName = argv[arg]; } else { @@ -145,6 +149,7 @@ int main(int argc, char **argv) Settings::self()->setExportDeclaration(exportMacro); Settings::self()->setNameSpace(nameSpace); Settings::self()->setOptionalElementType(optionalElementType); + Settings::self()->setKeepUnusedTypes(keepUnusedTypes); KWSDL::Compiler compiler; // so that we have an event loop, for downloads diff --git a/kdwsdl2cpp/src/settings.cpp b/kdwsdl2cpp/src/settings.cpp index b46fd3cee..7041a36dd 100644 --- a/kdwsdl2cpp/src/settings.cpp +++ b/kdwsdl2cpp/src/settings.cpp @@ -42,6 +42,7 @@ Settings::Settings() mOutputFileName = QString::fromLatin1("kwsdl_generated"); mImpl = false; mServer = false; + mKeepUnusedTypes = false; mOptionalElementType = Settings::ENone; } @@ -129,6 +130,16 @@ Settings::OptionalElementType Settings::optionalElementType() const return mOptionalElementType; } +void Settings::setKeepUnusedTypes(bool b) +{ + mKeepUnusedTypes = b; +} + +bool Settings::keepUnusedTypes() const +{ + return mKeepUnusedTypes; +} + void Settings::setNamespaceMapping(const NSMapping &namespaceMapping) { mNamespaceMapping = namespaceMapping; diff --git a/kdwsdl2cpp/src/settings.h b/kdwsdl2cpp/src/settings.h index f8b9e8359..3aacf8dd5 100644 --- a/kdwsdl2cpp/src/settings.h +++ b/kdwsdl2cpp/src/settings.h @@ -56,6 +56,9 @@ class Settings void setOptionalElementType(OptionalElementType optionalElementType); OptionalElementType optionalElementType() const; + void setKeepUnusedTypes(bool b); + bool keepUnusedTypes() const; + // UNUSED void setNamespaceMapping(const NSMapping &namespaceMapping); NSMapping namespaceMapping() const; @@ -84,6 +87,7 @@ class Settings bool mImpl; bool mServer; OptionalElementType mOptionalElementType; + bool mKeepUnusedTypes; }; #endif diff --git a/unittests/keep_unused_types/CMakeLists.txt b/unittests/keep_unused_types/CMakeLists.txt new file mode 100755 index 000000000..9a719c7f1 --- /dev/null +++ b/unittests/keep_unused_types/CMakeLists.txt @@ -0,0 +1,11 @@ +project(keep_unused_types) + +#this is the option given to KDWSDL2CPP when generating cpp from wsdl +set(KSWSDL2CPP_OPTION "-keep-unused-types") + +set(WSDL_FILES keep_unused_types.wsdl) +set(keep_unused_types_SRCS keep_unused_types.cpp) + +set(EXTRA_LIBS ${QT_QTXML_LIBRARY}) + +add_unittest(${keep_unused_types_SRCS}) diff --git a/unittests/keep_unused_types/keep_unused_types.cpp b/unittests/keep_unused_types/keep_unused_types.cpp new file mode 100644 index 000000000..cafeb67ab --- /dev/null +++ b/unittests/keep_unused_types/keep_unused_types.cpp @@ -0,0 +1,48 @@ +/**************************************************************************** +** Copyright (C) 2010-2017 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com. +** All rights reserved. +** +** This file is part of the KD Soap library. +** +** Licensees holding valid commercial KD Soap licenses may use this file in +** accordance with the KD Soap Commercial License Agreement provided with +** the Software. +** +** +** This file may be distributed and/or modified under the terms of the +** GNU Lesser General Public License version 2.1 and version 3 as published by the +** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** Contact info@kdab.com if any conditions of this licensing are not +** clear to you. +** +**********************************************************************/ + +#include "KDSoapClientInterface.h" +#include "wsdl_keep_unused_types.h" + +#include +#include + +class KeepUnusedTypesArgumentKDWSDL2CPP: public QObject +{ + Q_OBJECT + +private slots: + + void testKeepUnusedTypesArgument() + { + // Unused type within WSDL, if this compiles, then -keep-unused-types works since + // otherwise cleanupUnusedTypes function would have removed it from the cpp generation + TNS__UnusedElement element; + Q_UNUSED(element); + } +}; + +QTEST_MAIN(KeepUnusedTypesArgumentKDWSDL2CPP) + +#include "keep_unused_types.moc" + diff --git a/unittests/keep_unused_types/keep_unused_types.pro b/unittests/keep_unused_types/keep_unused_types.pro new file mode 100755 index 000000000..23f8f97e8 --- /dev/null +++ b/unittests/keep_unused_types/keep_unused_types.pro @@ -0,0 +1,13 @@ +#this is the option given to KDWSDL2CPP when generating cpp from wsdl +KDWSDL_OPTIONS = -keep-unused-types + +include( $${TOP_SOURCE_DIR}/unittests/unittests.pri ) + +QT += network xml +SOURCES = keep_unused_types.cpp +test.target = test +test.commands = ./$(TARGET) +test.depends = $(TARGET) +QMAKE_EXTRA_TARGETS += test + +KDWSDL = keep_unused_types.wsdl diff --git a/unittests/keep_unused_types/keep_unused_types.wsdl b/unittests/keep_unused_types/keep_unused_types.wsdl new file mode 100755 index 000000000..bf7108762 --- /dev/null +++ b/unittests/keep_unused_types/keep_unused_types.wsdl @@ -0,0 +1,165 @@ + + + A WebService retreiving the names of German cities starting with a specific string. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Return Lookup entries that start with the given prefix. + + + + + + + + + + + Return Lookup entries that start with the given prefix. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A WebService retreiving the names of German cities starting with a specific string. + + + + + + + + + + +