mingw: handle GITPERLLIB in t0021 in a Windows-compatible way
[git.git] / t / helper / test-example-decorate.c
blob90dc97a9d0444bc2dd8beaa1bfdd970f4280efb7
1 #include "cache.h"
2 #include "object.h"
3 #include "decorate.h"
5 int cmd_main(int argc, const char **argv)
7 struct decoration n;
8 struct object_id one_oid = { {1} };
9 struct object_id two_oid = { {2} };
10 struct object_id three_oid = { {3} };
11 struct object *one, *two, *three;
13 int decoration_a, decoration_b;
15 void *ret;
17 int i, objects_noticed = 0;
20 * The struct must be zero-initialized.
22 memset(&n, 0, sizeof(n));
25 * Add 2 objects, one with a non-NULL decoration and one with a NULL
26 * decoration.
28 one = lookup_unknown_object(one_oid.hash);
29 two = lookup_unknown_object(two_oid.hash);
30 ret = add_decoration(&n, one, &decoration_a);
31 if (ret)
32 die("BUG: when adding a brand-new object, NULL should be returned");
33 ret = add_decoration(&n, two, NULL);
34 if (ret)
35 die("BUG: when adding a brand-new object, NULL should be returned");
38 * When re-adding an already existing object, the old decoration is
39 * returned.
41 ret = add_decoration(&n, one, NULL);
42 if (ret != &decoration_a)
43 die("BUG: when readding an already existing object, existing decoration should be returned");
44 ret = add_decoration(&n, two, &decoration_b);
45 if (ret)
46 die("BUG: when readding an already existing object, existing decoration should be returned");
49 * Lookup returns the added declarations, or NULL if the object was
50 * never added.
52 ret = lookup_decoration(&n, one);
53 if (ret)
54 die("BUG: lookup should return added declaration");
55 ret = lookup_decoration(&n, two);
56 if (ret != &decoration_b)
57 die("BUG: lookup should return added declaration");
58 three = lookup_unknown_object(three_oid.hash);
59 ret = lookup_decoration(&n, three);
60 if (ret)
61 die("BUG: lookup for unknown object should return NULL");
64 * The user can also loop through all entries.
66 for (i = 0; i < n.size; i++) {
67 if (n.entries[i].base)
68 objects_noticed++;
70 if (objects_noticed != 2)
71 die("BUG: should have 2 objects");
73 return 0;