From 4c8b6288ceb70c4cf1287b63bb5c3145d3ffcfe7 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Tue, 8 Oct 2019 13:03:00 +0200 Subject: [PATCH] tests/unittests/base64: add test case for empty buffers --- tests/unittests/tests-base64/tests-base64.c | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/unittests/tests-base64/tests-base64.c b/tests/unittests/tests-base64/tests-base64.c index 762b1d972e81..f988c3d39382 100644 --- a/tests/unittests/tests-base64/tests-base64.c +++ b/tests/unittests/tests-base64/tests-base64.c @@ -383,6 +383,33 @@ static void test_base64_09_encode_size_determination(void) TEST_ASSERT_EQUAL_INT(required_out_size, expected_out_size); } +static void test_base64_10_encode_empty(void) +{ + unsigned char data_in[] = ""; + + size_t base64_out_size = 8; + unsigned char base64_out[8]; + + int ret = base64_encode(data_in, 0, base64_out, &base64_out_size); + + TEST_ASSERT_EQUAL_INT(BASE64_SUCCESS, ret); + TEST_ASSERT_EQUAL_INT(0, base64_out_size); +} + +static void test_base64_10_decode_empty(void) +{ + unsigned char data_in[] = ""; + + size_t base64_out_size = 8; + unsigned char base64_out[8]; + + int ret = base64_decode(data_in, 0, base64_out, &base64_out_size); + + TEST_ASSERT_EQUAL_INT(BASE64_SUCCESS, ret); + TEST_ASSERT_EQUAL_INT(0, base64_out_size); +} + + Test *tests_base64_tests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { @@ -395,6 +422,8 @@ Test *tests_base64_tests(void) new_TestFixture(test_base64_07_stream_decode), new_TestFixture(test_base64_08_encode_16_bytes), new_TestFixture(test_base64_09_encode_size_determination), + new_TestFixture(test_base64_10_encode_empty), + new_TestFixture(test_base64_10_decode_empty), }; EMB_UNIT_TESTCALLER(base64_tests, NULL, NULL, fixtures);