|
| 1 | +# Copyright 2014-2015 Insight Software Consortium. |
| 2 | +# Copyright 2004-2008 Roman Yakovenko. |
| 3 | +# Distributed under the Boost Software License, Version 1.0. |
| 4 | +# See http://www.boost.org/LICENSE_1_0.txt |
| 5 | + |
| 6 | +import os |
| 7 | +import unittest |
| 8 | +import parser_test_case |
| 9 | + |
| 10 | +from pygccxml import parser |
| 11 | +from pygccxml import declarations |
| 12 | +from pygccxml import utils |
| 13 | + |
| 14 | + |
| 15 | +class tester_t(parser_test_case.parser_test_case_t): |
| 16 | + |
| 17 | + """ |
| 18 | + Test the remove__va_list_tag option |
| 19 | +
|
| 20 | + With CastXML and clang some __va_list_tag declarations are present in the |
| 21 | + tree. This options allows to remove them when parsing the xml file. |
| 22 | +
|
| 23 | + """ |
| 24 | + |
| 25 | + def __init__(self, *args): |
| 26 | + parser_test_case.parser_test_case_t.__init__(self, *args) |
| 27 | + self.__code = os.linesep.join(['struct a{};']) |
| 28 | + |
| 29 | + def test_keep_va_list_tag(self): |
| 30 | + utils.remove__va_list_tag = False |
| 31 | + src_reader = parser.source_reader_t(self.config) |
| 32 | + decls = declarations.make_flatten(src_reader.read_string(self.__code)) |
| 33 | + |
| 34 | + classes = [ |
| 35 | + i for i in decls if isinstance(i, declarations.class_t)] |
| 36 | + |
| 37 | + typedefs = [ |
| 38 | + i for i in decls if isinstance(i, declarations.typedef_t)] |
| 39 | + |
| 40 | + variables = [ |
| 41 | + i for i in decls if isinstance(i, declarations.variable_t)] |
| 42 | + |
| 43 | + tag = "__va_list_tag" |
| 44 | + |
| 45 | + self.assertTrue(tag in [class_.name for class_ in classes]) |
| 46 | + self.assertTrue("a" in [class_.name for class_ in classes]) |
| 47 | + self.assertTrue(len(classes) == 2) |
| 48 | + |
| 49 | + self.assertTrue(tag in [ty.name for ty in typedefs]) |
| 50 | + self.assertTrue(len(typedefs) == 4) |
| 51 | + |
| 52 | + self.assertTrue( |
| 53 | + tag in [var.decl_string.split("::")[1] for var in variables]) |
| 54 | + self.assertTrue(len(variables) == 4) |
| 55 | + |
| 56 | + def test_remove_va_list_tag(self): |
| 57 | + utils.remove__va_list_tag = True |
| 58 | + src_reader = parser.source_reader_t(self.config) |
| 59 | + decls = declarations.make_flatten(src_reader.read_string(self.__code)) |
| 60 | + |
| 61 | + classes = [ |
| 62 | + i for i in decls if isinstance(i, declarations.class_t)] |
| 63 | + |
| 64 | + typedefs = [ |
| 65 | + i for i in decls if isinstance(i, declarations.typedef_t)] |
| 66 | + |
| 67 | + variables = [ |
| 68 | + i for i in decls if isinstance(i, declarations.variable_t)] |
| 69 | + |
| 70 | + tag = "__va_list_tag" |
| 71 | + |
| 72 | + self.assertFalse(tag in [class_.name for class_ in classes]) |
| 73 | + self.assertTrue("a" in [class_.name for class_ in classes]) |
| 74 | + self.assertTrue(len(classes) == 1) |
| 75 | + |
| 76 | + self.assertFalse(tag in [ty.name for ty in typedefs]) |
| 77 | + self.assertTrue(len(typedefs) == 3) |
| 78 | + |
| 79 | + self.assertFalse( |
| 80 | + tag in [var.decl_string.split("::")[1] for var in variables]) |
| 81 | + self.assertTrue(len(variables) == 0) |
| 82 | + |
| 83 | + |
| 84 | +def create_suite(): |
| 85 | + suite = unittest.TestSuite() |
| 86 | + suite.addTest(unittest.makeSuite(tester_t)) |
| 87 | + return suite |
| 88 | + |
| 89 | + |
| 90 | +def run_suite(): |
| 91 | + unittest.TextTestRunner(verbosity=2).run(create_suite()) |
| 92 | + |
| 93 | +if __name__ == "__main__": |
| 94 | + run_suite() |
0 commit comments