diff options
Diffstat (limited to 'sources/shiboken2/tests/libsmart')
-rw-r--r-- | sources/shiboken2/tests/libsmart/CMakeLists.txt | 11 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/libsmartmacros.h | 46 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart.cpp | 261 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart.h | 37 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart_integer.h | 56 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart_obj.h | 62 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart_registry.h | 68 | ||||
-rw-r--r-- | sources/shiboken2/tests/libsmart/smart_sharedptr.h | 140 |
8 files changed, 0 insertions, 681 deletions
diff --git a/sources/shiboken2/tests/libsmart/CMakeLists.txt b/sources/shiboken2/tests/libsmart/CMakeLists.txt deleted file mode 100644 index 152c57f25..000000000 --- a/sources/shiboken2/tests/libsmart/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -project(libsmart) - -set(libsmart_SRC -smart.cpp -) - -add_library(libsmart SHARED ${libsmart_SRC}) -target_include_directories(libsmart PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_compile_definitions(libsmart PRIVATE LIBSMART_BUILD) -set_property(TARGET libsmart PROPERTY PREFIX "") - diff --git a/sources/shiboken2/tests/libsmart/libsmartmacros.h b/sources/shiboken2/tests/libsmart/libsmartmacros.h deleted file mode 100644 index d85e219bb..000000000 --- a/sources/shiboken2/tests/libsmart/libsmartmacros.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef LIB_SMART_MACROS_H -#define LIB_SMART_MACROS_H - -#if defined _WIN32 || defined __CYGWIN__ - #if LIBSMART_BUILD - #define LIB_SMART_API __declspec(dllexport) - #else - #define LIB_SMART_API __declspec(dllimport) - #endif -#else -#if __GNUC__ >= 4 - #define LIB_SMART_API __attribute__ ((visibility("default"))) -#else - #define LIB_SMART_API -#endif -#endif - -#endif diff --git a/sources/shiboken2/tests/libsmart/smart.cpp b/sources/shiboken2/tests/libsmart/smart.cpp deleted file mode 100644 index 81fa30c7e..000000000 --- a/sources/shiboken2/tests/libsmart/smart.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#include "smart.h" - -#include <algorithm> -#include <iostream> - -static inline bool shouldPrint() -{ - return Registry::getInstance()->shouldPrint(); -} - -void SharedPtrBase::logDefaultConstructor(const void *t) -{ - if (shouldPrint()) - std::cout << "shared_ptr default constructor " << t << '\n'; -} - -void SharedPtrBase::logConstructor(const void *t, const void *pointee) -{ - if (shouldPrint()) { - std::cout << "shared_ptr constructor " << t << " with pointer " - << pointee << '\n'; - } -} - -void SharedPtrBase::logCopyConstructor(const void *t, const void *refData) -{ - if (shouldPrint()) { - std::cout << "shared_ptr copy constructor " << t << " with pointer " - << refData << '\n'; - } -} - -void SharedPtrBase::logAssignment(const void *t, const void *refData) -{ - if (shouldPrint()) { - std::cout << "shared_ptr assignment operator " << t << " with pointer " - << refData << "\n"; - } -} - -void SharedPtrBase::logDestructor(const void *t, int remainingRefCount) -{ - if (shouldPrint()) { - std::cout << "shared_ptr destructor " << t << " remaining refcount " - << remainingRefCount << '\n'; - } -} - -Obj::Obj() : m_integer(123), m_internalInteger(new Integer) -{ - Registry::getInstance()->add(this); - if (shouldPrint()) - std::cout << "Object constructor " << this << '\n'; -} - -Obj::~Obj() -{ - Registry::getInstance()->remove(this); - delete m_internalInteger; - if (shouldPrint()) - std::cout << "Object destructor " << this << '\n'; -} - - -void Obj::printObj() { - if (shouldPrint()) { - std::cout << "integer value: " << m_integer - << " internal integer value: " << m_internalInteger->value() << '\n'; - } -} - - -SharedPtr<Obj> Obj::giveSharedPtrToObj() -{ - SharedPtr<Obj> o(new Obj); - return o; -} - -std::vector<SharedPtr<Obj> > Obj::giveSharedPtrToObjList(int size) -{ - std::vector<SharedPtr<Obj> > r; - for (int i=0; i < size; i++) - r.push_back(giveSharedPtrToObj()); - return r; -} - - -SharedPtr<Integer> Obj::giveSharedPtrToInteger() -{ - SharedPtr<Integer> o(new Integer); - return o; -} - -SharedPtr<Smart::Integer2> Obj::giveSharedPtrToInteger2() -{ - SharedPtr<Smart::Integer2> o(new Smart::Integer2); - return o; -} - -int Obj::takeSharedPtrToObj(SharedPtr<Obj> pObj) -{ - pObj->printObj(); - return pObj->m_integer; -} - -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; -} - -Integer Obj::takeInteger(Integer val) -{ - return val; -} - -Integer::Integer() : m_int(456) -{ - Registry::getInstance()->add(this); - if (shouldPrint()) - std::cout << "Integer constructor " << this << '\n'; -} - -Integer::Integer(const Integer &other) -{ - Registry::getInstance()->add(this); - if (shouldPrint()) - std::cout << "Integer copy constructor " << this << '\n'; - m_int = other.m_int; -} - -Integer &Integer::operator=(const Integer &other) -{ - Registry::getInstance()->add(this); - if (shouldPrint()) - std::cout << "Integer operator= " << this << '\n'; - m_int = other.m_int; - return *this; -} - -Integer::~Integer() -{ - Registry::getInstance()->remove(this); - if (shouldPrint()) - std::cout << "Integer destructor " << this << '\n'; -} - -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'; -} - -Registry *Registry::getInstance() -{ - static Registry registry; - return ®istry; -} - -Registry::Registry() = default; - -Registry::~Registry() = default; - -void Registry::add(Obj *p) -{ - m_objects.push_back(p); -} - -void Registry::add(Integer *p) -{ - m_integers.push_back(p); -} - -void Registry::remove(Obj *p) -{ - m_objects.erase(std::remove(m_objects.begin(), m_objects.end(), p), m_objects.end()); -} - -void Registry::remove(Integer *p) -{ - m_integers.erase(std::remove(m_integers.begin(), m_integers.end(), p), m_integers.end()); -} - -int Registry::countObjects() const -{ - return static_cast<int>(m_objects.size()); -} - -int Registry::countIntegers() const -{ - return static_cast<int>(m_integers.size()); -} - -bool Registry::shouldPrint() const -{ - return m_printStuff; -} - -void Registry::setShouldPrint(bool flag) -{ - m_printStuff = flag; -} - -Smart::Integer2::Integer2() - : Integer () -{ -} - -Smart::Integer2::Integer2(const Smart::Integer2 &other) - : Integer (other) -{ -} diff --git a/sources/shiboken2/tests/libsmart/smart.h b/sources/shiboken2/tests/libsmart/smart.h deleted file mode 100644 index 6238f27d5..000000000 --- a/sources/shiboken2/tests/libsmart/smart.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** -** -** 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 SMART_H -#define SMART_H - -#include "smart_sharedptr.h" -#include "smart_integer.h" -#include "smart_obj.h" -#include "smart_registry.h" - -#endif // SMART_H diff --git a/sources/shiboken2/tests/libsmart/smart_integer.h b/sources/shiboken2/tests/libsmart/smart_integer.h deleted file mode 100644 index 126894120..000000000 --- a/sources/shiboken2/tests/libsmart/smart_integer.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** -** -** 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 SMART_INTEGER_H -#define SMART_INTEGER_H - -#include "libsmartmacros.h" - -class LIB_SMART_API Integer { -public: - Integer(); - Integer(const Integer &other); - Integer &operator=(const Integer &other); - ~Integer(); - void printInteger() const; - - int value() const; - void setValue(int v); - - int m_int; // public for testing member field access. -}; - -namespace Smart { -class LIB_SMART_API Integer2 : public Integer { -public: - Integer2(); - Integer2(const Integer2 &other); -}; -} // namespace Smart - -#endif // SMART_INTEGER_H diff --git a/sources/shiboken2/tests/libsmart/smart_obj.h b/sources/shiboken2/tests/libsmart/smart_obj.h deleted file mode 100644 index 8fe45993f..000000000 --- a/sources/shiboken2/tests/libsmart/smart_obj.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** 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 SMART_OBJ_H -#define SMART_OBJ_H - -#include "libsmartmacros.h" -#include "smart_sharedptr.h" - -#include <vector> - -class Integer; -class Obj; -namespace Smart { class Integer2; } - -// Couldn't name it Object because it caused some namespace clashes. -class LIB_SMART_API Obj { -public: - Obj(); - 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(); - int takeSharedPtrToConstInteger(SharedPtr<const Integer> pInt); - SharedPtr<Smart::Integer2> giveSharedPtrToInteger2(); - int takeSharedPtrToObj(SharedPtr<Obj> pObj); - int takeSharedPtrToInteger(SharedPtr<Integer> pInt); - - int m_integer; // public for testing member field access. - Integer *m_internalInteger; -}; - -#endif // SMART_OBJ_H diff --git a/sources/shiboken2/tests/libsmart/smart_registry.h b/sources/shiboken2/tests/libsmart/smart_registry.h deleted file mode 100644 index 6171ddb59..000000000 --- a/sources/shiboken2/tests/libsmart/smart_registry.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 SMART_REGISTRY_H -#define SMART_REGISTRY_H - -#include <vector> - -#include "libsmartmacros.h" - -class Obj; -class Integer; - -// Used to track which C++ objects are alive. -class LIB_SMART_API Registry { -public: - static Registry *getInstance(); - ~Registry(); - - Registry(const Registry &) = delete; - Registry &operator=(const Registry &) = delete; - Registry(Registry &&) = delete; - Registry &operator=(Registry &&) = delete; - - void add(Obj *p); - void add(Integer *p); - void remove(Obj *p); - void remove(Integer *p); - int countObjects() const; - int countIntegers() const; - bool shouldPrint() const; - void setShouldPrint(bool flag); - -protected: - Registry(); - -private: - std::vector<Obj *> m_objects; - std::vector<Integer *> m_integers; - bool m_printStuff = false; -}; - -#endif // SMART_REGISTRY_H diff --git a/sources/shiboken2/tests/libsmart/smart_sharedptr.h b/sources/shiboken2/tests/libsmart/smart_sharedptr.h deleted file mode 100644 index 84184e1f8..000000000 --- a/sources/shiboken2/tests/libsmart/smart_sharedptr.h +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** 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 SMART_SHARED_PTR_H -#define SMART_SHARED_PTR_H - -#include "libsmartmacros.h" - -template <class T> -class RefData { -public: - RefData(T *ptr) : m_refCount(1), m_heldPtr(ptr) {} - ~RefData() { delete m_heldPtr; } - int inc() { return ++m_refCount; } - int dec() { return --m_refCount; } - int useCount() { return m_refCount; } - int m_refCount; - T *m_heldPtr; -}; - -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); -}; - -template <class T> -class SharedPtr : public SharedPtrBase { -public: - SharedPtr() { logDefaultConstructor(this); } - - SharedPtr(T *v) - { - logConstructor(this, v); - if (v) - m_refData = new RefData<T>(v); - } - - SharedPtr(const SharedPtr<T> &other) : m_refData(other.m_refData) - { - logCopyConstructor(this, other.m_refData); - if (m_refData) - m_refData->inc(); - } - - SharedPtr<T> &operator=(const SharedPtr<T>& other) - { - if (this != &other) { - logAssignment(this, other.m_refData); - if (m_refData && m_refData->dec() == 0) - delete m_refData; - m_refData = other.m_refData; - if (m_refData) - m_refData->inc(); - } - return *this; - } - - T *data() const - { - return m_refData ? m_refData->m_heldPtr : nullptr; - } - - int useCount() const - { - return m_refData ? m_refData->useCount() : 0; - } - - void dummyMethod1() - { - - } - - T& operator*() const - { - // Crashes if smart pointer is empty (just like std::shared_ptr). - return *(m_refData->m_heldPtr); - } - - T *operator->() const - { - return m_refData ? m_refData->m_heldPtr : nullptr; - } - - bool operator!() const - { - return !m_refData || !m_refData->m_heldPtr; - } - - bool isNull() const - { - return !m_refData || !m_refData->m_heldPtr; - } - - operator bool() const - { - return m_refData && m_refData->m_heldPtr; - } - - ~SharedPtr() - { - if (m_refData) - logDestructor(this, m_refData->useCount() - 1); - if (m_refData && m_refData->dec() == 0) - delete m_refData; - } - -private: - RefData<T> *m_refData = nullptr; -}; - -#endif // SMART_SHARED_PTR_H |