[cfe-commits] r150971 - /cfe/trunk/bindings/python/tests/cindex/test_type.py

Gregory Szorc gregory.szorc at gmail.com
Mon Feb 20 09:58:02 PST 2012


Author: gps
Date: Mon Feb 20 11:58:02 2012
New Revision: 150971

URL: http://llvm.org/viewvc/llvm-project?rev=150971&view=rev
Log:
[clang.py] Add tests for Type.is_volatile_qualified and Type.is_restrict_qualified

Modified:
    cfe/trunk/bindings/python/tests/cindex/test_type.py

Modified: cfe/trunk/bindings/python/tests/cindex/test_type.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_type.py?rev=150971&r1=150970&r2=150971&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Mon Feb 20 11:58:02 2012
@@ -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 @@
     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 @@
         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()





More information about the cfe-commits mailing list