test_opt_peekNextHunk.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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_opt_peekNextHunk.c
  10. * @brief unittest for shellmatta opt_peekNextHunk
  11. * @author Stefan Strobel <stefan.strobel@shimatta.net>
  12. */
  13. #include "test/framework/catch.hpp"
  14. #include "src/shellmatta_opt.c"
  15. #include <string.h>
  16. TEST_CASE( "shellmatta_opt peekNextHunk next char without space" ) {
  17. char ret = 0;
  18. shellmatta_instance_t inst;
  19. char *dummyData = (char*) "Welcome... to Jurassic Park.";
  20. char buffer[1024u];
  21. memcpy(buffer, dummyData, strlen(dummyData));
  22. inst.buffer = buffer;
  23. inst.bufferSize = sizeof(buffer);
  24. inst.inputCount = 28u;
  25. inst.optionParser.nextOffset = 11u;
  26. ret = peekNextHunk(&inst);
  27. CHECK( ret == 't' );
  28. }
  29. TEST_CASE( "shellmatta_opt peekNextHunk next char with space" ) {
  30. char ret = 0;
  31. shellmatta_instance_t inst;
  32. char *dummyData = (char*) "Welcome... to Jurassic Park.\0";
  33. char buffer[1024u];
  34. memcpy(buffer, dummyData, strlen(dummyData));
  35. inst.buffer = buffer;
  36. inst.bufferSize = sizeof(buffer);
  37. inst.inputCount = 28u;
  38. inst.optionParser.nextOffset = 13u;
  39. ret = peekNextHunk(&inst);
  40. CHECK( ret == 'J' );
  41. }
  42. TEST_CASE( "shellmatta_opt peekNextHunk next hunk escape and space" ) {
  43. char ret = 0;
  44. shellmatta_instance_t inst;
  45. char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
  46. char buffer[1024u];
  47. uint16_t stringsize = 77u;
  48. memcpy(buffer, dummyData, stringsize);
  49. inst.buffer = buffer;
  50. inst.bufferSize = sizeof(buffer);
  51. inst.inputCount = stringsize;
  52. inst.optionParser.nextOffset = 28u;
  53. ret = peekNextHunk(&inst);
  54. CHECK( ret == 'R' );
  55. }
  56. TEST_CASE( "shellmatta_opt peekNextHunk next char with spaces" ) {
  57. char ret = 0;
  58. shellmatta_instance_t inst;
  59. char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
  60. char buffer[1024u];
  61. uint16_t stringsize = 77u;
  62. memcpy(buffer, dummyData, stringsize);
  63. inst.buffer = buffer;
  64. inst.bufferSize = sizeof(buffer);
  65. inst.inputCount = stringsize;
  66. inst.optionParser.nextOffset = 36u;
  67. ret = peekNextHunk(&inst);
  68. CHECK( ret == 'm' );
  69. }