Debian Codegraph @

extra_tests/cffi_tests/cffi0/test_model.py

raw symbols SCIP
1 # Generated by pypy/tool/import_cffi.py
2 from cffi.model import *
3
4
5 def test_void_type():
6 assert void_type.get_c_name() == "void"
7 assert void_type.get_c_name("foo") == "void foo"
8 assert void_type.get_c_name("*foo") == "void *foo"
9
10 def test_primitive_type():
11 int_type = PrimitiveType("int")
12 assert int_type.get_c_name() == "int"
13 assert int_type.get_c_name("foo") == "int foo"
14 assert int_type.get_c_name("*foo") == "int *foo"
15 assert int_type.get_c_name("[5]") == "int[5]"
16
17 def test_raw_function_type():
18 int_type = PrimitiveType("int")
19 fn_type = RawFunctionType([], int_type, False)
20 assert fn_type.get_c_name() == "int()(void)"
21 assert fn_type.get_c_name("*") == "int( *)(void)"
22 assert fn_type.get_c_name("*foo") == "int( *foo)(void)"
23 fn_type = RawFunctionType([int_type], int_type, False)
24 assert fn_type.get_c_name() == "int()(int)"
25 fn_type = RawFunctionType([int_type] * 2, int_type, False)
26 assert fn_type.get_c_name() == "int()(int, int)"
27 #
28 fn_type = RawFunctionType([int_type], int_type, True)
29 assert fn_type.get_c_name() == "int()(int, ...)"
30 assert fn_type.get_c_name("*foo") == "int( *foo)(int, ...)"
31 #
32 res_type = FunctionPtrType([int_type], int_type, True)
33 fn_type = RawFunctionType([int_type], res_type, True)
34 assert fn_type.get_c_name("x") == "int(*( x)(int, ...))(int, ...)"
35
36 def test_function_ptr_type():
37 int_type = PrimitiveType("int")
38 fn_type = FunctionPtrType([], int_type, False)
39 assert fn_type.get_c_name() == "int(*)(void)"
40 assert fn_type.get_c_name("*") == "int(* *)(void)"
41 assert fn_type.get_c_name("*foo") == "int(* *foo)(void)"
42 fn_type = FunctionPtrType([int_type], int_type, False)
43 assert fn_type.get_c_name() == "int(*)(int)"
44 fn_type = FunctionPtrType([int_type] * 2, int_type, False)
45 assert fn_type.get_c_name() == "int(*)(int, int)"
46 #
47 fn_type = FunctionPtrType([int_type], int_type, True)
48 assert fn_type.get_c_name() == "int(*)(int, ...)"
49
50 def test_pointer_type():
51 ptr_type = PointerType(PrimitiveType("int"))
52 assert ptr_type.get_c_name("x") == "int * x"
53
54 def test_const_pointer_type():
55 ptr_type = ConstPointerType(PrimitiveType("int"))
56 assert ptr_type.get_c_name("x") == "int const * x"
57 ptr_type = ConstPointerType(ArrayType(PrimitiveType("int"), 5))
58 assert ptr_type.get_c_name("") == "int const (*)[5]"
59 assert ptr_type.get_c_name("*x") == "int const (* *x)[5]"
60 ptr_type = ConstPointerType(ArrayType(
61 ConstPointerType(PrimitiveType("int")), 5))
62 assert ptr_type.get_c_name("x") == "int const * const (* x)[5]"
63 ptr_type = PointerType(ArrayType(
64 ConstPointerType(PrimitiveType("int")), 5))
65 assert ptr_type.get_c_name("x") == "int const *(* x)[5]"
66 ptr_type = ConstPointerType(ArrayType(
67 PointerType(PrimitiveType("int")), 5))
68 assert ptr_type.get_c_name("x") == "int * const (* x)[5]"
69
70 def test_qual_pointer_type():
71 ptr_type = PointerType(PrimitiveType("long long"), Q_RESTRICT)
72 assert ptr_type.get_c_name("") == "long long __restrict *"
73 assert const_voidp_type.get_c_name("") == "void const *"
74
75 def test_unknown_pointer_type():
76 ptr_type = unknown_ptr_type("foo_p")
77 assert ptr_type.get_c_name("") == "foo_p"
78 assert ptr_type.get_c_name("x") == "foo_p x"
79
80 def test_unknown_type():
81 u_type = unknown_type("foo_t")
82 assert u_type.get_c_name("") == "foo_t"
83 assert u_type.get_c_name("x") == "foo_t x"
84
85 def test_array_type():
86 a_type = ArrayType(PrimitiveType("int"), None)
87 assert a_type.get_c_name("") == "int[]"
88 assert a_type.get_c_name("x") == "int x[]"
89 assert a_type.get_c_name("*x") == "int(*x)[]"
90 assert a_type.get_c_name(" *x") == "int(*x)[]"
91 assert a_type.get_c_name("[5]") == "int[5][]"
92 a_type = ArrayType(unknown_type("foo_t"), 5)
93 assert a_type.get_c_name("") == "foo_t[5]"
94 assert a_type.get_c_name("x") == "foo_t x[5]"
95 assert a_type.get_c_name("*x") == "foo_t(*x)[5]"
96 a_type = ArrayType(unknown_ptr_type("foo_p"), None)
97 assert a_type.get_c_name("") == "foo_p[]"
98 assert a_type.get_c_name("x") == "foo_p x[]"
99 assert a_type.get_c_name("*x") == "foo_p(*x)[]"
100 a_type = ArrayType(ConstPointerType(PrimitiveType("int")), None)
101 assert a_type.get_c_name("") == "int const *[]"
102 assert a_type.get_c_name("x") == "int const * x[]"
103 assert a_type.get_c_name("*x") == "int const *(*x)[]"
104 fn_type = FunctionPtrType([], PrimitiveType("int"), False)
105 a_type = ArrayType(fn_type, 5)
106 assert a_type.get_c_name("") == "int(*[5])(void)"
107 assert a_type.get_c_name("x") == "int(* x[5])(void)"
108 assert a_type.get_c_name("*x") == "int(*(*x)[5])(void)"
109
110 def test_struct_type():
111 struct_type = StructType("foo_s", None, None, None)
112 assert struct_type.get_c_name() == "struct foo_s"
113 assert struct_type.get_c_name("*x") == "struct foo_s *x"
114
115 def test_union_type():
116 union_type = UnionType("foo_s", None, None, None)
117 assert union_type.get_c_name() == "union foo_s"
118
119 def test_enum_type():
120 enum_type = EnumType("foo_e", [], [])
121 assert enum_type.get_c_name() == "enum foo_e"