"Fossies" - the Fresh Open Source Software Archive

Member "php-7.4.1/ext/shmop/tests/001.phpt" (17 Dec 2019, 2140 Bytes) of package /linux/www/php-7.4.1.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 --TEST--
    2 shmop extension test
    3 --SKIPIF--
    4 <?php
    5 	if (!extension_loaded("shmop")) {
    6 		die("skip shmop() extension not available");
    7 	}
    8 ?>
    9 --FILE--
   10 <?php
   11 	$hex_shm_id = 0xff3;
   12 	$write_d1 = "test #1 of the shmop() extension";
   13 	$write_d2 = "test #2 append data to shared memory segment";
   14 
   15 	echo "shm open for create: ";
   16 	$shm_id = shmop_open($hex_shm_id, "n", 0644, 1024);
   17 	if (!$shm_id) {
   18 		die("failed\n");
   19 	} else {
   20 		echo "ok\n";
   21 	}
   22 
   23 	echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n";
   24 
   25 	echo "shm write test #1: ";
   26 	$written = shmop_write($shm_id, $write_d1, 0);
   27 	if ($written != strlen($write_d1)) {
   28 		echo "failed\n";
   29 	} else {
   30 		echo "ok\n";
   31 	}
   32 
   33 	echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
   34 
   35 	shmop_close($shm_id);
   36 
   37 	echo "shm open for read only: ";
   38 	$shm_id = shmop_open($hex_shm_id, "a", 0644, 1024);
   39 	if (!$shm_id) {
   40 		echo "failed\n";
   41 	} else {
   42 		echo "ok\n";
   43 	}
   44 
   45 	echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n";
   46 
   47 	/* try to append data to the shared memory segment, this should fail */
   48 	shmop_write($shm_id, $write_d1, $written);
   49 
   50 	shmop_close($shm_id);
   51 
   52 	echo "shm open for read only: ";
   53 	$shm_id = shmop_open($hex_shm_id, "w", 0644, 1024);
   54 	if (!$shm_id) {
   55 		echo "failed\n";
   56 	} else {
   57 		echo "ok\n";
   58 	}
   59 
   60 	echo "shm write test #1: ";
   61 	$written = shmop_write($shm_id, $write_d2, $written);
   62 	if ($written != strlen($write_d2)) {
   63 		die("failed\n");
   64 	} else {
   65 		echo "ok\n";
   66 	}
   67 
   68 	echo "data in memory is: " . shmop_read($shm_id, 0, strlen($write_d1 . $write_d2)) . "\n";
   69 
   70 	echo "deletion of shm segment: ";
   71 	if (!shmop_delete($shm_id)) {
   72 		echo "failed\n";
   73 	} else {
   74 		echo "ok\n";
   75 	}
   76 
   77 	shmop_close($shm_id);
   78 ?>
   79 --EXPECTF--
   80 shm open for create: ok
   81 shm size is: 1024
   82 shm write test #1: ok
   83 data in memory is: test #1 of the shmop() extension
   84 shm open for read only: ok
   85 data in memory is: test #1 of the shmop() extension
   86 
   87 Warning: shmop_write(): trying to write to a read only segment in %s on line %d
   88 shm open for read only: ok
   89 shm write test #1: ok
   90 data in memory is: test #1 of the shmop() extensiontest #2 append data to shared memory segment
   91 deletion of shm segment: ok