[pygccxml-commit] SF.net SVN: pygccxml: [217] pygccxml_dev/unittests
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2006-06-08 10:42:51
|
Revision: 217 Author: roman_yakovenko Date: 2006-06-08 00:02:03 -0700 (Thu, 08 Jun 2006) ViewCVS: http://svn.sourceforge.net/pygccxml/?rev=217&view=rev Log Message: ----------- adding is_std_[w]string traits Modified Paths: -------------- pygccxml_dev/pygccxml/declarations/__init__.py pygccxml_dev/pygccxml/declarations/type_traits.py pygccxml_dev/unittests/test_all.py Added Paths: ----------- pygccxml_dev/unittests/data/string_traits.hpp pygccxml_dev/unittests/string_traits_tester.py Modified: pygccxml_dev/pygccxml/declarations/__init__.py =================================================================== --- pygccxml_dev/pygccxml/declarations/__init__.py 2006-06-08 05:52:33 UTC (rev 216) +++ pygccxml_dev/pygccxml/declarations/__init__.py 2006-06-08 07:02:03 UTC (rev 217) @@ -119,6 +119,8 @@ from type_traits import is_base_and_derived from type_traits import is_convertible from type_traits import is_noncopyable +from type_traits import is_std_string +from type_traits import is_std_wstring from type_traits import is_unary_operator from type_traits import is_binary_operator @@ -142,8 +144,11 @@ from type_traits import find_trivial_constructor from type_traits import has_any_non_copyconstructor -from type_traits import vector_traits +from type_traits import vector_traits +from type_traits import smart_pointer_traits + + import templates import call_invocation Modified: pygccxml_dev/pygccxml/declarations/type_traits.py =================================================================== --- pygccxml_dev/pygccxml/declarations/type_traits.py 2006-06-08 05:52:33 UTC (rev 216) +++ pygccxml_dev/pygccxml/declarations/type_traits.py 2006-06-08 07:02:03 UTC (rev 217) @@ -790,7 +790,7 @@ """returns reference to the class declaration, """ cls = vector_traits.declaration_or_none( type ) if not cls: - raise TypeError( 'Type "%s" is not instantiation ov std::vector' % type.decl_string ) + raise TypeError( 'Type "%s" is not instantiation of std::vector' % type.decl_string ) return cls @staticmethod @@ -809,14 +809,36 @@ return found[0] else: raise RuntimeError( "Unable to find out vector value type. vector class is: %s" % cls.decl_string ) - -def is_smart_pointer( type ): - type = remove_alias( type ) - type = remove_cv( type ) - if not is_defined_in_xxx( 'boost', type ): - return False - return type.decl_string.startswith( '::boost::shared_ptr<' ) - + +class smart_pointer_traits: + @staticmethod + def is_smart_pointer( type ): + type = remove_alias( type ) + type = remove_cv( type ) + if not is_defined_in_xxx( 'boost', type ): + return False + return type.decl_string.startswith( '::boost::shared_ptr<' ) + + @staticmethod + def value_type( type ): + if not smart_pointer_traits.is_smart_pointer( type ): + raise TypeError( 'Type "%s" is not instantiation of boost::shared_ptr' % type.decl_string ) + type = remove_alias( type ) + cls = remove_cv( type ) + if isinstance( cls, class_declaration.class_t ): + return cls.typedef( "value_type" ).type + else: + value_type_str = templates.args( cls.name )[0] + found = cls.top_parent.classes( value_type_str, allow_empty=True ) + if not found: + if cpptypes.FUNDAMENTAL_TYPES.has_key( value_type_str ): + return cpptypes.FUNDAMENTAL_TYPES[value_type_str] + if len( found ) == 1: + return found[0] + else: + raise RuntimeError( "Unable to find out shared_ptr value type. shared_ptr class is: %s" % cls.decl_string ) + + def is_std_string( type ): decl_strings = [ '::std::basic_string<char,std::char_traits<char>,std::allocator<char> >' Added: pygccxml_dev/unittests/data/string_traits.hpp =================================================================== --- pygccxml_dev/unittests/data/string_traits.hpp (rev 0) +++ pygccxml_dev/unittests/data/string_traits.hpp 2006-06-08 07:02:03 UTC (rev 217) @@ -0,0 +1,32 @@ +// 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) + +#include <string> + +namespace string_traits{ +namespace yes{ + typedef std::string x1; + typedef const std::string x2; +} + +namespace no{ + typedef int x1; + typedef std::string& x2; +} + +} + +namespace wstring_traits{ +namespace yes{ + typedef std::wstring x1; + typedef const std::wstring x2; +} + +namespace no{ + typedef int x1; + typedef std::wstring& x2; +} + +} \ No newline at end of file Added: pygccxml_dev/unittests/string_traits_tester.py =================================================================== --- pygccxml_dev/unittests/string_traits_tester.py (rev 0) +++ pygccxml_dev/unittests/string_traits_tester.py 2006-06-08 07:02:03 UTC (rev 217) @@ -0,0 +1,55 @@ +# 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 unittest +import autoconfig +import parser_test_case + +from pygccxml import utils +from pygccxml import parser +from pygccxml import declarations + +class tester_t( parser_test_case.parser_test_case_t ): + COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE + global_ns = None + def __init__(self, *args ): + parser_test_case.parser_test_case_t.__init__( self, *args ) + self.header = 'string_traits.hpp' + self.global_ns = None + + def setUp(self): + if not tester_t.global_ns: + decls = parser.parse( [self.header], self.config ) + tester_t.global_ns = declarations.get_global_namespace( decls ) + self.global_ns = tester_t.global_ns + + def validate_yes( self, ns, controller ): + for typedef in ns.typedefs(): + self.failUnless( controller( typedef.type ) ) + + def validate_no( self, ns, controller ): + for typedef in ns.typedefs(): + self.failUnless( not controller( typedef.type ) ) + + def test_string( self ): + string_traits = self.global_ns.namespace( 'string_traits' ) + self.validate_yes( string_traits.namespace( 'yes' ), declarations.is_std_string ) + self.validate_no( string_traits.namespace( 'no' ), declarations.is_std_string ) + + def test_wstring( self ): + wstring_traits = self.global_ns.namespace( 'wstring_traits' ) + self.validate_yes( wstring_traits.namespace( 'yes' ), declarations.is_std_wstring ) + self.validate_no( wstring_traits.namespace( 'no' ), declarations.is_std_wstring ) + +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() \ No newline at end of file Modified: pygccxml_dev/unittests/test_all.py =================================================================== --- pygccxml_dev/unittests/test_all.py 2006-06-08 05:52:33 UTC (rev 216) +++ pygccxml_dev/unittests/test_all.py 2006-06-08 07:02:03 UTC (rev 217) @@ -35,6 +35,8 @@ import demangled_tester import unnamed_enums_bug_tester import vector_traits_tester +import string_traits_tester + def create_suite(): testers = [ @@ -68,7 +70,8 @@ , typedefs_tester , demangled_tester , unnamed_enums_bug_tester - , vector_traits_tester + , vector_traits_tester + , string_traits_tester ] main_suite = unittest.TestSuite() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |