test_integration_opt.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2019 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_integration_opt.cpp
  10. * @brief integration test implementation for the option parser of the shellmatta
  11. * @author Stefan Strobel <stefan.strobel@shimatta.net>
  12. */
  13. #include "test/framework/catch.hpp"
  14. extern "C" {
  15. #include "shellmatta.h"
  16. }
  17. #include <string.h>
  18. static uint32_t write_callCnt = 0u;
  19. static char write_data[1024];
  20. static uint32_t write_length;
  21. static shellmatta_retCode_t writeFct(const char* data, uint32_t length)
  22. {
  23. write_callCnt ++;
  24. while((length > 0) && (write_length < sizeof(write_data)))
  25. {
  26. write_data[write_length] = *data;
  27. data ++;
  28. length --;
  29. write_length ++;
  30. }
  31. return SHELLMATTA_OK;
  32. }
  33. static shellmatta_retCode_t parseOpts(shellmatta_handle_t handle, const char *arguments, uint32_t length)
  34. {
  35. (void) arguments;
  36. (void) length;
  37. char option;
  38. char *argumentString;
  39. uint32_t argumentLength;
  40. while(SHELLMATTA_OK == shellmatta_opt(handle, (char*)"abcde:f::", &option, &argumentString, &argumentLength))
  41. {
  42. switch(option)
  43. {
  44. case 'a':
  45. break;
  46. case 'b':
  47. break;
  48. case 'c':
  49. break;
  50. case 'd':
  51. break;
  52. case 'e':
  53. break;
  54. case 'f':
  55. break;
  56. default:
  57. break;
  58. }
  59. }
  60. return SHELLMATTA_OK;
  61. }
  62. shellmatta_cmd_t parseOptsCmd = {(char*)"parseOpts", (char*)"opt", NULL, NULL, parseOpts, NULL};
  63. static shellmatta_retCode_t empty(shellmatta_handle_t handle, const char *arguments, uint32_t length)
  64. {
  65. shellmatta_printf(handle, "empty - %s - length: %u", arguments, length);
  66. return SHELLMATTA_OK;
  67. }
  68. shellmatta_cmd_t emptyCmd = {(char*)"empty", NULL, NULL, NULL, empty, NULL};
  69. TEST_CASE( "shellmatta option parser 1" ) {
  70. shellmatta_instance_t inst;
  71. shellmatta_handle_t handle;
  72. char buffer[1024];
  73. char historyBuffer[1024];
  74. //char *dummyData = (char*)"\r\nshellmatta->";
  75. shellmatta_doInit( &inst,
  76. &handle,
  77. buffer,
  78. sizeof(buffer),
  79. historyBuffer,
  80. sizeof(historyBuffer),
  81. "shellmatta->",
  82. NULL,
  83. writeFct);
  84. write_callCnt = 0u;
  85. memset(write_data, 0, sizeof(write_data));
  86. write_length = 0u;
  87. shellmatta_processData(handle, (char*)"parseOpts -a -e meow\r", 1);
  88. // CHECK( write_length == 14u);
  89. // REQUIRE( strcmp(dummyData, write_data) == 0);
  90. REQUIRE( 1 == 1 );
  91. }