| 1 | #define USE_THE_REPOSITORY_VARIABLE |
| 2 | |
| 3 | #include "unit-test.h" |
| 4 | #include "object.h" |
| 5 | #include "decorate.h" |
| 6 | #include "repository.h" |
| 7 | |
| 8 | struct test_vars { |
| 9 | struct object *one, *two, *three; |
| 10 | struct decoration n; |
| 11 | int decoration_a, decoration_b; |
| 12 | }; |
| 13 | |
| 14 | static struct test_vars vars; |
| 15 | |
| 16 | void test_example_decorate__initialize(void) |
| 17 | { |
| 18 | struct object_id one_oid = { { 1 } }, two_oid = { { 2 } }, three_oid = { { 3 } }; |
| 19 | |
| 20 | vars.one = lookup_unknown_object(the_repository, &one_oid); |
| 21 | vars.two = lookup_unknown_object(the_repository, &two_oid); |
| 22 | vars.three = lookup_unknown_object(the_repository, &three_oid); |
| 23 | } |
| 24 | |
| 25 | void test_example_decorate__cleanup(void) |
| 26 | { |
| 27 | clear_decoration(&vars.n, NULL); |
| 28 | } |
| 29 | |
| 30 | void test_example_decorate__add(void) |
| 31 | { |
| 32 | cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL); |
| 33 | cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL); |
| 34 | } |
| 35 | |
| 36 | void test_example_decorate__readd(void) |
| 37 | { |
| 38 | cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL); |
| 39 | cl_assert_equal_p(add_decoration(&vars.n, vars.two, NULL), NULL); |
| 40 | cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), &vars.decoration_a); |
| 41 | cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL); |
| 42 | } |
| 43 | |
| 44 | void test_example_decorate__lookup(void) |
| 45 | { |
| 46 | cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL); |
| 47 | cl_assert_equal_p(add_decoration(&vars.n, vars.one, NULL), NULL); |
| 48 | cl_assert_equal_p(lookup_decoration(&vars.n, vars.two), &vars.decoration_b); |
| 49 | cl_assert_equal_p(lookup_decoration(&vars.n, vars.one), NULL); |
| 50 | } |
| 51 | |
| 52 | void test_example_decorate__loop(void) |
| 53 | { |
| 54 | int objects_noticed = 0; |
| 55 | |
| 56 | cl_assert_equal_p(add_decoration(&vars.n, vars.one, &vars.decoration_a), NULL); |
| 57 | cl_assert_equal_p(add_decoration(&vars.n, vars.two, &vars.decoration_b), NULL); |
| 58 | |
| 59 | for (size_t i = 0; i < vars.n.size; i++) |
| 60 | if (vars.n.entries[i].base) |
| 61 | objects_noticed++; |
| 62 | |
| 63 | cl_assert_equal_i(objects_noticed, 2); |
| 64 | } |