]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-example-decorate.c
Merge branch 'bb/unicode-width-table-15'
[thirdparty/git.git] / t / helper / test-example-decorate.c
CommitLineData
dbceb3ec 1#include "test-tool.h"
a64215b6 2#include "git-compat-util.h"
ddd3e312
JT
3#include "object.h"
4#include "decorate.h"
d1cbe1e6 5#include "repository.h"
ddd3e312 6
126e3b3d 7int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED)
ddd3e312
JT
8{
9 struct decoration n;
10 struct object_id one_oid = { {1} };
11 struct object_id two_oid = { {2} };
12 struct object_id three_oid = { {3} };
13 struct object *one, *two, *three;
14
15 int decoration_a, decoration_b;
16
17 void *ret;
18
19 int i, objects_noticed = 0;
20
21 /*
22 * The struct must be zero-initialized.
23 */
24 memset(&n, 0, sizeof(n));
25
26 /*
27 * Add 2 objects, one with a non-NULL decoration and one with a NULL
28 * decoration.
29 */
45a187cc
JK
30 one = lookup_unknown_object(the_repository, &one_oid);
31 two = lookup_unknown_object(the_repository, &two_oid);
ddd3e312
JT
32 ret = add_decoration(&n, one, &decoration_a);
33 if (ret)
033abf97 34 BUG("when adding a brand-new object, NULL should be returned");
ddd3e312
JT
35 ret = add_decoration(&n, two, NULL);
36 if (ret)
033abf97 37 BUG("when adding a brand-new object, NULL should be returned");
ddd3e312
JT
38
39 /*
40 * When re-adding an already existing object, the old decoration is
41 * returned.
42 */
43 ret = add_decoration(&n, one, NULL);
44 if (ret != &decoration_a)
033abf97 45 BUG("when readding an already existing object, existing decoration should be returned");
ddd3e312
JT
46 ret = add_decoration(&n, two, &decoration_b);
47 if (ret)
033abf97 48 BUG("when readding an already existing object, existing decoration should be returned");
ddd3e312
JT
49
50 /*
51 * Lookup returns the added declarations, or NULL if the object was
52 * never added.
53 */
54 ret = lookup_decoration(&n, one);
55 if (ret)
033abf97 56 BUG("lookup should return added declaration");
ddd3e312
JT
57 ret = lookup_decoration(&n, two);
58 if (ret != &decoration_b)
033abf97 59 BUG("lookup should return added declaration");
45a187cc 60 three = lookup_unknown_object(the_repository, &three_oid);
ddd3e312
JT
61 ret = lookup_decoration(&n, three);
62 if (ret)
033abf97 63 BUG("lookup for unknown object should return NULL");
ddd3e312
JT
64
65 /*
66 * The user can also loop through all entries.
67 */
68 for (i = 0; i < n.size; i++) {
69 if (n.entries[i].base)
70 objects_noticed++;
71 }
72 if (objects_noticed != 2)
033abf97 73 BUG("should have 2 objects");
ddd3e312
JT
74
75 return 0;
76}