Переглянути джерело

Add unittest for otp_peekNextHunk

S.Hentges 4 роки тому
батько
коміт
e495346d44
2 змінених файлів з 48 додано та 0 видалено
  1. 1 0
      makefile
  2. 47 0
      test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp

+ 1 - 0
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         \

+ 47 - 0
test/unittest/shellmatta_opt/test_opt_peekNextHunk.cpp

@@ -0,0 +1,47 @@
+#include "test/framework/catch.hpp"
+#include "src/shellmatta_opt.c"
+#include <string.h>
+
+
+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' );
+}