[pygccxml-commit] SF.net SVN: pygccxml: [584] pyplusplus_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-09-25 10:12:32
|
Revision: 584 http://svn.sourceforge.net/pygccxml/?rev=584&view=rev Author: roman_yakovenko Date: 2006-09-25 03:12:18 -0700 (Mon, 25 Sep 2006) Log Message: ----------- creating split_module unit test Modified Paths: -------------- pyplusplus_dev/unittests/algorithms_tester.py pyplusplus_dev/unittests/call_policies_tester.py pyplusplus_dev/unittests/data/call_policies_to_be_exported.hpp pyplusplus_dev/unittests/fundamental_tester_base.py pyplusplus_dev/unittests/test_all.py Added Paths: ----------- pyplusplus_dev/unittests/data/split_module_to_be_exported.hpp pyplusplus_dev/unittests/split_module_tester.py Modified: pyplusplus_dev/unittests/algorithms_tester.py =================================================================== --- pyplusplus_dev/unittests/algorithms_tester.py 2006-09-25 10:10:06 UTC (rev 583) +++ pyplusplus_dev/unittests/algorithms_tester.py 2006-09-25 10:12:18 UTC (rev 584) @@ -121,57 +121,6 @@ minus_minus = xxx.operator( symbol='--' ) self.failUnless( 1 == len( minus_minus.readme() ), os.linesep.join( minus_minus.readme() ) ) -class multiple_files_tester_t(unittest.TestCase): - CLASS_DEF = \ - """ - namespace tester{ - - struct op_struct{}; - - op_struct* get_opaque(); - - void check_overload( int i=0, int j=1, int k=2 ); - - - struct b{ - enum EColor{ red, blue }; - enum EFruit{ apple, orange }; - - b(){} - b( int ){} - - void do_nothing(){} - - int do_something(){ return 1; } - - op_struct* get_opaque(); - - void check_overload( int i=0, int j=1, int k=2 ); - - int m_dummy; - - struct b_nested{}; - }; - } - """ - def test(self): - mb = module_builder.module_builder_t( - [ module_builder.create_text_fc( self.CLASS_DEF ) ] - , gccxml_path=autoconfig.gccxml.executable ) - mb.namespace( name='::tester' ).include() - mb.calldefs( 'check_overload' ).use_overload_macro = True - mb.calldefs( 'get_opaque' ).call_policies \ - = module_builder.call_policies.return_value_policy( module_builder.call_policies.return_opaque_pointer ) - mb.class_( 'op_struct' ).exclude() - b = mb.class_( 'b' ) - b.add_declaration_code( '//hello world' ) - nested = b.class_( 'b_nested' ) - nested.add_declaration_code( '//hello nested decl' ) - nested.add_registration_code( '//hello nested reg', False ) - - mb.build_code_creator('b_multi') - mb.split_module( autoconfig.build_dir, on_unused_file_found=lambda fpath: fpath ) - class class_multiple_files_tester_t(unittest.TestCase): CLASS_DEF = \ """ @@ -193,7 +142,7 @@ void do_nothing(){} int do_something(){ return 1; } - + void check_overload( int i=0, int j=1, int k=2 ); op_struct* get_opaque(); @@ -242,8 +191,6 @@ def create_suite(): suite = unittest.TestSuite() - multiple_files_tester_t - suite.addTest( unittest.makeSuite(multiple_files_tester_t)) suite.addTest( unittest.makeSuite(doc_extractor_tester_t)) suite.addTest( unittest.makeSuite(class_organizer_tester_t)) suite.addTest( unittest.makeSuite(indent_tester_t)) Modified: pyplusplus_dev/unittests/call_policies_tester.py =================================================================== --- pyplusplus_dev/unittests/call_policies_tester.py 2006-09-25 10:10:06 UTC (rev 583) +++ pyplusplus_dev/unittests/call_policies_tester.py 2006-09-25 10:12:18 UTC (rev 584) @@ -21,9 +21,14 @@ def customize(self, mb ): mb.calldef( 'return_second_arg' ).call_policies = call_policies.return_arg( 2 ) mb.calldef( 'return_self' ).call_policies = call_policies.return_self() + + mb.class_( 'impl_details_t' ).exclude() mb.calldef( 'get_impl_details' ).call_policies \ = call_policies.return_value_policy( call_policies.return_opaque_pointer ) + mb.calldef( 'get_opaque' ).call_policies \ + = call_policies.return_value_policy( call_policies.return_opaque_pointer ) + def run_tests(self, module): self.failUnless( module.compare( module.my_address() ) ) @@ -40,8 +45,10 @@ cont = module.container() self.failUnless( 1977 == cont[1977] ) - x = module.get_impl_details() - print x + module.get_impl_details() + + module.get_opaque() + def create_suite(): suite = unittest.TestSuite() suite.addTest( unittest.makeSuite(tester_t)) Modified: pyplusplus_dev/unittests/data/call_policies_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/call_policies_to_be_exported.hpp 2006-09-25 10:10:06 UTC (rev 583) +++ pyplusplus_dev/unittests/data/call_policies_to_be_exported.hpp 2006-09-25 10:12:18 UTC (rev 584) @@ -55,6 +55,10 @@ inline impl_details_t* get_impl_details(){ return (impl_details_t*)( 0x11223344 ); } + + typedef struct opaque_ *opaque_pointer; + opaque_pointer get_opaque(){ return 0; } + } } Added: pyplusplus_dev/unittests/data/split_module_to_be_exported.hpp =================================================================== --- pyplusplus_dev/unittests/data/split_module_to_be_exported.hpp (rev 0) +++ pyplusplus_dev/unittests/data/split_module_to_be_exported.hpp 2006-09-25 10:12:18 UTC (rev 584) @@ -0,0 +1,43 @@ +// Copyright 2004 Roman Yakovenko. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef __split_module_to_be_exported_hpp__ +#define __split_module_to_be_exported_hpp__ + +namespace split_module{ + +struct op_struct{}; + +inline op_struct* get_opaque(){ + return 0; +} + +inline void check_overload( int i=0, int j=1, int k=2 ){ +} + + +struct item_t{ + + enum EColor{ red, blue }; + enum EFruit{ apple, orange }; + + item_t(){} + item_t( int ){} + + void do_nothing(){} + int do_something(){ return 1; } + + op_struct* get_opaque(){ return 0; } + + void check_overload( int i=0, int j=1, int k=2 ){} + + int m_dummy; + + struct nested_t{}; +}; +} + + +#endif//__split_module_to_be_exported_hpp__ Modified: pyplusplus_dev/unittests/fundamental_tester_base.py =================================================================== --- pyplusplus_dev/unittests/fundamental_tester_base.py 2006-09-25 10:10:06 UTC (rev 583) +++ pyplusplus_dev/unittests/fundamental_tester_base.py 2006-09-25 10:12:18 UTC (rev 584) @@ -16,21 +16,21 @@ class fundamental_tester_base_t( unittest.TestCase ): SUFFIX_TO_BE_EXPORTED = '_to_be_exported.hpp' - + def __init__(self, module_name, *args, **keywd ): unittest.TestCase.__init__(self, *args) self.__module_name = module_name self.__to_be_exported_header \ = os.path.join( autoconfig.data_directory , self.__module_name + self.SUFFIX_TO_BE_EXPORTED ) - + self.__generated_source_file_name = os.path.join( autoconfig.build_dir , self.__module_name + '.cpp' ) self.__generated_scons_file_name = os.path.join( autoconfig.build_dir , self.__module_name + '.scons' ) - + self.__indexing_suite_version = keywd.get( 'indexing_suite_version', 1 ) - + def failIfRaisesAny(self, callableObj, *args, **kwargs): try: callableObj(*args, **kwargs) @@ -43,10 +43,21 @@ callableObj(*args, **kwargs) except: was_exception = True - self.failUnless(was_exception, 'exception has not been raised during execution.') + self.failUnless(was_exception, 'exception has not been raised during execution.') + def customize(self, generator): pass - + + def get_source_files( self ): + sources = [ self.__generated_source_file_name ] + to_be_exported_cpp = os.path.splitext( self.__to_be_exported_header )[0] + '.cpp' + if os.path.exists( to_be_exported_cpp ): + sources.append( to_be_exported_cpp ) + return sources + + def generate_source_files( self, mb ): + mb.write_module( self.__generated_source_file_name ) + def run_tests(self, module): raise NotImplementedError() @@ -65,9 +76,9 @@ mb.build_code_creator( self.__module_name, doc_extractor=doc_extractor ) mb.code_creator.std_directories.extend( autoconfig.scons_config.cpppath ) mb.code_creator.user_defined_directories.append( autoconfig.data_directory ) - mb.code_creator.precompiled_header = "boost/python.hpp" + mb.code_creator.precompiled_header = "boost/python.hpp" mb.code_creator.license = LICENSE - mb.write_module( self.__generated_source_file_name ) + self.generate_source_files( mb ) def _create_sconstruct(self, sources ): sources_str = [] @@ -80,7 +91,7 @@ sconstruct_file = file( self.__generated_scons_file_name, 'w+b' ) sconstruct_file.write( sconstruct_script ) sconstruct_file.close() - + def _create_extension(self): cmd = autoconfig.scons.cmd_build % self.__generated_scons_file_name output = os.popen( cmd ) @@ -116,16 +127,13 @@ pypp = None try: self._create_extension_source_file() - sources = [ self.__generated_source_file_name ] - to_be_exported_cpp = os.path.splitext( self.__to_be_exported_header )[0] + '.cpp' - if os.path.exists( to_be_exported_cpp ): - sources.append( to_be_exported_cpp ) + sources = self.get_source_files() self._create_sconstruct(sources) - self._create_extension() + self._create_extension() pypp = __import__( self.__module_name ) self.run_tests(pypp) finally: if sys.modules.has_key( self.__module_name ): del sys.modules[self.__module_name] del pypp - #self._clean_build(self.__generated_scons_file_name) \ No newline at end of file + #self._clean_build(self.__generated_scons_file_name) Added: pyplusplus_dev/unittests/split_module_tester.py =================================================================== --- pyplusplus_dev/unittests/split_module_tester.py (rev 0) +++ pyplusplus_dev/unittests/split_module_tester.py 2006-09-25 10:12:18 UTC (rev 584) @@ -0,0 +1,66 @@ +# Copyright 2004 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import os +import sys +import unittest +import autoconfig +import fundamental_tester_base + +from pyplusplus import module_builder +from pyplusplus.module_builder import call_policies + +class tester_t(fundamental_tester_base.fundamental_tester_base_t): + EXTENSION_NAME = 'split_module' + + def __init__( self, *args ): + fundamental_tester_base.fundamental_tester_base_t.__init__( + self + , tester_t.EXTENSION_NAME + , *args ) + self.files = [] + + def customize( self, mb ): + mb.global_ns.exclude() + sm = mb.global_ns.namespace( name='split_module' ) + sm.include() + sm.class_( 'op_struct' ).exclude() + + mb.calldefs( 'check_overload' ).use_overload_macro = True + mb.calldefs( 'get_opaque' ).call_policies \ + = call_policies.return_value_policy( call_policies.return_opaque_pointer ) + + mb.class_( 'op_struct' ).exclude() + item = mb.class_( 'item_t' ) + item.add_declaration_code( '//hello world' ) + nested = item.class_( 'nested_t' ) + nested.add_declaration_code( '//hello nested decl' ) + nested.add_registration_code( '//hello nested reg', False ) + + def generate_source_files( self, mb ): + files = mb.split_module( autoconfig.build_dir, on_unused_file_found=lambda fpath: fpath ) + self.files = filter( lambda fname: fname.endswith( 'cpp' ), files ) + print self.files + + def get_source_files( self ): + return self.files + + def run_tests(self, module): + module.get_opaque() + item = module.item_t() + item.get_opaque() + module.check_overload() + item.check_overload() + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( unittest.makeSuite(tester_t)) + return suite + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run( create_suite() ) + +if __name__ == "__main__": + run_suite() Modified: pyplusplus_dev/unittests/test_all.py =================================================================== --- pyplusplus_dev/unittests/test_all.py 2006-09-25 10:10:06 UTC (rev 583) +++ pyplusplus_dev/unittests/test_all.py 2006-09-25 10:12:18 UTC (rev 584) @@ -61,6 +61,7 @@ import cppexceptions_tester import no_init_tester import overloads_macro_tester +import split_module_tester def create_suite(times): testers = [ @@ -118,6 +119,7 @@ , cppexceptions_tester , no_init_tester , overloads_macro_tester + , split_module_tester ] main_suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |