summaryrefslogtreecommitdiff
path: root/ext/ffi/tests/031.phpt
blob: 3298df4961065db8610741ece833cd4a4f2d7e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--TEST--
FFI 031: bit-fields packing
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--INI--
ffi.enable=1
--FILE--
<?php
function test_size($expected_size, $type) {
	try {
		$size = FFI::sizeof(FFI::new($type));
		if ($size !== $expected_size) {
			echo "FAIL: sizeof($type) != $expected_size ($size)\n";
		}
	} catch (Throwable $e) {
		echo $type . "=>" . get_class($e) . ": " . $e->getMessage()."\n";
	}
}

test_size( 4, "struct {int a:2; int b:2;}");
test_size( 1, "struct __attribute__((packed)) {int a:2; int b:2;}");
test_size( 8, "struct {int a:2; unsigned long long :60; int b:2;}");
test_size( 9, "struct __attribute__((packed)) {int a:2; unsigned long long :64; int b:2;}");
test_size( 4, "union {int a:2; int b:8;}");
test_size( 1, "union __attribute__((packed)) {int a:2; int b:8;}");
?>
ok
--EXPECT--
ok