diff options
author | Michael Janssen <jamuraa@chromium.org> | 2014-12-09 15:08:33 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-12-10 09:54:23 +0200 |
commit | e5af5138b1531ef28fe30423d8dc6b5f9649dadb (patch) | |
tree | 1da892ca8763dd002fa51d3c4382d571415bb4c9 /unit/test-uuid.c | |
parent | 20dd67fd18a2e2bebbc7e5e4a76ff41133741e96 (diff) | |
download | bluez-e5af5138b1531ef28fe30423d8dc6b5f9649dadb.tar.gz |
lib/uuid: Simplify BT base UUIDs when possible
When converting a UUID from string to bt_uuid_t, prefer using
the 16-bit version when possible, which should generate shorter
sequences by increasing the number of 16-bit types.
Diffstat (limited to 'unit/test-uuid.c')
-rw-r--r-- | unit/test-uuid.c | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/unit/test-uuid.c b/unit/test-uuid.c index 49ea0312d..01f44f403 100644 --- a/unit/test-uuid.c +++ b/unit/test-uuid.c @@ -46,9 +46,9 @@ static unsigned char uuid_base_binary[] = { 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }; static struct uuid_test_data uuid_base = { - .str = "00000000-0000-1000-8000-00805f9b34fb", - .binary = uuid_base_binary, - .type = BT_UUID128, + .str = "0000", + .val16 = 0x0000, + .type = BT_UUID16, .str128 = "00000000-0000-1000-8000-00805f9b34fb", .binary128 = uuid_base_binary, }; @@ -93,6 +93,18 @@ static struct uuid_test_data uuid_32_2 = { .binary128 = uuid_32_binary, }; +static unsigned char uuid_128_binary[] = { + 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }; + +static struct uuid_test_data uuid_128 = { + .str = "F0000000-0000-1000-8000-00805f9b34fb", + .binary = uuid_128_binary, + .type = BT_UUID128, + .str128 = "F0000000-0000-1000-8000-00805f9b34fb", + .binary128 = uuid_128_binary, +}; + static void test_uuid(gconstpointer data) { const struct uuid_test_data *test_data = data; @@ -164,6 +176,26 @@ static void test_cmp(gconstpointer data) g_assert(bt_uuid_cmp(&uuid1, &uuid2) == 0); } +static const struct uuid_test_data compress[] = { + { + .str = "00001234-0000-1000-8000-00805f9b34fb", + .type = BT_UUID16, + .val16 = 0x1234, + }, { + .str = "0000FFFF-0000-1000-8000-00805f9b34fb", + .type = BT_UUID16, + .val16 = 0xFFFF, + }, { + .str = "0000FFFF-0000-1000-8000-00805F9B34FB", + .type = BT_UUID16, + .val16 = 0xFFFF, + }, { + .str = "F0000000-0000-1000-8000-00805f9b34fb", + .type = BT_UUID128, + .binary = uuid_128_binary, + }, +}; + static const char *malformed[] = { "0", "01", @@ -193,7 +225,7 @@ static void test_malformed(gconstpointer data) int main(int argc, char *argv[]) { - int i; + size_t i; g_test_init(&argc, &argv, NULL); @@ -217,6 +249,10 @@ int main(int argc, char *argv[]) g_test_add_data_func("/uuid/thritytwo2/str", &uuid_32_2, test_str); g_test_add_data_func("/uuid/thirtytwo2/cmp", &uuid_32_2, test_cmp); + g_test_add_data_func("/uuid/onetwentyeight", &uuid_128, test_uuid); + g_test_add_data_func("/uuid/onetwentyeight/str", &uuid_128, test_str); + g_test_add_data_func("/uuid/onetwentyeight/cmp", &uuid_128, test_cmp); + for (i = 0; malformed[i]; i++) { char *testpath; @@ -225,5 +261,14 @@ int main(int argc, char *argv[]) g_free(testpath); } + for (i = 0; i < (sizeof(compress) / sizeof(compress[0])); i++) { + char *testpath; + + testpath = g_strdup_printf("/uuid/compress/%s", + compress[i].str); + g_test_add_data_func(testpath, compress + i, test_uuid); + g_free(testpath); + } + return g_test_run(); } |