winmain.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright Vladimir Prus 2002-2004.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt
  4. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if defined(_WIN32)
  6. #include <string>
  7. #include <vector>
  8. #include <cctype>
  9. #include <iostream>
  10. #include <stdlib.h>
  11. using namespace std;
  12. #include <boost/program_options/parsers.hpp>
  13. using namespace boost::program_options;
  14. void check_equal(const std::vector<string>& actual, char **expected, int n)
  15. {
  16. if (actual.size() != n)
  17. {
  18. std::cerr << "Size mismatch between expected and actual data\n";
  19. abort();
  20. }
  21. for (int i = 0; i < n; ++i)
  22. {
  23. if (actual[i] != expected[i])
  24. {
  25. std::cerr << "Unexpected content\n";
  26. abort();
  27. }
  28. }
  29. }
  30. #include <boost/preprocessor/cat.hpp>
  31. void test_winmain()
  32. {
  33. #define C ,
  34. #define TEST(input, expected) \
  35. char* BOOST_PP_CAT(e, __LINE__)[] = expected;\
  36. vector<string> BOOST_PP_CAT(v, __LINE__) = split_winmain(input);\
  37. check_equal(BOOST_PP_CAT(v, __LINE__), BOOST_PP_CAT(e, __LINE__),\
  38. sizeof(BOOST_PP_CAT(e, __LINE__))/sizeof(char*));
  39. // The following expectations were obtained in Win2000 shell:
  40. TEST("1 ", {"1"});
  41. TEST("1\"2\" ", {"12"});
  42. TEST("1\"2 ", {"12 "});
  43. TEST("1\"\\\"2\" ", {"1\"2"});
  44. TEST("\"1\" \"2\" ", {"1" C "2"});
  45. TEST("1\\\" ", {"1\""});
  46. TEST("1\\\\\" ", {"1\\ "});
  47. TEST("1\\\\\\\" ", {"1\\\""});
  48. TEST("1\\\\\\\\\" ", {"1\\\\ "});
  49. TEST("1\" 1 ", {"1 1 "});
  50. TEST("1\\\" 1 ", {"1\"" C "1"});
  51. TEST("1\\1 ", {"1\\1"});
  52. TEST("1\\\\1 ", {"1\\\\1"});
  53. }
  54. int main(int, char*[])
  55. {
  56. test_winmain();
  57. return 0;
  58. }
  59. #else
  60. int main(int, char*[])
  61. {
  62. return 0;
  63. }
  64. #endif