1 1.1.1.2 christos /* Copyright libuv project contributors. All rights reserved. 2 1.1.1.2 christos * 3 1.1.1.2 christos * Permission is hereby granted, free of charge, to any person obtaining a copy 4 1.1.1.2 christos * of this software and associated documentation files (the "Software"), to 5 1.1.1.2 christos * deal in the Software without restriction, including without limitation the 6 1.1.1.2 christos * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 7 1.1.1.2 christos * sell copies of the Software, and to permit persons to whom the Software is 8 1.1.1.2 christos * furnished to do so, subject to the following conditions: 9 1.1.1.2 christos * 10 1.1.1.2 christos * The above copyright notice and this permission notice shall be included in 11 1.1.1.2 christos * all copies or substantial portions of the Software. 12 1.1.1.2 christos * 13 1.1.1.2 christos * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 1.1.1.2 christos * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 1.1.1.2 christos * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 1.1.1.2 christos * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 1.1.1.2 christos * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 1.1.1.2 christos * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 19 1.1.1.2 christos * IN THE SOFTWARE. 20 1.1.1.2 christos */ 21 1.1.1.2 christos 22 1.1 christos #include "uv.h" 23 1.1 christos #include "task.h" 24 1.1 christos #include <string.h> 25 1.1 christos #include <sys/stat.h> 26 1.1 christos 27 1.1.1.3 christos #ifdef _WIN32 28 1.1.1.3 christos # define S_IFDIR _S_IFDIR 29 1.1.1.3 christos #endif 30 1.1.1.3 christos 31 1.1 christos int cookie1; 32 1.1 christos int cookie2; 33 1.1 christos int cookie3; 34 1.1 christos 35 1.1 christos 36 1.1 christos TEST_IMPL(handle_type_name) { 37 1.1.1.3 christos ASSERT_OK(strcmp(uv_handle_type_name(UV_NAMED_PIPE), "pipe")); 38 1.1.1.3 christos ASSERT_OK(strcmp(uv_handle_type_name(UV_UDP), "udp")); 39 1.1.1.3 christos ASSERT_OK(strcmp(uv_handle_type_name(UV_FILE), "file")); 40 1.1.1.2 christos ASSERT_NULL(uv_handle_type_name(UV_HANDLE_TYPE_MAX)); 41 1.1.1.2 christos ASSERT_NULL(uv_handle_type_name(UV_HANDLE_TYPE_MAX + 1)); 42 1.1.1.2 christos ASSERT_NULL(uv_handle_type_name(UV_UNKNOWN_HANDLE)); 43 1.1 christos return 0; 44 1.1 christos } 45 1.1 christos 46 1.1 christos 47 1.1 christos TEST_IMPL(req_type_name) { 48 1.1.1.3 christos ASSERT_OK(strcmp(uv_req_type_name(UV_REQ), "req")); 49 1.1.1.3 christos ASSERT_OK(strcmp(uv_req_type_name(UV_UDP_SEND), "udp_send")); 50 1.1.1.3 christos ASSERT_OK(strcmp(uv_req_type_name(UV_WORK), "work")); 51 1.1.1.2 christos ASSERT_NULL(uv_req_type_name(UV_REQ_TYPE_MAX)); 52 1.1.1.2 christos ASSERT_NULL(uv_req_type_name(UV_REQ_TYPE_MAX + 1)); 53 1.1.1.2 christos ASSERT_NULL(uv_req_type_name(UV_UNKNOWN_REQ)); 54 1.1 christos return 0; 55 1.1 christos } 56 1.1 christos 57 1.1 christos 58 1.1 christos TEST_IMPL(getters_setters) { 59 1.1 christos uv_loop_t* loop; 60 1.1 christos uv_pipe_t* pipe; 61 1.1 christos uv_fs_t* fs; 62 1.1 christos int r; 63 1.1 christos 64 1.1 christos loop = malloc(uv_loop_size()); 65 1.1.1.2 christos ASSERT_NOT_NULL(loop); 66 1.1 christos r = uv_loop_init(loop); 67 1.1.1.3 christos ASSERT_OK(r); 68 1.1 christos 69 1.1 christos uv_loop_set_data(loop, &cookie1); 70 1.1.1.3 christos ASSERT_PTR_EQ(loop->data, &cookie1); 71 1.1.1.3 christos ASSERT_PTR_EQ(uv_loop_get_data(loop), &cookie1); 72 1.1 christos 73 1.1 christos pipe = malloc(uv_handle_size(UV_NAMED_PIPE)); 74 1.1 christos r = uv_pipe_init(loop, pipe, 0); 75 1.1.1.3 christos ASSERT_OK(r); 76 1.1.1.3 christos ASSERT_EQ(uv_handle_get_type((uv_handle_t*)pipe), UV_NAMED_PIPE); 77 1.1 christos 78 1.1.1.3 christos ASSERT_PTR_EQ(uv_handle_get_loop((uv_handle_t*)pipe), loop); 79 1.1 christos pipe->data = &cookie2; 80 1.1.1.3 christos ASSERT_PTR_EQ(uv_handle_get_data((uv_handle_t*)pipe), &cookie2); 81 1.1 christos uv_handle_set_data((uv_handle_t*)pipe, &cookie1); 82 1.1.1.3 christos ASSERT_PTR_EQ(uv_handle_get_data((uv_handle_t*)pipe), &cookie1); 83 1.1.1.3 christos ASSERT_PTR_EQ(pipe->data, &cookie1); 84 1.1 christos 85 1.1.1.3 christos ASSERT_OK(uv_stream_get_write_queue_size((uv_stream_t*)pipe)); 86 1.1 christos pipe->write_queue_size++; 87 1.1.1.3 christos ASSERT_EQ(1, uv_stream_get_write_queue_size((uv_stream_t*)pipe)); 88 1.1 christos pipe->write_queue_size--; 89 1.1 christos uv_close((uv_handle_t*)pipe, NULL); 90 1.1 christos 91 1.1 christos r = uv_run(loop, UV_RUN_DEFAULT); 92 1.1.1.3 christos ASSERT_OK(r); 93 1.1 christos 94 1.1 christos fs = malloc(uv_req_size(UV_FS)); 95 1.1 christos uv_fs_stat(loop, fs, ".", NULL); 96 1.1 christos 97 1.1 christos r = uv_run(loop, UV_RUN_DEFAULT); 98 1.1.1.3 christos ASSERT_OK(r); 99 1.1 christos 100 1.1.1.3 christos ASSERT_EQ(uv_fs_get_type(fs), UV_FS_STAT); 101 1.1.1.3 christos ASSERT_OK(uv_fs_get_result(fs)); 102 1.1.1.3 christos ASSERT_PTR_EQ(uv_fs_get_ptr(fs), uv_fs_get_statbuf(fs)); 103 1.1 christos ASSERT(uv_fs_get_statbuf(fs)->st_mode & S_IFDIR); 104 1.1.1.3 christos ASSERT_OK(strcmp(uv_fs_get_path(fs), ".")); 105 1.1 christos uv_fs_req_cleanup(fs); 106 1.1 christos 107 1.1 christos r = uv_loop_close(loop); 108 1.1.1.3 christos ASSERT_OK(r); 109 1.1 christos 110 1.1 christos free(pipe); 111 1.1 christos free(fs); 112 1.1 christos free(loop); 113 1.1 christos return 0; 114 1.1 christos } 115