contrib/coverage-diff: avoid redundant pipelines
[git/gitster.git] / t / helper / test-example-decorate.c
blob8f59f6be4cff6c53da68ebb4ea7201e71793cbe1
1 #include "test-tool.h"
2 #include "git-compat-util.h"
3 #include "object.h"
4 #include "decorate.h"
5 #include "repository.h"
7 int cmd__example_decorate(int argc UNUSED, const char **argv UNUSED)
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;
15 int decoration_a, decoration_b;
17 void *ret;
19 int i, objects_noticed = 0;
22 * The struct must be zero-initialized.
24 memset(&n, 0, sizeof(n));
27 * Add 2 objects, one with a non-NULL decoration and one with a NULL
28 * decoration.
30 one = lookup_unknown_object(the_repository, &one_oid);
31 two = lookup_unknown_object(the_repository, &two_oid);
32 ret = add_decoration(&n, one, &decoration_a);
33 if (ret)
34 BUG("when adding a brand-new object, NULL should be returned");
35 ret = add_decoration(&n, two, NULL);
36 if (ret)
37 BUG("when adding a brand-new object, NULL should be returned");
40 * When re-adding an already existing object, the old decoration is
41 * returned.
43 ret = add_decoration(&n, one, NULL);
44 if (ret != &decoration_a)
45 BUG("when readding an already existing object, existing decoration should be returned");
46 ret = add_decoration(&n, two, &decoration_b);
47 if (ret)
48 BUG("when readding an already existing object, existing decoration should be returned");
51 * Lookup returns the added declarations, or NULL if the object was
52 * never added.
54 ret = lookup_decoration(&n, one);
55 if (ret)
56 BUG("lookup should return added declaration");
57 ret = lookup_decoration(&n, two);
58 if (ret != &decoration_b)
59 BUG("lookup should return added declaration");
60 three = lookup_unknown_object(the_repository, &three_oid);
61 ret = lookup_decoration(&n, three);
62 if (ret)
63 BUG("lookup for unknown object should return NULL");
66 * The user can also loop through all entries.
68 for (i = 0; i < n.size; i++) {
69 if (n.entries[i].base)
70 objects_noticed++;
72 if (objects_noticed != 2)
73 BUG("should have 2 objects");
75 clear_decoration(&n, NULL);
77 return 0;