test-loop-stop.c
Go to the documentation of this file.
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 
27 static int prepare_called = 0;
28 static int timer_called = 0;
29 static int num_ticks = 10;
30 
31 
37 }
38 
39 
40 static void timer_cb(uv_timer_t* handle) {
42  timer_called++;
43  if (timer_called == 1)
45  else if (timer_called == num_ticks)
47 }
48 
49 
50 TEST_IMPL(loop_stop) {
51  int r;
56 
58  ASSERT(r != 0);
59  ASSERT(timer_called == 1);
60 
62  ASSERT(r != 0);
64 
66  ASSERT(r == 0);
67  ASSERT(timer_called == 10);
68  ASSERT(prepare_called == 10);
69 
70  return 0;
71 }
timer_called
static int timer_called
Definition: test-loop-stop.c:28
num_ticks
static int num_ticks
Definition: test-loop-stop.c:29
uv_prepare_init
UV_EXTERN int uv_prepare_init(uv_loop_t *, uv_prepare_t *prepare)
task.h
uv_prepare_s
Definition: uv.h:804
UV_RUN_NOWAIT
@ UV_RUN_NOWAIT
Definition: uv.h:256
uv_prepare_stop
UV_EXTERN int uv_prepare_stop(uv_prepare_t *prepare)
ASSERT
#define ASSERT(expr)
Definition: task.h:102
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
uv_timer_stop
UV_EXTERN int uv_timer_stop(uv_timer_t *handle)
Definition: timer.c:97
prepare_cb
static void prepare_cb(uv_prepare_t *handle)
Definition: test-loop-stop.c:32
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
timer_handle
static uv_timer_t timer_handle
Definition: test-loop-stop.c:26
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
uv_prepare_start
UV_EXTERN int uv_prepare_start(uv_prepare_t *prepare, uv_prepare_cb cb)
uv_timer_s
Definition: uv.h:850
uv.h
TEST_IMPL
TEST_IMPL(loop_stop)
Definition: test-loop-stop.c:50
fix_build_deps.r
r
Definition: fix_build_deps.py:491
uv_stop
UV_EXTERN void uv_stop(uv_loop_t *)
Definition: uv-common.c:532
handle
static csh handle
Definition: test_arm_regression.c:16
prepare_called
static int prepare_called
Definition: test-loop-stop.c:27
uv_timer_start
UV_EXTERN int uv_timer_start(uv_timer_t *handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat)
Definition: timer.c:66
uv_timer_init
UV_EXTERN int uv_timer_init(uv_loop_t *, uv_timer_t *handle)
Definition: timer.c:58
timer_cb
static void timer_cb(uv_timer_t *handle)
Definition: test-loop-stop.c:40
prepare_handle
static uv_prepare_t prepare_handle
Definition: test-loop-stop.c:25


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:30