Skip to content

Commit

Permalink
tests/unittests/base64: add test case for empty buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
aabadie committed Oct 8, 2019
1 parent 1d8e86c commit 4c8b628
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/unittests/tests-base64/tests-base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 4c8b628

Please sign in to comment.