1#include"cache.h" 2#include"object.h" 3#include"decorate.h" 4 5intcmd_main(int argc,const char**argv) 6{ 7struct decoration n; 8struct object_id one_oid = { {1} }; 9struct object_id two_oid = { {2} }; 10struct object_id three_oid = { {3} }; 11struct object *one, *two, *three; 12 13int decoration_a, decoration_b; 14 15void*ret; 16 17int i, objects_noticed =0; 18 19/* 20 * The struct must be zero-initialized. 21 */ 22memset(&n,0,sizeof(n)); 23 24/* 25 * Add 2 objects, one with a non-NULL decoration and one with a NULL 26 * decoration. 27 */ 28 one =lookup_unknown_object(one_oid.hash); 29 two =lookup_unknown_object(two_oid.hash); 30 ret =add_decoration(&n, one, &decoration_a); 31if(ret) 32die("BUG: when adding a brand-new object, NULL should be returned"); 33 ret =add_decoration(&n, two, NULL); 34if(ret) 35die("BUG: when adding a brand-new object, NULL should be returned"); 36 37/* 38 * When re-adding an already existing object, the old decoration is 39 * returned. 40 */ 41 ret =add_decoration(&n, one, NULL); 42if(ret != &decoration_a) 43die("BUG: when readding an already existing object, existing decoration should be returned"); 44 ret =add_decoration(&n, two, &decoration_b); 45if(ret) 46die("BUG: when readding an already existing object, existing decoration should be returned"); 47 48/* 49 * Lookup returns the added declarations, or NULL if the object was 50 * never added. 51 */ 52 ret =lookup_decoration(&n, one); 53if(ret) 54die("BUG: lookup should return added declaration"); 55 ret =lookup_decoration(&n, two); 56if(ret != &decoration_b) 57die("BUG: lookup should return added declaration"); 58 three =lookup_unknown_object(three_oid.hash); 59 ret =lookup_decoration(&n, three); 60if(ret) 61die("BUG: lookup for unknown object should return NULL"); 62 63/* 64 * The user can also loop through all entries. 65 */ 66for(i =0; i < n.size; i++) { 67if(n.entries[i].base) 68 objects_noticed++; 69} 70if(objects_noticed !=2) 71die("BUG: should have 2 objects"); 72 73return0; 74}