* [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr()
@ 2013-01-11 1:22 Anderson Lizardo
2013-01-11 1:22 ` [PATCH BlueZ 2/2] unit: Add tests for SDP integer Data Elements Anderson Lizardo
2013-01-16 12:36 ` [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() Johan Hedberg
0 siblings, 2 replies; 3+ messages in thread
From: Anderson Lizardo @ 2013-01-11 1:22 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Anderson Lizardo
These tests are for valid data. Other tests might be added later to
check for error paths, but will require separate macros.
{TEXT,URL}_STR32 cannot be tested with the same macros because
sdp_extract_attr() does not support them. They will be tested
separately with other SDP library functions.
As example of failure output, if commit
504a0cf46ad89cab8005ce9cffb22e41048f6a30 is reverted for testing, the
STR16 test will fail with:
ERROR:unit/test-sdp.c:776:test_sdp_de_attr: assertion failed
(test->input_size == size): (7 == 11)
---
unit/test-sdp.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 77a4c6c..7879e58 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -85,6 +85,29 @@ struct test_data {
#define define_ssa(name, args...) define_test("/TP/SERVER/SSA/" name, 48, args)
#define define_brw(name, args...) define_test("/TP/SERVER/BRW/" name, 672, args)
+/* SDP Data Element (DE) tests */
+struct test_data_de {
+ const void *input_data;
+ size_t input_size;
+ sdp_data_t expected;
+};
+
+#define exp_data(_dtd, val_type, val_data) \
+ ((const sdp_data_t) { \
+ .dtd = _dtd, \
+ .val.val_type = val_data, \
+ })
+
+#define define_test_de_attr(name, input, exp) \
+ do { \
+ static struct test_data_de data; \
+ data.input_data = input; \
+ data.input_size = sizeof(input); \
+ data.expected = exp; \
+ g_test_add_data_func("/sdp/DE/ATTR/" name, &data, \
+ test_sdp_de_attr); \
+ } while (0)
+
struct context {
GMainLoop *main_loop;
guint server_source;
@@ -742,6 +765,34 @@ static void test_sdp(gconstpointer data)
g_free(test->pdu_list);
}
+static void test_sdp_de_attr(gconstpointer data)
+{
+ const struct test_data_de *test = data;
+ sdp_data_t *d;
+ int size = 0;
+
+ d = sdp_extract_attr(test->input_data, test->input_size, &size, NULL);
+ g_assert(d != NULL);
+ g_assert_cmpuint(test->input_size, ==, size);
+ g_assert_cmpuint(test->expected.dtd, ==, d->dtd);
+
+ if (g_test_verbose() == TRUE)
+ g_print("DTD=0x%02x\n", d->dtd);
+
+ switch (d->dtd) {
+ case SDP_TEXT_STR8:
+ case SDP_TEXT_STR16:
+ case SDP_URL_STR8:
+ case SDP_URL_STR16:
+ g_assert_cmpstr(test->expected.val.str, ==, d->val.str);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ sdp_data_free(d);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -2697,5 +2748,32 @@ int main(int argc, char *argv[])
0x08, 0x09, 0x00, 0x01, 0x35, 0x03, 0x19, 0x11,
0x06, 0x00));
+ /*
+ * SDP Data Element (DE) tests
+ *
+ * Test extraction of valid DEs supported by sdp_extract_attr().
+ */
+ define_test_de_attr("TEXT_STR8/empty",
+ raw_data(0x25, 0x00),
+ exp_data(SDP_TEXT_STR8, str, ""));
+ define_test_de_attr("TEXT_STR8",
+ raw_data(0x25, 0x04, 0x41, 0x42, 0x43, 0x44),
+ exp_data(SDP_TEXT_STR8, str, "ABCD"));
+ define_test_de_attr("TEXT_STR16",
+ raw_data(0x26, 0x00, 0x04, 0x41, 0x42, 0x43, 0x44),
+ exp_data(SDP_TEXT_STR16, str, "ABCD"));
+ define_test_de_attr("URL_STR8",
+ raw_data(0x45, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a,
+ 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x62, 0x6c,
+ 0x75, 0x65, 0x7a, 0x2e, 0x6f, 0x72, 0x67,
+ 0x2f),
+ exp_data(SDP_URL_STR8, str, "http://www.bluez.org/"));
+ define_test_de_attr("URL_STR16",
+ raw_data(0x46, 0x00, 0x15, 0x68, 0x74, 0x74, 0x70,
+ 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x62,
+ 0x6c, 0x75, 0x65, 0x7a, 0x2e, 0x6f, 0x72, 0x67,
+ 0x2f),
+ exp_data(SDP_URL_STR16, str, "http://www.bluez.org/"));
+
return g_test_run();
}
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH BlueZ 2/2] unit: Add tests for SDP integer Data Elements 2013-01-11 1:22 [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() Anderson Lizardo @ 2013-01-11 1:22 ` Anderson Lizardo 2013-01-16 12:36 ` [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() Johan Hedberg 1 sibling, 0 replies; 3+ messages in thread From: Anderson Lizardo @ 2013-01-11 1:22 UTC (permalink / raw) To: linux-bluetooth; +Cc: Anderson Lizardo SDP_DATA_NIL does not have a value, but its sdp_data_t val field is zeroed by memset(), so just treat it as UINT8 with zero value to simplify checking (and not require a separate macro.) SDP_BOOL is handled by SDP library as a INT8. SDP_UINT128/SDP_INT128 are just byte arrays converted to host order, so use memcmp() to compare them (converting from host to network order first.) --- unit/test-sdp.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/unit/test-sdp.c b/unit/test-sdp.c index 7879e58..8c0ce98 100644 --- a/unit/test-sdp.c +++ b/unit/test-sdp.c @@ -52,6 +52,7 @@ struct test_data { }; #define raw_data(args...) ((const unsigned char[]) { args }) +#define build_u128(args...) ((const uint128_t) { .data = { args } }) #define raw_pdu(args...) \ { \ @@ -768,6 +769,7 @@ static void test_sdp(gconstpointer data) static void test_sdp_de_attr(gconstpointer data) { const struct test_data_de *test = data; + uint128_t u128; sdp_data_t *d; int size = 0; @@ -786,6 +788,39 @@ static void test_sdp_de_attr(gconstpointer data) case SDP_URL_STR16: g_assert_cmpstr(test->expected.val.str, ==, d->val.str); break; + case SDP_DATA_NIL: + case SDP_UINT8: + g_assert_cmpuint(test->expected.val.uint8, ==, d->val.uint8); + break; + case SDP_UINT16: + g_assert_cmpuint(test->expected.val.uint16, ==, d->val.uint16); + break; + case SDP_UINT32: + g_assert_cmpuint(test->expected.val.uint32, ==, d->val.uint32); + break; + case SDP_UINT64: + g_assert_cmpuint(test->expected.val.uint64, ==, d->val.uint64); + break; + case SDP_BOOL: + case SDP_INT8: + g_assert_cmpuint(test->expected.val.int8, ==, d->val.int8); + break; + case SDP_INT16: + g_assert_cmpuint(test->expected.val.int16, ==, d->val.int16); + break; + case SDP_INT32: + g_assert_cmpuint(test->expected.val.int32, ==, d->val.int32); + break; + case SDP_INT64: + g_assert_cmpuint(test->expected.val.int64, ==, d->val.int64); + break; + case SDP_UINT128: + case SDP_INT128: + /* Expected bytes are in network order */ + hton128(&d->val.uint128, &u128); + g_assert(memcmp(&test->expected.val.uint128, &u128, + sizeof(uint128_t)) == 0); + break; default: g_assert_not_reached(); } @@ -2774,6 +2809,55 @@ int main(int argc, char *argv[]) 0x6c, 0x75, 0x65, 0x7a, 0x2e, 0x6f, 0x72, 0x67, 0x2f), exp_data(SDP_URL_STR16, str, "http://www.bluez.org/")); + define_test_de_attr("NIL", + raw_data(0x00), + exp_data(SDP_DATA_NIL, uint8, 0)); + define_test_de_attr("UINT8", + raw_data(0x08, 0xff), + exp_data(SDP_UINT8, uint8, UINT8_MAX)); + define_test_de_attr("INT8", + raw_data(0x10, 0x80), + exp_data(SDP_INT8, int8, INT8_MIN)); + define_test_de_attr("BOOL", + raw_data(0x28, 0x01), + exp_data(SDP_BOOL, int8, 1)); + define_test_de_attr("UINT16", + raw_data(0x09, 0xff, 0xff), + exp_data(SDP_UINT16, uint16, UINT16_MAX)); + define_test_de_attr("INT16", + raw_data(0x11, 0x80, 0x00), + exp_data(SDP_INT16, int16, INT16_MIN)); + define_test_de_attr("UINT32", + raw_data(0x0A, 0xff, 0xff, 0xff, 0xff), + exp_data(SDP_UINT32, uint32, UINT32_MAX)); + define_test_de_attr("INT32", + raw_data(0x12, 0x80, 0x00, 0x00, 0x00), + exp_data(SDP_INT32, int32, INT32_MIN)); + define_test_de_attr("UINT64", + raw_data(0x0B, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff), + exp_data(SDP_UINT64, uint64, UINT64_MAX)); + define_test_de_attr("INT64", + raw_data(0x13, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00), + exp_data(SDP_INT64, int64, INT64_MIN)); + /* UINT128/INT128 are just byte arrays parsed as uint128_t */ + define_test_de_attr("UINT128", + raw_data(0x0C, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff), + exp_data(SDP_UINT128, uint128, + build_u128(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff))); + define_test_de_attr("INT128", + raw_data(0x14, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00), + exp_data(SDP_INT128, uint128, + build_u128(0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00))); return g_test_run(); } -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() 2013-01-11 1:22 [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() Anderson Lizardo 2013-01-11 1:22 ` [PATCH BlueZ 2/2] unit: Add tests for SDP integer Data Elements Anderson Lizardo @ 2013-01-16 12:36 ` Johan Hedberg 1 sibling, 0 replies; 3+ messages in thread From: Johan Hedberg @ 2013-01-16 12:36 UTC (permalink / raw) To: Anderson Lizardo; +Cc: linux-bluetooth Hi Lizardo, On Thu, Jan 10, 2013, Anderson Lizardo wrote: > These tests are for valid data. Other tests might be added later to > check for error paths, but will require separate macros. > > {TEXT,URL}_STR32 cannot be tested with the same macros because > sdp_extract_attr() does not support them. They will be tested > separately with other SDP library functions. > > As example of failure output, if commit > 504a0cf46ad89cab8005ce9cffb22e41048f6a30 is reverted for testing, the > STR16 test will fail with: > > ERROR:unit/test-sdp.c:776:test_sdp_de_attr: assertion failed > (test->input_size == size): (7 == 11) > --- > unit/test-sdp.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 78 insertions(+) Both patches have been applied. Thanks. Johan ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-01-16 12:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-11 1:22 [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() Anderson Lizardo
2013-01-11 1:22 ` [PATCH BlueZ 2/2] unit: Add tests for SDP integer Data Elements Anderson Lizardo
2013-01-16 12:36 ` [PATCH BlueZ 1/2] unit: Add {TEXT,URL}_STR{8,16} tests for sdp_extract_attr() Johan Hedberg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).