xref: /PHP-8.3/ext/shmop/tests/002.phpt (revision e9f783fc)
1--TEST--
2shmop extension error messages
3--CREDITS--
4edgarsandi - <edgar.r.sandi@gmail.com>
5--EXTENSIONS--
6shmop
7--FILE--
8<?php
9
10echo PHP_EOL, '## shmop_open function tests ##', PHP_EOL;
11
12// Invalid flag when the flags length != 1
13try {
14    shmop_open(1338, '', 0644, 1024);
15} catch (ValueError $exception) {
16    echo $exception->getMessage() . "\n";
17}
18
19try {
20    shmop_open(1338, 'b', 0644, 1024);
21} catch (ValueError $exception) {
22    echo $exception->getMessage() . "\n";
23}
24
25// Warning outputs: Unable to attach or create shared memory segment
26var_dump(shmop_open(0, 'a', 0644, 1024));
27
28// Shared memory segment size must be greater than zero
29try {
30    shmop_open(0, 'a', 0644, 1024);
31} catch (ValueError $exception) {
32    echo $exception->getMessage() . "\n";
33}
34
35//Shared memory segment size must be greater than zero
36try {
37    shmop_open(1338, "c", 0666, 0);
38} catch (ValueError $exception) {
39    echo $exception->getMessage() . "\n";
40}
41
42echo PHP_EOL, '## shmop_read function tests ##', PHP_EOL;
43// Start is out of range
44$shm_id = shmop_open(1338, 'n', 0600, 1024);
45try {
46    shmop_read($shm_id, -10, 0);
47} catch (ValueError $exception) {
48    echo $exception->getMessage() . "\n";
49}
50shmop_delete($shm_id);
51
52// Count is out of range
53$shm_id = shmop_open(1339, 'n', 0600, 1024);
54try {
55    shmop_read($shm_id, 0, -10);
56} catch (ValueError $exception) {
57    echo $exception->getMessage() . "\n";
58}
59shmop_delete($shm_id);
60
61echo PHP_EOL, '## shmop_write function tests ##', PHP_EOL;
62// Offset out of range
63$shm_id = shmop_open(1340, 'n', 0600, 1024);
64try {
65    shmop_write($shm_id, 'text to try write', -10);
66} catch (ValueError $exception) {
67    echo $exception->getMessage() . "\n";
68}
69shmop_delete($shm_id);
70?>
71--EXPECTF--
72## shmop_open function tests ##
73shmop_open(): Argument #2 ($mode) must be a valid access mode
74shmop_open(): Argument #2 ($mode) must be a valid access mode
75
76Warning: shmop_open(): Unable to attach or create shared memory segment "%s" in %s on line %d
77bool(false)
78
79Warning: shmop_open(): Unable to attach or create shared memory segment "%s" in %s on line %d
80shmop_open(): Argument #4 ($size) must be greater than 0 for the "c" and "n" access modes
81
82## shmop_read function tests ##
83shmop_read(): Argument #2 ($offset) must be between 0 and the segment size
84shmop_read(): Argument #3 ($size) is out of range
85
86## shmop_write function tests ##
87shmop_write(): Argument #3 ($offset) is out of range
88