002.phpt 2.4 KB

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