aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-06 17:10:54 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:09 -0300
commit05e7ecede5304ee56a805c7b5a10d3df11cf8952 (patch)
tree02980a49df0f0b7b5224dbcf1425e1f2396dfd83 /tests
parent6bd9d58b31cabedbce5131548d2447341df76e21 (diff)
Added tests for a class that its only constructor is the copy one.
This simulates a situation found in QtWebKit's QWebDatabase and QWebSecurityOrigin classes. Reviewed by Luciano Wolf <luciano.wolf@openbossa.org> Reviewed by Renato Ara├║jo <renato.filho@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/CMakeLists.txt1
-rw-r--r--tests/libsample/onlycopy.cpp51
-rw-r--r--tests/libsample/onlycopy.h53
-rw-r--r--tests/samplebinding/CMakeLists.txt2
-rw-r--r--tests/samplebinding/global.h1
-rw-r--r--tests/samplebinding/onlycopyclass_test.py52
-rw-r--r--tests/samplebinding/typesystem_sample.xml2
7 files changed, 162 insertions, 0 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
index 9148281e..6b951b6d 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 00000000..c40a012b
--- /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 <contact@pyside.org>
+ *
+ * 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<OnlyCopy>
+FriendOfOnlyCopy::createListOfOnlyCopy(int quantity)
+{
+ std::list<OnlyCopy> 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 00000000..f81c174b
--- /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 <contact@pyside.org>
+ *
+ * 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 <list>
+
+// 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<OnlyCopy> createListOfOnlyCopy(int quantity);
+};
+
+#endif
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 7a8ab7e8..2f4f33cc 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 a4736a78..5f917913 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 00000000..eeeb201c
--- /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 <contact@pyside.org>
+#
+# 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 d52fdbe8..c7d9c696 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -306,6 +306,8 @@
</object-type>
<value-type name="ObjectTypeHolder"/>
+ <value-type name="OnlyCopy"/>
+ <value-type name="FriendOfOnlyCopy"/>
<object-type name="ObjectModel">
<enum-type name="MethodCalled" />