aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2012-08-09 13:32:28 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2012-08-16 12:40:17 +0300
commit74fbc64e8adb8d2725be243d298a612aaca308ab (patch)
tree764c26c831bcd68fccf3eab2a97ffc8f1127a01d
parentb6d67f1a64984edc2b2c2a22548c88bb1ab2c8cd (diff)
downloadobexd-74fbc64e8adb8d2725be243d298a612aaca308ab.tar.gz
gobex: Add unit test for encoding/decoding apparam headers
-rw-r--r--unit/test-gobex-header.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/unit/test-gobex-header.c b/unit/test-gobex-header.c
index 86e69f3..feb7d17 100644
--- a/unit/test-gobex-header.c
+++ b/unit/test-gobex-header.c
@@ -47,6 +47,8 @@ static uint8_t hdr_bytes_nval_short[] = { G_OBEX_HDR_BODY, 0xab, 0xcd,
0x01, 0x02, 0x03 };
static uint8_t hdr_bytes_nval_data[] = { G_OBEX_HDR_BODY, 0xab };
static uint8_t hdr_bytes_nval_len[] = { G_OBEX_HDR_BODY, 0x00, 0x00 };
+static uint8_t hdr_apparam[] = { G_OBEX_HDR_APPARAM, 0x00, 0x09, 0x00, 0x04,
+ 0x01, 0x02, 0x03, 0x04 };
static void test_header_name_empty(void)
{
@@ -115,6 +117,27 @@ static void test_header_bytes(void)
g_obex_header_free(header);
}
+static void test_header_apparam(void)
+{
+ GObexHeader *header;
+ GObexApparam *apparam;
+ uint8_t buf[1024];
+ size_t len;
+
+ apparam = g_obex_apparam_set_uint32(NULL, 0, 0x01020304);
+ g_assert(apparam != NULL);
+
+ header = g_obex_header_new_apparam(apparam);
+ g_assert(header != NULL);
+
+ len = g_obex_header_encode(header, buf, sizeof(buf));
+
+ assert_memequal(hdr_apparam, sizeof(hdr_apparam), buf, len);
+
+ g_obex_apparam_free(apparam);
+ g_obex_header_free(header);
+}
+
static void test_header_uint8(void)
{
GObexHeader *header;
@@ -247,6 +270,26 @@ static void test_header_encode_body(void)
g_obex_header_free(header);
}
+static void test_header_encode_apparam(void)
+{
+ GObexHeader *header;
+ GObexApparam *apparam;
+ gboolean ret;
+ guint32 data;
+
+ header = parse_and_encode(hdr_apparam, sizeof(hdr_apparam));
+
+ apparam = g_obex_header_get_apparam(header);
+ g_assert(apparam != NULL);
+
+ ret = g_obex_apparam_get_uint32(apparam, 0x00, &data);
+ g_assert(ret == TRUE);
+ g_assert(data == 0x01020304);
+
+ g_obex_apparam_free(apparam);
+ g_obex_header_free(header);
+}
+
static void test_header_encode_actionid(void)
{
GObexHeader *header;
@@ -507,6 +550,8 @@ int main(int argc, char *argv[])
test_header_encode_body);
g_test_add_func("/gobex/test_header_encode_connid",
test_header_encode_actionid);
+ g_test_add_func("/gobex/test_header_encode_apparam",
+ test_header_encode_apparam);
g_test_add_func("/gobex/test_header_name_empty",
test_header_name_empty);
@@ -517,6 +562,7 @@ int main(int argc, char *argv[])
g_test_add_func("/gobex/test_header_bytes", test_header_bytes);
g_test_add_func("/gobex/test_header_uint8", test_header_uint8);
g_test_add_func("/gobex/test_header_uint32", test_header_uint32);
+ g_test_add_func("/gobex/test_header_apparam", test_header_apparam);
g_test_run();