test_opt_peekNextHunk.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "test/framework/catch.hpp"
  2. #include "src/shellmatta_opt.c"
  3. #include <string.h>
  4. TEST_CASE( "shellmatta_opt peekNextHunk next char without space" ) {
  5. char ret = 0;
  6. shellmatta_instance_t inst;
  7. char *dummyData = (char*) "Welcome... to Jurassic Park.";
  8. char buffer[1024u];
  9. memcpy(buffer, dummyData, strlen(dummyData));
  10. inst.buffer = buffer;
  11. inst.bufferSize = sizeof(buffer);
  12. inst.inputCount = 28u;
  13. inst.optionParser.nextOffset = 11u;
  14. ret = peekNextHunk(&inst);
  15. CHECK( ret == 't' );
  16. }
  17. TEST_CASE( "shellmatta_opt peekNextHunk next char with space" ) {
  18. char ret = 0;
  19. shellmatta_instance_t inst;
  20. char *dummyData = (char*) "Welcome... to Jurassic Park.\0";
  21. char buffer[1024u];
  22. memcpy(buffer, dummyData, strlen(dummyData));
  23. inst.buffer = buffer;
  24. inst.bufferSize = sizeof(buffer);
  25. inst.inputCount = 28u;
  26. inst.optionParser.nextOffset = 13u;
  27. ret = peekNextHunk(&inst);
  28. CHECK( ret == 'J' );
  29. }
  30. TEST_CASE( "shellmatta_opt peekNextHunk next hunk escape and space" ) {
  31. char ret = 0;
  32. shellmatta_instance_t inst;
  33. char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
  34. char buffer[1024u];
  35. uint16_t stringsize = 77u;
  36. memcpy(buffer, dummyData, stringsize);
  37. inst.buffer = buffer;
  38. inst.bufferSize = sizeof(buffer);
  39. inst.inputCount = stringsize;
  40. inst.optionParser.nextOffset = 28u;
  41. ret = peekNextHunk(&inst);
  42. CHECK( ret == 'R' );
  43. }
  44. TEST_CASE( "shellmatta_opt peekNextHunk next char with spaces" ) {
  45. char ret = 0;
  46. shellmatta_instance_t inst;
  47. char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
  48. char buffer[1024u];
  49. uint16_t stringsize = 77u;
  50. memcpy(buffer, dummyData, stringsize);
  51. inst.buffer = buffer;
  52. inst.bufferSize = sizeof(buffer);
  53. inst.inputCount = stringsize;
  54. inst.optionParser.nextOffset = 36u;
  55. ret = peekNextHunk(&inst);
  56. CHECK( ret == 'm' );
  57. }