aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-01-11 17:34:28 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:12:53 -0300
commit0e7ecded1f8d944ee138d79b46f10e5f6c6618c7 (patch)
treefbe345554c65c9f7f6b10a01bccda099bf1b34da /tests
parent640537a691a2cd0830e12810714ec0cc5164242a (diff)
Added test to assert the precedence of enum arguments over int implicit conversions.
This test is inspired by bug #511 [1], and it checks the precedence of an enum argument over a class that can be implicitly built from an integer. [1] http://bugs.openbossa.org/show_bug.cgi?id=511 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/pen.h52
-rw-r--r--tests/samplebinding/CMakeLists.txt2
-rw-r--r--tests/samplebinding/global.h1
-rw-r--r--tests/samplebinding/pen_test.py59
-rw-r--r--tests/samplebinding/typesystem_sample.xml5
5 files changed, 119 insertions, 0 deletions
diff --git a/tests/libsample/pen.h b/tests/libsample/pen.h
new file mode 100644
index 000000000..9c97c2e36
--- /dev/null
+++ b/tests/libsample/pen.h
@@ -0,0 +1,52 @@
+/*
+ * 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 PEN_H
+#define PEN_H
+
+#include "libsamplemacros.h"
+#include "samplenamespace.h"
+
+class LIBSAMPLE_API Color
+{
+public:
+ Color() {}
+ Color(SampleNamespace::InValue arg) {}
+ Color(unsigned int arg) {}
+};
+
+class LIBSAMPLE_API Pen
+{
+public:
+ enum { EmptyCtor, EnumCtor, ColorCtor, CopyCtor };
+
+ Pen() : m_ctor(EmptyCtor) {}
+ Pen(SampleNamespace::Option option) : m_ctor(EnumCtor) {}
+ Pen(const Color& color) : m_ctor(ColorCtor) {}
+ Pen(const Pen& pen) : m_ctor(CopyCtor) {}
+
+ int ctorType() { return m_ctor; }
+private:
+ int m_ctor;
+};
+
+#endif
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 1fa95501a..c81209c21 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -16,6 +16,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/base6_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/blackbox_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/bucket_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/collector_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/color_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/ctorconvrule_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/sbkdate_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp
@@ -51,6 +52,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/objtypereference_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/pen_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pointf_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pointerholder_wrapper.cpp
diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h
index 181ed29f9..18ad56466 100644
--- a/tests/samplebinding/global.h
+++ b/tests/samplebinding/global.h
@@ -29,6 +29,7 @@
#include "oddbool.h"
#include "overload.h"
#include "pairuser.h"
+#include "pen.h"
#include "point.h"
#include "pointf.h"
#include "pointerholder.h"
diff --git a/tests/samplebinding/pen_test.py b/tests/samplebinding/pen_test.py
new file mode 100644
index 000000000..52e79e2d1
--- /dev/null
+++ b/tests/samplebinding/pen_test.py
@@ -0,0 +1,59 @@
+#!/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
+
+'''Test cases for <add-function> with const char* as argument'''
+
+import unittest
+
+from sample import Color, Pen, SampleNamespace
+
+class TestPen(unittest.TestCase):
+ '''Simple test case for Pen.'''
+
+ def testPenWithEmptyConstructor(self):
+ pen = Pen()
+ self.assertEqual(pen.ctorType(), Pen.EmptyCtor)
+
+ def testPenWithEnumConstructor(self):
+ pen = Pen(SampleNamespace.RandomNumber)
+ self.assertEqual(pen.ctorType(), Pen.EnumCtor)
+
+ def testPenWithColorConstructor(self):
+ pen = Pen(Color())
+ self.assertEqual(pen.ctorType(), Pen.ColorCtor)
+
+ def testPenWithCopyConstructor(self):
+ pen = Pen(Pen())
+ self.assertEqual(pen.ctorType(), Pen.CopyCtor)
+
+ def testPenWithIntConvertedToColor(self):
+ pen = Pen(1)
+ self.assertEqual(pen.ctorType(), Pen.ColorCtor)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 5a518c34a..2667c16d5 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -1238,6 +1238,11 @@
</add-function>
</value-type>
+ <value-type name="Color" />
+ <value-type name="Pen">
+ <enum-type identified-by-value="EnumCtor"/>
+ </value-type>
+
<value-type name="CtorConvRule">
<modify-function signature="CtorConvRule(long)">
<modify-argument index="1">