1 /* Copyright (c) 2016-2020, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
7 #include "lib/container/handles.h"
8 #include "lib/log/util_bug.h"
12 typedef struct demo_t
{
13 HANDLE_ENTRY(demo
, demo_t
);
17 HANDLE_DECL(demo
, demo_t
, static)
18 #define demo_handle_free(h) \
19 FREE_AND_NULL(demo_handle_t, demo_handle_free_, (h))
20 HANDLE_IMPL(demo
, demo_t
, static)
25 demo_t
*d
= tor_malloc_zero(sizeof(demo_t
));
35 demo_handles_clear(d
);
40 test_handle_basic(void *arg
)
43 demo_t
*d1
= NULL
, *d2
= NULL
;
44 demo_handle_t
*wr1
= NULL
, *wr2
= NULL
, *wr3
= NULL
, *wr4
= NULL
;
49 wr1
= demo_handle_new(d1
);
50 wr2
= demo_handle_new(d1
);
51 wr3
= demo_handle_new(d1
);
52 wr4
= demo_handle_new(d2
);
59 tt_ptr_op(demo_handle_get(wr1
), OP_EQ
, d1
);
60 tt_ptr_op(demo_handle_get(wr2
), OP_EQ
, d1
);
61 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, d1
);
62 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
64 demo_handle_free(wr1
);
66 tt_ptr_op(demo_handle_get(wr2
), OP_EQ
, d1
);
67 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, d1
);
68 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
72 tt_ptr_op(demo_handle_get(wr2
), OP_EQ
, NULL
);
73 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, NULL
);
74 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
76 demo_handle_free(wr2
);
78 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, NULL
);
79 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
81 demo_handle_free(wr3
);
84 demo_handle_free(wr1
);
85 demo_handle_free(wr2
);
86 demo_handle_free(wr3
);
87 demo_handle_free(wr4
);
92 #define HANDLE_TEST(name, flags) \
93 { #name, test_handle_ ##name, (flags), NULL, NULL }
95 struct testcase_t handle_tests
[] = {
96 HANDLE_TEST(basic
, 0),