xref: /PHP-8.3/ext/ffi/tests/021.phpt (revision 4acf0084)
1--TEST--
2FFI 021: packed enums
3--EXTENSIONS--
4ffi
5--INI--
6ffi.enable=1
7--FILE--
8<?php
9function test($size, $type) {
10    if (FFI::sizeof(FFI::new($type)) !== $size) {
11        echo "FAIL: sizeof($type) != $size\n";
12    }
13}
14
15test(4, "enum {a1, b1}");
16test(1, "enum __attribute__((packed)) {a2, b2}");
17
18test(4, "enum {a3=0, b3=0x80000000}");
19test(8, "enum {a4=-1, b4=0x80000000}");
20test(8, "enum {a5=0x80000000, b5=-1}");
21test(4, "enum {a6=-1, b6=0x7fffffff}");
22test(8, "enum {a7=-1, b7=0x7fffffff, c7}");
23
24test(1, "enum __attribute__((packed)) {a8=0, b8=0xff}");
25test(2, "enum __attribute__((packed)) {a9=0, b9=0x100}");
26
27test(1, "enum __attribute__((packed)) {a10=-1, b10=0x7f}");
28test(2, "enum __attribute__((packed)) {a11=-1, b11=0x80}");
29test(1, "enum __attribute__((packed)) {a12=0x7f, b12=-0x80}");
30test(2, "enum __attribute__((packed)) {a13=0x7f, b13=-0x81}");
31
32test(2, "enum __attribute__((packed)) {a8=0, b8=0xffff}");
33test(4, "enum __attribute__((packed)) {a9=0, b9=0x10000}");
34
35test(2, "enum __attribute__((packed)) {a10=-1, b10=0x7f00}");
36test(4, "enum __attribute__((packed)) {a11=-1, b11=0x8000}");
37test(2, "enum __attribute__((packed)) {a12=0x7f00, b12=-0x8000}");
38test(4, "enum __attribute__((packed)) {a13=0x7f00, b13=-0x8001}");
39
40test(4, "enum __attribute__((packed)) {a8=0, b8=0xffffffff}");
41test(8, "enum __attribute__((packed)) {a9=0, b9=0x100000000}");
42
43test(4, "enum __attribute__((packed)) {a10=-1, b10=0x7f000000}");
44test(8, "enum __attribute__((packed)) {a11=-1, b11=0x80000000}");
45test(4, "enum __attribute__((packed)) {a12=0x7f000000, b12=-0x80000000}");
46test(8, "enum __attribute__((packed)) {a13=0x7f000000, b13=-0x80000001}");
47
48test(1, "enum __attribute__((packed)) {a14=-0x80}");
49test(2, "enum __attribute__((packed)) {a14=-0x81}");
50test(2, "enum __attribute__((packed)) {a14=-0x8000}");
51test(4, "enum __attribute__((packed)) {a14=-0x8001}");
52test(4, "enum __attribute__((packed)) {a14=-0x80000000}");
53test(8, "enum __attribute__((packed)) {a14=-0x80000001}");
54?>
55ok
56--EXPECTF--
57Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
58
59Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
60
61Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
62
63Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
64
65Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
66
67Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
68
69Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
70
71Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
72
73Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
74
75Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
76
77Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
78
79Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
80
81Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
82
83Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
84
85Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
86
87Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
88
89Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
90
91Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
92
93Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
94
95Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
96
97Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
98
99Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
100
101Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
102
103Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
104
105Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
106
107Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
108
109Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
110
111Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
112
113Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
114
115Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
116
117Deprecated: Calling FFI::new() statically is deprecated in %s on line %d
118ok
119