mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add some sysvmsg coverage tests
This commit is contained in:
parent
24829e8d4e
commit
3be50a26a7
3 changed files with 199 additions and 0 deletions
59
ext/sysvmsg/tests/004.phpt
Normal file
59
ext/sysvmsg/tests/004.phpt
Normal file
|
@ -0,0 +1,59 @@
|
|||
--TEST--
|
||||
msg_set_queue() and msg_stat_queue()
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("sysvmsg")) die("skip sysvmsg extension is not available")?>
|
||||
--FILE--
|
||||
<?php
|
||||
$id = ftok(__FILE__, 'r');
|
||||
|
||||
$q = msg_get_queue($id);
|
||||
|
||||
echo "Set mode:\n";
|
||||
$arr = array('msg_perm.mode' => 0600);
|
||||
var_dump(msg_set_queue($q, $arr));
|
||||
echo "Did really work:\n";
|
||||
var_dump(count(array_diff_assoc($arr, msg_stat_queue($q))) == 0);
|
||||
|
||||
echo "Set uid:\n"; // same as the running user to make it succeed
|
||||
$arr = array('msg_perm.uid' => getmyuid());
|
||||
var_dump(msg_set_queue($q, $arr));
|
||||
echo "Did really work:\n";
|
||||
var_dump(count(array_diff_assoc($arr, msg_stat_queue($q))) == 0);
|
||||
|
||||
echo "Set gid:\n"; // same as the running user to make it succeed
|
||||
$arr = array('msg_perm.gid' => getmygid());
|
||||
var_dump(msg_set_queue($q, $arr));
|
||||
echo "Did really work:\n";
|
||||
var_dump(count(array_diff_assoc($arr, msg_stat_queue($q))) == 0);
|
||||
|
||||
echo "Set smaller qbytes:\n";
|
||||
$res = msg_stat_queue($q);
|
||||
$arr = array('msg_qbytes' => ($res['msg_qbytes'] -1));
|
||||
var_dump(msg_set_queue($q, $arr));
|
||||
echo "Did really work:\n";
|
||||
var_dump(count(array_diff_assoc($arr, msg_stat_queue($q))) == 0);
|
||||
|
||||
if (!msg_remove_queue($q)) {
|
||||
echo "BAD: queue removal failed\n";
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Set mode:
|
||||
bool(true)
|
||||
Did really work:
|
||||
bool(true)
|
||||
Set uid:
|
||||
bool(true)
|
||||
Did really work:
|
||||
bool(true)
|
||||
Set gid:
|
||||
bool(true)
|
||||
Did really work:
|
||||
bool(true)
|
||||
Set smaller qbytes:
|
||||
bool(true)
|
||||
Did really work:
|
||||
bool(true)
|
||||
Done
|
71
ext/sysvmsg/tests/005.phpt
Normal file
71
ext/sysvmsg/tests/005.phpt
Normal file
|
@ -0,0 +1,71 @@
|
|||
--TEST--
|
||||
sysvmsg functions on non-existing queue
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("sysvmsg")) die("skip sysvmsg extension is not available")?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$tests = array(null, 'foo');
|
||||
|
||||
foreach ($tests as $q) {
|
||||
|
||||
if ($q === null) {
|
||||
do {
|
||||
$id = ftok(__FILE__, chr(mt_rand(0, 255)));
|
||||
} while (msg_queue_exists($id));
|
||||
|
||||
$q = msg_get_queue($id) or die("Failed to create queue");
|
||||
msg_remove_queue($q) or die("Failed to close queue");
|
||||
}
|
||||
|
||||
echo "Using '$q' as queue resource:\n";
|
||||
|
||||
$errno = 0;
|
||||
|
||||
var_dump(msg_set_queue($q, array('msg_qbytes' => 1)));
|
||||
|
||||
var_dump(msg_stat_queue($q));
|
||||
|
||||
var_dump(msg_receive($q, 0, $null, 1, $msg, true, 0, $errno));
|
||||
var_dump($errno != 0);
|
||||
// again, but triggering an E_WARNING
|
||||
var_dump(msg_receive($q, 0, $null, 0, $msg));
|
||||
|
||||
var_dump(msg_send($q, 1, 'foo', true, true, $errno));
|
||||
var_dump($errno != 0);
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Using 'Resource id #4' as queue resource:
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(true)
|
||||
|
||||
Warning: msg_receive(): maximum size of the message has to be greater than zero in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: msg_send(): msgsnd failed: Invalid argument in %s on line %d
|
||||
bool(false)
|
||||
bool(true)
|
||||
Using 'foo' as queue resource:
|
||||
|
||||
Warning: msg_set_queue() expects parameter 1 to be resource, string given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: msg_stat_queue() expects parameter 1 to be resource, string given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: msg_receive() expects parameter 1 to be resource, string given in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
|
||||
Warning: msg_receive() expects parameter 1 to be resource, string given in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: msg_send() expects parameter 1 to be resource, string given in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
Done
|
69
ext/sysvmsg/tests/006.phpt
Normal file
69
ext/sysvmsg/tests/006.phpt
Normal file
|
@ -0,0 +1,69 @@
|
|||
--TEST--
|
||||
msg_send() data types when not serializing
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("sysvmsg")) die("skip sysvmsg extenions is not available")?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$queue = msg_get_queue (ftok(__FILE__, 'r'), 0600);
|
||||
|
||||
$tests = array('foo', 123, PHP_INT_MAX +1, true, 1.01, null, array('bar'));
|
||||
|
||||
foreach ($tests as $elem) {
|
||||
echo "Sending/receiving '$elem':\n";
|
||||
var_dump(msg_send($queue, 1, $elem, false));
|
||||
|
||||
unset($msg);
|
||||
var_dump(msg_receive($queue, 1, $msg_type, 1024, $msg, false, MSG_IPC_NOWAIT));
|
||||
|
||||
var_dump($elem == $msg);
|
||||
var_dump($elem === $msg);
|
||||
}
|
||||
|
||||
if (!msg_remove_queue($queue)) {
|
||||
echo "BAD: queue removal failed\n";
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
Sending/receiving 'foo':
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
Sending/receiving '123':
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
Sending/receiving '%d':
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
Sending/receiving '1':
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
Sending/receiving '1.01':
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(false)
|
||||
Sending/receiving '':
|
||||
|
||||
Warning: msg_send(): Message parameter must be either a string or a number. in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(true)
|
||||
bool(false)
|
||||
Sending/receiving 'Array':
|
||||
|
||||
Warning: msg_send(): Message parameter must be either a string or a number. in %s on line %d
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
Done
|
Loading…
Add table
Add a link
Reference in a new issue