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
25static uv_timer_t timer_handle;
26
27static void timer_cb(uv_timer_t* handle) {
28 ASSERT(handle);
29 uv_stop(handle->loop);
30}
31
32
33TEST_IMPL(loop_close) {
34 int r;
35 uv_loop_t loop;
36
37 loop.data = &loop;
38 ASSERT(0 == uv_loop_init(&loop));
39 ASSERT(loop.data == (void*) &loop);
40
41 uv_timer_init(&loop, &timer_handle);
42 uv_timer_start(&timer_handle, timer_cb, 100, 100);
43
44 ASSERT(UV_EBUSY == uv_loop_close(&loop));
45
46 uv_run(&loop, UV_RUN_DEFAULT);
47
48 uv_close((uv_handle_t*) &timer_handle, NULL);
49 r = uv_run(&loop, UV_RUN_DEFAULT);
50 ASSERT(r == 0);
51
52 ASSERT(loop.data == (void*) &loop);
53 ASSERT(0 == uv_loop_close(&loop));
54 ASSERT(loop.data == (void*) &loop);
55
56 return 0;
57}
58
59static void loop_instant_close_work_cb(uv_work_t* req) {
60}
61
62static void loop_instant_close_after_work_cb(uv_work_t* req, int status) {
63}
64
65TEST_IMPL(loop_instant_close) {
66 static uv_loop_t loop;
67 static uv_work_t req;
68 ASSERT(0 == uv_loop_init(&loop));
69 ASSERT(0 == uv_queue_work(&loop,
70 &req,
71 loop_instant_close_work_cb,
72 loop_instant_close_after_work_cb));
73 MAKE_VALGRIND_HAPPY();
74 return 0;
75}
76