test-getters-setters.c
Go to the documentation of this file.
1 #include "uv.h"
2 #include "task.h"
3 #include <string.h>
4 #include <sys/stat.h>
5 
6 int cookie1;
7 int cookie2;
8 int cookie3;
9 
10 
11 TEST_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);
18  return 0;
19 }
20 
21 
22 TEST_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);
29  return 0;
30 }
31 
32 
33 TEST_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 
45  ASSERT(loop->data == &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 
53  pipe->data = &cookie2;
57  ASSERT(pipe->data == &cookie1);
58 
60  pipe->write_queue_size++;
62  pipe->write_queue_size--;
63  uv_close((uv_handle_t*)pipe, NULL);
64 
66  ASSERT(r == 0);
67 
68  fs = malloc(uv_req_size(UV_FS));
69  uv_fs_stat(loop, fs, ".", NULL);
70 
72  ASSERT(r == 0);
73 
75  ASSERT(uv_fs_get_result(fs) == 0);
77  ASSERT(uv_fs_get_statbuf(fs)->st_mode & S_IFDIR);
78  ASSERT(strcmp(uv_fs_get_path(fs), ".") == 0);
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 }
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
uv_loop_size
UV_EXTERN size_t uv_loop_size(void)
Definition: uv-common.c:152
task.h
uv_pipe_init
UV_EXTERN int uv_pipe_init(uv_loop_t *, uv_pipe_t *handle, int ipc)
Definition: unix/pipe.c:33
uv_fs_get_result
UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t *)
Definition: uv-data-getter-setters.c:76
uv_handle_type_name
const UV_EXTERN char * uv_handle_type_name(uv_handle_type type)
Definition: uv-data-getter-setters.c:3
uv_loop_set_data
UV_EXTERN void uv_loop_set_data(uv_loop_t *, void *data)
Definition: uv-data-getter-setters.c:96
uv_fs_stat
UV_EXTERN int uv_fs_stat(uv_loop_t *loop, uv_fs_t *req, const char *path, uv_fs_cb cb)
Definition: unix/fs.c:1954
string.h
ASSERT
#define ASSERT(expr)
Definition: task.h:102
cookie3
int cookie3
Definition: test-getters-setters.c:8
uv_fs_get_path
const UV_EXTERN char * uv_fs_get_path(const uv_fs_t *)
Definition: uv-data-getter-setters.c:84
uv_loop_get_data
UV_EXTERN void * uv_loop_get_data(const uv_loop_t *)
Definition: uv-data-getter-setters.c:92
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
uv_fs_s
Definition: uv.h:1294
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
uv_stream_s
Definition: uv.h:491
uv_loop_close
UV_EXTERN int uv_loop_close(uv_loop_t *loop)
Definition: uv-common.c:761
UV_FS_STAT
@ UV_FS_STAT
Definition: uv.h:1253
uv_fs_get_statbuf
UV_EXTERN uv_stat_t * uv_fs_get_statbuf(uv_fs_t *)
Definition: uv-data-getter-setters.c:88
uv_req_type_name
const UV_EXTERN char * uv_req_type_name(uv_req_type type)
Definition: uv-data-getter-setters.c:31
uv_stream_get_write_queue_size
UV_EXTERN size_t uv_stream_get_write_queue_size(const uv_stream_t *stream)
Definition: uv-data-getter-setters.c:56
UV_FILE
@ UV_FILE
Definition: uv.h:194
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
TEST_IMPL
TEST_IMPL(handle_type_name)
Definition: test-getters-setters.c:11
uv_loop_init
UV_EXTERN int uv_loop_init(uv_loop_t *loop)
Definition: loop.c:30
uv_fs_get_ptr
UV_EXTERN void * uv_fs_get_ptr(const uv_fs_t *)
Definition: uv-data-getter-setters.c:80
uv_handle_get_loop
UV_EXTERN uv_loop_t * uv_handle_get_loop(const uv_handle_t *handle)
Definition: uv-data-getter-setters.c:23
uv_fs_get_type
UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t *)
Definition: uv-data-getter-setters.c:72
uv.h
uv_req_size
UV_EXTERN size_t uv_req_size(uv_req_type type)
Definition: uv-common.c:141
cookie1
int cookie1
Definition: test-getters-setters.c:6
UV_REQ_TYPE_MAX
@ UV_REQ_TYPE_MAX
Definition: uv.h:204
fix_build_deps.r
r
Definition: fix_build_deps.py:491
uv_pipe_s
Definition: uv.h:757
uv_handle_set_data
UV_EXTERN void uv_handle_set_data(uv_handle_t *handle, void *data)
Definition: uv-data-getter-setters.c:27
uv_handle_get_type
UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t *handle)
Definition: uv-data-getter-setters.c:15
uv_fs_req_cleanup
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t *req)
Definition: unix/fs.c:2024
UV_UNKNOWN_REQ
@ UV_UNKNOWN_REQ
Definition: uv.h:199
uv_handle_size
UV_EXTERN size_t uv_handle_size(uv_handle_type type)
Definition: uv-common.c:133
uv_handle_s
Definition: uv.h:441
uv_loop_s
Definition: uv.h:1767
uv_handle_get_data
UV_EXTERN void * uv_handle_get_data(const uv_handle_t *handle)
Definition: uv-data-getter-setters.c:19
cookie2
int cookie2
Definition: test-getters-setters.c:7
UV_HANDLE_TYPE_MAX
@ UV_HANDLE_TYPE_MAX
Definition: uv.h:195
UV_UNKNOWN_HANDLE
@ UV_UNKNOWN_HANDLE
Definition: uv.h:190


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26