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 os 7import unittest 8 9from . import autoconfig 10from . import parser_test_case 11 12from pygccxml import parser 13from pygccxml import declarations 14 15 16class tester_impl_t(parser_test_case.parser_test_case_t): 17 COMPILATION_MODE = parser.COMPILATION_MODE.ALL_AT_ONCE 18 19 def __init__(self, *args): 20 parser_test_case.parser_test_case_t.__init__(self, *args) 21 self.header = os.path.join( 22 autoconfig.data_directory, 23 'declarations_enums.hpp') 24 self.cache_file = os.path.join( 25 autoconfig.data_directory, 26 'pygccxml.cache') 27 if os.path.exists(self.cache_file) and os.path.isfile(self.cache_file): 28 os.remove(self.cache_file) 29 30 def test_cache(self): 31 cache = parser.file_cache_t(self.cache_file) 32 reader = parser.source_reader_t(self.config, cache) 33 decls1 = reader.read_file(self.header) 34 cache.flush() 35 cache = parser.file_cache_t(self.cache_file) 36 reader = parser.source_reader_t(self.config, cache) 37 decls2 = reader.read_file(self.header) 38 39 enum_matcher = declarations.declaration_matcher_t( 40 name="EColor", 41 decl_type=declarations.enumeration_t) 42 43 color1 = declarations.matcher.get_single(enum_matcher, decls1) 44 color2 = declarations.matcher.get_single(enum_matcher, decls2) 45 self.assertTrue(color1.values == color2.values) 46 47# there is no progress with this parser 48# class synopsis_tester_t( tester_impl_t ): 49# CXX_PARSER_CFG = autoconfig.cxx_parsers_cfg.synopsis 50 51 52class gccxml_tester_t(tester_impl_t): 53 CXX_PARSER_CFG = autoconfig.cxx_parsers_cfg.config 54 55 56def create_suite(): 57 suite = unittest.TestSuite() 58 # suite.addTest( unittest.makeSuite(synopsis_tester_t)) 59 suite.addTest(unittest.makeSuite(gccxml_tester_t)) 60 return suite 61 62 63def run_suite(): 64 unittest.TextTestRunner(verbosity=2).run(create_suite()) 65 66 67if __name__ == "__main__": 68 run_suite() 69