|
| 1 | +# Copyright 2014-2016 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 | +import parser_test_case |
| 8 | + |
| 9 | +from pygccxml import parser |
| 10 | +from pygccxml import declarations |
| 11 | + |
| 12 | + |
| 13 | +class tester_t(parser_test_case.parser_test_case_t): |
| 14 | + |
| 15 | + def __init__(self, *args): |
| 16 | + parser_test_case.parser_test_case_t.__init__(self, *args) |
| 17 | + self.header = "test_argument_without_name.hpp" |
| 18 | + self.config.cflags = "-std=c++11" |
| 19 | + |
| 20 | + def test_argument_without_name(self): |
| 21 | + |
| 22 | + """ |
| 23 | + Test passing an object without name to a templated function. |
| 24 | +
|
| 25 | + The test was failing when building the declaration string. |
| 26 | + The declaration string will be 'void (*)( & )'. If the passed |
| 27 | + object had a name the result would then be 'void (*)(Name & )'. |
| 28 | +
|
| 29 | + See bug #55 |
| 30 | +
|
| 31 | + """ |
| 32 | + |
| 33 | + if self.config.xml_generator == "gccxml": |
| 34 | + return |
| 35 | + |
| 36 | + decls = parser.parse([self.header], self.config) |
| 37 | + global_ns = declarations.get_global_namespace(decls) |
| 38 | + |
| 39 | + criteria = declarations.calldef_matcher(name="function") |
| 40 | + free_funcs = declarations.matcher.find(criteria, global_ns) |
| 41 | + for free_func in free_funcs: |
| 42 | + decl_string = free_func.create_decl_string(with_defaults=False) |
| 43 | + self.assertEqual(decl_string, "void (*)( & )") |
| 44 | + |
| 45 | + |
| 46 | +def create_suite(): |
| 47 | + suite = unittest.TestSuite() |
| 48 | + suite.addTest(unittest.makeSuite(tester_t)) |
| 49 | + return suite |
| 50 | + |
| 51 | + |
| 52 | +def run_suite(): |
| 53 | + unittest.TextTestRunner(verbosity=2).run(create_suite()) |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + run_suite() |
0 commit comments