tokenizecmd.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2012-2014 Branimir Karadzic. All rights reserved.
  3. * License: http://www.opensource.org/licenses/BSD-2-Clause
  4. */
  5. #include "test.h"
  6. #include <bx/tokenizecmd.h>
  7. #include <string.h>
  8. TEST(tokenizeCommandLine)
  9. {
  10. #if 0
  11. const char* input[] =
  12. {
  13. " ",
  14. "\\",
  15. // "\"a b c\" d e",
  16. "\"ab\\\"c\" \"\\\\\" d",
  17. "a\\\\\\b d\"e f\"g h",
  18. "a\\\\\\\"b c d",
  19. "a\\\\\\\\\"b c\" d e",
  20. };
  21. const int expected_argc[] =
  22. {
  23. 0,
  24. 0,
  25. // 3,
  26. 3,
  27. 3,
  28. 3,
  29. 3
  30. };
  31. const char* expected_results[] =
  32. {
  33. "a b c", "d", "e",
  34. "ab\"c", "\\", "d",
  35. "a\\\\\\b", "de fg", "h",
  36. "a\\\"b", "c", "d",
  37. "a\\\\b c", "d", "e",
  38. };
  39. const char** expected_argv[] =
  40. {
  41. NULL,
  42. NULL,
  43. // &expected_results[0],
  44. &expected_results[3],
  45. &expected_results[6],
  46. &expected_results[9],
  47. &expected_results[12],
  48. };
  49. for (uint32_t ii = 0; ii < BX_COUNTOF(exptected_argv); ++ii)
  50. {
  51. printf("x\n");
  52. char commandLine[1024];
  53. uint32_t size = BX_COUNTOF(commandLine);
  54. char* argv[50];
  55. int32_t argc;
  56. bx::tokenizeCommandLine(input[ii], commandLine, size, argc, argv, BX_COUNTOF(argv) );
  57. printf("\n%d (%d): %s %s\n", ii, argc, input[ii], expected_argc[ii] == argc ? "" : "FAILED!");
  58. for (uint32_t jj = 0; jj < argc; ++jj)
  59. {
  60. printf("\t%d: {%s} %s\n"
  61. , jj
  62. , argv[jj]
  63. , jj < argc ? (0==strcmp(argv[jj], expected_argv[ii][jj]) ? "" : "FAILED!") : "FAILED!"
  64. );
  65. }
  66. }
  67. #endif // 0
  68. }