shellmatta/test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp

72 lines
2.0 KiB
C++
Raw Permalink Normal View History

2020-10-31 15:16:16 +01:00
#include "test/framework/catch.hpp"
#include "src/shellmatta_opt.c"
#include <string.h>
TEST_CASE( "shellmatta_opt peekNextHunk next char without space" ) {
2020-10-31 15:16:16 +01:00
char ret = 0;
shellmatta_instance_t inst;
char *dummyData = (char*) "Welcome... to Jurassic Park.";
2020-10-31 15:16:16 +01:00
char buffer[1024u];
memcpy(buffer, dummyData, strlen(dummyData));
inst.buffer = buffer;
inst.bufferSize = sizeof(buffer);
inst.inputCount = 28u;
2020-10-31 15:16:16 +01:00
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;
2020-10-31 15:16:16 +01:00
inst.optionParser.nextOffset = 13u;
2020-10-31 15:16:16 +01:00
ret = peekNextHunk(&inst);
CHECK( ret == 'J' );
}
2020-10-31 15:16:16 +01:00
TEST_CASE( "shellmatta_opt peekNextHunk next hunk escape and space" ) {
2020-10-31 15:16:16 +01:00
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;
2020-10-31 15:16:16 +01:00
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;
2020-10-31 15:16:16 +01:00
inst.optionParser.nextOffset = 36u;
ret = peekNextHunk(&inst);
CHECK( ret == 'm' );
}