Expand unittest for utils_removeChars

This commit is contained in:
S.Hentges 2020-05-28 22:39:53 +02:00
parent 15c846a9f1
commit 2060cd61eb

View File

@ -28,7 +28,7 @@ TEST_CASE("shellmatta_utils_removeChars_nothing_removed"){
inst.cursor = 20u;
inst.inputCount = 20u;
char buffer[20] = "abcdefghijklmnopqr\0";
char buffer[20] = "abcdefghijklmnopqr";
inst.buffer = buffer;
inst.bufferSize = 20u;
@ -36,12 +36,12 @@ TEST_CASE("shellmatta_utils_removeChars_nothing_removed"){
CHECK( inst.cursor == 20u);
CHECK( inst.inputCount == 20);
REQUIRE(strncmp("abcdefghijklmnopqr\0", buffer, sizeof(buffer)) == 0);
REQUIRE(strncmp("abcdefghijklmnopqr", buffer, sizeof(buffer)) == 0);
}
TEST_CASE("shellmatta_utils_removeChars_backspace_false"){
shellmatta_instance_t inst;
char buffer[20] = "abcdefghijklmnopqr\0";
char buffer[20] = "abcdefghijklmnopqr";
memset(&inst, 0, sizeof(inst));
uint32_t length = 5u;
bool backspace = false;
@ -61,12 +61,12 @@ TEST_CASE("shellmatta_utils_removeChars_backspace_false"){
CHECK( inst.cursor == 20u);
CHECK( inst.inputCount == 20);
REQUIRE(strncmp("abcdefghijklmnopqr\0", buffer, sizeof(buffer)) == 0);
REQUIRE(strncmp("abcdefghijklmnopqr", buffer, sizeof(buffer)) == 0);
}
TEST_CASE("shellmatta_utils_removeChars_remove_five"){
shellmatta_instance_t inst;
char buffer[20] = "abcdefghijklmnopqr\0";
char buffer[20] = "abcdefghijklmnopqr";
memset(&inst, 0, sizeof(inst));
@ -88,12 +88,12 @@ TEST_CASE("shellmatta_utils_removeChars_remove_five"){
CHECK( inst.cursor == 5u);
CHECK( inst.inputCount == 15u);
REQUIRE(strncmp("abcdeklmnopqr\0", buffer, sizeof(buffer)) == 0);
REQUIRE(strncmp("abcdeklmnopqr", buffer, sizeof(buffer)) == 0);
}
TEST_CASE("shellmatta_utils_removeChars_length_greater_than_CursorPos"){
shellmatta_instance_t inst;
char buffer[20] = "abcdefghijklmnopqr\0";
char buffer[20] = "abcdefghijklmnopqr";
memset(&inst, 0, sizeof(inst));
@ -115,5 +115,86 @@ TEST_CASE("shellmatta_utils_removeChars_length_greater_than_CursorPos"){
CHECK( inst.cursor == 0u);
CHECK( inst.inputCount == 10u);
REQUIRE(strncmp("klmnopqr\0", buffer, sizeof(buffer)) == 0);
REQUIRE(strncmp("klmnopqr", buffer, sizeof(buffer)) == 0);
}
TEST_CASE("shellmatta_utils_removeChars_remove_chars_in_the_middle_of_the_buffer_backspace_false"){
shellmatta_instance_t inst;
char buffer[20] = "abcdefghijklmnopqr";
memset(&inst, 0, sizeof(inst));
inst.write = writeFct;
write_callCnt = 0u;
memset(write_data, 0, sizeof(write_data));
write_idx = 0u;
uint32_t length = 5u;
bool backspace = false;
inst.cursor = 10u;
inst.inputCount = 20u;
inst.bufferSize = 20u;
inst.buffer = buffer;
utils_removeChars(&inst, length, backspace);
CHECK( inst.cursor == 10u);
CHECK( inst.inputCount == 20u);
REQUIRE(strncmp("abcdefghijklmnopqr", buffer, sizeof(buffer)) == 0);
}
TEST_CASE("shellmatta_utils_removeChars_remove_more_chars_in_middle_of_buffer_than_are_present_backspace_false"){
shellmatta_instance_t inst;
char buffer[20] = "abcdefghijklmnopqr";
memset(&inst, 0, sizeof(inst));
inst.write = writeFct;
write_callCnt = 0u;
memset(write_data, 0, sizeof(write_data));
write_idx = 0u;
uint32_t length = 15u;
bool backspace = false;
inst.cursor = 10u;
inst.inputCount = 20u;
inst.bufferSize = 20u;
inst.buffer = buffer;
utils_removeChars(&inst, length, backspace);
CHECK( inst.cursor == 10u);
CHECK( inst.inputCount == 20u);
REQUIRE(strncmp("abcdefghijklmnopqr", buffer, sizeof(buffer)) == 0);
}
TEST_CASE("shellmatta_utils_removeChars_curser_outside_buffer"){
shellmatta_instance_t inst;
char buffer[20] = "abcdefghijklmnopqr";
memset(&inst, 0, sizeof(inst));
inst.write = writeFct;
write_callCnt = 0u;
memset(write_data, 0, sizeof(write_data));
write_idx = 0u;
uint32_t length = 15u;
bool backspace = false;
inst.cursor = 21u;
inst.inputCount = 20u;
inst.bufferSize = 20u;
inst.buffer = buffer;
utils_removeChars(&inst, length, backspace);
CHECK( inst.cursor == 21u);
CHECK( inst.inputCount == 20u);
REQUIRE(strncmp("abcdefghijklmnopqr", buffer, sizeof(buffer)) == 0);
}