From e495346d44bb419c7b0624fcae289758d5faf90c Mon Sep 17 00:00:00 2001 From: "S.Hentges" Date: Sat, 31 Oct 2020 15:16:16 +0100 Subject: [PATCH 1/2] Add unittest for otp_peekNextHunk --- makefile | 1 + .../shellmatta_opt/test_opt_peekNextHunk.cpp | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp diff --git a/makefile b/makefile index d96c36f..e47043a 100644 --- a/makefile +++ b/makefile @@ -23,6 +23,7 @@ INCLUDES := api . UNITTEST_SOURCES := test/unittest/test_main.cpp \ test/unittest/shellmatta_opt/test_opt_findNextHunk.cpp \ + test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp \ test/unittest/shellmatta_utils/test_utils_writeEcho.cpp \ test/unittest/shellmatta_utils/test_utils_shellItoa.cpp \ test/unittest/shellmatta_utils/test_utils_saveCursorPos.cpp \ diff --git a/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp b/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp new file mode 100644 index 0000000..0bded4e --- /dev/null +++ b/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp @@ -0,0 +1,47 @@ +#include "test/framework/catch.hpp" +#include "src/shellmatta_opt.c" +#include + + +TEST_CASE( "shellmatta_opt peekNextHunk" ) { + + char ret = 0; + shellmatta_instance_t inst; + char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend."; + char buffer[1024u]; + memcpy(buffer, dummyData, strlen(dummyData)); + + inst.buffer = buffer; + inst.bufferSize = sizeof(buffer); + inst.inputCount = 28u; + inst.optionParser.nextOffset = 11u; + + ret = peekNextHunk(&inst); + CHECK( ret == 't' ); + + inst.optionParser.nextOffset = 13u; + ret = peekNextHunk(&inst); + CHECK( ret == 'J' ); + + inst.optionParser.nextOffset = 22u; + ret = peekNextHunk(&inst); + CHECK( ret == 'P' ); + + inst.optionParser.nextOffset = 23u; + ret = peekNextHunk(&inst); + CHECK( ret == 'P' ); + + //Copy whole string including escape sequence + inst.inputCount = 77u; + memcpy(buffer, dummyData, 77u); + + //Check for combination of \0 and space + inst.optionParser.nextOffset = 28u; + ret = peekNextHunk(&inst); + CHECK( ret == 'R' ); + + //Check for two spaces in a Row + inst.optionParser.nextOffset = 36u; + ret = peekNextHunk(&inst); + CHECK( ret == 'm' ); +} \ No newline at end of file From 68ec0ab3dc4ef312a8e12cf37689a9b7082cdde4 Mon Sep 17 00:00:00 2001 From: "S.Hentges" Date: Wed, 11 Nov 2020 21:25:05 +0100 Subject: [PATCH 2/2] refactor testcases, delete doubling testcases --- .../shellmatta_opt/test_opt_peekNextHunk.cpp | 77 ++++++++++++------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp b/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp index 0bded4e..e6148fe 100644 --- a/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp +++ b/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp @@ -3,44 +3,69 @@ #include -TEST_CASE( "shellmatta_opt peekNextHunk" ) { +TEST_CASE( "shellmatta_opt peekNextHunk next char without space" ) { + + char ret = 0; + shellmatta_instance_t inst; + char *dummyData = (char*) "Welcome... to Jurassic Park."; + char buffer[1024u]; + memcpy(buffer, dummyData, strlen(dummyData)); + inst.buffer = buffer; + inst.bufferSize = sizeof(buffer); + inst.inputCount = 28u; + + inst.optionParser.nextOffset = 11u; + + ret = peekNextHunk(&inst); + CHECK( ret == 't' ); +} + +TEST_CASE( "shellmatta_opt peekNextHunk next char with space" ) { + + char ret = 0; + shellmatta_instance_t inst; + char *dummyData = (char*) "Welcome... to Jurassic Park.\0"; + char buffer[1024u]; + memcpy(buffer, dummyData, strlen(dummyData)); + inst.buffer = buffer; + inst.bufferSize = sizeof(buffer); + inst.inputCount = 28u; + + inst.optionParser.nextOffset = 13u; + + ret = peekNextHunk(&inst); + CHECK( ret == 'J' ); +} + +TEST_CASE( "shellmatta_opt peekNextHunk next hunk escape and space" ) { char ret = 0; shellmatta_instance_t inst; char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend."; char buffer[1024u]; - memcpy(buffer, dummyData, strlen(dummyData)); - + uint16_t stringsize = 77u; + memcpy(buffer, dummyData, stringsize); inst.buffer = buffer; inst.bufferSize = sizeof(buffer); - inst.inputCount = 28u; - inst.optionParser.nextOffset = 11u; - - ret = peekNextHunk(&inst); - CHECK( ret == 't' ); - - inst.optionParser.nextOffset = 13u; - ret = peekNextHunk(&inst); - CHECK( ret == 'J' ); - - inst.optionParser.nextOffset = 22u; - ret = peekNextHunk(&inst); - CHECK( ret == 'P' ); + inst.inputCount = stringsize; - inst.optionParser.nextOffset = 23u; - ret = peekNextHunk(&inst); - CHECK( ret == 'P' ); - - //Copy whole string including escape sequence - inst.inputCount = 77u; - memcpy(buffer, dummyData, 77u); - - //Check for combination of \0 and space inst.optionParser.nextOffset = 28u; ret = peekNextHunk(&inst); CHECK( ret == 'R' ); +} + +TEST_CASE( "shellmatta_opt peekNextHunk next char with spaces" ) { + + char ret = 0; + shellmatta_instance_t inst; + char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend."; + char buffer[1024u]; + uint16_t stringsize = 77u; + memcpy(buffer, dummyData, stringsize); + inst.buffer = buffer; + inst.bufferSize = sizeof(buffer); + inst.inputCount = stringsize; - //Check for two spaces in a Row inst.optionParser.nextOffset = 36u; ret = peekNextHunk(&inst); CHECK( ret == 'm' );