test-pipe-set-fchmod.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright libuv project contributors. All rights reserved.
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to
  5. * deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. * sell copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19. * IN THE SOFTWARE.
  20. */
  21. #include "uv.h"
  22. #include "task.h"
  23. TEST_IMPL(pipe_set_chmod) {
  24. uv_pipe_t pipe_handle;
  25. uv_loop_t* loop;
  26. int r;
  27. #ifndef _WIN32
  28. struct stat stat_buf;
  29. #endif
  30. loop = uv_default_loop();
  31. r = uv_pipe_init(loop, &pipe_handle, 0);
  32. ASSERT(r == 0);
  33. r = uv_pipe_bind(&pipe_handle, TEST_PIPENAME);
  34. ASSERT(r == 0);
  35. /* No easy way to test if this works, we will only make sure that the call is
  36. * successful. */
  37. r = uv_pipe_chmod(&pipe_handle, UV_READABLE);
  38. if (r == UV_EPERM) {
  39. MAKE_VALGRIND_HAPPY();
  40. RETURN_SKIP("Insufficient privileges to alter pipe fmode");
  41. }
  42. ASSERT(r == 0);
  43. #ifndef _WIN32
  44. stat(TEST_PIPENAME, &stat_buf);
  45. ASSERT(stat_buf.st_mode & S_IRUSR);
  46. ASSERT(stat_buf.st_mode & S_IRGRP);
  47. ASSERT(stat_buf.st_mode & S_IROTH);
  48. #endif
  49. r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE);
  50. ASSERT(r == 0);
  51. #ifndef _WIN32
  52. stat(TEST_PIPENAME, &stat_buf);
  53. ASSERT(stat_buf.st_mode & S_IWUSR);
  54. ASSERT(stat_buf.st_mode & S_IWGRP);
  55. ASSERT(stat_buf.st_mode & S_IWOTH);
  56. #endif
  57. r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE | UV_READABLE);
  58. ASSERT(r == 0);
  59. #ifndef _WIN32
  60. stat(TEST_PIPENAME, &stat_buf);
  61. ASSERT(stat_buf.st_mode & S_IRUSR);
  62. ASSERT(stat_buf.st_mode & S_IRGRP);
  63. ASSERT(stat_buf.st_mode & S_IROTH);
  64. ASSERT(stat_buf.st_mode & S_IWUSR);
  65. ASSERT(stat_buf.st_mode & S_IWGRP);
  66. ASSERT(stat_buf.st_mode & S_IWOTH);
  67. #endif
  68. r = uv_pipe_chmod(NULL, UV_WRITABLE | UV_READABLE);
  69. ASSERT(r == UV_EBADF);
  70. r = uv_pipe_chmod(&pipe_handle, 12345678);
  71. ASSERT(r == UV_EINVAL);
  72. uv_close((uv_handle_t*)&pipe_handle, NULL);
  73. r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE | UV_READABLE);
  74. ASSERT(r == UV_EBADF);
  75. MAKE_VALGRIND_HAPPY();
  76. return 0;
  77. }