aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthew Woehlke <matthew.woehlke@kitware.com>2013-07-26 12:16:45 -0400
committerJohn Ehresman <jpe@wingware.com>2013-07-30 17:26:24 +0200
commit46db89a2a500c5b760c6f2b35ecde38d7e5ebfb6 (patch)
tree1feb857d0b8a1a8e34496b57e72300703e8f78ed /tests
parentae2a80453b95775364e93ed1a4647429b2fd7bad (diff)
Fix '%#' substitution for # > 9
Change '%#' substitution to use a regular expression for the 'old' text to enforce a word boundary after '#', such that we don't perform e.g. '%1' replacement on inputs like '%10'. This fixes problems trying to modify functions with more than nine arguments, such as the example from the previous commit (which now compiles and passes). Also add a test case for this. Change-Id: I9956804b3c65bddf7e36838866641b24ceb87c57 Reviewed-by: John Ehresman <jpe@wingware.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/CMakeLists.txt1
-rw-r--r--tests/libsample/transform.cpp54
-rw-r--r--tests/libsample/transform.h40
-rw-r--r--tests/samplebinding/global.h1
-rw-r--r--tests/samplebinding/transform_test.py53
-rw-r--r--tests/samplebinding/typesystem_sample.xml21
6 files changed, 170 insertions, 0 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
index 074de61fc..30205ed0c 100644
--- a/tests/libsample/CMakeLists.txt
+++ b/tests/libsample/CMakeLists.txt
@@ -43,6 +43,7 @@ size.cpp
sometime.cpp
str.cpp
strlist.cpp
+transform.cpp
virtualmethods.cpp
expression.cpp
filter.cpp
diff --git a/tests/libsample/transform.cpp b/tests/libsample/transform.cpp
new file mode 100644
index 000000000..2984ed391
--- /dev/null
+++ b/tests/libsample/transform.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2013 Kitware, Inc.
+ *
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2013 Digia Plc 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 "transform.h"
+
+#include <cmath>
+
+using namespace std;
+
+Point applyHomogeneousTransform(
+ const Point& in,
+ double m11, double m12, double m13,
+ double m21, double m22, double m23,
+ double m31, double m32, double m33,
+ bool* okay)
+{
+ double x = m11 * in.x() + m12 * in.y() + m13;
+ double y = m21 * in.x() + m22 * in.y() + m23;
+ double w = m31 * in.x() + m32 * in.y() + m33;
+
+ if (isfinite(w) && fabs(w) > 1e-10)
+ {
+ if (okay)
+ *okay = true;
+ return Point(x / w, y / w);
+ }
+ else
+ {
+ if (okay)
+ *okay = false;
+ return Point();
+ }
+}
diff --git a/tests/libsample/transform.h b/tests/libsample/transform.h
new file mode 100644
index 000000000..d21232889
--- /dev/null
+++ b/tests/libsample/transform.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2013 Kitware, Inc.
+ *
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2013 Digia Plc 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 TRANSFORM_H
+#define TRANSFORM_H
+
+#include "point.h"
+
+#include "libsamplemacros.h"
+
+LIBSAMPLE_API Point
+applyHomogeneousTransform(
+ const Point& in,
+ double m11, double m12, double m13,
+ double m21, double m22, double m23,
+ double m31, double m32, double m33,
+ bool* okay);
+
+#endif // TRANSFORM_H
diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h
index 37e00b372..28bac0a4e 100644
--- a/tests/samplebinding/global.h
+++ b/tests/samplebinding/global.h
@@ -53,6 +53,7 @@
#include "str.h"
#include "strlist.h"
#include "sometime.h"
+#include "transform.h"
#include "virtualmethods.h"
#include "voidholder.h"
#include "valueandvirtual.h"
diff --git a/tests/samplebinding/transform_test.py b/tests/samplebinding/transform_test.py
new file mode 100644
index 000000000..7b87300a9
--- /dev/null
+++ b/tests/samplebinding/transform_test.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright 2013 Kitware, Inc.
+#
+# This file is part of the Shiboken Python Bindings Generator project.
+#
+# Copyright (C) 2013 Digia Plc 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 StrList class that inherits from std::list<Str>.'''
+
+import unittest
+
+from sample import Point, applyHomogeneousTransform
+
+class TransformTest(unittest.TestCase):
+ '''Test cases for modifying a function with > 9 arguments.'''
+
+ def testTransform_ValidMatrix(self):
+ '''Transform applies successfully.'''
+ p = Point(3, 4)
+ r = applyHomogeneousTransform(p, 0, 1, 0, -1, 0, 0, 0, 0, 1)
+ self.assertTrue(type(r) is Point)
+ self.assertEqual(r.x(), 4)
+ self.assertEqual(r.y(), -3)
+
+ def testTransform_InvalidMatrix(self):
+ '''Transform does not apply successfully.'''
+ p = Point(3, 4)
+ r = applyHomogeneousTransform(p, 1, 0, 0, 0, 1, 0, 0, 0, 0)
+ self.assertTrue(r is None)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 813e0a09e..14b4f9d0f 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -1492,6 +1492,27 @@
</modify-function>
</value-type>
+ <function signature="applyHomogeneousTransform(Point,double,double,double,double,double,double,double,double,double,bool*)">
+ <!--
+ Tests handling of the '%#' substitution for # > 9.
+ -->
+ <modify-function signature="applyHomogeneousTransform(Point,double,double,double,double,double,double,double,double,double,bool*)">
+ <modify-argument index="11">
+ <remove-argument/>
+ </modify-argument>
+ <inject-code class="target" position="beginning">
+ bool ok_;
+ %RETURN_TYPE retval_ =
+ %FUNCTION_NAME(%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, &amp;ok_);
+ if (!ok_)
+ %PYARG_0 = Py_None;
+ else
+ %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval_);
+ </inject-code>
+ </modify-function>
+ </function>
+
+
<value-type name="InjectCode">
<!--
Various tests for inject codes.