2 * Copyright (c) 2012 Your File System Inc. All rights reserved.
12 #include <tests/tap/basic.h>
15 main(int argc
, char **argv
)
17 opr_uuid_t uuidA
= {{0x4F, 0x44, 0x94, 0x47, 0x76, 0xBA, 0x47, 0x2C,
18 0x97, 0x1A, 0x86, 0x6B, 0xC0, 0x10, 0x1A, 0x4B}};
19 opr_uuid_t uuidB
= {{0x5D, 0x2A, 0x39, 0x36, 0x94, 0xB2, 0x48, 0x90,
20 0xA8, 0xD2, 0x7F, 0xBC, 0x1B, 0x29, 0xDA, 0x9B}};
24 struct opr_uuid_unpacked raw
;
28 memset(&uuidC
, 0, sizeof(opr_uuid_t
));
30 ok(opr_uuid_isNil(&uuidC
), "opr_uuid_isNil(nilUuid) works");
31 ok(!opr_uuid_isNil(&uuidA
), "opr_uuid_isNil(uuid) works");
33 ok(opr_uuid_equal(&uuidA
, &uuidA
), "opr_uuid_equal(A, A) works");
34 ok(!opr_uuid_equal(&uuidA
, &uuidB
), "opr_uuid_equal(A, B) works");
35 ok(!opr_uuid_equal(&uuidA
, &uuidC
), "opr_uuid_equal(A, nilUid) works");
37 is_int(1187447773, opr_uuid_hash(&uuidA
), "opr_uuid_hash(A) works");
38 is_int(1251907497, opr_uuid_hash(&uuidB
), "opr_uuid_hash(B) works");
40 ok(!opr_uuid_toString(&uuidA
, &str
), "opr_uuid_toString(uuidA) works");
41 ok(str
!= NULL
, "... and result is not NULL");
42 is_string("4f449447-76ba-472c-971a-866bc0101a4b", str
,
43 "... and string is correct");
44 opr_uuid_freeString(str
);
46 is_int(0, opr_uuid_fromString(&uuidC
, "4F449447-76BA-472C-971A-866BC0101A4B"),
47 "opr_uuid_fromString works with conventional UUID");
48 ok(opr_uuid_equal(&uuidA
, &uuidC
), " ... and UUID is correct");
50 memset(&uuidC
, 0, sizeof(opr_uuid_t
));
51 is_int(0, opr_uuid_fromString(&uuidC
, "4F449447-76BA-472C-97-1A-866BC0101A4B"),
52 "opr_uuid_fromString works with AFS style UUID");
53 ok(opr_uuid_equal(&uuidA
, &uuidC
), " ... and UUID is correct");
55 memset(&uuidC
, 0, sizeof(opr_uuid_t
));
56 opr_uuid_create(&uuidC
);
57 ok(!opr_uuid_isNil(&uuidC
), "opr_uuid_create makes non-nil UUID");
58 is_int(0x80, uuidC
.data
[8] & 0x80, "variant is DCE as expected");
59 version
= (uuidC
.data
[6] & 0xF0) >> 4;
60 ok(version
>=1 && version
<=5, "version %d is in expected range", version
);
62 opr_uuid_unpack(&uuidB
, &raw
);
63 opr_uuid_pack(&uuidC
, &raw
);
64 ok(opr_uuid_equal(&uuidB
, &uuidC
),
65 "opr_uuid_pack(opr_uuid_unpack()) works as expected");