-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_stub_source.cpp
54 lines (47 loc) · 1.27 KB
/
test_stub_source.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "../source/h2_unit.cpp"
#include "test_types.hpp"
static h2::h2_string h2_source_tojson(h2::h2_source* s)
{
h2::h2_string out;
out.sprintf("{"
"\"reference_count\": %d"
"}",
s->reference_count);
return out;
}
static h2::h2_string h2_sources_tojson(h2::h2_sources& a)
{
h2::h2_string out;
out.sprintf("[");
h2_list_for_each_entry (p, i, a.sources, h2::h2_source, x) {
if (i) out += ",";
out += h2_source_tojson(p);
}
out.sprintf("]");
return out;
}
SUITE(sources)
{
h2::h2_sources pool;
Case(init)
{
JE("[]", h2_sources_tojson(pool));
OK(NULL, pool.get((void*)foobar2));
}
Case(add del)
{
auto a = pool.add((void*)foobar2, "foobar2", H2_FILINE);
OK(Not(nullptr), a);
JE("[{'reference_count':1}]", h2_sources_tojson(pool));
auto b = pool.add((void*)foobar2, "foobar2", H2_FILINE);
OK(Not(nullptr), b);
JE("[{'reference_count':2}]", h2_sources_tojson(pool));
auto ret = pool.get((void*)foobar2);
OK(Not(nullptr), ret);
JE("{'reference_count':2}", h2_source_tojson(ret));
pool.del(ret);
JE("[{'reference_count':1}]", h2_sources_tojson(pool));
pool.del(ret);
JE("[]", h2_sources_tojson(pool));
}
}