From 2eaf2c5fcb3802e775d723c67b57955b2a3fa243 Mon Sep 17 00:00:00 2001 From: Peter Atkinson Date: Fri, 27 Sep 2024 16:00:11 -0400 Subject: [PATCH] added "test_array_argument" test to accompany PR #194 --- tests/test_array_argument.py | 76 ++++++++++++++++++++++++++ unittests/data/test_array_argument.hpp | 13 +++++ 2 files changed, 89 insertions(+) create mode 100644 tests/test_array_argument.py create mode 100644 unittests/data/test_array_argument.hpp diff --git a/tests/test_array_argument.py b/tests/test_array_argument.py new file mode 100644 index 00000000..9d832854 --- /dev/null +++ b/tests/test_array_argument.py @@ -0,0 +1,76 @@ +# Copyright 2014-2017 Insight Software Consortium. +# Copyright 2004-2009 Roman Yakovenko. +# Distributed under the Boost Software License, Version 1.0. +# See http://www.boost.org/LICENSE_1_0.txt + +import unittest + +from . import parser_test_case + +from pygccxml import parser +from pygccxml import declarations + + +class Test(parser_test_case.parser_test_case_t): + + def __init__(self, *args): + parser_test_case.parser_test_case_t.__init__(self, *args) + self.header = "test_array_argument.hpp" + self.config.cflags = "-std=c++11" + + def test_array_argument(self): + + """ + Test to ensure that function arguments' array size are kept intact + rather than presented as pointers. + + """ + + decls = parser.parse([self.header], self.config) + global_ns = declarations.get_global_namespace(decls) + + criteria = declarations.calldef_matcher(name="function") + free_funcs = declarations.matcher.find(criteria, global_ns) + for free_func in free_funcs: + decl_string = free_func.create_decl_string(with_defaults=False) + self.assertEqual( + decl_string, + "void ( ::test::* )( int [1024],int [512] )" + ) + arg1 = free_func.arguments[0] + arg2 = free_func.arguments[1] + self.assertEqual(arg1.decl_type.decl_string, "int [1024]") + self.assertEqual(arg1.name, "arg1") + self.assertEqual( + declarations.type_traits.array_size(arg1.decl_type), + 1024 + ) + self.assertIsInstance( + declarations.type_traits.array_item_type(arg1.decl_type), + declarations.cpptypes.int_t + ) + self.assertEqual(arg2.decl_type.decl_string, "int [512]") + self.assertEqual(arg2.name, "arg2") + self.assertEqual( + declarations.type_traits.array_size(arg2.decl_type), + 512 + ) + self.assertIsInstance( + declarations.type_traits.array_item_type(arg2.decl_type), + declarations.cpptypes.int_t + ) + + +def create_suite(): + suite = unittest.TestSuite() + suite.addTest( + unittest.TestLoader().loadTestsFromTestCase(testCaseClass=Test)) + return suite + + +def run_suite(): + unittest.TextTestRunner(verbosity=2).run(create_suite()) + + +if __name__ == "__main__": + run_suite() diff --git a/unittests/data/test_array_argument.hpp b/unittests/data/test_array_argument.hpp new file mode 100644 index 00000000..8973e0e2 --- /dev/null +++ b/unittests/data/test_array_argument.hpp @@ -0,0 +1,13 @@ +// Copyright 2014-2017 Insight Software Consortium. +// Copyright 2004-2009 Roman Yakovenko. +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +class test +{ + public: + // A constructor + test(const float & t0){}; + + void function(int arg1[1024], int arg2[512]) {}; +};