From bfbc1752c4e9877f25b293ca5d8b2acdfb6fc696 Mon Sep 17 00:00:00 2001 From: Beman Date: Mon, 25 Aug 2014 15:47:03 -0400 Subject: [PATCH] Uncomment path_unit_test.cpp lines previously commented out to speed testing. --- test/path_unit_test.cpp | 1393 ++++++++++++++++++++------------------- 1 file changed, 697 insertions(+), 696 deletions(-) diff --git a/test/path_unit_test.cpp b/test/path_unit_test.cpp index 25684e6..c84da48 100644 --- a/test/path_unit_test.cpp +++ b/test/path_unit_test.cpp @@ -37,7 +37,6 @@ #include #include // used constructor tests #include - #include #include #include @@ -141,7 +140,6 @@ namespace std::list wl; // see main() for initialization to w, s, t, r, i, n, g std::vector v; // see main() for initialization to f, u, z std::vector wv; // see main() for initialization to w, f, u, z - class Base {}; class Derived : public Base {}; void fun(const boost::shared_ptr< Base >&) {} @@ -241,381 +239,345 @@ namespace path x; path y; -// // test_assignments ----------------------------------------------------------------// -// -// void test_assignments() -// { -// std::cout << "testing assignments..." << std::endl; -// -// x = path("yet another path"); // another path -// PATH_IS(x, L"yet another path"); -// BOOST_TEST_EQ(x.native().size(), 16U); -// -// x = x; // self-assignment -// PATH_IS(x, L"yet another path"); -// BOOST_TEST_EQ(x.native().size(), 16U); -// -// x.assign(l.begin(), l.end()); // iterator range char -// PATH_IS(x, L"string"); -// -// x.assign(wl.begin(), wl.end()); // iterator range wchar_t -// PATH_IS(x, L"wstring"); -// -// x = string("std::string"); // container char -// PATH_IS(x, L"std::string"); -// -// x = wstring(L"std::wstring"); // container wchar_t -// PATH_IS(x, L"std::wstring"); -// -// x = "array char"; // array char -// PATH_IS(x, L"array char"); -// -// x = L"array wchar"; // array wchar_t -// PATH_IS(x, L"array wchar"); -// -// x = s.c_str(); // const char* null terminated -// PATH_IS(x, L"string"); -// -// x = ws.c_str(); // const wchar_t* null terminated -// PATH_IS(x, L"wstring"); -// } -// -// // test_appends --------------------------------------------------------------------// -// -// void test_appends() -// { -// std::cout << "testing appends..." << std::endl; -// -//# ifdef BOOST_WINDOWS_API -//# define BOOST_FS_FOO L"/foo\\" -//# else // POSIX paths -//# define BOOST_FS_FOO L"/foo/" -//# endif -// -// x = "/foo"; -// x /= path(""); // empty path -// PATH_IS(x, L"/foo"); -// -// x = "/foo"; -// x /= path("/"); // slash path -// PATH_IS(x, L"/foo/"); -// -// x = "/foo"; -// x /= path("/boo"); // slash path -// PATH_IS(x, L"/foo/boo"); -// -// x = "/foo"; -// x /= x; // self-append -// PATH_IS(x, L"/foo/foo"); -// -// x = "/foo"; -// x /= path("yet another path"); // another path -// PATH_IS(x, BOOST_FS_FOO L"yet another path"); -// -// x = "/foo"; -// x.append(l.begin(), l.end()); // iterator range char -// PATH_IS(x, BOOST_FS_FOO L"string"); -// -// x = "/foo"; -// x.append(wl.begin(), wl.end()); // iterator range wchar_t -// PATH_IS(x, BOOST_FS_FOO L"wstring"); -// -// x = "/foo"; -// x /= string("std::string"); // container char -// PATH_IS(x, BOOST_FS_FOO L"std::string"); -// -// x = "/foo"; -// x /= wstring(L"std::wstring"); // container wchar_t -// PATH_IS(x, BOOST_FS_FOO L"std::wstring"); -// -// x = "/foo"; -// x /= "array char"; // array char -// PATH_IS(x, BOOST_FS_FOO L"array char"); -// -// x = "/foo"; -// x /= L"array wchar"; // array wchar_t -// PATH_IS(x, BOOST_FS_FOO L"array wchar"); -// -// x = "/foo"; -// x /= s.c_str(); // const char* null terminated -// PATH_IS(x, BOOST_FS_FOO L"string"); -// -// x = "/foo"; -// x /= ws.c_str(); // const wchar_t* null terminated -// PATH_IS(x, BOOST_FS_FOO L"wstring"); -// } -// -// // test_concats --------------------------------------------------------------------// -// -// void test_concats() -// { -// std::cout << "testing concats..." << std::endl; -// -// x = "/foo"; -// x += path(""); // empty path -// PATH_IS(x, L"/foo"); -// -// x = "/foo"; -// x += path("/"); // slash path -// PATH_IS(x, L"/foo/"); -// -// x = "/foo"; -// x += path("boo"); // slash path -// PATH_IS(x, L"/fooboo"); -// -// x = "foo"; -// x += x; // self-append -// PATH_IS(x, L"foofoo"); -// -// x = "foo-"; -// x += path("yet another path"); // another path -// PATH_IS(x, L"foo-yet another path"); -// -// x = "foo-"; -// x.concat(l.begin(), l.end()); // iterator range char -// PATH_IS(x, L"foo-string"); -// -// x = "foo-"; -// x.concat(wl.begin(), wl.end()); // iterator range wchar_t -// PATH_IS(x, L"foo-wstring"); -// -// x = "foo-"; -// x += string("std::string"); // container char -// PATH_IS(x, L"foo-std::string"); -// -// x = "foo-"; -// x += wstring(L"std::wstring"); // container wchar_t -// PATH_IS(x, L"foo-std::wstring"); -// -// x = "foo-"; -// x += "array char"; // array char -// PATH_IS(x, L"foo-array char"); -// -// x = "foo-"; -// x += L"array wchar"; // array wchar_t -// PATH_IS(x, L"foo-array wchar"); -// -// x = "foo-"; -// x += s.c_str(); // const char* null terminated -// PATH_IS(x, L"foo-string"); -// -// x = "foo-"; -// x += ws.c_str(); // const wchar_t* null terminated -// PATH_IS(x, L"foo-wstring"); -// -// x = "foo-"; -// x += 'x'; // char -// PATH_IS(x, L"foo-x"); -// -// x = "foo-"; -// x += L'x'; // wchar -// PATH_IS(x, L"foo-x"); -// } -// -// // test_observers ------------------------------------------------------------------// -// -// void test_observers() -// { -// std::cout << "testing observers..." << std::endl; -// -// path p0("abc"); -// -// CHECK(p0.native().size() == 3); -// CHECK(p0.string() == "abc"); -// CHECK(p0.string().size() == 3); -// CHECK(p0.wstring() == L"abc"); -// CHECK(p0.wstring().size() == 3); -// -//# ifdef BOOST_WINDOWS_API -// -// path p("abc\\def/ghi"); -// -// CHECK(std::wstring(p.c_str()) == L"abc\\def/ghi"); -// -// CHECK(p.string() == "abc\\def/ghi"); -// CHECK(p.wstring() == L"abc\\def/ghi"); -// -// CHECK(p.generic_string() == "abc/def/ghi"); -// CHECK(p.generic_wstring() == L"abc/def/ghi"); -// -// CHECK(p.generic_string() == "abc/def/ghi"); -// CHECK(p.generic_string() == L"abc/def/ghi"); -// CHECK(p.generic_string() == L"abc/def/ghi"); -// -//# else // BOOST_POSIX_API -// -// path p("abc\\def/ghi"); -// -// CHECK(string(p.c_str()) == "abc\\def/ghi"); -// -// CHECK(p.string() == "abc\\def/ghi"); -// CHECK(p.wstring() == L"abc\\def/ghi"); -// -// CHECK(p.generic_string() == "abc\\def/ghi"); -// CHECK(p.generic_wstring() == L"abc\\def/ghi"); -// -// CHECK(p.generic_string() == "abc\\def/ghi"); -// CHECK(p.generic_string() == L"abc\\def/ghi"); -// CHECK(p.generic_string() == "abc\\def/ghi"); -// -//# endif -// } -// -// // test_relationals ----------------------------------------------------------------// -// -// void test_relationals() -// { -// std::cout << "testing relationals..." << std::endl; -// -// boost::hash hash; -// -//# ifdef BOOST_WINDOWS_API -// // this is a critical use case to meet user expectations -// CHECK(path("c:\\abc") == path("c:/abc")); -// CHECK(hash(path("c:\\abc")) == hash(path("c:/abc"))); -//# endif -// -// const path p("bar"); -// const path p2("baz"); -// -// CHECK(!(p < p)); -// CHECK(p < p2); -// CHECK(!(p2 < p)); -// CHECK(p < "baz"); -// CHECK(p < string("baz")); -// CHECK(p < L"baz"); -// CHECK(p < wstring(L"baz")); -// CHECK(!("baz" < p)); -// CHECK(!(string("baz") < p)); -// CHECK(!(L"baz" < p)); -// CHECK(!(wstring(L"baz") < p)); -// -// CHECK(p == p); -// CHECK(!(p == p2)); -// CHECK(!(p2 == p)); -// CHECK(p2 == "baz"); -// CHECK(p2 == string("baz")); -// CHECK(p2 == L"baz"); -// CHECK(p2 == wstring(L"baz")); -// CHECK("baz" == p2); -// CHECK(string("baz") == p2); -// CHECK(L"baz" == p2); -// CHECK(wstring(L"baz") == p2); -// -// CHECK(hash(p) == hash(p)); -// CHECK(hash(p) != hash(p2)); // Not strictly required, but desirable -// -// CHECK(!(p != p)); -// CHECK(p != p2); -// CHECK(p2 != p); -// -// CHECK(p <= p); -// CHECK(p <= p2); -// CHECK(!(p2 <= p)); -// -// CHECK(!(p > p)); -// CHECK(!(p > p2)); -// CHECK(p2 > p); -// -// CHECK(p >= p); -// CHECK(!(p >= p2)); -// CHECK(p2 >= p); -//} -// -// // test_inserter_and_extractor -----------------------------------------------------// -// -// void test_inserter_and_extractor() -// { -// std::cout << "testing inserter and extractor..." << std::endl; -// -// path p1("foo bar"); // verify space in path roundtrips per ticket #3863 -// path p2; -// -// std::stringstream ss; -// -// CHECK(p1 != p2); -// ss << p1; -// ss >> p2; -// CHECK(p1 == p2); -// -// path wp1(L"foo bar"); -// path wp2; -// -// std::wstringstream wss; -// -// CHECK(wp1 != wp2); -// wss << wp1; -// wss >> wp2; -// CHECK(wp1 == wp2); -// } -// -// // test_other_non_members ----------------------------------------------------------// -// -// void test_other_non_members() -// { -// std::cout << "testing other_non_members..." << std::endl; -// -// path p1("foo"); -// path p2("bar"); -// -// // operator / -// -// CHECK(p1 / p2 == path("foo/bar").make_preferred()); -// CHECK("foo" / p2 == path("foo/bar").make_preferred()); -// CHECK(L"foo" / p2 == path("foo/bar").make_preferred()); -// CHECK(string("foo") / p2 == path("foo/bar").make_preferred()); -// CHECK(wstring(L"foo") / p2 == path("foo/bar").make_preferred()); -// CHECK(p1 / "bar" == path("foo/bar").make_preferred()); -// CHECK(p1 / L"bar" == path("foo/bar").make_preferred()); -// CHECK(p1 / string("bar") == path("foo/bar").make_preferred()); -// CHECK(p1 / wstring(L"bar") == path("foo/bar").make_preferred()); -// -// swap(p1, p2); -// -// CHECK(p1 == "bar"); -// CHECK(p2 == "foo"); -// -// CHECK(path("").remove_filename() == ""); -// CHECK(path("foo").remove_filename() == ""); -// CHECK(path("foo/bar").remove_filename() == "foo"); -// } -// -//// // test_modifiers ------------------------------------------------------------------// -//// -//// void test_modifiers() -//// { -//// std::cout << "testing modifiers..." << std::endl; -//// -//// } -// -// // test_iterators ------------------------------------------------------------------// -// -// void test_iterators() -// { -// std::cout << "testing iterators..." << std::endl; -// -// path p1; -// CHECK(p1.begin() == p1.end()); -// -// path p2("/"); -// CHECK(p2.begin() != p2.end()); -// CHECK(*p2.begin() == "/"); -// CHECK(++p2.begin() == p2.end()); -// -// path p3("foo/bar/baz"); -// -// path::iterator it(p3.begin()); -// CHECK(p3.begin() != p3.end()); -// CHECK(*it == "foo"); -// CHECK(*++it == "bar"); -// CHECK(*++it == "baz"); -// CHECK(*--it == "bar"); -// CHECK(*--it == "foo"); -// CHECK(*++it == "bar"); -// CHECK(*++it == "baz"); -// CHECK(++it == p3.end()); -// } -// + // test_assignments ----------------------------------------------------------------// + + void test_assignments() + { + std::cout << "testing assignments..." << std::endl; + + x = path("yet another path"); // another path + PATH_IS(x, L"yet another path"); + BOOST_TEST_EQ(x.native().size(), 16U); + + x = x; // self-assignment + PATH_IS(x, L"yet another path"); + BOOST_TEST_EQ(x.native().size(), 16U); + + x.assign(l.begin(), l.end()); // iterator range char + PATH_IS(x, L"string"); + + x.assign(wl.begin(), wl.end()); // iterator range wchar_t + PATH_IS(x, L"wstring"); + + x = string("std::string"); // container char + PATH_IS(x, L"std::string"); + + x = wstring(L"std::wstring"); // container wchar_t + PATH_IS(x, L"std::wstring"); + + x = "array char"; // array char + PATH_IS(x, L"array char"); + + x = L"array wchar"; // array wchar_t + PATH_IS(x, L"array wchar"); + + x = s.c_str(); // const char* null terminated + PATH_IS(x, L"string"); + + x = ws.c_str(); // const wchar_t* null terminated + PATH_IS(x, L"wstring"); + } + + // test_appends --------------------------------------------------------------------// + + void test_appends() + { + std::cout << "testing appends..." << std::endl; + +# ifdef BOOST_WINDOWS_API +# define BOOST_FS_FOO L"/foo\\" +# else // POSIX paths +# define BOOST_FS_FOO L"/foo/" +# endif + + x = "/foo"; + x /= path(""); // empty path + PATH_IS(x, L"/foo"); + + x = "/foo"; + x /= path("/"); // slash path + PATH_IS(x, L"/foo/"); + + x = "/foo"; + x /= path("/boo"); // slash path + PATH_IS(x, L"/foo/boo"); + + x = "/foo"; + x /= x; // self-append + PATH_IS(x, L"/foo/foo"); + + x = "/foo"; + x /= path("yet another path"); // another path + PATH_IS(x, BOOST_FS_FOO L"yet another path"); + + x = "/foo"; + x.append(l.begin(), l.end()); // iterator range char + PATH_IS(x, BOOST_FS_FOO L"string"); + + x = "/foo"; + x.append(wl.begin(), wl.end()); // iterator range wchar_t + PATH_IS(x, BOOST_FS_FOO L"wstring"); + + x = "/foo"; + x /= string("std::string"); // container char + PATH_IS(x, BOOST_FS_FOO L"std::string"); + + x = "/foo"; + x /= wstring(L"std::wstring"); // container wchar_t + PATH_IS(x, BOOST_FS_FOO L"std::wstring"); + + x = "/foo"; + x /= "array char"; // array char + PATH_IS(x, BOOST_FS_FOO L"array char"); + + x = "/foo"; + x /= L"array wchar"; // array wchar_t + PATH_IS(x, BOOST_FS_FOO L"array wchar"); + + x = "/foo"; + x /= s.c_str(); // const char* null terminated + PATH_IS(x, BOOST_FS_FOO L"string"); + + x = "/foo"; + x /= ws.c_str(); // const wchar_t* null terminated + PATH_IS(x, BOOST_FS_FOO L"wstring"); + } + + // test_concats --------------------------------------------------------------------// + + void test_concats() + { + std::cout << "testing concats..." << std::endl; + + x = "/foo"; + x += path(""); // empty path + PATH_IS(x, L"/foo"); + + x = "/foo"; + x += path("/"); // slash path + PATH_IS(x, L"/foo/"); + + x = "/foo"; + x += path("boo"); // slash path + PATH_IS(x, L"/fooboo"); + + x = "foo"; + x += x; // self-append + PATH_IS(x, L"foofoo"); + + x = "foo-"; + x += path("yet another path"); // another path + PATH_IS(x, L"foo-yet another path"); + + x = "foo-"; + x.concat(l.begin(), l.end()); // iterator range char + PATH_IS(x, L"foo-string"); + + x = "foo-"; + x.concat(wl.begin(), wl.end()); // iterator range wchar_t + PATH_IS(x, L"foo-wstring"); + + x = "foo-"; + x += string("std::string"); // container char + PATH_IS(x, L"foo-std::string"); + + x = "foo-"; + x += wstring(L"std::wstring"); // container wchar_t + PATH_IS(x, L"foo-std::wstring"); + + x = "foo-"; + x += "array char"; // array char + PATH_IS(x, L"foo-array char"); + + x = "foo-"; + x += L"array wchar"; // array wchar_t + PATH_IS(x, L"foo-array wchar"); + + x = "foo-"; + x += s.c_str(); // const char* null terminated + PATH_IS(x, L"foo-string"); + + x = "foo-"; + x += ws.c_str(); // const wchar_t* null terminated + PATH_IS(x, L"foo-wstring"); + + x = "foo-"; + x += 'x'; // char + PATH_IS(x, L"foo-x"); + + x = "foo-"; + x += L'x'; // wchar + PATH_IS(x, L"foo-x"); + } + + // test_observers ------------------------------------------------------------------// + + void test_observers() + { + std::cout << "testing observers..." << std::endl; + + path p0("abc"); + + CHECK(p0.native().size() == 3); + CHECK(p0.string() == "abc"); + CHECK(p0.string().size() == 3); + CHECK(p0.wstring() == L"abc"); + CHECK(p0.wstring().size() == 3); + +# ifdef BOOST_WINDOWS_API + + path p("abc\\def/ghi"); + + CHECK(std::wstring(p.c_str()) == L"abc\\def/ghi"); + + CHECK(p.string() == "abc\\def/ghi"); + CHECK(p.wstring() == L"abc\\def/ghi"); + + CHECK(p.generic_string() == "abc/def/ghi"); + CHECK(p.generic_wstring() == L"abc/def/ghi"); + + CHECK(p.generic_string() == "abc/def/ghi"); + CHECK(p.generic_string() == L"abc/def/ghi"); + CHECK(p.generic_string() == L"abc/def/ghi"); + +# else // BOOST_POSIX_API + + path p("abc\\def/ghi"); + + CHECK(string(p.c_str()) == "abc\\def/ghi"); + + CHECK(p.string() == "abc\\def/ghi"); + CHECK(p.wstring() == L"abc\\def/ghi"); + + CHECK(p.generic_string() == "abc\\def/ghi"); + CHECK(p.generic_wstring() == L"abc\\def/ghi"); + + CHECK(p.generic_string() == "abc\\def/ghi"); + CHECK(p.generic_string() == L"abc\\def/ghi"); + CHECK(p.generic_string() == "abc\\def/ghi"); + +# endif + } + + // test_relationals ----------------------------------------------------------------// + + void test_relationals() + { + std::cout << "testing relationals..." << std::endl; + + boost::hash hash; + +# ifdef BOOST_WINDOWS_API + // this is a critical use case to meet user expectations + CHECK(path("c:\\abc") == path("c:/abc")); + CHECK(hash(path("c:\\abc")) == hash(path("c:/abc"))); +# endif + + const path p("bar"); + const path p2("baz"); + + CHECK(!(p < p)); + CHECK(p < p2); + CHECK(!(p2 < p)); + CHECK(p < "baz"); + CHECK(p < string("baz")); + CHECK(p < L"baz"); + CHECK(p < wstring(L"baz")); + CHECK(!("baz" < p)); + CHECK(!(string("baz") < p)); + CHECK(!(L"baz" < p)); + CHECK(!(wstring(L"baz") < p)); + + CHECK(p == p); + CHECK(!(p == p2)); + CHECK(!(p2 == p)); + CHECK(p2 == "baz"); + CHECK(p2 == string("baz")); + CHECK(p2 == L"baz"); + CHECK(p2 == wstring(L"baz")); + CHECK("baz" == p2); + CHECK(string("baz") == p2); + CHECK(L"baz" == p2); + CHECK(wstring(L"baz") == p2); + + CHECK(hash(p) == hash(p)); + CHECK(hash(p) != hash(p2)); // Not strictly required, but desirable + + CHECK(!(p != p)); + CHECK(p != p2); + CHECK(p2 != p); + + CHECK(p <= p); + CHECK(p <= p2); + CHECK(!(p2 <= p)); + + CHECK(!(p > p)); + CHECK(!(p > p2)); + CHECK(p2 > p); + + CHECK(p >= p); + CHECK(!(p >= p2)); + CHECK(p2 >= p); +} + + // test_inserter_and_extractor -----------------------------------------------------// + + void test_inserter_and_extractor() + { + std::cout << "testing inserter and extractor..." << std::endl; + + path p1("foo bar"); // verify space in path roundtrips per ticket #3863 + path p2; + + std::stringstream ss; + + CHECK(p1 != p2); + ss << p1; + ss >> p2; + CHECK(p1 == p2); + + path wp1(L"foo bar"); + path wp2; + + std::wstringstream wss; + + CHECK(wp1 != wp2); + wss << wp1; + wss >> wp2; + CHECK(wp1 == wp2); + } + + // test_other_non_members ----------------------------------------------------------// + + void test_other_non_members() + { + std::cout << "testing other_non_members..." << std::endl; + + path p1("foo"); + path p2("bar"); + + // operator / + + CHECK(p1 / p2 == path("foo/bar").make_preferred()); + CHECK("foo" / p2 == path("foo/bar").make_preferred()); + CHECK(L"foo" / p2 == path("foo/bar").make_preferred()); + CHECK(string("foo") / p2 == path("foo/bar").make_preferred()); + CHECK(wstring(L"foo") / p2 == path("foo/bar").make_preferred()); + CHECK(p1 / "bar" == path("foo/bar").make_preferred()); + CHECK(p1 / L"bar" == path("foo/bar").make_preferred()); + CHECK(p1 / string("bar") == path("foo/bar").make_preferred()); + CHECK(p1 / wstring(L"bar") == path("foo/bar").make_preferred()); + + swap(p1, p2); + + CHECK(p1 == "bar"); + CHECK(p2 == "foo"); + + CHECK(path("").remove_filename() == ""); + CHECK(path("foo").remove_filename() == ""); + CHECK(path("foo/bar").remove_filename() == "foo"); + } + // // test_modifiers ------------------------------------------------------------------// // // void test_modifiers() @@ -623,204 +585,243 @@ namespace // std::cout << "testing modifiers..." << std::endl; // // } -// -// // test_decompositions -------------------------------------------------------------// -// -// void test_decompositions() -// { -// std::cout << "testing decompositions..." << std::endl; -// -// CHECK(path("").root_name().string() == ""); -// CHECK(path("foo").root_name().string() == ""); -// CHECK(path("/").root_name().string() == ""); -// CHECK(path("/foo").root_name().string() == ""); -// CHECK(path("//netname").root_name().string() == "//netname"); -// CHECK(path("//netname/foo").root_name().string() == "//netname"); -// -// CHECK(path("").root_directory().string() == ""); -// CHECK(path("foo").root_directory().string() == ""); -// CHECK(path("/").root_directory().string() == "/"); -// CHECK(path("/foo").root_directory().string() == "/"); -// CHECK(path("//netname").root_directory().string() == ""); -// CHECK(path("//netname/foo").root_directory().string() == "/"); -// -// CHECK(path("").root_path().string() == ""); -// CHECK(path("/").root_path().string() == "/"); -// CHECK(path("/foo").root_path().string() == "/"); -// CHECK(path("//netname").root_path().string() == "//netname"); -// CHECK(path("//netname/foo").root_path().string() == "//netname/"); -// -//# ifdef BOOST_WINDOWS_API -// CHECK(path("c:/foo").root_path().string() == "c:/"); -//# endif -// -// CHECK(path("").relative_path().string() == ""); -// CHECK(path("/").relative_path().string() == ""); -// CHECK(path("/foo").relative_path().string() == "foo"); -// -// CHECK(path("").parent_path().string() == ""); -// CHECK(path("/").parent_path().string() == ""); -// CHECK(path("/foo").parent_path().string() == "/"); -// CHECK(path("/foo/bar").parent_path().string() == "/foo"); -// -// CHECK(path("/foo/bar/baz.zoo").filename().string() == "baz.zoo"); -// -// CHECK(path("/foo/bar/baz.zoo").stem().string() == "baz"); -// CHECK(path("/foo/bar.woo/baz").stem().string() == "baz"); -// -// CHECK(path("foo.bar.baz.tar.bz2").extension().string() == ".bz2"); -// CHECK(path("/foo/bar/baz.zoo").extension().string() == ".zoo"); -// CHECK(path("/foo/bar.woo/baz").extension().string() == ""); -// } -// -// // test_queries --------------------------------------------------------------------// -// -// void test_queries() -// { -// std::cout << "testing queries..." << std::endl; -// -// path p1(""); -// path p2("//netname/foo.doo"); -// -// CHECK(p1.empty()); -// CHECK(!p1.has_root_path()); -// CHECK(!p1.has_root_name()); -// CHECK(!p1.has_root_directory()); -// CHECK(!p1.has_relative_path()); -// CHECK(!p1.has_parent_path()); -// CHECK(!p1.has_filename()); -// CHECK(!p1.has_stem()); -// CHECK(!p1.has_extension()); -// CHECK(!p1.is_absolute()); -// CHECK(p1.is_relative()); -// -// CHECK(!p2.empty()); -// CHECK(p2.has_root_path()); -// CHECK(p2.has_root_name()); -// CHECK(p2.has_root_directory()); -// CHECK(p2.has_relative_path()); -// CHECK(p2.has_parent_path()); -// CHECK(p2.has_filename()); -// CHECK(p2.has_stem()); -// CHECK(p2.has_extension()); -// CHECK(p2.is_absolute()); -// CHECK(!p2.is_relative()); -// -// } -// -// // test_imbue_locale ---------------------------------------------------------------// -// -// void test_imbue_locale() -// { -// std::cout << "testing imbue locale..." << std::endl; -// -// // weak test case for before/after states since we don't know what characters the -// // default locale accepts. -// path before("abc"); -// -// // So that tests are run with known encoding, use Boost UTF-8 codecvt -// // \u2722 and \xE2\x9C\xA2 are UTF-16 and UTF-8 FOUR TEARDROP-SPOKED ASTERISK -// -// std::locale global_loc = std::locale(); -// std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet); -// std::cout << " imbuing locale ..." << std::endl; -// std::locale old_loc = path::imbue(loc); -// -// std::cout << " testing with the imbued locale ..." << std::endl; -// path p2("\xE2\x9C\xA2"); -// CHECK(p2.wstring().size() == 1); -// CHECK(p2.wstring()[0] == 0x2722); -// -// std::cout << " imbuing the original locale ..." << std::endl; -// path::imbue(old_loc); -// -// std::cout << " testing with the original locale ..." << std::endl; -// path after("abc"); -// CHECK(before == after); -// -// std::cout << " locale testing complete" << std::endl; -// } -// -// // test_codecvt_argument -----------------------------------------------------------// -// -// void test_codecvt_argument() -// { -// std::cout << "testing codecvt arguments..." << std::endl; -// -// const char * c1 = "a1"; -// const std::string s1(c1); -// const std::wstring ws1(L"b2"); // off-by-one mimics test_codecvt -// const std::string s2("y8"); -// const std::wstring ws2(L"z9"); -// -// test_codecvt cvt; // produces off-by-one values that will always differ from -// // the system's default locale codecvt facet -// -// int t = 0; -// -// // constructors -// std::cout << " constructors test " << ++t << std::endl; -// path p(c1, cvt); -// NATIVE_IS(p, s1, ws1); -// -// std::cout << " test " << ++t << std::endl; -// path p1(s1.begin(), s1.end(), cvt); -// NATIVE_IS(p1, s1, ws1); -// -// std::cout << " test " << ++t << std::endl; -// path p2(ws2, cvt); -// NATIVE_IS(p2, s2, ws2); -// -// std::cout << " test " << ++t << std::endl; -// path p3(ws2.begin(), ws2.end(), cvt); -// NATIVE_IS(p3, s2, ws2); -// -// // path p2(p1, cvt); // fails to compile, and that is OK -// -// // assigns -// p1.clear(); -// std::cout << " assigns test " << ++t << std::endl; -// p1.assign(s1,cvt); -// NATIVE_IS(p1, s1, ws1); -// p1.clear(); -// std::cout << " test " << ++t << std::endl; -// p1.assign(s1.begin(), s1.end(), cvt); -// NATIVE_IS(p1, s1, ws1); -// // p1.assign(p, cvt); // fails to compile, and that is OK -// -// // appends -// p1.clear(); -// std::cout << " appends test " << ++t << std::endl; -// p1.append(s1,cvt); -// NATIVE_IS(p1, s1, ws1); -// p1.clear(); -// std::cout << " test " << ++t << std::endl; -// p1.append(s1.begin(), s1.end(), cvt); -// NATIVE_IS(p1, s1, ws1); -// // p1.append(p, cvt); // fails to compile, and that is OK -// -// // native observers -// std::cout << " native observers test " << ++t << std::endl; -// CHECK(p.string(cvt) == s1); -// std::cout << " test " << ++t << std::endl; -// CHECK(p.string(cvt) == s1); -// std::cout << " test " << ++t << std::endl; -// CHECK(p.string(cvt) == ws1); -// std::cout << " test " << ++t << std::endl; -// CHECK(p.wstring(cvt) == ws1); -// -// // generic observers -// std::cout << " generic observers test " << ++t << std::endl; -// CHECK(p.generic_string(cvt) == s1); -// std::cout << " test " << ++t << std::endl; -// CHECK(p.generic_string(cvt) == s1); -// std::cout << " test " << ++t << std::endl; -// CHECK(p.generic_string(cvt) == ws1); -// std::cout << " test " << ++t << std::endl; -// CHECK(p.generic_wstring(cvt) == ws1); -// -// std::cout << " codecvt arguments testing complete" << std::endl; -// } + + // test_iterators ------------------------------------------------------------------// + + void test_iterators() + { + std::cout << "testing iterators..." << std::endl; + + path p1; + CHECK(p1.begin() == p1.end()); + + path p2("/"); + CHECK(p2.begin() != p2.end()); + CHECK(*p2.begin() == "/"); + CHECK(++p2.begin() == p2.end()); + + path p3("foo/bar/baz"); + + path::iterator it(p3.begin()); + CHECK(p3.begin() != p3.end()); + CHECK(*it == "foo"); + CHECK(*++it == "bar"); + CHECK(*++it == "baz"); + CHECK(*--it == "bar"); + CHECK(*--it == "foo"); + CHECK(*++it == "bar"); + CHECK(*++it == "baz"); + CHECK(++it == p3.end()); + } + + // test_modifiers ------------------------------------------------------------------// + + void test_modifiers() + { + std::cout << "testing modifiers..." << std::endl; + + } + + // test_decompositions -------------------------------------------------------------// + + void test_decompositions() + { + std::cout << "testing decompositions..." << std::endl; + + CHECK(path("").root_name().string() == ""); + CHECK(path("foo").root_name().string() == ""); + CHECK(path("/").root_name().string() == ""); + CHECK(path("/foo").root_name().string() == ""); + CHECK(path("//netname").root_name().string() == "//netname"); + CHECK(path("//netname/foo").root_name().string() == "//netname"); + + CHECK(path("").root_directory().string() == ""); + CHECK(path("foo").root_directory().string() == ""); + CHECK(path("/").root_directory().string() == "/"); + CHECK(path("/foo").root_directory().string() == "/"); + CHECK(path("//netname").root_directory().string() == ""); + CHECK(path("//netname/foo").root_directory().string() == "/"); + + CHECK(path("").root_path().string() == ""); + CHECK(path("/").root_path().string() == "/"); + CHECK(path("/foo").root_path().string() == "/"); + CHECK(path("//netname").root_path().string() == "//netname"); + CHECK(path("//netname/foo").root_path().string() == "//netname/"); + +# ifdef BOOST_WINDOWS_API + CHECK(path("c:/foo").root_path().string() == "c:/"); +# endif + + CHECK(path("").relative_path().string() == ""); + CHECK(path("/").relative_path().string() == ""); + CHECK(path("/foo").relative_path().string() == "foo"); + + CHECK(path("").parent_path().string() == ""); + CHECK(path("/").parent_path().string() == ""); + CHECK(path("/foo").parent_path().string() == "/"); + CHECK(path("/foo/bar").parent_path().string() == "/foo"); + + CHECK(path("/foo/bar/baz.zoo").filename().string() == "baz.zoo"); + + CHECK(path("/foo/bar/baz.zoo").stem().string() == "baz"); + CHECK(path("/foo/bar.woo/baz").stem().string() == "baz"); + + CHECK(path("foo.bar.baz.tar.bz2").extension().string() == ".bz2"); + CHECK(path("/foo/bar/baz.zoo").extension().string() == ".zoo"); + CHECK(path("/foo/bar.woo/baz").extension().string() == ""); + } + + // test_queries --------------------------------------------------------------------// + + void test_queries() + { + std::cout << "testing queries..." << std::endl; + + path p1(""); + path p2("//netname/foo.doo"); + + CHECK(p1.empty()); + CHECK(!p1.has_root_path()); + CHECK(!p1.has_root_name()); + CHECK(!p1.has_root_directory()); + CHECK(!p1.has_relative_path()); + CHECK(!p1.has_parent_path()); + CHECK(!p1.has_filename()); + CHECK(!p1.has_stem()); + CHECK(!p1.has_extension()); + CHECK(!p1.is_absolute()); + CHECK(p1.is_relative()); + + CHECK(!p2.empty()); + CHECK(p2.has_root_path()); + CHECK(p2.has_root_name()); + CHECK(p2.has_root_directory()); + CHECK(p2.has_relative_path()); + CHECK(p2.has_parent_path()); + CHECK(p2.has_filename()); + CHECK(p2.has_stem()); + CHECK(p2.has_extension()); + CHECK(p2.is_absolute()); + CHECK(!p2.is_relative()); + + } + + // test_imbue_locale ---------------------------------------------------------------// + + void test_imbue_locale() + { + std::cout << "testing imbue locale..." << std::endl; + + // weak test case for before/after states since we don't know what characters the + // default locale accepts. + path before("abc"); + + // So that tests are run with known encoding, use Boost UTF-8 codecvt + // \u2722 and \xE2\x9C\xA2 are UTF-16 and UTF-8 FOUR TEARDROP-SPOKED ASTERISK + + std::locale global_loc = std::locale(); + std::locale loc(global_loc, new fs::detail::utf8_codecvt_facet); + std::cout << " imbuing locale ..." << std::endl; + std::locale old_loc = path::imbue(loc); + + std::cout << " testing with the imbued locale ..." << std::endl; + path p2("\xE2\x9C\xA2"); + CHECK(p2.wstring().size() == 1); + CHECK(p2.wstring()[0] == 0x2722); + + std::cout << " imbuing the original locale ..." << std::endl; + path::imbue(old_loc); + + std::cout << " testing with the original locale ..." << std::endl; + path after("abc"); + CHECK(before == after); + + std::cout << " locale testing complete" << std::endl; + } + + // test_codecvt_argument -----------------------------------------------------------// + + void test_codecvt_argument() + { +#ifndef BOOST_FILESYSTEM_TS + + std::cout << "testing codecvt arguments..." << std::endl; + + const char * c1 = "a1"; + const std::string s1(c1); + const std::wstring ws1(L"b2"); // off-by-one mimics test_codecvt + const std::string s2("y8"); + const std::wstring ws2(L"z9"); + + test_codecvt cvt; // produces off-by-one values that will always differ from + // the system's default locale codecvt facet + + int t = 0; + + // constructors + std::cout << " constructors test " << ++t << std::endl; + path p(c1, cvt); + NATIVE_IS(p, s1, ws1); + + std::cout << " test " << ++t << std::endl; + path p1(s1.begin(), s1.end(), cvt); + NATIVE_IS(p1, s1, ws1); + + std::cout << " test " << ++t << std::endl; + path p2(ws2, cvt); + NATIVE_IS(p2, s2, ws2); + + std::cout << " test " << ++t << std::endl; + path p3(ws2.begin(), ws2.end(), cvt); + NATIVE_IS(p3, s2, ws2); + + // path p2(p1, cvt); // fails to compile, and that is OK + + // assigns + p1.clear(); + std::cout << " assigns test " << ++t << std::endl; + p1.assign(s1,cvt); + NATIVE_IS(p1, s1, ws1); + p1.clear(); + std::cout << " test " << ++t << std::endl; + p1.assign(s1.begin(), s1.end(), cvt); + NATIVE_IS(p1, s1, ws1); + // p1.assign(p, cvt); // fails to compile, and that is OK + + // appends + p1.clear(); + std::cout << " appends test " << ++t << std::endl; + p1.append(s1,cvt); + NATIVE_IS(p1, s1, ws1); + p1.clear(); + std::cout << " test " << ++t << std::endl; + p1.append(s1.begin(), s1.end(), cvt); + NATIVE_IS(p1, s1, ws1); + // p1.append(p, cvt); // fails to compile, and that is OK + + // native observers + std::cout << " native observers test " << ++t << std::endl; + CHECK(p.string(cvt) == s1); + std::cout << " test " << ++t << std::endl; + CHECK(p.string(cvt) == s1); + std::cout << " test " << ++t << std::endl; + CHECK(p.string(cvt) == ws1); + std::cout << " test " << ++t << std::endl; + CHECK(p.wstring(cvt) == ws1); + + // generic observers + std::cout << " generic observers test " << ++t << std::endl; + CHECK(p.generic_string(cvt) == s1); + std::cout << " test " << ++t << std::endl; + CHECK(p.generic_string(cvt) == s1); + std::cout << " test " << ++t << std::endl; + CHECK(p.generic_string(cvt) == ws1); + std::cout << " test " << ++t << std::endl; + CHECK(p.generic_wstring(cvt) == ws1); + + std::cout << " codecvt arguments testing complete" << std::endl; +#endif + } // test_overloads ------------------------------------------------------------------// @@ -842,112 +843,112 @@ namespace path wp4(L"foo"); } -// // test_error_handling -------------------------------------------------------------// -// -// class error_codecvt -// : public std::codecvt< wchar_t, char, std::mbstate_t > -// { -// public: -// explicit error_codecvt() -// : std::codecvt() {} -// protected: -// -// virtual bool do_always_noconv() const throw() { return false; } -// virtual int do_encoding() const throw() { return 0; } -// -// virtual std::codecvt_base::result do_in(std::mbstate_t&, -// const char*, const char*, const char*&, -// wchar_t*, wchar_t*, wchar_t*&) const -// { -// static std::codecvt_base::result r = std::codecvt_base::noconv; -// if (r == std::codecvt_base::partial) r = std::codecvt_base::error; -// else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv; -// else r = std::codecvt_base::partial; -// return r; -// } -// -// virtual std::codecvt_base::result do_out(std::mbstate_t &, -// const wchar_t*, const wchar_t*, const wchar_t*&, -// char*, char*, char*&) const -// { -// static std::codecvt_base::result r = std::codecvt_base::noconv; -// if (r == std::codecvt_base::partial) r = std::codecvt_base::error; -// else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv; -// else r = std::codecvt_base::partial; -// return r; -// } -// -// virtual std::codecvt_base::result do_unshift(std::mbstate_t&, -// char*, char*, char* &) const { return ok; } -// virtual int do_length(std::mbstate_t &, -// const char*, const char*, std::size_t) const { return 0; } -// virtual int do_max_length() const throw () { return 0; } -// }; -// -// void test_error_handling() -// { -// std::cout << "testing error handling..." << std::endl; -// -// std::locale global_loc = std::locale(); -// std::locale loc(global_loc, new error_codecvt); -// std::cout << " imbuing error locale ..." << std::endl; -// std::locale old_loc = path::imbue(loc); -// -// // These tests rely on a path constructor that fails in the locale conversion. -// // Thus construction has to call codecvt. Force that by using a narrow string -// // for Windows, and a wide string for POSIX. -//# ifdef BOOST_WINDOWS_API -//# define STRING_FOO_ "foo" -//# else -//# define STRING_FOO_ L"foo" -//# endif -// -// { -// std::cout << " testing std::codecvt_base::partial error..." << std::endl; -// bool exception_thrown (false); -// try { path(STRING_FOO_); } -// catch (const bs::system_error & ex) -// { -// exception_thrown = true; -// BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, -// fs::codecvt_error_category())); -// } -// catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } -// BOOST_TEST(exception_thrown); -// } -// -// { -// std::cout << " testing std::codecvt_base::error error..." << std::endl; -// bool exception_thrown (false); -// try { path(STRING_FOO_); } -// catch (const bs::system_error & ex) -// { -// exception_thrown = true; -// BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, -// fs::codecvt_error_category())); -// } -// catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } -// BOOST_TEST(exception_thrown); -// } -// -// { -// std::cout << " testing std::codecvt_base::noconv error..." << std::endl; -// bool exception_thrown (false); -// try { path(STRING_FOO_); } -// catch (const bs::system_error & ex) -// { -// exception_thrown = true; -// BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv, -// fs::codecvt_error_category())); -// } -// catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } -// BOOST_TEST(exception_thrown); -// } -// -// std::cout << " restoring original locale ..." << std::endl; -// path::imbue(old_loc); -// std::cout << " testing error handling complete" << std::endl; -// } + // test_error_handling -------------------------------------------------------------// + + class error_codecvt + : public std::codecvt< wchar_t, char, std::mbstate_t > + { + public: + explicit error_codecvt() + : std::codecvt() {} + protected: + + virtual bool do_always_noconv() const throw() { return false; } + virtual int do_encoding() const throw() { return 0; } + + virtual std::codecvt_base::result do_in(std::mbstate_t&, + const char*, const char*, const char*&, + wchar_t*, wchar_t*, wchar_t*&) const + { + static std::codecvt_base::result r = std::codecvt_base::noconv; + if (r == std::codecvt_base::partial) r = std::codecvt_base::error; + else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv; + else r = std::codecvt_base::partial; + return r; + } + + virtual std::codecvt_base::result do_out(std::mbstate_t &, + const wchar_t*, const wchar_t*, const wchar_t*&, + char*, char*, char*&) const + { + static std::codecvt_base::result r = std::codecvt_base::noconv; + if (r == std::codecvt_base::partial) r = std::codecvt_base::error; + else if (r == std::codecvt_base::error) r = std::codecvt_base::noconv; + else r = std::codecvt_base::partial; + return r; + } + + virtual std::codecvt_base::result do_unshift(std::mbstate_t&, + char*, char*, char* &) const { return ok; } + virtual int do_length(std::mbstate_t &, + const char*, const char*, std::size_t) const { return 0; } + virtual int do_max_length() const throw () { return 0; } + }; + + void test_error_handling() + { + std::cout << "testing error handling..." << std::endl; + + std::locale global_loc = std::locale(); + std::locale loc(global_loc, new error_codecvt); + std::cout << " imbuing error locale ..." << std::endl; + std::locale old_loc = path::imbue(loc); + + // These tests rely on a path constructor that fails in the locale conversion. + // Thus construction has to call codecvt. Force that by using a narrow string + // for Windows, and a wide string for POSIX. +# ifdef BOOST_WINDOWS_API +# define STRING_FOO_ "foo" +# else +# define STRING_FOO_ L"foo" +# endif + + { + std::cout << " testing std::codecvt_base::partial error..." << std::endl; + bool exception_thrown (false); + try { path(STRING_FOO_); } + catch (const bs::system_error & ex) + { + exception_thrown = true; + BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::partial, + fs::codecvt_error_category())); + } + catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } + BOOST_TEST(exception_thrown); + } + + { + std::cout << " testing std::codecvt_base::error error..." << std::endl; + bool exception_thrown (false); + try { path(STRING_FOO_); } + catch (const bs::system_error & ex) + { + exception_thrown = true; + BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::error, + fs::codecvt_error_category())); + } + catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } + BOOST_TEST(exception_thrown); + } + + { + std::cout << " testing std::codecvt_base::noconv error..." << std::endl; + bool exception_thrown (false); + try { path(STRING_FOO_); } + catch (const bs::system_error & ex) + { + exception_thrown = true; + BOOST_TEST_EQ(ex.code(), bs::error_code(std::codecvt_base::noconv, + fs::codecvt_error_category())); + } + catch (...) { std::cout << "***** unexpected exception type *****" << std::endl; } + BOOST_TEST(exception_thrown); + } + + std::cout << " restoring original locale ..." << std::endl; + path::imbue(old_loc); + std::cout << " testing error handling complete" << std::endl; + } # if 0 @@ -1073,23 +1074,23 @@ int cpp_main(int, char*[]) wv.push_back(L'f'); wv.push_back(L'u'); wv.push_back(L'z'); - + test_overloads(); test_constructors(); - //test_assignments(); - //test_appends(); - //test_concats(); - //test_modifiers(); - //test_observers(); - //test_relationals(); - //test_inserter_and_extractor(); - //test_other_non_members(); - //test_iterators(); - //test_decompositions(); - //test_queries(); - //test_imbue_locale(); - //test_codecvt_argument(); - //test_error_handling(); + test_assignments(); + test_appends(); + test_concats(); + test_modifiers(); + test_observers(); + test_relationals(); + test_inserter_and_extractor(); + test_other_non_members(); + test_iterators(); + test_decompositions(); + test_queries(); + test_imbue_locale(); + test_codecvt_argument(); + test_error_handling(); #if 0