From b3e78d7eece35d173853c9878dc2c4d36b511a31 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 8 Jan 2013 19:45:28 -0800 Subject: [PATCH] unit: Add inquiry data from MacBook Air for testing --- unit/test-eir.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/unit/test-eir.c b/unit/test-eir.c index 5ad6928a9..b876e112f 100644 --- a/unit/test-eir.c +++ b/unit/test-eir.c @@ -33,6 +33,55 @@ #include "src/eir.h" +struct test_data { + const void *eir_data; + size_t eir_size; + int flags; + const char *name; + gboolean name_complete; +}; + +static const unsigned char apple_data_1[] = { + 0x17, 0x09, 0x4d, 0x61, 0x72, 0x63, 0x65, 0x6c, + 0xe2, 0x80, 0x99, 0x73, 0x20, 0x4d, 0x61, 0x63, + 0x42, 0x6f, 0x6f, 0x6b, 0x20, 0x41, 0x69, 0x72, + 0x11, 0x03, 0x12, 0x11, 0x0c, 0x11, 0x0a, 0x11, + 0x1f, 0x11, 0x01, 0x11, 0x00, 0x10, 0x0a, 0x11, + 0x17, 0x11, 0x11, 0xff, 0x4c, 0x00, 0x01, 0x4d, + 0x61, 0x63, 0x42, 0x6f, 0x6f, 0x6b, 0x41, 0x69, + 0x72, 0x33, 0x2c, 0x31, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +static const struct test_data apple_test_1 = { + .eir_data = apple_data_1, + .eir_size = sizeof(apple_data_1), + .flags = -1, + .name = "Marcel’s MacBook Air", + .name_complete = TRUE, +}; + static void test_basic(void) { struct eir_data data; @@ -50,11 +99,37 @@ static void test_basic(void) eir_data_free(&data); } +static void test_parsing(gconstpointer data) +{ + const struct test_data *test = data; + struct eir_data eir; + int err; + + memset(&eir, 0, sizeof(eir)); + + err = eir_parse(&eir, test->eir_data, test->eir_size); + g_assert(err == 0); + + if (g_test_verbose() == TRUE) + g_print("Flags: %d\n", eir.flags); + + if (g_test_verbose() == TRUE) + g_print("Name: %s\n", eir.name); + + g_assert(eir.flags == test->flags); + g_assert(g_str_equal(eir.name, test->name) == TRUE); + g_assert(eir.name_complete == TRUE); + + eir_data_free(&eir); +} + int main(int argc, char *argv[]) { g_test_init(&argc, &argv, NULL); g_test_add_func("/eir/basic", test_basic); + g_test_add_data_func("/eir/apple/1", &apple_test_1, test_parsing); + return g_test_run(); } -- 2.47.3