|
| 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 | + |
| 6 | +import unittest |
| 7 | + |
| 8 | +from . import parser_test_case |
| 9 | + |
| 10 | +from pygccxml import parser |
| 11 | +from pygccxml import declarations |
| 12 | + |
| 13 | + |
| 14 | +class Test(parser_test_case.parser_test_case_t): |
| 15 | + |
| 16 | + def __init__(self, *args): |
| 17 | + parser_test_case.parser_test_case_t.__init__(self, *args) |
| 18 | + self.header = "test_array_argument.hpp" |
| 19 | + self.config.cflags = "-std=c++11" |
| 20 | + |
| 21 | + def test_array_argument(self): |
| 22 | + |
| 23 | + """ |
| 24 | + Test to ensure that function arguments' array size are kept intact |
| 25 | + rather than presented as pointers. |
| 26 | +
|
| 27 | + """ |
| 28 | + |
| 29 | + decls = parser.parse([self.header], self.config) |
| 30 | + global_ns = declarations.get_global_namespace(decls) |
| 31 | + |
| 32 | + criteria = declarations.calldef_matcher(name="function") |
| 33 | + free_funcs = declarations.matcher.find(criteria, global_ns) |
| 34 | + for free_func in free_funcs: |
| 35 | + decl_string = free_func.create_decl_string(with_defaults=False) |
| 36 | + self.assertEqual( |
| 37 | + decl_string, |
| 38 | + "void ( ::test::* )( int [1024],int [512] )" |
| 39 | + ) |
| 40 | + arg1 = free_func.arguments[0] |
| 41 | + arg2 = free_func.arguments[1] |
| 42 | + self.assertEqual(arg1.decl_type.decl_string, "int [1024]") |
| 43 | + self.assertEqual(arg1.name, "arg1") |
| 44 | + self.assertEqual( |
| 45 | + declarations.type_traits.array_size(arg1.decl_type), |
| 46 | + 1024 |
| 47 | + ) |
| 48 | + self.assertIsInstance( |
| 49 | + declarations.type_traits.array_item_type(arg1.decl_type), |
| 50 | + declarations.cpptypes.int_t |
| 51 | + ) |
| 52 | + self.assertEqual(arg2.decl_type.decl_string, "int [512]") |
| 53 | + self.assertEqual(arg2.name, "arg2") |
| 54 | + self.assertEqual( |
| 55 | + declarations.type_traits.array_size(arg2.decl_type), |
| 56 | + 512 |
| 57 | + ) |
| 58 | + self.assertIsInstance( |
| 59 | + declarations.type_traits.array_item_type(arg2.decl_type), |
| 60 | + declarations.cpptypes.int_t |
| 61 | + ) |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +def create_suite(): |
| 66 | + suite = unittest.TestSuite() |
| 67 | + suite.addTest( |
| 68 | + unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) |
| 69 | + return suite |
| 70 | + |
| 71 | + |
| 72 | +def run_suite(): |
| 73 | + unittest.TextTestRunner(verbosity=2).run(create_suite()) |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == "__main__": |
| 77 | + run_suite() |
0 commit comments