[cfe-commits] r137828 - /cfe/trunk/bindings/python/tests/cindex/test_type.py
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Aug 17 10:01:11 PDT 2011
Author: akirtzidis
Date: Wed Aug 17 12:01:10 2011
New Revision: 137828
URL: http://llvm.org/viewvc/llvm-project?rev=137828&view=rev
Log:
[python] Add test_type.py by Anders Waldenborg, which I forgot to commit in r137797.
Added:
cfe/trunk/bindings/python/tests/cindex/test_type.py
Added: 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=137828&view=auto
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (added)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Wed Aug 17 12:01:10 2011
@@ -0,0 +1,76 @@
+from clang.cindex import Index, CursorKind, TypeKind
+
+kInput = """\
+
+typedef int I;
+
+struct teststruct {
+ int a;
+ I b;
+ long c;
+ unsigned long d;
+ signed long e;
+ const int f;
+ int *g;
+ int ***h;
+};
+
+"""
+
+def test_a_struct():
+ index = Index.create()
+ tu = index.parse('t.c', unsaved_files = [('t.c',kInput)])
+
+ for n in tu.cursor.get_children():
+ if n.spelling == 'teststruct':
+ fields = list(n.get_children())
+
+ assert all(x.kind == CursorKind.FIELD_DECL for x in fields)
+
+ assert fields[0].spelling == 'a'
+ assert not fields[0].type.is_const_qualified()
+ assert fields[0].type.kind == TypeKind.INT
+ assert fields[0].type.get_canonical().kind == TypeKind.INT
+
+ assert fields[1].spelling == 'b'
+ assert not fields[1].type.is_const_qualified()
+ assert fields[1].type.kind == TypeKind.TYPEDEF
+ assert fields[1].type.get_canonical().kind == TypeKind.INT
+ assert fields[1].type.get_declaration().spelling == 'I'
+
+ assert fields[2].spelling == 'c'
+ assert not fields[2].type.is_const_qualified()
+ assert fields[2].type.kind == TypeKind.LONG
+ assert fields[2].type.get_canonical().kind == TypeKind.LONG
+
+ assert fields[3].spelling == 'd'
+ assert not fields[3].type.is_const_qualified()
+ assert fields[3].type.kind == TypeKind.ULONG
+ assert fields[3].type.get_canonical().kind == TypeKind.ULONG
+
+ assert fields[4].spelling == 'e'
+ assert not fields[4].type.is_const_qualified()
+ assert fields[4].type.kind == TypeKind.LONG
+ assert fields[4].type.get_canonical().kind == TypeKind.LONG
+
+ assert fields[5].spelling == 'f'
+ assert fields[5].type.is_const_qualified()
+ assert fields[5].type.kind == TypeKind.INT
+ assert fields[5].type.get_canonical().kind == TypeKind.INT
+
+ assert fields[6].spelling == 'g'
+ assert not fields[6].type.is_const_qualified()
+ assert fields[6].type.kind == TypeKind.POINTER
+ assert fields[6].type.get_pointee().kind == TypeKind.INT
+
+ assert fields[7].spelling == 'h'
+ assert not fields[7].type.is_const_qualified()
+ assert fields[7].type.kind == TypeKind.POINTER
+ assert fields[7].type.get_pointee().kind == TypeKind.POINTER
+ assert fields[7].type.get_pointee().get_pointee().kind == TypeKind.POINTER
+ assert fields[7].type.get_pointee().get_pointee().get_pointee().kind == TypeKind.INT
+
+ break
+
+ else:
+ assert False, "Didn't find teststruct??"
More information about the cfe-commits
mailing list