aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/libsmart/smart.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/tests/libsmart/smart.cpp')
-rw-r--r--sources/shiboken6/tests/libsmart/smart.cpp157
1 files changed, 84 insertions, 73 deletions
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;