From bd3ae9694c0e8669c8ce53aef685e8afede14f33 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 13 Dec 2015 17:47:14 +0100 Subject: Initial commit --- test/coap_parse_test.erl | 19 +++++++++++++++++++ test/coap_unparse_test.erl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/coap_parse_test.erl create mode 100644 test/coap_unparse_test.erl (limited to 'test') diff --git a/test/coap_parse_test.erl b/test/coap_parse_test.erl new file mode 100644 index 0000000..59b8510 --- /dev/null +++ b/test/coap_parse_test.erl @@ -0,0 +1,19 @@ +-module(coap_parse_test). +-include_lib("eunit/include/eunit.hrl"). + +-include("coaperl.hrl"). + +% Test descriptions +parse_test_() -> + [{"Option extration works", + check_get_option_values()} + ]. + +% Tests +check_get_option_values() -> + Ret = coap_parse:get_option_values(#coap_response{options=[{coap_option,11,<<"bar">>}, + {coap_option,11,<<"baz">>}, + {coap_option,12,<<"foo">>}]}, + 11), + [?_assertEqual(Ret, [<<"bar">>, <<"baz">>])]. + 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"])]. -- cgit v1.2.3