// ---------------------------------------------------------------------------- // Copyright (C) 2002-2006 Marcin Kalicinski // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // For more information, see www.boost.org // ---------------------------------------------------------------------------- #include "test_utils.hpp" #include #include #include #include namespace { // Test arguments char *argv[] = { "c:\\program.exe", "-Isrc/include1", " file2.cc ", "/L src/lib1", "-Lsrc/lib2", "/ooutput", "file1.cc", "-g", "-", "/", " /Isrc/include2 ", " file3.cc ", "-I src/include3 " }; // Test arguments count const int argc = sizeof(argv) / sizeof(*argv); } template void test_cmdline_parser() { using namespace boost::property_tree; typedef typename Ptree::key_type::value_type Ch; typedef std::basic_string Str; // Prepare arguments of proper char type std::vector p; std::vector strings; strings.reserve(argc); for (int i = 0; i < argc; ++i) { strings.push_back(detail::widen(argv[i])); p.push_back(const_cast(strings.back().c_str())); } Ptree pt1; read_cmdline(argc, &p.front(), detail::widen("-/"), pt1); // Check indices BOOST_CHECK(pt1.template get_optional(detail::widen("L.0")).get() == detail::widen("src/lib1")); BOOST_CHECK(pt1.template get_optional(detail::widen("L.1")).get() == detail::widen("src/lib2")); BOOST_CHECK(!pt1.template get_optional(detail::widen("L.2"))); BOOST_CHECK(pt1.template get_optional(detail::widen(".0")).get() == detail::widen("c:\\program.exe")); BOOST_CHECK(pt1.template get_optional(detail::widen(".1")).get() == detail::widen("file2.cc")); BOOST_CHECK(pt1.template get_optional(detail::widen(".2")).get() == detail::widen("file1.cc")); BOOST_CHECK(pt1.template get_optional(detail::widen(".3")).get() == detail::widen("file3.cc")); BOOST_CHECK(!pt1.template get_optional(detail::widen(".4"))); // Check total sizes //std::cerr << total_size(pt1) << " " << total_data_size(pt1) << " " << total_keys_size(pt1) << "\n"; BOOST_CHECK(total_size(pt1) == 21); BOOST_CHECK(total_data_size(pt1) == 130); BOOST_CHECK(total_keys_size(pt1) == 19); Ptree pt2; read_cmdline(argc, &p.front(), detail::widen("-"), pt2); // Check indices BOOST_CHECK(pt2.template get_optional(detail::widen("L.0")).get() == detail::widen("src/lib2")); BOOST_CHECK(!pt2.template get_optional(detail::widen("L.1"))); // Check total sizes //std::cerr << total_size(pt2) << " " << total_data_size(pt2) << " " << total_keys_size(pt2) << "\n"; BOOST_CHECK(total_size(pt2) == 19); BOOST_CHECK(total_data_size(pt2) == 135); BOOST_CHECK(total_keys_size(pt2) == 17); Ptree pt3; read_cmdline(argc, &p.front(), detail::widen("/"), pt3); // Check indices BOOST_CHECK(pt3.template get_optional(detail::widen("L.0")).get() == detail::widen("src/lib1")); BOOST_CHECK(!pt3.template get_optional(detail::widen("L.1"))); // Check total sizes //std::cerr << total_size(pt3) << " " << total_data_size(pt3) << " " << total_keys_size(pt3) << "\n"; BOOST_CHECK(total_size(pt3) == 19); BOOST_CHECK(total_data_size(pt3) == 149); BOOST_CHECK(total_keys_size(pt3) == 17); } int test_main(int argc, char *argv[]) { using namespace boost::property_tree; test_cmdline_parser(); #ifndef BOOST_NO_CWCHAR test_cmdline_parser(); #endif return 0; }