aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/libsmart
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/tests/libsmart')
-rw-r--r--sources/shiboken6/tests/libsmart/CMakeLists.txt14
-rw-r--r--sources/shiboken6/tests/libsmart/libsmartmacros.h29
-rw-r--r--sources/shiboken6/tests/libsmart/smart.cpp157
-rw-r--r--sources/shiboken6/tests/libsmart/smart.h33
-rw-r--r--sources/shiboken6/tests/libsmart/smart_integer.h69
-rw-r--r--sources/shiboken6/tests/libsmart/smart_obj.h47
-rw-r--r--sources/shiboken6/tests/libsmart/smart_registry.h35
-rw-r--r--sources/shiboken6/tests/libsmart/smart_sharedptr.h56
-rw-r--r--sources/shiboken6/tests/libsmart/smart_test.h13
-rw-r--r--sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp58
-rw-r--r--sources/shiboken6/tests/libsmart/stdoptionaltestbench.h30
-rw-r--r--sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp106
-rw-r--r--sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h49
-rw-r--r--sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp133
-rw-r--r--sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h50
15 files changed, 622 insertions, 257 deletions
diff --git a/sources/shiboken6/tests/libsmart/CMakeLists.txt b/sources/shiboken6/tests/libsmart/CMakeLists.txt
index 152c57f25..95f0cffd6 100644
--- a/sources/shiboken6/tests/libsmart/CMakeLists.txt
+++ b/sources/shiboken6/tests/libsmart/CMakeLists.txt
@@ -1,7 +1,19 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
project(libsmart)
set(libsmart_SRC
-smart.cpp
+libsmartmacros.h
+smart.cpp smart.h
+smart_integer.h
+smart_obj.h
+smart_registry.h
+smart_sharedptr.h
+smart_test.h
+stdoptionaltestbench.cpp stdoptionaltestbench.h
+stdsharedptrtestbench.cpp stdsharedptrtestbench.h
+stduniqueptrtestbench.cpp stduniqueptrtestbench.h
)
add_library(libsmart SHARED ${libsmart_SRC})
diff --git a/sources/shiboken6/tests/libsmart/libsmartmacros.h b/sources/shiboken6/tests/libsmart/libsmartmacros.h
index 03edab049..c1f229b6c 100644
--- a/sources/shiboken6/tests/libsmart/libsmartmacros.h
+++ b/sources/shiboken6/tests/libsmart/libsmartmacros.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef LIB_SMART_MACROS_H
#define LIB_SMART_MACROS_H
diff --git a/sources/shiboken6/tests/libsmart/smart.cpp b/sources/shiboken6/tests/libsmart/smart.cpp
index 81fa30c7e..2273040f9 100644
--- a/sources/shiboken6/tests/libsmart/smart.cpp
+++ b/sources/shiboken6/tests/libsmart/smart.cpp
@@ -1,75 +1,53 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 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$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "smart.h"
#include <algorithm>
#include <iostream>
-static inline bool shouldPrint()
+static inline bool verbose()
{
- return Registry::getInstance()->shouldPrint();
+ return Registry::getInstance()->verbose();
}
-void SharedPtrBase::logDefaultConstructor(const void *t)
+void SharedPtrBase::logDefaultConstructor(const char *instantiation, const void *t)
{
- if (shouldPrint())
- std::cout << "shared_ptr default constructor " << t << '\n';
+ if (verbose())
+ std::cout << "SharedPtr<" << instantiation << "> default constructor " << t << '\n';
}
-void SharedPtrBase::logConstructor(const void *t, const void *pointee)
+void SharedPtrBase::logConstructor(const char *instantiation, const void *t,
+ const void *pointee)
{
- if (shouldPrint()) {
- std::cout << "shared_ptr constructor " << t << " with pointer "
- << pointee << '\n';
+ if (verbose()) {
+ std::cout << "SharedPtr<" << instantiation << "> constructor "
+ << t << " with pointer " << pointee << '\n';
}
}
-void SharedPtrBase::logCopyConstructor(const void *t, const void *refData)
+void SharedPtrBase::logCopyConstructor(const char *instantiation, const void *t,
+ const void *refData)
{
- if (shouldPrint()) {
- std::cout << "shared_ptr copy constructor " << t << " with pointer "
- << refData << '\n';
+ if (verbose()) {
+ std::cout << "SharedPtr<" << instantiation << ">) copy constructor "
+ << t << " with pointer " << refData << '\n';
}
}
-void SharedPtrBase::logAssignment(const void *t, const void *refData)
+void SharedPtrBase::logAssignment(const char *instantiation, const void *t, const void *refData)
{
- if (shouldPrint()) {
- std::cout << "shared_ptr assignment operator " << t << " with pointer "
- << refData << "\n";
+ if (verbose()) {
+ std::cout << "SharedPtr<" << instantiation << ">::operator= " << t
+ << " with pointer " << refData << "\n";
}
}
-void SharedPtrBase::logDestructor(const void *t, int remainingRefCount)
+void SharedPtrBase::logDestructor(const char *instantiation, const void *t,
+ int remainingRefCount)
{
- if (shouldPrint()) {
- std::cout << "shared_ptr destructor " << t << " remaining refcount "
+ if (verbose()) {
+ std::cout << "~SharedPtr<" << instantiation << "> " << t << ", remaining refcount "
<< remainingRefCount << '\n';
}
}
@@ -77,49 +55,49 @@ void SharedPtrBase::logDestructor(const void *t, int remainingRefCount)
Obj::Obj() : m_integer(123), m_internalInteger(new Integer)
{
Registry::getInstance()->add(this);
- if (shouldPrint())
- std::cout << "Object constructor " << this << '\n';
+ if (verbose())
+ std::cout << "Obj constructor " << this << '\n';
}
Obj::~Obj()
{
Registry::getInstance()->remove(this);
delete m_internalInteger;
- if (shouldPrint())
- std::cout << "Object destructor " << this << '\n';
+ if (verbose())
+ std::cout << "~Obj " << this << '\n';
}
void Obj::printObj() {
- if (shouldPrint()) {
- std::cout << "integer value: " << m_integer
+ if (verbose()) {
+ std::cout << "Obj::printObj(): integer value: " << m_integer
<< " internal integer value: " << m_internalInteger->value() << '\n';
}
}
-SharedPtr<Obj> Obj::giveSharedPtrToObj()
+SharedPtr<Obj> Obj::createSharedPtrObj()
{
SharedPtr<Obj> o(new Obj);
return o;
}
-std::vector<SharedPtr<Obj> > Obj::giveSharedPtrToObjList(int size)
+std::vector<SharedPtr<Obj> > Obj::createSharedPtrObjList(int size)
{
std::vector<SharedPtr<Obj> > r;
for (int i=0; i < size; i++)
- r.push_back(giveSharedPtrToObj());
+ r.push_back(createSharedPtrObj());
return r;
}
-SharedPtr<Integer> Obj::giveSharedPtrToInteger()
+SharedPtr<Integer> Obj::createSharedPtrInteger()
{
SharedPtr<Integer> o(new Integer);
return o;
}
-SharedPtr<Smart::Integer2> Obj::giveSharedPtrToInteger2()
+SharedPtr<Smart::Integer2> Obj::createSharedPtrInteger2()
{
SharedPtr<Smart::Integer2> o(new Smart::Integer2);
return o;
@@ -133,11 +111,37 @@ int Obj::takeSharedPtrToObj(SharedPtr<Obj> pObj)
int Obj::takeSharedPtrToInteger(SharedPtr<Integer> pInt)
{
+ if (pInt.isNull()) {
+ std::cout << "SharedPtr<Integer>(nullptr) passed!\n";
+ return -1;
+ }
pInt->printInteger();
return pInt->value();
}
-SharedPtr<const Integer> Obj::giveSharedPtrToConstInteger()
+int Obj::takeSharedPtrToIntegerByConstRef(const SharedPtr<Integer> &pInt)
+{
+ if (pInt.isNull()) {
+ std::cout << "SharedPtr<Integer>(nullptr) passed!\n";
+ return -1;
+ }
+ pInt->printInteger();
+ return pInt->value();
+}
+
+SharedPtr<Integer> Obj::createSharedPtrInteger(int value)
+{
+ auto *i = new Integer;
+ i->setValue(value);
+ return SharedPtr<Integer>(i);
+}
+
+SharedPtr<Integer> Obj::createNullSharedPtrInteger()
+{
+ return {};
+}
+
+SharedPtr<const Integer> Obj::createSharedPtrConstInteger()
{
SharedPtr<const Integer> co(new Integer);
return co;
@@ -156,14 +160,14 @@ Integer Obj::takeInteger(Integer val)
Integer::Integer() : m_int(456)
{
Registry::getInstance()->add(this);
- if (shouldPrint())
+ if (verbose())
std::cout << "Integer constructor " << this << '\n';
}
Integer::Integer(const Integer &other)
{
Registry::getInstance()->add(this);
- if (shouldPrint())
+ if (verbose())
std::cout << "Integer copy constructor " << this << '\n';
m_int = other.m_int;
}
@@ -171,7 +175,7 @@ Integer::Integer(const Integer &other)
Integer &Integer::operator=(const Integer &other)
{
Registry::getInstance()->add(this);
- if (shouldPrint())
+ if (verbose())
std::cout << "Integer operator= " << this << '\n';
m_int = other.m_int;
return *this;
@@ -180,8 +184,8 @@ Integer &Integer::operator=(const Integer &other)
Integer::~Integer()
{
Registry::getInstance()->remove(this);
- if (shouldPrint())
- std::cout << "Integer destructor " << this << '\n';
+ if (verbose())
+ std::cout << "~Integer " << this << " (" << m_int << ")\n";
}
int Integer::value() const
@@ -192,11 +196,20 @@ int Integer::value() const
void Integer::setValue(int v)
{
m_int = v;
+ if (verbose())
+ std::cout << "Integer::setValue(" << v << ") " << this << '\n';
+}
+
+int Integer::compare(const Integer &rhs) const
+{
+ if (m_int < rhs.m_int)
+ return -1;
+ return m_int > rhs.m_int ? 1 : 0;
}
void Integer::printInteger() const
{
- if (shouldPrint())
+ if (verbose())
std::cout << "Integer value for object " << this << " is " << m_int << '\n';
}
@@ -240,14 +253,14 @@ int Registry::countIntegers() const
return static_cast<int>(m_integers.size());
}
-bool Registry::shouldPrint() const
+bool Registry::verbose() const
{
- return m_printStuff;
+ return m_verbose;
}
-void Registry::setShouldPrint(bool flag)
+void Registry::setVerbose(bool flag)
{
- m_printStuff = flag;
+ m_verbose = flag;
}
Smart::Integer2::Integer2()
@@ -255,7 +268,5 @@ Smart::Integer2::Integer2()
{
}
-Smart::Integer2::Integer2(const Smart::Integer2 &other)
- : Integer (other)
-{
-}
+Smart::Integer2::Integer2(const Smart::Integer2 &) = default;
+Smart::Integer2 &Smart::Integer2::operator=(const Integer2 &) = default;
diff --git a/sources/shiboken6/tests/libsmart/smart.h b/sources/shiboken6/tests/libsmart/smart.h
index 6238f27d5..1f610b302 100644
--- a/sources/shiboken6/tests/libsmart/smart.h
+++ b/sources/shiboken6/tests/libsmart/smart.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef SMART_H
#define SMART_H
@@ -33,5 +8,9 @@
#include "smart_integer.h"
#include "smart_obj.h"
#include "smart_registry.h"
+#include "smart_test.h"
+#include "stdsharedptrtestbench.h"
+#include "stdoptionaltestbench.h"
+#include "stduniqueptrtestbench.h"
#endif // SMART_H
diff --git a/sources/shiboken6/tests/libsmart/smart_integer.h b/sources/shiboken6/tests/libsmart/smart_integer.h
index 126894120..42a441a00 100644
--- a/sources/shiboken6/tests/libsmart/smart_integer.h
+++ b/sources/shiboken6/tests/libsmart/smart_integer.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef SMART_INTEGER_H
#define SMART_INTEGER_H
@@ -36,20 +11,58 @@ public:
Integer();
Integer(const Integer &other);
Integer &operator=(const Integer &other);
+ Integer(Integer &&other) noexcept = default;
+ Integer &operator=(Integer &&other) noexcept = default;
~Integer();
void printInteger() const;
int value() const;
void setValue(int v);
+ int compare(const Integer &rhs) const;
+
int m_int; // public for testing member field access.
};
+inline bool operator==(const Integer &lhs, const Integer &rhs)
+{
+ return lhs.compare(rhs) == 0;
+}
+
+inline bool operator!=(const Integer &lhs, const Integer &rhs)
+{
+ return lhs.compare(rhs) != 0;
+}
+
+inline bool operator<(const Integer &lhs, const Integer &rhs)
+{
+ return lhs.compare(rhs) < 0;
+}
+
+inline bool operator<=(const Integer &lhs, const Integer &rhs)
+{
+ return lhs.compare(rhs) <= 0;
+}
+
+inline bool operator>(const Integer &lhs, const Integer &rhs)
+{
+ return lhs.compare(rhs) > 0;
+}
+
+inline bool operator>=(const Integer &lhs, const Integer &rhs)
+{
+ return lhs.compare(rhs) >= 0;
+}
+
namespace Smart {
class LIB_SMART_API Integer2 : public Integer {
public:
Integer2();
- Integer2(const Integer2 &other);
+ Integer2(const Integer2 &);
+ Integer2 &operator=(const Integer2 &);
+ Integer2(Integer2 &&other) = delete;
+ Integer2 &operator=(Integer2 &&other) = delete;
+ ~Integer2() = default;
};
} // namespace Smart
diff --git a/sources/shiboken6/tests/libsmart/smart_obj.h b/sources/shiboken6/tests/libsmart/smart_obj.h
index 8fe45993f..9f4f8425d 100644
--- a/sources/shiboken6/tests/libsmart/smart_obj.h
+++ b/sources/shiboken6/tests/libsmart/smart_obj.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef SMART_OBJ_H
#define SMART_OBJ_H
@@ -42,18 +17,26 @@ namespace Smart { class Integer2; }
class LIB_SMART_API Obj {
public:
Obj();
+ Obj(const Obj &other) = delete;
+ Obj &operator=(const Obj &other) = delete;
+ Obj(Obj &&other) = delete;
+ Obj &operator=(Obj &&other) = delete;
virtual ~Obj();
void printObj();
Integer takeInteger(Integer val);
- SharedPtr<Obj> giveSharedPtrToObj();
- std::vector<SharedPtr<Obj> > giveSharedPtrToObjList(int size);
- virtual SharedPtr<Integer> giveSharedPtrToInteger(); // virtual for PYSIDE-1188
- SharedPtr<const Integer> giveSharedPtrToConstInteger();
+ static SharedPtr<Obj> createSharedPtrObj();
+ std::vector<SharedPtr<Obj> > createSharedPtrObjList(int size);
+ virtual SharedPtr<Integer> createSharedPtrInteger(); // virtual for PYSIDE-1188
+ SharedPtr<const Integer> createSharedPtrConstInteger();
int takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt);
- SharedPtr<Smart::Integer2> giveSharedPtrToInteger2();
+ SharedPtr<Smart::Integer2> createSharedPtrInteger2();
int takeSharedPtrToObj(SharedPtr<Obj> pObj);
int takeSharedPtrToInteger(SharedPtr<Integer> pInt);
+ int takeSharedPtrToIntegerByConstRef(const SharedPtr<Integer> &pInt);
+
+ static SharedPtr<Integer> createSharedPtrInteger(int value);
+ static SharedPtr<Integer> createNullSharedPtrInteger();
int m_integer; // public for testing member field access.
Integer *m_internalInteger;
diff --git a/sources/shiboken6/tests/libsmart/smart_registry.h b/sources/shiboken6/tests/libsmart/smart_registry.h
index 6171ddb59..abf7edc84 100644
--- a/sources/shiboken6/tests/libsmart/smart_registry.h
+++ b/sources/shiboken6/tests/libsmart/smart_registry.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef SMART_REGISTRY_H
#define SMART_REGISTRY_H
@@ -53,8 +28,8 @@ public:
void remove(Integer *p);
int countObjects() const;
int countIntegers() const;
- bool shouldPrint() const;
- void setShouldPrint(bool flag);
+ bool verbose() const;
+ void setVerbose(bool flag);
protected:
Registry();
@@ -62,7 +37,7 @@ protected:
private:
std::vector<Obj *> m_objects;
std::vector<Integer *> m_integers;
- bool m_printStuff = false;
+ bool m_verbose = false;
};
#endif // SMART_REGISTRY_H
diff --git a/sources/shiboken6/tests/libsmart/smart_sharedptr.h b/sources/shiboken6/tests/libsmart/smart_sharedptr.h
index 65a489c68..dc665810a 100644
--- a/sources/shiboken6/tests/libsmart/smart_sharedptr.h
+++ b/sources/shiboken6/tests/libsmart/smart_sharedptr.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef SMART_SHARED_PTR_H
#define SMART_SHARED_PTR_H
@@ -35,37 +10,40 @@
struct SharedPtrBase
{
- LIB_SMART_API static void logDefaultConstructor(const void *t);
- LIB_SMART_API static void logConstructor(const void *t, const void *pointee);
- LIB_SMART_API static void logCopyConstructor(const void *t, const void *refData);
- LIB_SMART_API static void logAssignment(const void *t, const void *refData);
- LIB_SMART_API static void logDestructor(const void *t, int remainingRefCount);
+ LIB_SMART_API static void logDefaultConstructor(const char *instantiation, const void *t);
+ LIB_SMART_API static void logConstructor(const char *instantiation, const void *t, const void *pointee);
+ LIB_SMART_API static void logCopyConstructor(const char *instantiation, const void *t, const void *refData);
+ LIB_SMART_API static void logAssignment(const char *instantiation, const void *t, const void *refData);
+ LIB_SMART_API static void logDestructor(const char *instantiation, const void *t, int remainingRefCount);
};
template <class T>
class SharedPtr : public SharedPtrBase {
public:
- SharedPtr() { logDefaultConstructor(this); }
+ LIBMINIMAL_DEFAULT_MOVE(SharedPtr)
+
+ SharedPtr() { logDefaultConstructor(typeid(T).name(), this); }
SharedPtr(T *v) : mPtr(v)
{
- logConstructor(this, v);
+ logConstructor(typeid(T).name(), this, v);
}
SharedPtr(const SharedPtr<T> &other) : mPtr(other.mPtr)
{
- logCopyConstructor(this, data());
+ logCopyConstructor(typeid(T).name(), this, data());
}
template<class X>
SharedPtr(const SharedPtr<X> &other) : mPtr(other.mPtr)
{
- logCopyConstructor(this, data());
+ logCopyConstructor(typeid(T).name(), this, data());
}
- SharedPtr& operator=(const SharedPtr& other)
+ SharedPtr &operator=(const SharedPtr &other)
{
- mPtr = other.mPtr;
+ if (this != &other)
+ mPtr = other.mPtr;
return *this;
}
@@ -107,7 +85,7 @@ public:
~SharedPtr()
{
if (mPtr.use_count() >= 1)
- logDestructor(this, mPtr.use_count() - 1);
+ logDestructor(typeid(T).name(), this, mPtr.use_count() - 1);
}
std::shared_ptr<T> mPtr;
diff --git a/sources/shiboken6/tests/libsmart/smart_test.h b/sources/shiboken6/tests/libsmart/smart_test.h
new file mode 100644
index 000000000..89d8cbc7c
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/smart_test.h
@@ -0,0 +1,13 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#ifndef SMART_TEST_H
+#define SMART_TEST_H
+
+namespace Test {
+
+enum DummyEnum { Dummy1, Dummy2 };
+
+}
+
+#endif // SMART_TEST_H
diff --git a/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp
new file mode 100644
index 000000000..69100720c
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp
@@ -0,0 +1,58 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include "stdoptionaltestbench.h"
+
+#include <iostream>
+
+std::ostream &operator<<(std::ostream &str, const Integer &i)
+{
+ str << i.value();
+ return str;
+}
+
+template <class T>
+std::ostream &operator<<(std::ostream &str, const std::optional<T> &o)
+{
+ if (o.has_value())
+ str << o.value();
+ else
+ str << "nullopt";
+ return str;
+}
+
+StdOptionalTestBench::StdOptionalTestBench() = default;
+
+std::optional<int> StdOptionalTestBench::optionalInt() const
+{
+ return m_optionalInt;
+}
+
+void StdOptionalTestBench::setOptionalInt(const std::optional<int> &i)
+{
+ std::cout << __FUNCTION__ << ' ' << i << '\n';
+ m_optionalInt = i;
+}
+
+void StdOptionalTestBench::setOptionalIntValue(int i)
+{
+ std::cout << __FUNCTION__ << ' ' << i << '\n';
+ m_optionalInt.emplace(i);
+}
+
+std::optional<Integer> StdOptionalTestBench::optionalInteger() const
+{
+ return m_optionalInteger;
+}
+
+void StdOptionalTestBench::setOptionalInteger(const std::optional<Integer> &s)
+{
+ std::cout << __FUNCTION__ << ' ' << s << '\n';
+ m_optionalInteger = s;
+}
+
+void StdOptionalTestBench::setOptionalIntegerValue(Integer &s)
+{
+ std::cout << __FUNCTION__ << ' ' << s << '\n';
+ m_optionalInteger.emplace(s);
+}
diff --git a/sources/shiboken6/tests/libsmart/stdoptionaltestbench.h b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.h
new file mode 100644
index 000000000..baa709821
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/stdoptionaltestbench.h
@@ -0,0 +1,30 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#ifndef OPTIONALTEST_H
+#define OPTIONALTEST_H
+
+#include "libsmartmacros.h"
+#include "smart_integer.h"
+
+#include <optional>
+
+class LIB_SMART_API StdOptionalTestBench
+{
+public:
+ StdOptionalTestBench();
+
+ std::optional<int> optionalInt() const;
+ void setOptionalInt(const std::optional<int> &i);
+ void setOptionalIntValue(int i);
+
+ std::optional<Integer> optionalInteger() const;
+ void setOptionalInteger(const std::optional<Integer> &s);
+ void setOptionalIntegerValue(Integer &s);
+
+private:
+ std::optional<int> m_optionalInt;
+ std::optional<Integer> m_optionalInteger;
+};
+
+#endif // OPTIONALTEST_H
diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp
new file mode 100644
index 000000000..472f807f2
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp
@@ -0,0 +1,106 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#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';
+}
+
+std::shared_ptr<int> StdSharedPtrTestBench::createInt(int v)
+{
+ return std::make_shared<int>(v);
+}
+
+std::shared_ptr<int> StdSharedPtrTestBench::createNullInt()
+{
+ return {};
+}
+
+void StdSharedPtrTestBench::printInt(const std::shared_ptr<int> &p)
+{
+ std::cerr << __FUNCTION__ << ' ';
+ if (p.get())
+ std::cerr << *p;
+ else
+ std::cerr << "nullptr";
+ std::cerr << '\n';
+}
+
+std::shared_ptr<double> StdSharedPtrTestBench::createDouble(double v)
+{
+ return std::make_shared<double>(v);
+}
+
+std::shared_ptr<double> StdSharedPtrTestBench::createNullDouble()
+{
+ return {};
+}
+
+void StdSharedPtrTestBench::printDouble(const std::shared_ptr<double> &p)
+{
+ std::cerr << __FUNCTION__ << ' ';
+ if (p.get())
+ std::cerr << *p;
+ else
+ std::cerr << "nullptr";
+ std::cerr << '\n';
+}
+
+std::shared_ptr<std::string> StdSharedPtrTestBench::createString(const char *text)
+{
+ return std::make_shared<std::string>(text);
+}
+
+std::shared_ptr<std::string> StdSharedPtrTestBench::createNullString()
+{
+ return {};
+}
+
+void StdSharedPtrTestBench::printString(const std::shared_ptr<std::string> &p)
+{
+ std::cerr << __FUNCTION__ << ' ';
+ if (p.get())
+ std::cerr << '"' << *p << '"';
+ else
+ std::cerr << "nullptr";
+ std::cerr << '\n';
+}
+
+StdSharedPtrVirtualMethodTester::StdSharedPtrVirtualMethodTester() = default;
+StdSharedPtrVirtualMethodTester::~StdSharedPtrVirtualMethodTester() = default;
+
+std::shared_ptr<Integer> StdSharedPtrVirtualMethodTester::callModifyInteger(const std::shared_ptr<Integer> &p)
+{
+ return doModifyInteger(p);
+}
+
+std::shared_ptr<Integer> StdSharedPtrVirtualMethodTester::doModifyInteger(std::shared_ptr<Integer> p)
+{
+ p->setValue(p->value() + 1);
+ return p;
+}
diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h
new file mode 100644
index 000000000..9d4c207b5
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h
@@ -0,0 +1,49 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#ifndef STDSHAREDPTRTESTBENCH_H
+#define STDSHAREDPTRTESTBENCH_H
+
+#include "libsmartmacros.h"
+
+#include <memory>
+#include <string>
+
+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> &);
+
+ static std::shared_ptr<int> createInt(int v = 42);
+ static std::shared_ptr<int> createNullInt();
+ static void printInt(const std::shared_ptr<int> &);
+
+ static std::shared_ptr<double> createDouble(double v = 42);
+ static std::shared_ptr<double> createNullDouble();
+ static void printDouble(const std::shared_ptr<double> &);
+
+ static std::shared_ptr<std::string> createString(const char *text);
+ static std::shared_ptr<std::string> createNullString();
+ static void printString(const std::shared_ptr<std::string> &);
+};
+
+class LIB_SMART_API StdSharedPtrVirtualMethodTester
+{
+public:
+ StdSharedPtrVirtualMethodTester();
+ virtual ~StdSharedPtrVirtualMethodTester();
+
+ std::shared_ptr<Integer> callModifyInteger(const std::shared_ptr<Integer> &p);
+
+protected:
+ virtual std::shared_ptr<Integer> doModifyInteger(std::shared_ptr<Integer> p);
+};
+
+#endif // STDSHAREDPTRTESTBENCH_H
diff --git a/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp
new file mode 100644
index 000000000..df4b566fa
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.cpp
@@ -0,0 +1,133 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include "stduniqueptrtestbench.h"
+#include "smart_integer.h"
+
+#include <iostream>
+
+std::ostream &operator<<(std::ostream &str, const std::unique_ptr<Integer> &p)
+{
+ str << "unique_ptr<Integer>(";
+ if (p.get())
+ str << p->value();
+ else
+ str << "nullptr";
+ str << ')';
+ return str;
+}
+
+std::ostream &operator<<(std::ostream &str, const std::unique_ptr<Smart::Integer2> &p)
+{
+ str << "unique_ptr<Integer>(";
+ if (p.get())
+ str << p->value();
+ else
+ str << "nullptr";
+ str << ')';
+ return str;
+}
+
+std::ostream &operator<<(std::ostream &str, const std::unique_ptr<int> &p)
+{
+ str << "unique_ptr<int>(";
+ if (p.get())
+ str << *p;
+ else
+ str << "nullptr";
+ str << ')';
+ return str;
+}
+
+StdUniquePtrTestBench::StdUniquePtrTestBench() = default;
+StdUniquePtrTestBench::~StdUniquePtrTestBench() = default;
+
+std::unique_ptr<Integer> StdUniquePtrTestBench::createInteger(int v)
+{
+ auto result = std::make_unique<Integer>();
+ result->setValue(v);
+ return result;
+}
+
+std::unique_ptr<Integer> StdUniquePtrTestBench::createNullInteger()
+{
+ return {};
+}
+
+void StdUniquePtrTestBench::printInteger(const std::unique_ptr<Integer> &p)
+{
+ std::cerr << __FUNCTION__ << ' ' << p << '\n';
+}
+
+void StdUniquePtrTestBench::takeInteger(std::unique_ptr<Integer> p)
+{
+ std::cerr << __FUNCTION__ << ' ' << p << '\n';
+}
+
+std::unique_ptr<int> StdUniquePtrTestBench::createInt(int v)
+{
+ return std::make_unique<int>(v);
+}
+
+std::unique_ptr<int> StdUniquePtrTestBench::createNullInt()
+{
+ return {};
+}
+
+void StdUniquePtrTestBench::printInt(const std::unique_ptr<int> &p)
+{
+ std::cerr << __FUNCTION__ << ' ' << p << '\n';
+}
+
+void StdUniquePtrTestBench::takeInt(std::unique_ptr<int> p)
+{
+ std::cerr << __FUNCTION__ << ' ' << p << '\n';
+}
+
+StdUniquePtrVirtualMethodTester::StdUniquePtrVirtualMethodTester() = default;
+
+StdUniquePtrVirtualMethodTester::~StdUniquePtrVirtualMethodTester() = default;
+
+bool StdUniquePtrVirtualMethodTester::testModifyIntegerByRef(int value, int expectedValue)
+{
+ auto p = std::make_unique<Integer>();
+ p->setValue(value);
+ const int actualValue = doModifyIntegerByRef(p);
+ return p.get() != nullptr && actualValue == expectedValue;
+}
+
+bool StdUniquePtrVirtualMethodTester::testModifyIntegerValue(int value, int expectedValue)
+{
+ auto p = std::make_unique<Integer>();
+ p->setValue(value);
+ const int actualValue = doModifyIntegerByValue(std::move(p));
+ return p.get() == nullptr && actualValue == expectedValue;
+}
+
+bool StdUniquePtrVirtualMethodTester::testCreateInteger(int value, int expectedValue)
+{
+ auto p = doCreateInteger(value);
+ return p.get() != nullptr && p->value() == expectedValue;
+}
+
+std::unique_ptr<Integer> StdUniquePtrVirtualMethodTester::doCreateInteger(int v)
+{
+ auto result = std::make_unique<Integer>();
+ result->setValue(v);
+ return result;
+}
+
+int StdUniquePtrVirtualMethodTester::doModifyIntegerByRef(const std::unique_ptr<Integer> &p)
+{
+ return p->value() + 1;
+}
+
+int StdUniquePtrVirtualMethodTester::doModifyIntegerByValue(std::unique_ptr<Integer> p)
+{
+ return p->value() + 1;
+}
+
+void StdUniquePtrTestBench::printInteger2(const std::unique_ptr<Smart::Integer2> &p)
+{
+ std::cerr << __FUNCTION__ << ' ' << p << '\n';
+}
diff --git a/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h
new file mode 100644
index 000000000..868c6d08c
--- /dev/null
+++ b/sources/shiboken6/tests/libsmart/stduniqueptrtestbench.h
@@ -0,0 +1,50 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#ifndef STDUNIQUEPTRTESTBENCH_H
+#define STDUNIQUEPTRTESTBENCH_H
+
+#include "libsmartmacros.h"
+
+#include <memory>
+
+class Integer;
+namespace Smart {
+class Integer2;
+}
+
+class LIB_SMART_API StdUniquePtrTestBench
+{
+public:
+ StdUniquePtrTestBench();
+ ~StdUniquePtrTestBench();
+
+ static std::unique_ptr<Integer> createInteger(int v = 42);
+ static std::unique_ptr<Integer> createNullInteger();
+ static void printInteger2(const std::unique_ptr<Smart::Integer2> &p);
+ static void printInteger(const std::unique_ptr<Integer> &p);
+ static void takeInteger(std::unique_ptr<Integer> p); // Call with std::move()
+
+ static std::unique_ptr<int> createInt(int v = 42);
+ static std::unique_ptr<int> createNullInt();
+ static void printInt(const std::unique_ptr<int> &p);
+ static void takeInt(std::unique_ptr<int> p); // Call with std::move()
+};
+
+class LIB_SMART_API StdUniquePtrVirtualMethodTester
+{
+public:
+ StdUniquePtrVirtualMethodTester();
+ virtual ~StdUniquePtrVirtualMethodTester();
+
+ bool testModifyIntegerByRef(int value, int expectedValue);
+ bool testModifyIntegerValue(int value, int expectedValue);
+ bool testCreateInteger(int value, int expectedValue);
+
+protected:
+ virtual std::unique_ptr<Integer> doCreateInteger(int v);
+ virtual int doModifyIntegerByRef(const std::unique_ptr<Integer> &p);
+ virtual int doModifyIntegerByValue(std::unique_ptr<Integer> p);
+};
+
+#endif // STDUNIQUEPTRTESTBENCH_H