xref: /PHP-8.1/ext/sysvshm/tests/002.phpt (revision 74859783)
1--TEST--
2shm_attach() tests
3--EXTENSIONS--
4sysvshm
5--SKIPIF--
6<?php
7
8if (!function_exists('ftok')){ print 'skip'; }
9?>
10--FILE--
11<?php
12
13$key = ftok(__FILE__, 't');
14
15try {
16    shm_attach(-1, 0);
17} catch (ValueError $exception) {
18    echo $exception->getMessage() . "\n";
19}
20
21try {
22    shm_attach(0, -1);
23} catch (ValueError $exception) {
24    echo $exception->getMessage() . "\n";
25}
26
27try {
28    shm_attach(123, -1);
29} catch (ValueError $exception) {
30    echo $exception->getMessage() . "\n";
31}
32
33try {
34    shm_attach($key, -1);
35} catch (ValueError $exception) {
36    echo $exception->getMessage() . "\n";
37}
38
39try {
40    shm_attach($key, 0);
41} catch (ValueError $exception) {
42    echo $exception->getMessage() . "\n";
43}
44
45var_dump($s = shm_attach($key, 1024));
46shm_remove($s);
47var_dump($s = shm_attach($key, 1024));
48shm_remove($s);
49var_dump($s = shm_attach($key, 1024, 0666));
50shm_remove($s);
51
52var_dump($s = shm_attach($key, 1024));
53shm_remove($s);
54var_dump($s = shm_attach($key));
55shm_remove($s);
56
57echo "Done\n";
58?>
59--EXPECTF--
60shm_attach(): Argument #2 ($size) must be greater than 0
61shm_attach(): Argument #2 ($size) must be greater than 0
62shm_attach(): Argument #2 ($size) must be greater than 0
63shm_attach(): Argument #2 ($size) must be greater than 0
64shm_attach(): Argument #2 ($size) must be greater than 0
65object(SysvSharedMemory)#%d (0) {
66}
67object(SysvSharedMemory)#%d (0) {
68}
69object(SysvSharedMemory)#%d (0) {
70}
71object(SysvSharedMemory)#%d (0) {
72}
73object(SysvSharedMemory)#%d (0) {
74}
75Done
76