libuv-svace-build
84 строки · 2.5 Кб
1/* Copyright Joyent, Inc. and other Node 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#include "uv.h"
23#include "task.h"
24
25#include <stdio.h>
26#include <stdlib.h>
27
28
29static int close_cb_called = 0;
30
31
32static void close_cb(uv_handle_t* handle) {
33ASSERT_NOT_NULL(handle);
34close_cb_called++;
35}
36
37
38static void timer_cb(uv_timer_t* handle) {
39ASSERT(0 && "timer_cb should not have been called");
40}
41
42
43TEST_IMPL(active) {
44int r;
45uv_timer_t timer;
46
47r = uv_timer_init(uv_default_loop(), &timer);
48ASSERT_OK(r);
49
50/* uv_is_active() and uv_is_closing() should always return either 0 or 1. */
51ASSERT_OK(uv_is_active((uv_handle_t*) &timer));
52ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
53
54r = uv_timer_start(&timer, timer_cb, 1000, 0);
55ASSERT_OK(r);
56
57ASSERT_EQ(1, uv_is_active((uv_handle_t*) &timer));
58ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
59
60r = uv_timer_stop(&timer);
61ASSERT_OK(r);
62
63ASSERT_OK(uv_is_active((uv_handle_t*) &timer));
64ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
65
66r = uv_timer_start(&timer, timer_cb, 1000, 0);
67ASSERT_OK(r);
68
69ASSERT_EQ(1, uv_is_active((uv_handle_t*) &timer));
70ASSERT_OK(uv_is_closing((uv_handle_t*) &timer));
71
72uv_close((uv_handle_t*) &timer, close_cb);
73
74ASSERT_OK(uv_is_active((uv_handle_t*) &timer));
75ASSERT_EQ(1, uv_is_closing((uv_handle_t*) &timer));
76
77r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
78ASSERT_OK(r);
79
80ASSERT_EQ(1, close_cb_called);
81
82MAKE_VALGRIND_HAPPY(uv_default_loop());
83return 0;
84}
85