test_utils_writeEcho.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2019 - 2024 Stefan Strobel <stefan.strobel@shimatta.net>
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file test_utils_writeEcho.c
  10. * @brief unittest for shellmatta utils_writeEcho
  11. * @author Stefan Strobel <stefan.strobel@shimatta.net>
  12. */
  13. #include "test/framework/catch.hpp"
  14. #include "src/shellmatta_utils.c"
  15. #include <string.h>
  16. static uint32_t write_callCnt = 0u;
  17. static const char *write_data;
  18. static uint32_t write_length;
  19. static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
  20. {
  21. write_callCnt ++;
  22. write_data = data;
  23. write_length = length;
  24. return SHELLMATTA_OK;
  25. }
  26. TEST_CASE( "shellmatta_writeEcho echo enabled" ) {
  27. shellmatta_instance_t inst;
  28. char buffer[20] = {0};
  29. char dummyData[29] = "asd";
  30. inst.buffer = buffer;
  31. inst.bufferSize = 20;
  32. inst.cursor = 10;
  33. inst.inputCount = 10;
  34. inst.echoEnabled = true;
  35. inst.write = writeFct;
  36. write_callCnt = 0u;
  37. write_data = 0u;
  38. write_length = 0u;
  39. utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
  40. CHECK( write_callCnt == 1u );
  41. CHECK( write_data == (char*)&dummyData );
  42. REQUIRE( write_length == sizeof(dummyData));
  43. }
  44. TEST_CASE( "shellmatta_writeEcho echo disabled" ) {
  45. shellmatta_instance_t inst;
  46. char buffer[20] = {0};
  47. char dummyData[29] = "asd";
  48. inst.buffer = buffer;
  49. inst.bufferSize = 20;
  50. inst.cursor = 10;
  51. inst.inputCount = 10;
  52. inst.echoEnabled = false;
  53. inst.write = writeFct;
  54. write_callCnt = 0u;
  55. write_data = 0u;
  56. write_length = 0u;
  57. utils_writeEcho(&inst, (char*)&dummyData, sizeof(dummyData));
  58. CHECK( write_callCnt == 0u );
  59. CHECK( write_data == (char*)0u );
  60. REQUIRE( write_length == 0u );
  61. }