diff options
Diffstat (limited to 'sources/shiboken2/tests')
26 files changed, 536 insertions, 14 deletions
diff --git a/sources/shiboken2/tests/helper.py b/sources/shiboken2/tests/helper.py new file mode 100644 index 000000000..2564c91d4 --- /dev/null +++ b/sources/shiboken2/tests/helper.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +############################################################################# +## +## Copyright (C) 2019 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + + +def objectFullname(t): + module = t.__module__ + if module is None or module == str.__class__.__module__: + return t.__name__ + else: + return module + '.' + t.__name__ diff --git a/sources/shiboken2/tests/libother/CMakeLists.txt b/sources/shiboken2/tests/libother/CMakeLists.txt index 6aba91e13..d1e4c4354 100644 --- a/sources/shiboken2/tests/libother/CMakeLists.txt +++ b/sources/shiboken2/tests/libother/CMakeLists.txt @@ -5,12 +5,13 @@ number.cpp otherderived.cpp otherobjecttype.cpp othermultiplederived.cpp +smartptrtester.cpp ) add_library(libother SHARED ${libother_SRC}) target_include_directories(libother PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_definitions(libother PRIVATE LIBOTHER_BUILD) -target_link_libraries(libother PUBLIC libsample) +target_link_libraries(libother PUBLIC libsample libsmart) set_property(TARGET libother PROPERTY PREFIX "") diff --git a/sources/shiboken2/tests/libother/otherobjecttype.cpp b/sources/shiboken2/tests/libother/otherobjecttype.cpp index ca356ce94..1f782ecd8 100644 --- a/sources/shiboken2/tests/libother/otherobjecttype.cpp +++ b/sources/shiboken2/tests/libother/otherobjecttype.cpp @@ -34,3 +34,13 @@ operator<<(Collector& collector, const OtherObjectType& obj) collector << obj.identifier()*2; return collector; } + +int OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value) +{ + return static_cast<int>(value); +} + +int OtherObjectType::enumAsIntForInvisibleNamespace(Invisible::EnumOnNamespace value) +{ + return static_cast<int>(value); +} diff --git a/sources/shiboken2/tests/libother/otherobjecttype.h b/sources/shiboken2/tests/libother/otherobjecttype.h index 22687c8bd..efd394347 100644 --- a/sources/shiboken2/tests/libother/otherobjecttype.h +++ b/sources/shiboken2/tests/libother/otherobjecttype.h @@ -35,11 +35,14 @@ #include "libothermacros.h" #include "objecttype.h" #include "collector.h" +#include "samplenamespace.h" -class OtherObjectType : public ObjectType + +class LIBOTHER_API OtherObjectType : public ObjectType { public: - + static int enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value); + static int enumAsIntForInvisibleNamespace(Invisible::EnumOnNamespace value); }; diff --git a/sources/shiboken2/tests/libother/smartptrtester.cpp b/sources/shiboken2/tests/libother/smartptrtester.cpp new file mode 100644 index 000000000..9636c7521 --- /dev/null +++ b/sources/shiboken2/tests/libother/smartptrtester.cpp @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "smartptrtester.h" + +SharedPtr<Str> SmartPtrTester::createSharedPtrStr(const char *what) +{ + return SharedPtr<Str>(new Str(what)); +} + +std::string SmartPtrTester::valueOfSharedPtrStr(const SharedPtr<Str> &str) +{ + return str->cstring(); +} + +SharedPtr<Integer> SmartPtrTester::createSharedPtrInteger(int v) +{ + auto i = SharedPtr<Integer>(new Integer); + i->m_int = v; + return i; +} + +int SmartPtrTester::valueOfSharedPtrInteger(const SharedPtr<Integer> &v) +{ + return v->m_int; +} + +void SmartPtrTester::fiddleInt(const SharedPtr<int> &) // no binding, should not cause errors +{ +} diff --git a/sources/shiboken2/tests/libother/smartptrtester.h b/sources/shiboken2/tests/libother/smartptrtester.h new file mode 100644 index 000000000..a560bcf2f --- /dev/null +++ b/sources/shiboken2/tests/libother/smartptrtester.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SMARTPTRTESTER_H +#define SMARTPTRTESTER_H + +#include "libothermacros.h" + +#include <smart.h> +#include <str.h> + +class LIBOTHER_API SmartPtrTester +{ +public: + SharedPtr<Str> createSharedPtrStr(const char *what); + std::string valueOfSharedPtrStr(const SharedPtr<Str> &); + + SharedPtr<Integer> createSharedPtrInteger(int v); + int valueOfSharedPtrInteger(const SharedPtr<Integer> &); + + void fiddleInt(const SharedPtr<int> &); +}; + +#endif // SMARTPTRTESTER_H diff --git a/sources/shiboken2/tests/libsample/CMakeLists.txt b/sources/shiboken2/tests/libsample/CMakeLists.txt index 170829fbc..ae13cd9f2 100644 --- a/sources/shiboken2/tests/libsample/CMakeLists.txt +++ b/sources/shiboken2/tests/libsample/CMakeLists.txt @@ -36,6 +36,7 @@ pointf.cpp polygon.cpp protected.cpp reference.cpp +renaming.cpp sample.cpp samplenamespace.cpp sbkdate.cpp diff --git a/sources/shiboken2/tests/libsample/renaming.cpp b/sources/shiboken2/tests/libsample/renaming.cpp new file mode 100644 index 000000000..30586e1db --- /dev/null +++ b/sources/shiboken2/tests/libsample/renaming.cpp @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "renaming.h" + +#include <iostream> + +int ToBeRenamedValue::value() const +{ + return m_value; +} + +void ToBeRenamedValue::setValue(int v) +{ + m_value = v; +} + +void RenamedUser::useRenamedValue(const ToBeRenamedValue &v) +{ + std::cout << __FUNCTION__ << ' ' << v.value() << '\n'; +} diff --git a/sources/shiboken2/tests/libsample/renaming.h b/sources/shiboken2/tests/libsample/renaming.h new file mode 100644 index 000000000..cd88b36bf --- /dev/null +++ b/sources/shiboken2/tests/libsample/renaming.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of Qt for Python. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RENAMING_H +#define RENAMING_H + +#include "libsamplemacros.h" + +class LIBSAMPLE_API ToBeRenamedValue +{ +public: + int value() const; + void setValue(int v); + +private: + int m_value = 42; +}; + +class LIBSAMPLE_API RenamedUser +{ +public: + void useRenamedValue(const ToBeRenamedValue &v); +}; + +#endif // POINT_H diff --git a/sources/shiboken2/tests/libsample/samplenamespace.h b/sources/shiboken2/tests/libsample/samplenamespace.h index 6868b5f0a..9e46b2ad6 100644 --- a/sources/shiboken2/tests/libsample/samplenamespace.h +++ b/sources/shiboken2/tests/libsample/samplenamespace.h @@ -51,6 +51,13 @@ enum EnumOnNamespace { Option3 = 3 }; +struct ObjectOnInvisibleNamespace +{ + bool exists() const { return true; } + static int toInt(EnumOnNamespace e) { return static_cast<int>(e); } + static ObjectOnInvisibleNamespace consume(const ObjectOnInvisibleNamespace &other) { return other; } +}; + }; namespace SampleNamespace @@ -137,6 +144,8 @@ protected: PublicScopedEnum protectedMethodReturningPublicScopedEnum() const; }; +LIBSAMPLE_API inline int enumAsInt(SomeClass::PublicScopedEnum value) { return static_cast<int>(value); } + class DerivedFromNamespace : public SomeClass::SomeInnerClass::OkThisIsRecursiveEnough { public: diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp index 6a4deb50a..81fa30c7e 100644 --- a/sources/shiboken2/tests/libsmart/smart.cpp +++ b/sources/shiboken2/tests/libsmart/smart.cpp @@ -93,7 +93,7 @@ Obj::~Obj() void Obj::printObj() { if (shouldPrint()) { std::cout << "integer value: " << m_integer - << " internal integer value: " << m_internalInteger->m_int << '\n'; + << " internal integer value: " << m_internalInteger->value() << '\n'; } } @@ -134,6 +134,17 @@ int Obj::takeSharedPtrToObj(SharedPtr<Obj> pObj) int Obj::takeSharedPtrToInteger(SharedPtr<Integer> pInt) { pInt->printInteger(); + return pInt->value(); +} + +SharedPtr<const Integer> Obj::giveSharedPtrToConstInteger() +{ + SharedPtr<const Integer> co(new Integer); + return co; +} + +int Obj::takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt) +{ return pInt->m_int; } @@ -173,7 +184,17 @@ Integer::~Integer() std::cout << "Integer destructor " << this << '\n'; } -void Integer::printInteger() +int Integer::value() const +{ + return m_int; +} + +void Integer::setValue(int v) +{ + m_int = v; +} + +void Integer::printInteger() const { if (shouldPrint()) std::cout << "Integer value for object " << this << " is " << m_int << '\n'; diff --git a/sources/shiboken2/tests/libsmart/smart_integer.h b/sources/shiboken2/tests/libsmart/smart_integer.h index 3756f68b0..126894120 100644 --- a/sources/shiboken2/tests/libsmart/smart_integer.h +++ b/sources/shiboken2/tests/libsmart/smart_integer.h @@ -37,8 +37,12 @@ public: Integer(const Integer &other); Integer &operator=(const Integer &other); ~Integer(); - void printInteger(); - int m_int; + void printInteger() const; + + int value() const; + void setValue(int v); + + int m_int; // public for testing member field access. }; namespace Smart { diff --git a/sources/shiboken2/tests/libsmart/smart_obj.h b/sources/shiboken2/tests/libsmart/smart_obj.h index 12425366e..8fe45993f 100644 --- a/sources/shiboken2/tests/libsmart/smart_obj.h +++ b/sources/shiboken2/tests/libsmart/smart_obj.h @@ -48,12 +48,14 @@ public: Integer takeInteger(Integer val); SharedPtr<Obj> giveSharedPtrToObj(); std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size); - SharedPtr<Integer> giveSharedPtrToInteger(); + virtual SharedPtr<Integer> giveSharedPtrToInteger(); // virtual for PYSIDE-1188 + SharedPtr<const Integer> giveSharedPtrToConstInteger(); + int takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt); SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); int takeSharedPtrToObj(SharedPtr<Obj> pObj); int takeSharedPtrToInteger(SharedPtr<Integer> pInt); - int m_integer; + int m_integer; // public for testing member field access. Integer *m_internalInteger; }; diff --git a/sources/shiboken2/tests/otherbinding/CMakeLists.txt b/sources/shiboken2/tests/otherbinding/CMakeLists.txt index bc5c4bdad..05a282838 100644 --- a/sources/shiboken2/tests/otherbinding/CMakeLists.txt +++ b/sources/shiboken2/tests/otherbinding/CMakeLists.txt @@ -10,6 +10,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/other/number_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/other/otherderived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/other/othermultiplederived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/other/otherobjecttype_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/other/sharedptr_str_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/other/smartptrtester_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/other/other_module_wrapper.cpp ) @@ -28,8 +30,9 @@ COMMENT "Running generator for 'other' test binding..." add_library(other MODULE ${other_SRC}) target_include_directories(other PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - ${sample_BINARY_DIR}/sample) -target_link_libraries(other PUBLIC libother libsample libshiboken) + ${sample_BINARY_DIR}/sample + ${smart_BINARY_DIR}/smart) +target_link_libraries(other PUBLIC libother libsample libsmart libshiboken) set_property(TARGET other PROPERTY PREFIX "") set_property(TARGET other PROPERTY OUTPUT_NAME "other${PYTHON_EXTENSION_SUFFIX}") @@ -38,6 +41,6 @@ if(WIN32) endif() -add_dependencies(other sample) +add_dependencies(other sample smart) create_generator_target(other) diff --git a/sources/shiboken2/tests/otherbinding/global.h b/sources/shiboken2/tests/otherbinding/global.h index 0fccabb92..763566ae0 100644 --- a/sources/shiboken2/tests/otherbinding/global.h +++ b/sources/shiboken2/tests/otherbinding/global.h @@ -32,4 +32,5 @@ #include "otherderived.h" #include "otherobjecttype.h" #include "othermultiplederived.h" +#include "smartptrtester.h" diff --git a/sources/shiboken2/tests/otherbinding/other-binding.txt.in b/sources/shiboken2/tests/otherbinding/other-binding.txt.in index a17b70fc1..dbe935a9f 100644 --- a/sources/shiboken2/tests/otherbinding/other-binding.txt.in +++ b/sources/shiboken2/tests/otherbinding/other-binding.txt.in @@ -8,11 +8,13 @@ typesystem-file = @other_TYPESYSTEM@ output-directory = @CMAKE_CURRENT_BINARY_DIR@ include-path = @libother_SOURCE_DIR@ +include-path = @libsmart_SOURCE_DIR@ include-path = @libsample_SOURCE_DIR@ include-path = @libsample_SOURCE_DIR@/.. typesystem-path = @CMAKE_CURRENT_SOURCE_DIR@ typesystem-path = @sample_SOURCE_DIR@ +typesystem-path = @smart_SOURCE_DIR@ enable-parent-ctor-heuristic diff --git a/sources/shiboken2/tests/otherbinding/signature_test.py b/sources/shiboken2/tests/otherbinding/signature_test.py new file mode 100644 index 000000000..06894eaf8 --- /dev/null +++ b/sources/shiboken2/tests/otherbinding/signature_test.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +############################################################################# +## +## Copyright (C) 2019 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for functions signature''' + +import os +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +from other import OtherObjectType +from helper import objectFullname + +class SignatureTest(unittest.TestCase): + + # Check if the argument of 'OtherObjectType::enumAsInt(SampleNamespace::SomeClass::PublicScopedEnum value)' + # has the correct representation + def testNamespaceFromOtherModule(self): + argType = OtherObjectType.enumAsInt.__signature__.parameters['value'].annotation + self.assertEqual(objectFullname(argType), 'sample.SampleNamespace.SomeClass.PublicScopedEnum') + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken2/tests/otherbinding/smartptr_test.py b/sources/shiboken2/tests/otherbinding/smartptr_test.py new file mode 100644 index 000000000..04f657757 --- /dev/null +++ b/sources/shiboken2/tests/otherbinding/smartptr_test.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +############################################################################# +## +## Copyright (C) 2020 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for the SmartPtrTester class''' + +import os +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +from smart import Integer +from sample import Str +from other import SmartPtrTester + + +class SmartPtrTest(unittest.TestCase): + '''Test case for the SmartPtrTester class''' + + def test(self): + tester = SmartPtrTester() + + integerPtr = tester.createSharedPtrInteger(42) + self.assertEqual(tester.valueOfSharedPtrInteger(integerPtr), 42) + + strPtr = tester.createSharedPtrStr('hello') + self.assertEqual(tester.valueOfSharedPtrStr(strPtr), 'hello') + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken2/tests/otherbinding/typesystem_other.xml b/sources/shiboken2/tests/otherbinding/typesystem_other.xml index 2932dafb3..78c4dd016 100644 --- a/sources/shiboken2/tests/otherbinding/typesystem_other.xml +++ b/sources/shiboken2/tests/otherbinding/typesystem_other.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="other"> <load-typesystem name="typesystem_sample.xml" generate="no" /> + <load-typesystem name="typesystem_smart.xml" generate="no" /> <object-type name="OtherObjectType" /> <object-type name="OtherDerived" /> @@ -9,6 +10,10 @@ <value-type name="ExtendsNoImplicitConversion" /> <value-type name="Number" /> + <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" + instantiations="Str"/> + <value-type name="SmartPtrTester"/> + <suppress-warning text="signature 'operator!=(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> <suppress-warning text="signature 'operator+(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> <suppress-warning text="signature 'operator==(ByteArray,const char*)' for function modification in 'ByteArray' not found." /> diff --git a/sources/shiboken2/tests/samplebinding/CMakeLists.txt b/sources/shiboken2/tests/samplebinding/CMakeLists.txt index 61090d30e..b65068dc3 100644 --- a/sources/shiboken2/tests/samplebinding/CMakeLists.txt +++ b/sources/shiboken2/tests/samplebinding/CMakeLists.txt @@ -94,6 +94,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/rect_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/rectf_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/reference_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/referentmodelindex_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/toberenamedvalue_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/renameduser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_sample_wrapper.cpp @@ -123,6 +125,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/filter_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/data_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/intersection_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/union_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/invisible_objectoninvisiblenamespace_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/sample-binding.txt.in" diff --git a/sources/shiboken2/tests/samplebinding/global.h b/sources/shiboken2/tests/samplebinding/global.h index 3984102a8..f4e20b74f 100644 --- a/sources/shiboken2/tests/samplebinding/global.h +++ b/sources/shiboken2/tests/samplebinding/global.h @@ -75,6 +75,7 @@ #include "protected.h" #include "rect.h" #include "reference.h" +#include "renaming.h" #include "removednamespaces.h" #include "sample.h" #include "samplenamespace.h" diff --git a/sources/shiboken2/tests/samplebinding/namespace_test.py b/sources/shiboken2/tests/samplebinding/namespace_test.py index aeaf81cff..b1977cf6f 100644 --- a/sources/shiboken2/tests/samplebinding/namespace_test.py +++ b/sources/shiboken2/tests/samplebinding/namespace_test.py @@ -40,12 +40,17 @@ from shiboken_paths import init_paths init_paths() from sample import * +from helper import objectFullname class TestEnumUnderNamespace(unittest.TestCase): def testInvisibleNamespace(self): o1 = EnumOnNamespace.Option1 self.assertEqual(o1, 1) + def testTpNames(self): + self.assertEqual(objectFullname(EnumOnNamespace), "sample.EnumOnNamespace") + self.assertEqual(str(EnumOnNamespace.Option1), + "sample.EnumOnNamespace.Option1") class TestClassesUnderNamespace(unittest.TestCase): def testIt(self): @@ -72,5 +77,19 @@ class TestClassesUnderNamespace(unittest.TestCase): self.assertEqual(str(SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum), "<class 'sample.SampleNamespace.SomeClass.SomeInnerClass.OkThisIsRecursiveEnough.NiceEnum'>") + # Test if enum inside of class is correct represented + self.assertEqual(objectFullname(SampleNamespace.enumInEnumOut.__signature__.parameters['in_'].annotation), + "sample.SampleNamespace.InValue") + self.assertEqual(objectFullname(SampleNamespace.enumAsInt.__signature__.parameters['value'].annotation), + "sample.SampleNamespace.SomeClass.PublicScopedEnum") + self.assertEqual(objectFullname(ObjectOnInvisibleNamespace.toInt.__signature__.parameters['e'].annotation), + "sample.EnumOnNamespace") + + # Test if enum on namespace that was marked as not gerenated does not appear on type name + self.assertEqual(objectFullname(ObjectOnInvisibleNamespace), + "sample.ObjectOnInvisibleNamespace") + self.assertEqual(objectFullname(ObjectOnInvisibleNamespace.consume.__signature__.parameters['other'].annotation), + "sample.ObjectOnInvisibleNamespace") + if __name__ == '__main__': unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/renaming_test.py b/sources/shiboken2/tests/samplebinding/renaming_test.py new file mode 100644 index 000000000..cb59dce3a --- /dev/null +++ b/sources/shiboken2/tests/samplebinding/renaming_test.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +############################################################################# +## +## Copyright (C) 2019 The Qt Company Ltd. +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the test suite of Qt for Python. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT$ +## Commercial License Usage +## Licensees holding valid commercial Qt licenses may use this file in +## accordance with the commercial license agreement provided with the +## Software or, alternatively, in accordance with the terms contained in +## a written agreement between you and The Qt Company. For licensing terms +## and conditions see https://www.qt.io/terms-conditions. For further +## information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +'''Test cases for renaming using target-lang-name attribute.''' + +import os +import re +import sys +import unittest + +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from shiboken_paths import init_paths +init_paths() + +from sample import RenamedValue, RenamedUser + +class RenamingTest(unittest.TestCase): + def test(self): + '''Tests whether the C++ class ToBeRenamedValue renamed via attribute + target-lang-name to RenamedValue shows up in consuming function + signature strings correctly. + ''' + renamed_value = RenamedValue() + self.assertEqual(str(type(renamed_value)), + "<class 'sample.RenamedValue'>") + rename_user = RenamedUser() + rename_user.useRenamedValue(renamed_value) + actual_signature = str(rename_user.useRenamedValue.__signature__) + self.assertTrue(re.match(r"^\(self,\s*v:\s*sample.RenamedValue\)$", + actual_signature)) + + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml index 30ad5def7..c3db91324 100644 --- a/sources/shiboken2/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken2/tests/samplebinding/typesystem_sample.xml @@ -543,8 +543,9 @@ <enum-type identified-by-value="AnonymousGlobalEnum_Value0"/> - <namespace-type name="Invisible" generate="no"> + <namespace-type name="Invisible" visible="no"> <enum-type name="EnumOnNamespace" /> + <value-type name="ObjectOnInvisibleNamespace" /> </namespace-type> <namespace-type name="SampleNamespace"> @@ -2432,6 +2433,9 @@ <modify-function signature="dummy(std::list<std::pair<BlackBox *, BlackBox *> > &)" rename="dummy_method" /> </object-type> + <value-type name="ToBeRenamedValue" target-lang-name="RenamedValue"/> + <value-type name="RenamedUser"/> + <suppress-warning text="horribly broken type '__off64_t'" /> <suppress-warning text="enum '__codecvt_result' does not have a type entry or is not an enum" /> <suppress-warning text="Pure virtual method "Abstract::hideFunction(HideType*)" must be implement but was completely removed on typesystem." /> diff --git a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py index 6210916d3..50b2120a2 100644 --- a/sources/shiboken2/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken2/tests/smartbinding/smart_pointer_test.py @@ -128,6 +128,10 @@ class SmartPointerTests(unittest.TestCase): self.assertEqual(integer.m_int, 50) # Set and get a member value via shared pointer (like operator->). + ptrToInteger.setValue(150) + self.assertEqual(ptrToInteger.value(), 150) + + # Set and get a member field via shared pointer (like operator->). ptrToInteger.m_int = 100 self.assertEqual(ptrToInteger.m_int, 100) @@ -155,6 +159,18 @@ class SmartPointerTests(unittest.TestCase): self.assertEqual(objCount(), 0) self.assertEqual(integerCount(), 0) + def testConstIntegerSmartPointer(self): + # Uncomment to see more debug info about creation of objects and ref counts. + # Registry.getInstance().setShouldPrint(True) + + # Create Obj. + o = Obj() + ptrToConstInteger = o.giveSharedPtrToConstInteger() + self.assertEqual(ptrToConstInteger.m_int, 456) + result = o.takeSharedPtrToConstInteger(ptrToConstInteger) + self.assertEqual(result, 456) + self.assertEqual(ptrToConstInteger.value(), 456) + def testSmartPointersWithNamespace(self): # Create the main object o = Obj() diff --git a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml index 0bb485957..8fb3082a0 100644 --- a/sources/shiboken2/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken2/tests/smartbinding/typesystem_smart.xml @@ -43,7 +43,8 @@ possible to explicitly instantiate a new shared pointer in python e.g. o = SharedPtr_Foo() won't work. --> - <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" /> + <smart-pointer-type name="SharedPtr" type="shared" getter="data" ref-count-method="useCount" + instantiations="Integer,Smart::Integer2,Obj"/> <object-type name="Obj" /> <value-type name="Integer" /> |