diff options
author | Gregory Szorc <gregory.szorc@gmail.com> | 2012-02-20 17:58:02 +0000 |
---|---|---|
committer | Gregory Szorc <gregory.szorc@gmail.com> | 2012-02-20 17:58:02 +0000 |
commit | 0e1f4f8de57b4462f8d41c64de1427c5c1cf7e8f (patch) | |
tree | 2c7d519e0d8a7d9daaf019bcb7eb8d8232e2c40c /bindings/python | |
parent | 826fce53d64e0ca8fdcfdd11f4e9aab6c8be224f (diff) |
[clang.py] Add tests for Type.is_volatile_qualified and Type.is_restrict_qualified
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150971 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python')
-rw-r--r-- | bindings/python/tests/cindex/test_type.py | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/bindings/python/tests/cindex/test_type.py b/bindings/python/tests/cindex/test_type.py index 86b8142259..0ddfe4fb0a 100644 --- a/bindings/python/tests/cindex/test_type.py +++ b/bindings/python/tests/cindex/test_type.py @@ -1,3 +1,4 @@ +from clang.cindex import Cursor from clang.cindex import CursorKind from clang.cindex import Index from clang.cindex import TypeKind @@ -30,11 +31,23 @@ def get_tu(source=kInput, lang='c'): assert tu is not None return tu -def get_cursor(tu, spelling): - for cursor in tu.cursor.get_children(): +def get_cursor(source, spelling): + children = [] + if isinstance(source, Cursor): + children = source.get_children() + else: + # Assume TU + children = source.cursor.get_children() + + for cursor in children: if cursor.spelling == spelling: return cursor + # Recurse into children. + result = get_cursor(cursor, spelling) + if result is not None: + return result + return None def test_a_struct(): @@ -249,3 +262,33 @@ def test_element_count(): assert False except: assert True + +def test_is_volatile_qualified(): + """Ensure Type.is_volatile_qualified works.""" + + tu = get_tu('volatile int i = 4; int j = 2;') + + i = get_cursor(tu, 'i') + j = get_cursor(tu, 'j') + + assert i is not None + assert j is not None + + assert isinstance(i.type.is_volatile_qualified(), bool) + assert i.type.is_volatile_qualified() + assert not j.type.is_volatile_qualified() + +def test_is_restrict_qualified(): + """Ensure Type.is_restrict_qualified works.""" + + tu = get_tu('struct s { void * restrict i; void * j };') + + i = get_cursor(tu, 'i') + j = get_cursor(tu, 'j') + + assert i is not None + assert j is not None + + assert isinstance(i.type.is_restrict_qualified(), bool) + assert i.type.is_restrict_qualified() + assert not j.type.is_restrict_qualified() |