test_utils_terminateInput.cpp 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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_idx;
  7. static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
  8. {
  9. write_callCnt ++;
  10. strncpy(&write_data[write_idx], data, length);
  11. write_idx += length;
  12. return SHELLMATTA_OK;
  13. }
  14. TEST_CASE( "shellmatta_utils_terminateInput" ) {
  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.prompt = "->";
  23. inst.write = writeFct;
  24. write_callCnt = 0u;
  25. memset(write_data, 0, sizeof(write_data));
  26. write_idx = 0u;
  27. utils_terminateInput(&inst);
  28. CHECK( inst.cursor == 0u );
  29. CHECK( inst.inputCount == 0u );
  30. CHECK( write_callCnt == 2u );
  31. CHECK( write_idx == 4u );
  32. REQUIRE( strncmp("\r\n->", write_data, 4u) == 0);
  33. }