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