xref: /PHP-8.3/ext/ffi/tests/004.phpt (revision bd9f4fa6)
1--TEST--
2FFI 004: Enum declarations
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9$ffi = FFI::cdef(<<<EOF
10enum _a;
11enum _a {e1};
12
13enum _b {e2};
14enum _b;
15
16typedef enum _c c;
17enum _c {e3};
18
19enum _d {e4};
20typedef enum _d d;
21
22enum _e;
23
24enum _f;
25typedef enum _f f;
26
27enum _g {
28    _c1,
29    _c2,
30    _c3 = 1,
31    _c4,
32};
33EOF
34);
35var_dump($ffi->new("enum _a"));
36var_dump($ffi->new("enum _b"));
37var_dump($ffi->new("c"));
38var_dump($ffi->new("d"));
39var_dump($ffi->new("int[_c2]"));
40var_dump($ffi->new("int[_c3]"));
41var_dump($ffi->new("int[_c4]"));
42try {
43    var_dump($ffi->new("enum _e"));
44} catch (Throwable $e) {
45    echo get_class($e) . ": " . $e->getMessage()."\n";
46}
47try {
48    var_dump($ffi->new("f"));
49} catch (Throwable $e) {
50    echo get_class($e) . ": " . $e->getMessage()."\n";
51}
52echo "ok\n";
53?>
54--EXPECTF--
55object(FFI\CData:enum _a)#%d (1) {
56  ["cdata"]=>
57  int(0)
58}
59object(FFI\CData:enum _b)#%d (1) {
60  ["cdata"]=>
61  int(0)
62}
63object(FFI\CData:enum _c)#%d (1) {
64  ["cdata"]=>
65  int(0)
66}
67object(FFI\CData:enum _d)#%d (1) {
68  ["cdata"]=>
69  int(0)
70}
71object(FFI\CData:int32_t[1])#%d (1) {
72  [0]=>
73  int(0)
74}
75object(FFI\CData:int32_t[1])#%d (1) {
76  [0]=>
77  int(0)
78}
79object(FFI\CData:int32_t[2])#%d (2) {
80  [0]=>
81  int(0)
82  [1]=>
83  int(0)
84}
85FFI\ParserException: Incomplete enum "_e" at line 1
86FFI\ParserException: Incomplete enum "_f" at line 1
87ok
88