test_utils_writeEcho.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 const char *write_data;
  6. static uint32_t write_length;
  7. static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
  8. {
  9. write_callCnt ++;
  10. write_data = data;
  11. write_length = length;
  12. return SHELLMATTA_OK;
  13. }
  14. TEST_CASE( "shellmatta_writeEcho echo enabled" ) {
  15. shellmatta_instance_t inst;
  16. char buffer[20];
  17. char dummyData[29] = "asd";
  18. inst.buffer = buffer;
  19. inst.bufferSize = 20;
  20. inst.cursor = 10;
  21. inst.inputCount = 10;
  22. inst.echoEnabled = true;
  23. inst.write = writeFct;
  24. write_callCnt = 0u;
  25. write_data = 0u;
  26. write_length = 0u;
  27. utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
  28. CHECK( write_callCnt == 1u );
  29. CHECK( write_data == (char*)&dummyData );
  30. REQUIRE( write_length == sizeof(dummyData));
  31. }
  32. TEST_CASE( "shellmatta_writeEcho echo disabled" ) {
  33. shellmatta_instance_t inst;
  34. char buffer[20];
  35. char dummyData[29] = "asd";
  36. inst.buffer = buffer;
  37. inst.bufferSize = 20;
  38. inst.cursor = 10;
  39. inst.inputCount = 10;
  40. inst.echoEnabled = false;
  41. inst.write = writeFct;
  42. write_callCnt = 0u;
  43. write_data = 0u;
  44. write_length = 0u;
  45. utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
  46. CHECK( write_callCnt == 0u );
  47. CHECK( write_data == (char*)0u );
  48. REQUIRE( write_length == 0u );
  49. }