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