tokenizecmd.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. const char* input[] =
  11. {
  12. " ",
  13. "\\",
  14. // "\"a b c\" d e",
  15. "\"ab\\\"c\" \"\\\\\" d",
  16. "a\\\\\\b d\"e f\"g h",
  17. "a\\\\\\\"b c d",
  18. "a\\\\\\\\\"b c\" d e",
  19. };
  20. const int expected_argc[] =
  21. {
  22. 0,
  23. 0,
  24. // 3,
  25. 3,
  26. 3,
  27. 3,
  28. 3
  29. };
  30. const char* expected_results[] =
  31. {
  32. "a b c", "d", "e",
  33. "ab\"c", "\\", "d",
  34. "a\\\\\\b", "de fg", "h",
  35. "a\\\"b", "c", "d",
  36. "a\\\\b c", "d", "e",
  37. };
  38. const char** expected_argv[] =
  39. {
  40. NULL,
  41. NULL,
  42. // &expected_results[0],
  43. &expected_results[3],
  44. &expected_results[6],
  45. &expected_results[9],
  46. &expected_results[12],
  47. };
  48. for (uint32_t ii = 0; ii < BX_COUNTOF(exptected_argv); ++ii)
  49. {
  50. printf("x\n");
  51. char commandLine[1024];
  52. uint32_t size = BX_COUNTOF(commandLine);
  53. char* argv[50];
  54. int32_t argc;
  55. bx::tokenizeCommandLine(input[ii], commandLine, size, argc, argv, BX_COUNTOF(argv) );
  56. printf("\n%d (%d): %s %s\n", ii, argc, input[ii], expected_argc[ii] == argc ? "" : "FAILED!");
  57. for (uint32_t jj = 0; jj < argc; ++jj)
  58. {
  59. printf("\t%d: {%s} %s\n"
  60. , jj
  61. , argv[jj]
  62. , jj < argc ? (0==strcmp(argv[jj], expected_argv[ii][jj]) ? "" : "FAILED!") : "FAILED!"
  63. );
  64. }
  65. }
  66. }