1#include "uv.h"
2#include "task.h"
3#include <string.h>
4#include <sys/stat.h>
5
6int cookie1;
7int cookie2;
8int cookie3;
9
10
11TEST_IMPL(handle_type_name) {
12 ASSERT(strcmp(uv_handle_type_name(UV_NAMED_PIPE), "pipe") == 0);
13 ASSERT(strcmp(uv_handle_type_name(UV_UDP), "udp") == 0);
14 ASSERT(strcmp(uv_handle_type_name(UV_FILE), "file") == 0);
15 ASSERT(uv_handle_type_name(UV_HANDLE_TYPE_MAX) == NULL);
16 ASSERT(uv_handle_type_name(UV_HANDLE_TYPE_MAX + 1) == NULL);
17 ASSERT(uv_handle_type_name(UV_UNKNOWN_HANDLE) == NULL);
18 return 0;
19}
20
21
22TEST_IMPL(req_type_name) {
23 ASSERT(strcmp(uv_req_type_name(UV_REQ), "req") == 0);
24 ASSERT(strcmp(uv_req_type_name(UV_UDP_SEND), "udp_send") == 0);
25 ASSERT(strcmp(uv_req_type_name(UV_WORK), "work") == 0);
26 ASSERT(uv_req_type_name(UV_REQ_TYPE_MAX) == NULL);
27 ASSERT(uv_req_type_name(UV_REQ_TYPE_MAX + 1) == NULL);
28 ASSERT(uv_req_type_name(UV_UNKNOWN_REQ) == NULL);
29 return 0;
30}
31
32
33TEST_IMPL(getters_setters) {
34 uv_loop_t* loop;
35 uv_pipe_t* pipe;
36 uv_fs_t* fs;
37 int r;
38
39 loop = malloc(uv_loop_size());
40 ASSERT(loop != NULL);
41 r = uv_loop_init(loop);
42 ASSERT(r == 0);
43
44 uv_loop_set_data(loop, &cookie1);
45 ASSERT(loop->data == &cookie1);
46 ASSERT(uv_loop_get_data(loop) == &cookie1);
47
48 pipe = malloc(uv_handle_size(UV_NAMED_PIPE));
49 r = uv_pipe_init(loop, pipe, 0);
50 ASSERT(uv_handle_get_type((uv_handle_t*)pipe) == UV_NAMED_PIPE);
51
52 ASSERT(uv_handle_get_loop((uv_handle_t*)pipe) == loop);
53 pipe->data = &cookie2;
54 ASSERT(uv_handle_get_data((uv_handle_t*)pipe) == &cookie2);
55 uv_handle_set_data((uv_handle_t*)pipe, &cookie1);
56 ASSERT(uv_handle_get_data((uv_handle_t*)pipe) == &cookie1);
57 ASSERT(pipe->data == &cookie1);
58
59 ASSERT(uv_stream_get_write_queue_size((uv_stream_t*)pipe) == 0);
60 pipe->write_queue_size++;
61 ASSERT(uv_stream_get_write_queue_size((uv_stream_t*)pipe) == 1);
62 pipe->write_queue_size--;
63 uv_close((uv_handle_t*)pipe, NULL);
64
65 r = uv_run(loop, UV_RUN_DEFAULT);
66 ASSERT(r == 0);
67
68 fs = malloc(uv_req_size(UV_FS));
69 uv_fs_stat(loop, fs, ".", NULL);
70
71 r = uv_run(loop, UV_RUN_DEFAULT);
72 ASSERT(r == 0);
73
74 ASSERT(uv_fs_get_type(fs) == UV_FS_STAT);
75 ASSERT(uv_fs_get_result(fs) == 0);
76 ASSERT(uv_fs_get_ptr(fs) == uv_fs_get_statbuf(fs));
77 ASSERT(uv_fs_get_statbuf(fs)->st_mode & S_IFDIR);
78 ASSERT(strcmp(uv_fs_get_path(fs), ".") == 0);
79 uv_fs_req_cleanup(fs);
80
81 r = uv_loop_close(loop);
82 ASSERT(r == 0);
83
84 free(pipe);
85 free(fs);
86 free(loop);
87 return 0;
88}
89