5 int cmd_main(int argc
, const char **argv
)
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
;
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
28 one
= lookup_unknown_object(one_oid
.hash
);
29 two
= lookup_unknown_object(two_oid
.hash
);
30 ret
= add_decoration(&n
, one
, &decoration_a
);
32 die("BUG: when adding a brand-new object, NULL should be returned");
33 ret
= add_decoration(&n
, two
, NULL
);
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
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
);
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
52 ret
= lookup_decoration(&n
, one
);
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
);
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
)
70 if (objects_noticed
!= 2)
71 die("BUG: should have 2 objects");