Skip to content

Commit e3c9a03

Browse files
committed
Add test for None comparisons
1 parent 5ee6394 commit e3c9a03

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

unittests/data/null_comparison.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
namespace ns{
5+
class Test
6+
{
7+
public:
8+
string var;
9+
};
10+
11+
int TestFunction1(Test a, Test b)
12+
{
13+
return 0;
14+
}
15+
16+
int TestFunction2(Test a, Test b=Test())
17+
{
18+
return 0;
19+
}
20+
}

unittests/test_all.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
from . import test_order
8383
from . import test_find_noncopyable_vars
8484
from . import test_hash
85+
from . import test_null_comparison
8586

8687
testers = [
8788
pep8_tester,
@@ -154,7 +155,8 @@
154155
test_elaborated_types,
155156
test_order,
156157
test_find_noncopyable_vars,
157-
test_hash
158+
test_hash,
159+
test_null_comparison,
158160
]
159161

160162
if platform.system() != 'Windows':

unittests/test_null_comparison.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 = "null_comparison.hpp"
19+
20+
def test_argument_null_comparison(self):
21+
"""
22+
Test for None comparisons with default arguments
23+
"""
24+
25+
decls = parser.parse([self.header], self.config)
26+
global_ns = declarations.get_global_namespace(decls)
27+
28+
ns = global_ns.namespace("ns")
29+
30+
func = ns.free_function(name="TestFunction1")
31+
assert (func.arguments[0] > func.arguments[1]) == False
32+
33+
func = ns.free_function(name="TestFunction2")
34+
assert (func.arguments[0] > func.arguments[1]) == False
35+
36+
37+
def create_suite():
38+
suite = unittest.TestSuite()
39+
suite.addTest(unittest.makeSuite(Test))
40+
return suite
41+
42+
43+
def run_suite():
44+
unittest.TextTestRunner(verbosity=2).run(create_suite())
45+
46+
47+
if __name__ == "__main__":
48+
run_suite()

0 commit comments

Comments
 (0)