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
6 #if defined(_WIN32)
7 #include <string>
8 #include <vector>
9 #include <cctype>
10 #include <iostream>
11 #include <stdlib.h>
12
13 using namespace std;
14
15 #include <boost/program_options/parsers.hpp>
16 using namespace boost::program_options;
17
check_equal(const std::vector<string> & actual,char ** expected,int n)18 void check_equal(const std::vector<string>& actual, char **expected, int n)
19 {
20 if (actual.size() != n)
21 {
22 std::cerr << "Size mismatch between expected and actual data\n";
23 abort();
24 }
25 for (int i = 0; i < n; ++i)
26 {
27 if (actual[i] != expected[i])
28 {
29 std::cerr << "Unexpected content\n";
30 abort();
31 }
32 }
33 }
34
35 #include <boost/preprocessor/cat.hpp>
36
test_winmain()37 void test_winmain()
38 {
39
40 #define C ,
41 #define TEST(input, expected) \
42 char* BOOST_PP_CAT(e, __LINE__)[] = expected;\
43 vector<string> BOOST_PP_CAT(v, __LINE__) = split_winmain(input);\
44 check_equal(BOOST_PP_CAT(v, __LINE__), BOOST_PP_CAT(e, __LINE__),\
45 sizeof(BOOST_PP_CAT(e, __LINE__))/sizeof(char*));
46
47 // The following expectations were obtained in Win2000 shell:
48 TEST("1 ", {"1"});
49 TEST("1\"2\" ", {"12"});
50 TEST("1\"2 ", {"12 "});
51 TEST("1\"\\\"2\" ", {"1\"2"});
52 TEST("\"1\" \"2\" ", {"1" C "2"});
53 TEST("1\\\" ", {"1\""});
54 TEST("1\\\\\" ", {"1\\ "});
55 TEST("1\\\\\\\" ", {"1\\\""});
56 TEST("1\\\\\\\\\" ", {"1\\\\ "});
57
58 TEST("1\" 1 ", {"1 1 "});
59 TEST("1\\\" 1 ", {"1\"" C "1"});
60 TEST("1\\1 ", {"1\\1"});
61 TEST("1\\\\1 ", {"1\\\\1"});
62 }
63
main(int,char * [])64 int main(int, char*[])
65 {
66 test_winmain();
67 return 0;
68 }
69 #else
main(int,char * [])70 int main(int, char*[])
71 {
72 return 0;
73 }
74 #endif
75