1 #define USE_THE_REPOSITORY_VARIABLE
6 #include "repository.h"
9 struct object
*one
, *two
, *three
;
11 int decoration_a
, decoration_b
;
14 static void t_add(struct test_vars
*vars
)
16 void *ret
= add_decoration(&vars
->n
, vars
->one
, &vars
->decoration_a
);
19 ret
= add_decoration(&vars
->n
, vars
->two
, NULL
);
23 static void t_readd(struct test_vars
*vars
)
25 void *ret
= add_decoration(&vars
->n
, vars
->one
, NULL
);
27 check(ret
== &vars
->decoration_a
);
28 ret
= add_decoration(&vars
->n
, vars
->two
, &vars
->decoration_b
);
32 static void t_lookup(struct test_vars
*vars
)
34 void *ret
= lookup_decoration(&vars
->n
, vars
->one
);
37 ret
= lookup_decoration(&vars
->n
, vars
->two
);
38 check(ret
== &vars
->decoration_b
);
39 ret
= lookup_decoration(&vars
->n
, vars
->three
);
43 static void t_loop(struct test_vars
*vars
)
45 int i
, objects_noticed
= 0;
47 for (i
= 0; i
< vars
->n
.size
; i
++) {
48 if (vars
->n
.entries
[i
].base
)
51 check_int(objects_noticed
, ==, 2);
54 int cmd_main(int argc UNUSED
, const char **argv UNUSED
)
56 struct object_id one_oid
= { { 1 } }, two_oid
= { { 2 } }, three_oid
= { { 3 } };
57 struct test_vars vars
= { 0 };
59 vars
.one
= lookup_unknown_object(the_repository
, &one_oid
);
60 vars
.two
= lookup_unknown_object(the_repository
, &two_oid
);
61 vars
.three
= lookup_unknown_object(the_repository
, &three_oid
);
64 "Add 2 objects, one with a non-NULL decoration and one with a NULL decoration.");
66 "When re-adding an already existing object, the old decoration is returned.");
68 "Lookup returns the added declarations, or NULL if the object was never added.");
69 TEST(t_loop(&vars
), "The user can also loop through all entries.");
71 clear_decoration(&vars
.n
, NULL
);