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