test_utils_restoreCursorPos.cpp 894 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. strncpy(write_data, data, length);
  11. write_length = length;
  12. return SHELLMATTA_OK;
  13. }
  14. TEST_CASE( "shellmatta_utils_restoreCursorPos" ) {
  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_restoreCursorPos(&inst);
  27. CHECK( write_callCnt == 1u);
  28. CHECK( write_length == 3u);
  29. REQUIRE( strncmp("\x1b[u", write_data, 3u) == 0);
  30. }