Blame test/test-pipe-set-fchmod.c

Packit b5b901
/* Copyright libuv project contributors. All rights reserved.
Packit b5b901
*
Packit b5b901
* Permission is hereby granted, free of charge, to any person obtaining a copy
Packit b5b901
* of this software and associated documentation files (the "Software"), to
Packit b5b901
* deal in the Software without restriction, including without limitation the
Packit b5b901
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
Packit b5b901
* sell copies of the Software, and to permit persons to whom the Software is
Packit b5b901
* furnished to do so, subject to the following conditions:
Packit b5b901
*
Packit b5b901
* The above copyright notice and this permission notice shall be included in
Packit b5b901
* all copies or substantial portions of the Software.
Packit b5b901
*
Packit b5b901
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit b5b901
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit b5b901
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Packit b5b901
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Packit b5b901
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
Packit b5b901
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
Packit b5b901
* IN THE SOFTWARE.
Packit b5b901
*/
Packit b5b901
Packit b5b901
Packit b5b901
#include "uv.h"
Packit b5b901
#include "task.h"
Packit b5b901
Packit b5b901
TEST_IMPL(pipe_set_chmod) {
Packit b5b901
  uv_pipe_t pipe_handle;
Packit b5b901
  uv_loop_t* loop;
Packit b5b901
  int r;
Packit b5b901
#ifndef _WIN32
Packit b5b901
  struct stat stat_buf;
Packit b5b901
#endif
Packit b5b901
Packit b5b901
  loop = uv_default_loop();
Packit b5b901
Packit b5b901
  r = uv_pipe_init(loop, &pipe_handle, 0);
Packit b5b901
  ASSERT(r == 0);
Packit b5b901
Packit b5b901
  r = uv_pipe_bind(&pipe_handle, TEST_PIPENAME);
Packit b5b901
  ASSERT(r == 0);
Packit b5b901
Packit b5b901
  /* No easy way to test if this works, we will only make sure that the call is
Packit b5b901
   * successful. */
Packit b5b901
  r = uv_pipe_chmod(&pipe_handle, UV_READABLE);
Packit b5b901
  if (r == UV_EPERM) {
Packit b5b901
    MAKE_VALGRIND_HAPPY();
Packit b5b901
    RETURN_SKIP("Insufficient privileges to alter pipe fmode");
Packit b5b901
  }
Packit b5b901
  ASSERT(r == 0);
Packit b5b901
#ifndef _WIN32
Packit b5b901
  stat(TEST_PIPENAME, &stat_buf);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IRUSR);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IRGRP);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IROTH);
Packit b5b901
#endif
Packit b5b901
Packit b5b901
  r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE);
Packit b5b901
  ASSERT(r == 0);
Packit b5b901
#ifndef _WIN32
Packit b5b901
  stat(TEST_PIPENAME, &stat_buf);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IWUSR);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IWGRP);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IWOTH);
Packit b5b901
#endif
Packit b5b901
Packit b5b901
  r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE | UV_READABLE);
Packit b5b901
  ASSERT(r == 0);
Packit b5b901
#ifndef _WIN32
Packit b5b901
  stat(TEST_PIPENAME, &stat_buf);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IRUSR);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IRGRP);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IROTH);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IWUSR);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IWGRP);
Packit b5b901
  ASSERT(stat_buf.st_mode & S_IWOTH);
Packit b5b901
#endif
Packit b5b901
Packit b5b901
  r = uv_pipe_chmod(NULL, UV_WRITABLE | UV_READABLE);
Packit b5b901
  ASSERT(r == UV_EBADF);
Packit b5b901
Packit b5b901
  r = uv_pipe_chmod(&pipe_handle, 12345678);
Packit b5b901
  ASSERT(r == UV_EINVAL);
Packit b5b901
Packit b5b901
  uv_close((uv_handle_t*)&pipe_handle, NULL);
Packit b5b901
  r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE | UV_READABLE);
Packit b5b901
  ASSERT(r == UV_EBADF);
Packit b5b901
Packit b5b901
  MAKE_VALGRIND_HAPPY();
Packit b5b901
  return 0;
Packit b5b901
}