aboutsummaryrefslogtreecommitdiff
path: root/test/coap_unparse_test.erl
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2015-12-13 17:47:14 +0100
committerGuido Günther <agx@sigxcpu.org>2015-12-13 17:47:14 +0100
commitbd3ae9694c0e8669c8ce53aef685e8afede14f33 (patch)
treee849857832827f7be9a3166932bae7fe749fc84a /test/coap_unparse_test.erl
Initial commitHEADmaster
Diffstat (limited to 'test/coap_unparse_test.erl')
-rw-r--r--test/coap_unparse_test.erl31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/coap_unparse_test.erl b/test/coap_unparse_test.erl
new file mode 100644
index 0000000..777913e
--- /dev/null
+++ b/test/coap_unparse_test.erl
@@ -0,0 +1,31 @@
+-module(coap_unparse_test).
+-include_lib("eunit/include/eunit.hrl").
+
+% Test descriptions
+unparse_test_() ->
+ [{"Building a get request should result in binary data",
+ check_build_request()},
+ {"Building a response without payload in binary data",
+ check_build_response()},
+ {"Building a response with payload in binary data",
+ check_build_text_response()}
+ ].
+
+% Tests
+check_build_request() ->
+ Uri = "coap://[::1]/.well-known/core",
+ Ret = coap_unparse:build_request(Uri, 1),
+ [?_assertEqual(Ret, {"::1", 5683,
+ [<<64,1,0,1>>,
+ [[<<11:4,11:4>>,".well-known"],
+ [<<0:4,4:4>>,"core"]]]})].
+
+check_build_response() ->
+ Ret = coap_unparse:build_response(4, 4, 1),
+ [?_assertEqual(Ret, [<<64,4:3, 4:5,0,1>>])].
+
+check_build_text_response() ->
+ Ret = coap_unparse:build_text_response(2, 5, 1, "payload"),
+ [?_assertEqual(Ret, [<<64,2:3, 5:5,0,1>>,
+ [[<<12:4,1:4>>,0]],
+ 255, "payload"])].