test_utils_eraseLine.cpp 879 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "test/framework/catch.hpp"
  2. #include "src/shellmatta_utils.c"
  3. #include <string.h>
  4. static uint32_t write_callCnt = 0u;
  5. static char write_data[10];
  6. static uint32_t write_length;
  7. static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
  8. {
  9. write_callCnt ++;
  10. memcpy(write_data, data, length);
  11. write_length = length;
  12. return SHELLMATTA_OK;
  13. }
  14. TEST_CASE( "shellmatta_utils_eraseLine" ) {
  15. shellmatta_instance_t inst;
  16. char buffer[20];
  17. inst.buffer = buffer;
  18. inst.bufferSize = 20;
  19. inst.cursor = 10;
  20. inst.inputCount = 10;
  21. inst.echoEnabled = true;
  22. inst.write = writeFct;
  23. write_callCnt = 0u;
  24. memset(write_data, 0, sizeof(write_data));
  25. write_length = 0u;
  26. utils_eraseLine(&inst);
  27. CHECK( write_callCnt == 1u);
  28. CHECK( write_length == 3u);
  29. REQUIRE( strncmp("\x1b[K", write_data, 3u) == 0);
  30. }