xref: /PHP-7.0/ext/shmop/tests/002.phpt (revision 3cb3979d)
1--TEST--
2shmop extension error messages
3--CREDITS--
4edgarsandi - <edgar.r.sandi@gmail.com>
5--SKIPIF--
6<?php
7	if( substr(PHP_OS, 0, 3) == "WIN") {
8		die('skip not for Windows');
9	}
10	if (!extension_loaded("shmop")) {
11		die("skip shmop() extension not available");
12	}
13?>
14--FILE--
15<?php
16	$hex_shm_id = function(){
17		return mt_rand(1338, 9999);
18	};
19
20echo PHP_EOL, '## shmop_open function tests ##';
21	// warning outputs: 4 parameters expected
22	var_dump($shm_id = shmop_open());
23
24	// warning outputs: invalid flag when the flags length != 1
25	var_dump(shmop_open($hex_shm_id(), '', 0644, 1024));
26
27	// warning outputs: invalid access mode
28	var_dump(shmop_open($hex_shm_id(), 'b', 0644, 1024));
29
30	// warning outputs: unable to attach or create shared memory segment
31	var_dump(shmop_open(null, 'a', 0644, 1024));
32
33	// warning outputs: Shared memory segment size must be greater than zero
34	var_dump(shmop_open($hex_shm_id(), "c", 0666, 0));
35
36echo PHP_EOL, '## shmop_read function tests ##';
37	// warning outputs: 3 parameters expected
38	var_dump(shmop_read());
39
40	// warning outputs: start is out of range
41	$shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
42	var_dump(shmop_read($shm_id, -10, 0));
43	shmop_delete($shm_id);
44
45	// warning outputs: count is out of range
46	$shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
47	var_dump(shmop_read($shm_id, 0, -10));
48	shmop_delete($shm_id);
49
50echo PHP_EOL, '## shmop_write function tests ##';
51	// warning outputs: 3 parameters expected
52	var_dump(shmop_write());
53
54	// warning outputs: offset out of range
55	$shm_id = shmop_open($hex_shm_id(), 'n', 0600, 1024);
56	var_dump(shmop_write($shm_id, 'text to try write', -10));
57	shmop_delete($shm_id);
58
59echo PHP_EOL, '## shmop_size function tests ##';
60	// warning outputs: 1 parameter expected
61	var_dump(shmop_size());
62
63echo PHP_EOL, '## shmop_delete function tests ##';
64	// warning outputs: 1 parameter expected
65	var_dump(shmop_delete());
66
67echo PHP_EOL, '## shmop_close function tests ##';
68	// warning outputs: 1 parameter expected
69	var_dump(shmop_close());
70?>
71--EXPECTF--
72## shmop_open function tests ##
73Warning: shmop_open() expects exactly 4 parameters, 0 given in %s on line %d
74NULL
75
76Warning: shmop_open():  is not a valid flag in %s on line %d
77bool(false)
78
79Warning: shmop_open(): invalid access mode in %s on line %d
80bool(false)
81
82Warning: shmop_open(): unable to attach or create shared memory segment 'Invalid argument' in %s on line %d
83bool(false)
84
85Warning: shmop_open(): Shared memory segment size must be greater than zero in %s on line %d
86bool(false)
87
88## shmop_read function tests ##
89Warning: shmop_read() expects exactly 3 parameters, 0 given in %s on line %d
90NULL
91
92Warning: shmop_read(): start is out of range in %s on line %d
93bool(false)
94
95Warning: shmop_read(): count is out of range in %s on line %d
96bool(false)
97
98## shmop_write function tests ##
99Warning: shmop_write() expects exactly 3 parameters, 0 given in %s on line %d
100NULL
101
102Warning: shmop_write(): offset out of range in %s on line %d
103bool(false)
104
105## shmop_size function tests ##
106Warning: shmop_size() expects exactly 1 parameter, 0 given in %s on line %d
107NULL
108
109## shmop_delete function tests ##
110Warning: shmop_delete() expects exactly 1 parameter, 0 given in %s on line %d
111NULL
112
113## shmop_close function tests ##
114Warning: shmop_close() expects exactly 1 parameter, 0 given in %s on line %d
115NULL
116