1# Copyright 2014-2017 Insight Software Consortium. 2# Copyright 2004-2009 Roman Yakovenko. 3# Distributed under the Boost Software License, Version 1.0. 4# See http://www.boost.org/LICENSE_1_0.txt 5 6import sys 7import unittest 8 9from . import parser_test_case 10 11from pygccxml import parser 12from pygccxml import declarations 13 14 15class Test(parser_test_case.parser_test_case_t): 16 17 def __init__(self, *args): 18 parser_test_case.parser_test_case_t.__init__(self, *args) 19 self.__files = [ 20 'core_ns_join_1.hpp', 21 'core_ns_join_2.hpp', 22 'core_ns_join_3.hpp', 23 'core_membership.hpp', 24 'core_class_hierarchy.hpp', 25 'core_types.hpp', 26 'core_diamand_hierarchy_base.hpp', 27 'core_diamand_hierarchy_derived1.hpp', 28 'core_diamand_hierarchy_derived2.hpp', 29 'core_diamand_hierarchy_final_derived.hpp', 30 'core_overloads_1.hpp', 31 'core_overloads_2.hpp', 32 'typedefs_base.hpp'] 33 34 # for i, f in enumerate(self.__files): 35 # f = parser.create_cached_source_fc( 36 # os.path.join( autoconfig.data_directory, f) 37 # , os.path.join( autoconfig.data_directory, f + '.xml') ) 38 # self.__files[i] = f 39 prj_reader = parser.project_reader_t(self.config) 40 self.decls = prj_reader.read_files( 41 self.__files, 42 compilation_mode=parser.COMPILATION_MODE.FILE_BY_FILE) 43 44 def test_printer(self): 45 46 # Redirect sys.stdout to a class with a writer doing nothing 47 # This greatly reduces the size of the test output and makes 48 # test log files readable. 49 # Note: flush needs to be defined; because if not this will 50 # result in an AttributeError on call. 51 class DontPrint(object): 52 def write(*args): 53 pass 54 55 def flush(*args): 56 pass 57 sys.stdout = DontPrint() 58 59 declarations.print_declarations(self.decls) 60 61 def test__str__(self): 62 decls = declarations.make_flatten(self.decls) 63 for decl in decls: 64 str(decl) 65 66 67def create_suite(): 68 suite = unittest.TestSuite() 69 suite.addTest(unittest.makeSuite(Test)) 70 return suite 71 72 73def run_suite(): 74 unittest.TextTestRunner(verbosity=2).run(create_suite()) 75 76 77if __name__ == "__main__": 78 run_suite() 79