Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a -keep-ununsed-types argument to kdwsdl2cpp #107

Merged
merged 1 commit into from
Sep 11, 2017
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
4 changes: 3 additions & 1 deletion kdwsdl2cpp/src/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions kdwsdl2cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static void showHelp(const char *appName)
" -optional-element-type <type>\n"
" use <type> as the getter return value for optional elements.\n"
" <type> 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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions kdwsdl2cpp/src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Settings::Settings()
mOutputFileName = QString::fromLatin1("kwsdl_generated");
mImpl = false;
mServer = false;
mKeepUnusedTypes = false;
mOptionalElementType = Settings::ENone;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions kdwsdl2cpp/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +87,7 @@ class Settings
bool mImpl;
bool mServer;
OptionalElementType mOptionalElementType;
bool mKeepUnusedTypes;
};

#endif
11 changes: 11 additions & 0 deletions unittests/keep_unused_types/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
48 changes: 48 additions & 0 deletions unittests/keep_unused_types/keep_unused_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/****************************************************************************
** Copyright (C) 2010-2017 Klaralvdalens Datakonsult AB, a KDAB Group company, [email protected].
** 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 [email protected] if any conditions of this licensing are not
** clear to you.
**
**********************************************************************/

#include "KDSoapClientInterface.h"
#include "wsdl_keep_unused_types.h"

#include <QtTest/QtTest>
#include <QDebug>

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"

13 changes: 13 additions & 0 deletions unittests/keep_unused_types/keep_unused_types.pro
Original file line number Diff line number Diff line change
@@ -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
165 changes: 165 additions & 0 deletions unittests/keep_unused_types/keep_unused_types.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.mathertel.de/OrteLookup/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.mathertel.de/OrteLookup/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">A WebService retreiving the names of German cities starting with a specific string.</wsdl:documentation>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.mathertel.de/OrteLookup/">
<s:element name="UnusedElement">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="prefix" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="OrteStartWith">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="prefix" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="OrteStartWithResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="OrteStartWithResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetPrefixedEntries">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="prefix" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetPrefixedEntriesResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetPrefixedEntriesResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</wsdl:types>
<wsdl:message name="OrteStartWithSoapIn">
<wsdl:part name="parameters" element="tns:OrteStartWith" />
</wsdl:message>
<wsdl:message name="OrteStartWithSoapOut">
<wsdl:part name="parameters" element="tns:OrteStartWithResponse" />
</wsdl:message>
<wsdl:message name="GetPrefixedEntriesSoapIn">
<wsdl:part name="parameters" element="tns:GetPrefixedEntries" />
</wsdl:message>
<wsdl:message name="GetPrefixedEntriesSoapOut">
<wsdl:part name="parameters" element="tns:GetPrefixedEntriesResponse" />
</wsdl:message>
<wsdl:message name="OrteStartWithHttpGetIn">
<wsdl:part name="prefix" type="s:string" />
</wsdl:message>
<wsdl:message name="OrteStartWithHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetPrefixedEntriesHttpGetIn">
<wsdl:part name="prefix" type="s:string" />
</wsdl:message>
<wsdl:message name="GetPrefixedEntriesHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:portType name="OrteLookupSoap">
<wsdl:operation name="OrteStartWith">
<wsdl:input message="tns:OrteStartWithSoapIn" />
<wsdl:output message="tns:OrteStartWithSoapOut" />
</wsdl:operation>
<wsdl:operation name="GetPrefixedEntries">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Return Lookup entries that start with the given prefix.</wsdl:documentation>
<wsdl:input message="tns:GetPrefixedEntriesSoapIn" />
<wsdl:output message="tns:GetPrefixedEntriesSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="OrteLookupHttpGet">
<wsdl:operation name="OrteStartWith">
<wsdl:input message="tns:OrteStartWithHttpGetIn" />
<wsdl:output message="tns:OrteStartWithHttpGetOut" />
</wsdl:operation>
<wsdl:operation name="GetPrefixedEntries">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Return Lookup entries that start with the given prefix.</wsdl:documentation>
<wsdl:input message="tns:GetPrefixedEntriesHttpGetIn" />
<wsdl:output message="tns:GetPrefixedEntriesHttpGetOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OrteLookupSoap" type="tns:OrteLookupSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="OrteStartWith">
<soap:operation soapAction="http://www.mathertel.de/OrteLookup/OrteStartWith" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetPrefixedEntries">
<soap:operation soapAction="http://www.mathertel.de/OrteLookup/GetPrefixedEntries" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="OrteLookupSoap12" type="tns:OrteLookupSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="OrteStartWith">
<soap12:operation soapAction="http://www.mathertel.de/OrteLookup/OrteStartWith" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetPrefixedEntries">
<soap12:operation soapAction="http://www.mathertel.de/OrteLookup/GetPrefixedEntries" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="OrteLookupHttpGet" type="tns:OrteLookupHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="OrteStartWith">
<http:operation location="/OrteStartWith" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetPrefixedEntries">
<http:operation location="/GetPrefixedEntries" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OrteLookup">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">A WebService retreiving the names of German cities starting with a specific string.</wsdl:documentation>
<wsdl:port name="OrteLookupSoap" binding="tns:OrteLookupSoap">
<soap:address location="http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx" />
</wsdl:port>
<wsdl:port name="OrteLookupSoap12" binding="tns:OrteLookupSoap12">
<soap12:address location="http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx" />
</wsdl:port>
<wsdl:port name="OrteLookupHttpGet" binding="tns:OrteLookupHttpGet">
<http:address location="http://mathertel.de/AJAXEngine/S02_AJAXCoreSamples/OrteLookup.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>