diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-08 20:27:33 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-08 20:30:00 -0300 |
commit | 3b98369c971d23b8a45cfbf1b3a60f6ccee1f7ab (patch) | |
tree | a71e9f2db33127ecbec84fe5f25f0fdcc6a3ec48 /tests | |
parent | 46eeae2c1bf48b221a6b97f7b9369e0d7e0f8a06 (diff) |
Adds test for argument removal plus argument type modification.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/injectcode.cpp | 8 | ||||
-rw-r--r-- | tests/libsample/injectcode.h | 1 | ||||
-rwxr-xr-x | tests/samplebinding/injectcode_test.py | 7 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 17 |
4 files changed, 33 insertions, 0 deletions
diff --git a/tests/libsample/injectcode.cpp b/tests/libsample/injectcode.cpp index f418b25f3..b69d81d77 100644 --- a/tests/libsample/injectcode.cpp +++ b/tests/libsample/injectcode.cpp @@ -93,3 +93,11 @@ const char* InjectCode::virtualMethod(int arg) return toStr(arg); } +int InjectCode::arrayMethod(int count, int* values) const +{ + int ret = 0; + for (int i=0; i < count; i++) + ret += values[i]; + return ret; +} + diff --git a/tests/libsample/injectcode.h b/tests/libsample/injectcode.h index 73c4f37e9..dfac5b672 100644 --- a/tests/libsample/injectcode.h +++ b/tests/libsample/injectcode.h @@ -53,6 +53,7 @@ public: const char* overloadedMethod(int arg0, double arg1); const char* overloadedMethod(int arg0, bool arg1); + int arrayMethod(int count, int* values) const; virtual const char* virtualMethod(int arg); private: // This attr is just to retain the memory pointed by all return values, diff --git a/tests/samplebinding/injectcode_test.py b/tests/samplebinding/injectcode_test.py index 322047918..d328de16b 100755 --- a/tests/samplebinding/injectcode_test.py +++ b/tests/samplebinding/injectcode_test.py @@ -61,5 +61,12 @@ class InjectCodeTest(unittest.TestCase): ret = ic.simpleMethod3(["1", "2", "3", "4"]) self.assertEqual(ret, "1234") + def testArgumentRemovalAndArgumentTypeModification(self): + '''A method has its first argument removed and the second modified.''' + ic = InjectCode() + values = (1, 2, 3, 4, 5) + result = ic.arrayMethod(values) + self.assertEqual(result, sum(values)) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 1531d6b08..292f6f10b 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -592,6 +592,23 @@ Various tests for inject codes. Note: Some uses of inject code here are used just for testing purposes, consider using the add-function tag. --> + + <modify-function signature="arrayMethod(int, int*) const"> + <modify-argument index="1"> + <remove-argument/> + </modify-argument> + <modify-argument index="2"> + <replace-type modified-type="PySequence"/> + </modify-argument> + <inject-code class="target" position="beginning"> + int numItems = PySequence_Size(%PYARG_1); + int cppItems[numItems]; + for (int i = 0; i < numItems; i++) + cppItems[i] = %CONVERTTOCPP[int](PySequence_GetItem(%PYARG_1, i)); + %PYARG_0 = %CONVERTTOPYTHON[int](%CPPSELF.%FUNCTION_NAME(numItems, cppItems)); + </inject-code> + </modify-function> + <!-- Inject the tp_str method using this alternative way Tested in InjectCodeTest.testTypeNativeBeginning_TypeTargetBeginning: |