]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/test/unit/path_test.cpp
1 /*=============================================================================
2 Copyright (c) 2015 Daniel James
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/filesystem/operations.hpp>
11 #include <boost/predef.h>
14 void file_path_to_url_tests()
16 using boost::filesystem::path
;
17 using quickbook::file_path_to_url
;
19 BOOST_TEST_EQ(std::string(), file_path_to_url(path()));
20 BOOST_TEST_EQ(std::string("."), file_path_to_url(path(".")));
21 BOOST_TEST_EQ(std::string("./"), file_path_to_url(path("./")));
22 BOOST_TEST_EQ(std::string("a/b"), file_path_to_url(path("a/b")));
23 BOOST_TEST_EQ(std::string("a/b/"), file_path_to_url(path("a/b/")));
24 BOOST_TEST_EQ(std::string("./a/b"), file_path_to_url(path("./a/./././b")));
25 BOOST_TEST_EQ(std::string("../a/b"), file_path_to_url(path("../a/b")));
27 std::string("A%20B%2bC%2520"), file_path_to_url(path("A B+C%20")));
28 BOOST_TEST_EQ(std::string("file:///"), file_path_to_url(path("/")));
29 BOOST_TEST_EQ(std::string("file:///a/b"), file_path_to_url(path("/a/b")));
30 BOOST_TEST_EQ(std::string("file:///a/b/"), file_path_to_url(path("/a/b/")));
32 std::string("file://hello/a/b"), file_path_to_url(path("//hello/a/b")));
34 #if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN
35 // Should this be file:///c:/x ?
37 std::string("file://?/a:/x"), file_path_to_url(path("\\\\?\\a:\\x")));
38 BOOST_TEST_EQ(std::string("file:///a"), file_path_to_url(path("\\a")));
39 BOOST_TEST_EQ(std::string("file:///c:/"), file_path_to_url(path("c:\\")));
41 std::string("file:///c:/foo/bar"),
42 file_path_to_url(path("c:\\foo\\bar")));
44 std::string("file://localhost/c:/foo/bar"),
45 file_path_to_url(path("\\\\localhost\\c:\\foo\\bar")));
47 // Really not sure what to do with these examples.
49 BOOST_TEST_EQ(std::string("file:///c:"), file_path_to_url(path("c:")));
51 std::string("file:///c:foo/bar"), file_path_to_url(path("c:foo\\bar")));
55 void dir_path_to_url_tests()
57 using boost::filesystem::path
;
58 using quickbook::dir_path_to_url
;
60 BOOST_TEST_EQ(std::string("./"), dir_path_to_url(path()));
61 BOOST_TEST_EQ(std::string("./"), dir_path_to_url(path(".")));
62 BOOST_TEST_EQ(std::string("./"), dir_path_to_url(path("./")));
63 BOOST_TEST_EQ(std::string("a/b/"), dir_path_to_url(path("a/b")));
64 BOOST_TEST_EQ(std::string("a/b/"), dir_path_to_url(path("a/b/")));
65 BOOST_TEST_EQ(std::string("./a/b/"), dir_path_to_url(path("./a/./././b")));
66 BOOST_TEST_EQ(std::string("../a/b/"), dir_path_to_url(path("../a/b")));
68 std::string("A%20B%2bC%2520/"), dir_path_to_url(path("A B+C%20")));
69 BOOST_TEST_EQ(std::string("file:///"), dir_path_to_url(path("/")));
70 BOOST_TEST_EQ(std::string("file:///a/b/"), dir_path_to_url(path("/a/b")));
71 BOOST_TEST_EQ(std::string("file:///a/b/"), dir_path_to_url(path("/a/b/")));
73 std::string("file://hello/a/b/"), dir_path_to_url(path("//hello/a/b")));
75 #if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN
76 // Should this be file:///c:/x/ ?
78 std::string("file://?/a:/x/"), dir_path_to_url(path("\\\\?\\a:\\x")));
79 BOOST_TEST_EQ(std::string("file:///a/"), dir_path_to_url(path("\\a")));
80 BOOST_TEST_EQ(std::string("file:///c:/"), dir_path_to_url(path("c:\\")));
82 std::string("file:///c:/foo/bar/"),
83 dir_path_to_url(path("c:\\foo\\bar")));
85 std::string("file://localhost/c:/foo/bar/"),
86 dir_path_to_url(path("\\\\localhost\\c:\\foo\\bar")));
88 // Really not sure what to do with these examples.
90 BOOST_TEST_EQ(std::string("file:///c:"), dir_path_to_url(path("c:")));
92 std::string("file:///c:foo/bar/"), dir_path_to_url(path("c:foo\\bar")));
96 void path_difference_tests()
98 using boost::filesystem::current_path
;
99 using boost::filesystem::path
;
100 using quickbook::path_difference
;
102 BOOST_TEST(path(".") == path_difference(path(""), path("")));
103 BOOST_TEST(path(".") == path_difference(path("a"), path("a")));
104 BOOST_TEST(path(".") == path_difference(path("a/../b"), path("b")));
105 BOOST_TEST(path(".") == path_difference(current_path(), current_path()));
106 BOOST_TEST(path("..") == path_difference(path("a"), path("")));
108 path("..") == path_difference(current_path() / "a", current_path()));
109 BOOST_TEST(path("a") == path_difference(path(""), path("a")));
111 path("a") == path_difference(current_path(), current_path() / "a"));
112 BOOST_TEST(path("b") == path_difference(path("a"), path("a/b")));
115 path_difference(current_path() / "a", current_path() / "a" / "b"));
116 BOOST_TEST(path("../a/b") == path_difference(path("c"), path("a/b")));
119 path_difference(current_path() / "c", current_path() / "a" / "b"));
120 BOOST_TEST(path("..") == path_difference(path(""), path("..")));
123 path_difference(current_path(), current_path().parent_path()));
124 BOOST_TEST(path("b") == path_difference(path("a/c/.."), path("a/b")));
125 BOOST_TEST(path("b") == path_difference(path("b/c/../../a"), path("a/b")));
128 path_difference(path("b/c/../../a"), path("d/f/../../a/b")));
130 path("../../x/a/b") ==
131 path_difference(path("b/c/../../a"), path("d/f/../../../x/a/b")));
133 // path_difference to a file, try to include the filename in the result,
134 // although not always possible. Maybe nonsense calls should be an error?
136 // Commented out cases are wrong because path_difference resolves the paths
137 // to the current working directory. In use this doesn't matter as it's
138 // always called with the full path, but it'd be nice to get this right.
139 // Or maybe just add the pre-condition to path_difference?
140 std::cout
<< path_difference(path(""), path(""), true) << std::endl
;
141 // BOOST_TEST(path(".") == path_difference(path(""), path(""), true));
142 BOOST_TEST(path("../a") == path_difference(path("a"), path("a"), true));
144 path("../../a") == path_difference(path("a/b"), path("a"), true));
146 path("../b") == path_difference(path("a/../b"), path("b"), true));
148 ".." / current_path().filename() ==
149 path_difference(current_path(), current_path(), true));
150 // BOOST_TEST(path("..") == path_difference(path("a"), path(""), true));
152 "../.." / current_path().filename() ==
153 path_difference(current_path() / "a", current_path(), true));
154 BOOST_TEST(path("a") == path_difference(path(""), path("a"), true));
157 path_difference(current_path(), current_path() / "a", true));
158 BOOST_TEST(path("b") == path_difference(path("a"), path("a/b"), true));
162 current_path() / "a", current_path() / "a" / "b", true));
163 BOOST_TEST(path("../a/b") == path_difference(path("c"), path("a/b"), true));
167 current_path() / "c", current_path() / "a" / "b", true));
168 // BOOST_TEST(path("..") == path_difference(path(""), path(".."), true));
170 "../.." / current_path().parent_path().filename() ==
171 path_difference(current_path(), current_path().parent_path(), true));
172 BOOST_TEST(path("b") == path_difference(path("a/c/.."), path("a/b"), true));
174 path("b") == path_difference(path("b/c/../../a"), path("a/b"), true));
177 path_difference(path("b/c/../../a"), path("d/f/../../a/b"), true));
179 path("../../x/a/b") ==
180 path_difference(path("b/c/../../a"), path("d/f/../../../x/a/b"), true));
185 file_path_to_url_tests();
186 dir_path_to_url_tests();
187 path_difference_tests();
188 return boost::report_errors();