xref: /php-src/ext/ffi/tests/046.phpt (revision 4acf0084)
1--TEST--
2FFI 046: FFI::CType reflection API
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9$x = FFI::type("uint8_t");
10var_dump($x->getKind() === $x::TYPE_UINT8);
11var_dump($x->getSize());
12var_dump($x->getAlignment());
13
14$x = FFI::type("enum __attribute__((packed)) {a2, b2}");
15var_dump($x->getKind() === $x::TYPE_ENUM);
16var_dump($x->getEnumKind() === $x::TYPE_UINT8);
17
18$x = FFI::type("char[5]");
19var_dump($x->getKind() === $x::TYPE_ARRAY);
20var_dump($x->getSize());
21var_dump($x->getArrayElementType()->getKind() === $x::TYPE_CHAR);
22var_dump($x->getArrayLength());
23
24$x = FFI::type("void*");
25var_dump($x->getKind() === $x::TYPE_POINTER);
26var_dump($x->getPointerType()->getKind() === $x::TYPE_VOID);
27
28$x = FFI::type("struct {double x; double y;}");
29var_dump($x->getKind() === $x::TYPE_STRUCT);
30var_dump(($x->getAttributes() & $x::ATTR_UNION) != 0);
31var_dump($x->getStructFieldNames());
32var_dump($x->getStructFieldOffset("x"));
33var_dump($x->getStructFieldOffset("y"));
34var_dump($x->getStructFieldType("x")->getKind() == $x::TYPE_DOUBLE);
35var_dump($x->getStructFieldType("y")->getKind() == $x::TYPE_DOUBLE);
36
37$x = FFI::type("union {double x; double y;}");
38var_dump($x->getKind() === $x::TYPE_STRUCT);
39var_dump(($x->getAttributes() & $x::ATTR_UNION) != 0);
40var_dump($x->getStructFieldNames());
41var_dump($x->getStructFieldOffset("x"));
42var_dump($x->getStructFieldOffset("y"));
43var_dump($x->getStructFieldType("x")->getKind() == $x::TYPE_DOUBLE);
44var_dump($x->getStructFieldType("y")->getKind() == $x::TYPE_DOUBLE);
45
46$x = FFI::type("void (*)(double,int32_t)");
47var_dump($x->getKind() === $x::TYPE_POINTER);
48var_dump($x->getPointerType()->getKind() === $x::TYPE_FUNC);
49var_dump($x->getPointerType()->getFuncReturnType()->getKind() === $x::TYPE_VOID);
50var_dump($x->getPointerType()->getFuncParameterCount());
51var_dump($x->getPointerType()->getFuncParameterType(0)->getKind() === $x::TYPE_DOUBLE);
52var_dump($x->getPointerType()->getFuncParameterType(1)->getKind() === $x::TYPE_SINT32);
53?>
54--EXPECTF--
55Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
56bool(true)
57int(1)
58int(1)
59
60Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
61bool(true)
62bool(true)
63
64Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
65bool(true)
66int(5)
67bool(true)
68int(5)
69
70Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
71bool(true)
72bool(true)
73
74Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
75bool(true)
76bool(false)
77array(2) {
78  [0]=>
79  string(1) "x"
80  [1]=>
81  string(1) "y"
82}
83int(0)
84int(8)
85bool(true)
86bool(true)
87
88Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
89bool(true)
90bool(true)
91array(2) {
92  [0]=>
93  string(1) "x"
94  [1]=>
95  string(1) "y"
96}
97int(0)
98int(0)
99bool(true)
100bool(true)
101
102Deprecated: Calling FFI::type() statically is deprecated in %s on line %d
103bool(true)
104bool(true)
105bool(true)
106int(2)
107bool(true)
108bool(true)
109