From 05e7ecede5304ee56a805c7b5a10d3df11cf8952 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Sat, 6 Aug 2011 17:10:54 -0300 Subject: Added tests for a class that its only constructor is the copy one. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simulates a situation found in QtWebKit's QWebDatabase and QWebSecurityOrigin classes. Reviewed by Luciano Wolf Reviewed by Renato Araújo --- tests/libsample/CMakeLists.txt | 1 + tests/libsample/onlycopy.cpp | 51 +++++++++++++++++++++++++++++ tests/libsample/onlycopy.h | 53 +++++++++++++++++++++++++++++++ tests/samplebinding/CMakeLists.txt | 2 ++ tests/samplebinding/global.h | 1 + tests/samplebinding/onlycopyclass_test.py | 52 ++++++++++++++++++++++++++++++ tests/samplebinding/typesystem_sample.xml | 2 ++ 7 files changed, 162 insertions(+) create mode 100644 tests/libsample/onlycopy.cpp create mode 100644 tests/libsample/onlycopy.h create mode 100644 tests/samplebinding/onlycopyclass_test.py (limited to 'tests') diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt index 9148281ef..6b951b6df 100644 --- a/tests/libsample/CMakeLists.txt +++ b/tests/libsample/CMakeLists.txt @@ -7,6 +7,7 @@ bytearray.cpp bucket.cpp collector.cpp complex.cpp +onlycopy.cpp derived.cpp echo.cpp functions.cpp diff --git a/tests/libsample/onlycopy.cpp b/tests/libsample/onlycopy.cpp new file mode 100644 index 000000000..c40a012b5 --- /dev/null +++ b/tests/libsample/onlycopy.cpp @@ -0,0 +1,51 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "onlycopy.h" + +OnlyCopy::OnlyCopy(const OnlyCopy& other) +{ + m_value = other.m_value; +} + +OnlyCopy& +OnlyCopy::operator=(const OnlyCopy& other) +{ + m_value = other.m_value; + return *this; +} + +OnlyCopy +FriendOfOnlyCopy::createOnlyCopy(int value) +{ + + return OnlyCopy(value); +} + +std::list +FriendOfOnlyCopy::createListOfOnlyCopy(int quantity) +{ + std::list list; + for (int i = 0; i < quantity; ++i) + list.push_back(createOnlyCopy(i)); + return list; +} diff --git a/tests/libsample/onlycopy.h b/tests/libsample/onlycopy.h new file mode 100644 index 000000000..f81c174b6 --- /dev/null +++ b/tests/libsample/onlycopy.h @@ -0,0 +1,53 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef ONLYCOPYCLASS_H +#define ONLYCOPYCLASS_H + +#include "libsamplemacros.h" +#include + +// These classes simulate a situation found in +// QtWebKit's QWebDatabase and QWebSecurityOrigin. + +class LIBSAMPLE_API OnlyCopy +{ +public: + OnlyCopy(const OnlyCopy& other); + OnlyCopy& operator=(const OnlyCopy& other); + int value() const { return m_value; } + static int getValue(OnlyCopy onlyCopy) { return onlyCopy.m_value; } + static int getValueFromReference(const OnlyCopy& onlyCopy) { return onlyCopy.m_value; } +private: + int m_value; + OnlyCopy(int value) : m_value(value) {}; + friend class FriendOfOnlyCopy; +}; + +class LIBSAMPLE_API FriendOfOnlyCopy +{ +public: + static OnlyCopy createOnlyCopy(int value); + static std::list createListOfOnlyCopy(int quantity); +}; + +#endif diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index 7a8ab7e88..2f4f33ccd 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -25,6 +25,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_someinnerclass_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/echo_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/event_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/expression_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/friendofonlycopy_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/handleholder_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/implicitconv_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/implicitbase_wrapper.cpp @@ -53,6 +54,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypeoperators_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objectview_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objtypereference_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/onlycopy_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/overload2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index a4736a784..5f9179138 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -30,6 +30,7 @@ #include "objecttypeoperators.h" #include "objectview.h" #include "oddbool.h" +#include "onlycopy.h" #include "overload.h" #include "pairuser.h" #include "pen.h" diff --git a/tests/samplebinding/onlycopyclass_test.py b/tests/samplebinding/onlycopyclass_test.py new file mode 100644 index 000000000..eeeb201c7 --- /dev/null +++ b/tests/samplebinding/onlycopyclass_test.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# +# Contact: PySide team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# version 2.1 as published by the Free Software Foundation. Please +# review the following information to ensure the GNU Lesser General +# Public License version 2.1 requirements will be met: +# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +# # +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +import unittest +from sample import OnlyCopy, FriendOfOnlyCopy + +class ClassWithOnlyCopyCtorTest(unittest.TestCase): + def testGetOne(self): + obj = FriendOfOnlyCopy.createOnlyCopy(123) + self.assertEqual(type(obj), OnlyCopy) + self.assertEqual(obj.value(), 123) + + def testGetMany(self): + objs = FriendOfOnlyCopy.createListOfOnlyCopy(3) + self.assertEqual(type(objs), list) + self.assertEqual(len(objs), 3) + for value, obj in enumerate(objs): + self.assertEqual(obj.value(), value) + + def testPassAsValue(self): + obj = FriendOfOnlyCopy.createOnlyCopy(123) + self.assertEqual(obj.value(), OnlyCopy.getValue(obj)) + + def testPassAsReference(self): + obj = FriendOfOnlyCopy.createOnlyCopy(123) + self.assertEqual(obj.value(), OnlyCopy.getValueFromReference(obj)) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index d52fdbe80..c7d9c6960 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -306,6 +306,8 @@ + + -- cgit v1.2.3