3 次代碼提交 0ebbcc602c ... 2060cd61eb

作者 SHA1 備註 提交日期
  S.Hentges 2060cd61eb Expand unittest for utils_removeChars 4 年之前
  S.Hentges 15c846a9f1 Fix identation 4 年之前
  S.Hentges 0ae7e24470 Revert "Fix identation" 4 年之前
共有 2 個文件被更改,包括 147 次插入66 次删除
  1. 57 57
      makefile
  2. 90 9
      test/unittest/shellmatta_utils/test_utils_removeChars.cpp

+ 57 - 57
makefile

@@ -73,87 +73,87 @@ DEPS    := $(OBJ:%.o=%.d)
 export
 
 help:
-    @echo Shellmatta help
-    @echo -----------------------------------------------
-    @echo test      - run all tests
-    @echo cppcheck  - run static code analysis (cppcheck)
-    @echo example   - build example
-    @echo -----------------------------------------------
+	@echo Shellmatta help
+	@echo -----------------------------------------------
+	@echo test      - run all tests
+	@echo cppcheck  - run static code analysis (cppcheck)
+	@echo example   - build example
+	@echo -----------------------------------------------
 
 test: unittest integrationtest
 
 cppcheck:
-    - @mkdir -p output/cppcheck/html
-    cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
-    cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
-    cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
+	- @mkdir -p output/cppcheck/html
+	cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES)
+	cppcheck --enable=all --template=gcc --cppcheck-build-dir=output/cppcheck $(SOURCES) --xml 2>output/cppcheck/cppcheck.xml
+	cppcheck-htmlreport --file=output/cppcheck/cppcheck.xml --title="Shellmatta" --report-dir=output/cppcheck/html
 
 unittest: $(UNITTEST_TARGET)
-    - @mkdir -p output/test/unittest/report
-    @echo running test:
-    @# remove coverage from former run
-    @-find . -name "*.gcda" -type f -delete
-    -$(UNITTEST_TARGET)
-    @#gcov -o output/test/unittest $(UNITTEST_CPPOBJ) -r src
-
-    @# remove report from former run
-    -rm -rf $(OBJ_DIR)test/unittest/report/*
-    gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api
-    @#-rm *.gcov
-    
+	- @mkdir -p output/test/unittest/report
+	@echo running test:
+	@# remove coverage from former run
+	@-find . -name "*.gcda" -type f -delete
+	-$(UNITTEST_TARGET)
+	@#gcov -o output/test/unittest $(UNITTEST_CPPOBJ) -r src
+
+	@# remove report from former run
+	-rm -rf $(OBJ_DIR)test/unittest/report/*
+	gcovr --html-details --output $(OBJ_DIR)test/unittest/report/report.html output/test/unittest -f src -f api
+	@#-rm *.gcov
+	
 integrationtest: $(INTEGRATIONTEST_TARGET)
-    - @mkdir -p output/test/integrationtest/report
-    @echo running test:
-    -$(INTEGRATIONTEST_TARGET)
-    #gcov -o output/test $(TEST_CPPOBJ) -r
-    gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api
-    #-rm *.gcov
-    
+	- @mkdir -p output/test/integrationtest/report
+	@echo running test:
+	-$(INTEGRATIONTEST_TARGET)
+	#gcov -o output/test $(TEST_CPPOBJ) -r
+	gcovr --html-details --output $(OBJ_DIR)test/integrationtest/report/report.html output/src -f src -f api
+	#-rm *.gcov
+	
 example: $(EXAMPLE_TARGET)
-    @echo building example
+	@echo building example
 
 doc:
-    - @mkdir -p output/doc/html
-    - @mkdir -p output/doc/latex
-    doxygen cfg/doxygen/doxyfile
-    
+	- @mkdir -p output/doc/html
+	- @mkdir -p output/doc/latex
+	doxygen cfg/doxygen/doxyfile
+	
 clean:
-    - rm -rf $(OBJ_DIR)
+	- rm -rf $(OBJ_DIR)
 
 $(EXAMPLE_TARGET): $(COBJ) $(EXAMPLE_COBJ)
-    - @mkdir -p $(@D)
-    $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
+	- @mkdir -p $(@D)
+	$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
 
 $(UNITTEST_TARGET): $(UNITTEST_CPPOBJ)
-    - @mkdir -p $(@D)
-    $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
-    
+	- @mkdir -p $(@D)
+	$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
+	
 $(INTEGRATIONTEST_TARGET): $(INTEGRATIONTEST_CPPOBJ) $(COBJ)
-    - @mkdir -p $(@D)
-    $(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
+	- @mkdir -p $(@D)
+	$(CPP) $(TESTLFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
 
 $(TARGET): $(OBJ)
-    - @mkdir -p $(@D)
-    $(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
-    
+	- @mkdir -p $(@D)
+	$(CC) $(LFLAGS) $(LIB_PATH) -o $@ $^ $(LIBS)
+	
 $(COBJ):
-    - @mkdir -p $(@D)
-    @$(CC) -c $(CFLAGS)  $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
-    $(CC) -c $(CFLAGS) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
+	- @mkdir -p $(@D)
+	@$(CC) -c $(CFLAGS)  $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
+	$(CC) -c $(CFLAGS) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
 
 $(EXAMPLE_COBJ):
-    - @mkdir -p $(@D)
-    @$(CC) -c $(CFLAGS) $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
-    $(CC) -c $(CFLAGS) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
+	- @mkdir -p $(@D)
+	@$(CC) -c $(CFLAGS) $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
+	$(CC) -c $(CFLAGS) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
 
 $(UNITTEST_CPPOBJ) $(INTEGRATIONTEST_CPPOBJ):
-    - @mkdir -p $(@D)
-    @$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
-    $(CPP) -c $(TESTFLAGS) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
+	- @mkdir -p $(@D)
+	@$(CPP) -c $(TESTFLAGS) $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
+	$(CPP) -c $(TESTFLAGS) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.cpp))
 
 %.o: %.cpp
-    - @mkdir -p $(@D)
-    @$(CPP) -c $(CFLAGS) $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
-    $(CPP) -c $(CFLAGS) -o $@  $<
+	- @mkdir -p $(@D)
+	@$(CPP) -c $(CFLAGS) $(DEPEND) -o $@  $(subst $(OBJ_DIR), ,$(@:%.o=%.c))
+	$(CPP) -c $(CFLAGS) -o $@  $<
 
 -include $(DEPS)

+ 90 - 9
test/unittest/shellmatta_utils/test_utils_removeChars.cpp

@@ -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);
+}