libuv-svace-build
92 строки · 2.8 Кб
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
22
23#include "uv.h"24#include "task.h"25#include <string.h>26
27TEST_IMPL(pipe_set_chmod) {28uv_pipe_t pipe_handle;29uv_loop_t* loop;30int r;31#ifndef _WIN3232struct stat stat_buf;33#endif34
35loop = uv_default_loop();36
37r = uv_pipe_init(loop, &pipe_handle, 0);38ASSERT_OK(r);39
40r = uv_pipe_bind(&pipe_handle, TEST_PIPENAME);41ASSERT_OK(r);42
43/* No easy way to test if this works, we will only make sure that the call is44* successful. */
45r = uv_pipe_chmod(&pipe_handle, UV_READABLE);46if (r == UV_EPERM) {47MAKE_VALGRIND_HAPPY(loop);48RETURN_SKIP("Insufficient privileges to alter pipe fmode");49}50ASSERT_OK(r);51#ifndef _WIN3252memset(&stat_buf, 0, sizeof(stat_buf));53ASSERT_OK(stat(TEST_PIPENAME, &stat_buf));54ASSERT(stat_buf.st_mode & S_IRUSR);55ASSERT(stat_buf.st_mode & S_IRGRP);56ASSERT(stat_buf.st_mode & S_IROTH);57#endif58
59r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE);60ASSERT_OK(r);61#ifndef _WIN3262stat(TEST_PIPENAME, &stat_buf);63ASSERT(stat_buf.st_mode & S_IWUSR);64ASSERT(stat_buf.st_mode & S_IWGRP);65ASSERT(stat_buf.st_mode & S_IWOTH);66#endif67
68r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE | UV_READABLE);69ASSERT_OK(r);70#ifndef _WIN3271stat(TEST_PIPENAME, &stat_buf);72ASSERT(stat_buf.st_mode & S_IRUSR);73ASSERT(stat_buf.st_mode & S_IRGRP);74ASSERT(stat_buf.st_mode & S_IROTH);75ASSERT(stat_buf.st_mode & S_IWUSR);76ASSERT(stat_buf.st_mode & S_IWGRP);77ASSERT(stat_buf.st_mode & S_IWOTH);78#endif79
80r = uv_pipe_chmod(NULL, UV_WRITABLE | UV_READABLE);81ASSERT_EQ(r, UV_EBADF);82
83r = uv_pipe_chmod(&pipe_handle, 12345678);84ASSERT_EQ(r, UV_EINVAL);85
86uv_close((uv_handle_t*)&pipe_handle, NULL);87r = uv_pipe_chmod(&pipe_handle, UV_WRITABLE | UV_READABLE);88ASSERT_EQ(r, UV_EBADF);89
90MAKE_VALGRIND_HAPPY(loop);91return 0;92}
93