xref: /PHP-8.3/ext/sysvmsg/tests/005.phpt (revision 7f2f0c00)
1--TEST--
2sysvmsg functions on non-existing queue
3--EXTENSIONS--
4sysvmsg
5--FILE--
6<?php
7
8$tests = array(null, 'foo');
9
10foreach ($tests as $i => $q) {
11
12    if ($q === null) {
13        do {
14            $id = ftok(__FILE__, chr(mt_rand(0, 255))); } while (msg_queue_exists($id));
15    }
16
17    $q = msg_get_queue($id) or die("Failed to create queue");
18    msg_remove_queue($q) or die("Failed to close queue");
19
20    echo "Iteration " . ($i + 1) . ":\n";
21
22    $errno = 0;
23
24    var_dump(msg_set_queue($q, array('msg_qbytes' => 1)));
25
26    var_dump(msg_stat_queue($q));
27
28    var_dump(msg_receive($q, 0, $null, 1, $msg, true, 0, $errno));
29    var_dump($errno != 0);
30    // again, but triggering an exception
31    try {
32        msg_receive($q, 0, $null, 0, $msg);
33    } catch (ValueError $exception) {
34        echo $exception->getMessage() . "\n";
35    }
36
37    var_dump(msg_send($q, 1, 'foo', true, true, $errno));
38    var_dump($errno != 0);
39}
40
41echo "Done\n";
42?>
43--EXPECTF--
44Iteration 1:
45bool(false)
46bool(false)
47bool(false)
48bool(true)
49msg_receive(): Argument #4 ($max_message_size) must be greater than 0
50
51Warning: msg_send(): msgsnd failed: Invalid argument in %s on line %d
52bool(false)
53bool(true)
54Iteration 2:
55bool(false)
56bool(false)
57bool(false)
58bool(true)
59msg_receive(): Argument #4 ($max_message_size) must be greater than 0
60
61Warning: msg_send(): msgsnd failed: Invalid argument in %s on line %d
62bool(false)
63bool(true)
64Done
65