test_opt_peekNextHunk.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "test/framework/catch.hpp"
  2. #include "src/shellmatta_opt.c"
  3. #include <string.h>
  4. TEST_CASE( "shellmatta_opt peekNextHunk" ) {
  5. char ret = 0;
  6. shellmatta_instance_t inst;
  7. char *dummyData = (char*) "Welcome... to Jurassic Park.\0 Remind me to thank John for a lovely weekend.";
  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. inst.optionParser.nextOffset = 13u;
  17. ret = peekNextHunk(&inst);
  18. CHECK( ret == 'J' );
  19. inst.optionParser.nextOffset = 22u;
  20. ret = peekNextHunk(&inst);
  21. CHECK( ret == 'P' );
  22. inst.optionParser.nextOffset = 23u;
  23. ret = peekNextHunk(&inst);
  24. CHECK( ret == 'P' );
  25. //Copy whole string including escape sequence
  26. inst.inputCount = 77u;
  27. memcpy(buffer, dummyData, 77u);
  28. //Check for combination of \0 and space
  29. inst.optionParser.nextOffset = 28u;
  30. ret = peekNextHunk(&inst);
  31. CHECK( ret == 'R' );
  32. //Check for two spaces in a Row
  33. inst.optionParser.nextOffset = 36u;
  34. ret = peekNextHunk(&inst);
  35. CHECK( ret == 'm' );
  36. }