[pygccxml-commit] SF.net SVN: pygccxml: [532] pyplusplus_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <mb...@us...> - 2006-09-07 12:47:17
|
Revision: 532 http://svn.sourceforge.net/pygccxml/?rev=532&view=rev Author: mbaas Date: 2006-09-07 05:47:12 -0700 (Thu, 07 Sep 2006) Log Message: ----------- Added tests for the output_array_t class Modified Paths: -------------- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp pyplusplus_dev/unittests/function_transformations_tester.py Modified: pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-09-07 12:46:20 UTC (rev 531) +++ pyplusplus_dev/unittests/data/function_transformations_to_be_exported.hpp 2006-09-07 12:47:12 UTC (rev 532) @@ -45,6 +45,13 @@ return v[0]+v[1]+v[2]; } + // A method with a output array of fixed size + virtual void fixed_output_array(int v[3]) { + v[0] = 1; + v[1] = 2; + v[2] = 3; + } + unsigned int m_width; unsigned int m_height; @@ -69,6 +76,14 @@ return v; } +// This is used for calling img.fixed_output_array() on an instance passed +// in by Python. +int image_fixed_output_array( image_t& img) { + int v[3]; + img.fixed_output_array(v); + return v[0]+v[1]+v[2]; } +} + #endif//__function_transformations_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/function_transformations_tester.py =================================================================== --- pyplusplus_dev/unittests/function_transformations_tester.py 2006-09-07 12:46:20 UTC (rev 531) +++ pyplusplus_dev/unittests/function_transformations_tester.py 2006-09-07 12:47:12 UTC (rev 532) @@ -26,6 +26,7 @@ image.member_function( "get_size2" ).function_transformers.extend([output_t(1), output_t(2)]) image.member_function( "input_arg" ).function_transformers.extend([input_t(1)]) image.member_function( "fixed_input_array" ).function_transformers.extend([input_array_t(1,3)]) + image.member_function( "fixed_output_array" ).function_transformers.extend([output_array_t(1,3)]) mb.free_function("get_cpp_instance").call_policies = return_value_policy(reference_existing_object) mb.variable( "cpp_instance" ).exclude() mb.decls(lambda decl: decl.name[0]=="_").exclude() @@ -62,16 +63,31 @@ self.assertRaises(ValueError, lambda : img.fixed_input_array(1)) self.assertRaises(ValueError, lambda : img.fixed_input_array(None)) + # Check the fixed_output_array method + self.assertEqual(img.fixed_output_array(), [1,2,3]) + ####### Do the tests on a class derived in Python ######## class py_image1_t(module.image_t): def __init__(self, h, w): module.image_t.__init__(self, h, w) + self.fixed_output_array_mode = 0 # Override a virtual method def get_one_value(self): return self.m_height+1 + def fixed_output_array(self): + # Produce a correct return value + if self.fixed_output_array_mode==0: + return (2,5,7) + # Produce the wrong type + elif self.fixed_output_array_mode==1: + return 5 + # Produce a sequence with the wrong number of items + elif self.fixed_output_array_mode==2: + return (2,5) + pyimg1 = py_image1_t(3,7) # Check a method that returns two values by reference @@ -83,6 +99,13 @@ # Check if the Python class can also be passed back to C++ self.assertEqual(module.get_image_one_value(pyimg1), 4) + # Check if fixed_output_array() is correctly called from C++ + self.assertEqual(module.image_fixed_output_array(pyimg1), 14) + pyimg1.fixed_output_array_mode = 1 + self.assertRaises(ValueError, lambda : module.image_fixed_output_array(pyimg1)) + pyimg1.fixed_output_array_mode = 2 + self.assertRaises(ValueError, lambda : module.image_fixed_output_array(pyimg1)) + class py_image2_t(module.image_t): def __init__(self, h, w): module.image_t.__init__(self, h, w) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |