| 1 |
|
| 2 |
|
| 3 |
#include <tests/test.h> |
| 4 |
#include <uuid.h> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
static void test_parse_uuid_correct(void **state) |
| 10 |
{ |
| 11 |
|
| 12 |
|
| 13 |
uint8_t uuid_buf[UUID_LEN] = { 0 }; |
| 14 |
const char *uuid_correct = "00112233-4455-6677-8899-aabbccddeeff"; |
| 15 |
const uint8_t uuid_correct_bin[UUID_LEN] = { |
| 16 |
0x33, 0x22, 0x11, 0x00, 0x55, 0x44, 0x77, 0x66, |
| 17 |
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, |
| 18 |
}; |
| 19 |
const char *uuid_zereos = "00000000-0000-0000-0000-000000000000"; |
| 20 |
const uint8_t uuid_zeros_bin[UUID_LEN] = { 0 }; |
| 21 |
const char *uuid_ff = "ffffffff-ffff-ffff-ffff-ffffffffffff"; |
| 22 |
const uint8_t uuid_ff_bin[UUID_LEN] = { |
| 23 |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 24 |
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 25 |
}; |
| 26 |
|
| 27 |
assert_int_equal(0, parse_uuid(uuid_buf, uuid_correct)); |
| 28 |
assert_memory_equal(uuid_correct_bin, uuid_buf, UUID_LEN); |
| 29 |
|
| 30 |
assert_int_equal(0, parse_uuid(uuid_buf, uuid_zereos)); |
| 31 |
assert_memory_equal(uuid_zeros_bin, uuid_buf, UUID_LEN); |
| 32 |
|
| 33 |
assert_int_equal(0, parse_uuid(uuid_buf, uuid_ff)); |
| 34 |
assert_memory_equal(uuid_ff_bin, uuid_buf, UUID_LEN); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
static void test_parse_uuid_incorrect(void **state) |
| 41 |
{ |
| 42 |
uint8_t uuid_buf[UUID_LEN] = { 0 }; |
| 43 |
|
| 44 |
const char *uuid_incorrect_1 = "ab372d0-34cc1-1337-688b-2211337777ee"; |
| 45 |
|
| 46 |
const char *uuid_incorrect_2 = "abbce711-5@51-7777-ffff-ahchbh999911"; |
| 47 |
|
| 48 |
const char *uuid_incorrect_3 = "a7a38502-7465-9cbd-98ea-73003906dad5dd"; |
| 49 |
|
| 50 |
const char *uuid_incorrect_4 = "72abd839-7109-64bd-cfef-a8266"; |
| 51 |
|
| 52 |
assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_1)); |
| 53 |
assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_2)); |
| 54 |
assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_3)); |
| 55 |
assert_int_equal(-1, parse_uuid(uuid_buf, uuid_incorrect_4)); |
| 56 |
} |
| 57 |
|
| 58 |
static void test_guid(void **state) |
| 59 |
{ |
| 60 |
guid_t guid = GUID_INIT(0x1F4D66BB, 0xDEAD, 0xBEEF, |
| 61 |
0x08, 0xAB, 0x21, 0x37, 0xBB, 0x07, 0xDD, 0x4C); |
| 62 |
guid_t guid_copy; |
| 63 |
const guid_t guid_bin = { { |
| 64 |
0xBB, 0x66, 0x4D, 0x1F, |
| 65 |
0xAD, 0xDE, |
| 66 |
0xEF, 0xBE, |
| 67 |
0x08, 0xAB, 0x21, 0x37, 0xBB, 0x07, 0xDD, 0x4C |
| 68 |
} }; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
assert_memory_equal(guid.b, guid_bin.b, UUID_LEN); |
| 73 |
assert_int_equal(0, guidcmp(&guid, &guid_bin)); |
| 74 |
|
| 75 |
|
| 76 |
guidcpy(&guid_copy, &guid); |
| 77 |
assert_memory_equal(guid.b, guid_copy.b, UUID_LEN); |
| 78 |
assert_int_equal(0, guidcmp(&guid, &guid_copy)); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
guid_copy.b[7] = ~guid_copy.b[7]; |
| 83 |
assert_int_not_equal(0, guidcmp(&guid, &guid_copy)); |
| 84 |
} |
| 85 |
|
| 86 |
int main(void) |
| 87 |
{ |
| 88 |
const struct CMUnitTest tests[] = { |
| 89 |
cmocka_unit_test(test_parse_uuid_correct), |
| 90 |
cmocka_unit_test(test_parse_uuid_incorrect), |
| 91 |
cmocka_unit_test(test_guid), |
| 92 |
}; |
| 93 |
|
| 94 |
return cb_run_group_tests(tests, NULL, NULL); |
| 95 |
} |