1 /* Copyright (c) 2016, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
10 typedef struct demo_t
{
11 HANDLE_ENTRY(demo
, demo_t
);
15 HANDLE_DECL(demo
, demo_t
, static)
16 HANDLE_IMPL(demo
, demo_t
, static)
21 demo_t
*d
= tor_malloc_zero(sizeof(demo_t
));
31 demo_handles_clear(d
);
36 test_handle_basic(void *arg
)
39 demo_t
*d1
= NULL
, *d2
= NULL
;
40 demo_handle_t
*wr1
= NULL
, *wr2
= NULL
, *wr3
= NULL
, *wr4
= NULL
;
45 wr1
= demo_handle_new(d1
);
46 wr2
= demo_handle_new(d1
);
47 wr3
= demo_handle_new(d1
);
48 wr4
= demo_handle_new(d2
);
55 tt_ptr_op(demo_handle_get(wr1
), OP_EQ
, d1
);
56 tt_ptr_op(demo_handle_get(wr2
), OP_EQ
, d1
);
57 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, d1
);
58 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
60 demo_handle_free(wr1
);
62 tt_ptr_op(demo_handle_get(wr2
), OP_EQ
, d1
);
63 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, d1
);
64 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
68 tt_ptr_op(demo_handle_get(wr2
), OP_EQ
, NULL
);
69 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, NULL
);
70 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
72 demo_handle_free(wr2
);
74 tt_ptr_op(demo_handle_get(wr3
), OP_EQ
, NULL
);
75 tt_ptr_op(demo_handle_get(wr4
), OP_EQ
, d2
);
77 demo_handle_free(wr3
);
80 demo_handle_free(wr1
);
81 demo_handle_free(wr2
);
82 demo_handle_free(wr3
);
83 demo_handle_free(wr4
);
88 #define HANDLE_TEST(name, flags) \
89 { #name, test_handle_ ##name, (flags), NULL, NULL }
91 struct testcase_t handle_tests
[] = {
92 HANDLE_TEST(basic
, 0),