diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-17 14:58:30 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-03-29 00:06:14 +0200 |
commit | 733ffe48210c95c1fe30cb1ec2c2a61867e21b80 (patch) | |
tree | f11316b2b9a4fdddb7aa296f927596f4305e9443 | |
parent | 5c6382ee849c769e39d3a017966cfd4deb7dc15e (diff) |
shiboken6: Add a test for std::shared_ptr
Task-number: PYSIDE-454
Change-Id: I67b89cccf4aae14b221fc13a98d53dd51f2a11e6
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Tismer <tismer@stackless.com>
7 files changed, 180 insertions, 2 deletions
diff --git a/sources/shiboken6/tests/libsmart/CMakeLists.txt b/sources/shiboken6/tests/libsmart/CMakeLists.txt index 152c57f25..79ccbac00 100644 --- a/sources/shiboken6/tests/libsmart/CMakeLists.txt +++ b/sources/shiboken6/tests/libsmart/CMakeLists.txt @@ -2,6 +2,7 @@ project(libsmart) set(libsmart_SRC smart.cpp +stdsharedptrtestbench.cpp ) add_library(libsmart SHARED ${libsmart_SRC}) diff --git a/sources/shiboken6/tests/libsmart/smart.h b/sources/shiboken6/tests/libsmart/smart.h index 6238f27d5..24009cda5 100644 --- a/sources/shiboken6/tests/libsmart/smart.h +++ b/sources/shiboken6/tests/libsmart/smart.h @@ -33,5 +33,6 @@ #include "smart_integer.h" #include "smart_obj.h" #include "smart_registry.h" +#include "stdsharedptrtestbench.h" #endif // SMART_H diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp new file mode 100644 index 000000000..3ee930041 --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 "stdsharedptrtestbench.h" +#include "smart_integer.h" + +#include <iostream> + +StdSharedPtrTestBench::StdSharedPtrTestBench() = default; +StdSharedPtrTestBench::~StdSharedPtrTestBench() = default; + +std::shared_ptr<Integer> StdSharedPtrTestBench::createInteger(int v) +{ + auto result = std::make_shared<Integer>(); + result->setValue(v); + return result; +} + +std::shared_ptr<Integer> StdSharedPtrTestBench::createNullInteger() +{ + return {}; +} + +void StdSharedPtrTestBench::printInteger(const std::shared_ptr<Integer> &p) +{ + std::cerr << __FUNCTION__ << ' '; + if (p.get()) + std::cerr << p->value(); + else + std::cerr << "nullptr"; + std::cerr << '\n'; +} diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h new file mode 100644 index 000000000..0cf5d78a4 --- /dev/null +++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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 STDSHAREDPTRTESTBENCH_H +#define STDSHAREDPTRTESTBENCH_H + +#include "libsmartmacros.h" + +#include <memory> + +class Integer; + +class LIB_SMART_API StdSharedPtrTestBench +{ +public: + StdSharedPtrTestBench(); + ~StdSharedPtrTestBench(); + + static std::shared_ptr<Integer> createInteger(int v = 42); + static std::shared_ptr<Integer> createNullInteger(); + static void printInteger(const std::shared_ptr<Integer> &); +}; + +#endif // STDSHAREDPTRTESTBENCH_H diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt index 0059305c2..1f89ce096 100644 --- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt +++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt @@ -13,6 +13,9 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/registry_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/smart_integer2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer2_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrtestbench_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_integer_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/smart/std_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/smart-binding.txt.in" diff --git a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py new file mode 100644 index 000000000..1b96569a7 --- /dev/null +++ b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +############################################################################# +## +## Copyright (C) 2022 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$ +## +############################################################################# + +import gc +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from shiboken_paths import init_paths +init_paths() +from smart import StdSharedPtrTestBench + + +class StdSharedPtrTests(unittest.TestCase): + def testIt(self): + p = StdSharedPtrTestBench.createInteger() + StdSharedPtrTestBench.printInteger(p) + np = StdSharedPtrTestBench.createNullInteger() + StdSharedPtrTestBench.printInteger(np) + + +if __name__ == '__main__': + unittest.main() diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml index 46221b9af..8a68bb18d 100644 --- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml +++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <typesystem package="smart"> + <rejection class="*" argument-type="^std::nullptr_t&?$"/> <template name="cpplist_to_pylist_convertion"> PyObject *%out = PyList_New(int(%in.size())); @@ -17,8 +18,6 @@ } </template> - <custom-type name="std::shared_ptr" /> - <!-- Used in tests to check what C++ objects are allocated. --> <object-type name="Registry" /> @@ -38,4 +37,19 @@ </namespace-type> <!-- Just used to silence the warnings that shiboken doens't know what to do with this type --> <custom-type name="RefData" /> + + <system-include file-name="memory"/> + + <namespace-type name="std"> + <include file-name="memory" location="global"/> + <modify-function signature="^.*$" remove="all"/> + <enum-type name="pointer_safety"/> + <smart-pointer-type name="shared_ptr" type="shared" getter="get" + ref-count-method="use_count" + instantiations="Integer"> + <include file-name="memory" location="global"/> + </smart-pointer-type> + </namespace-type> + <object-type name="StdSharedPtrTestBench"/> + </typesystem> |