]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // filesystem relative_test.cpp ---------------------------------------------------- // |
2 | ||
3 | // Copyright Beman Dawes 2015 | |
4 | ||
5 | // Distributed under the Boost Software License, Version 1.0. | |
6 | // See http://www.boost.org/LICENSE_1_0.txt | |
7 | ||
8 | // Library home page: http://www.boost.org/libs/filesystem | |
9 | ||
10 | // ---------------------------------------------------------------------------------- // | |
11 | // | |
12 | // At least initially, development is easier if these tests are in a separate file. | |
13 | // | |
14 | // ---------------------------------------------------------------------------------- // | |
15 | ||
16 | #include <boost/config/warning_disable.hpp> | |
17 | #include <boost/filesystem/path.hpp> | |
18 | #include <boost/detail/lightweight_test_report.hpp> | |
19 | #include <iostream> | |
20 | ||
21 | using boost::filesystem::path; | |
22 | using std::cout; | |
23 | using std::endl; | |
24 | ||
25 | namespace | |
26 | { | |
27 | void lexically_relative_test() | |
28 | { | |
29 | cout << "lexically_relative_test..." << endl; | |
30 | ||
31 | BOOST_TEST(path("").lexically_relative("") == ""); | |
32 | BOOST_TEST(path("").lexically_relative("/foo") == ""); | |
33 | BOOST_TEST(path("/foo").lexically_relative("") == ""); | |
34 | BOOST_TEST(path("/foo").lexically_relative("/foo") == "."); | |
35 | BOOST_TEST(path("").lexically_relative("foo") == ""); | |
36 | BOOST_TEST(path("foo").lexically_relative("") == ""); | |
37 | BOOST_TEST(path("foo").lexically_relative("foo") == "."); | |
38 | ||
39 | BOOST_TEST(path("a/b/c").lexically_relative("a") == "b/c"); | |
40 | BOOST_TEST(path("a//b//c").lexically_relative("a") == "b/c"); | |
41 | BOOST_TEST(path("a/b/c").lexically_relative("a/b") == "c"); | |
42 | BOOST_TEST(path("a///b//c").lexically_relative("a//b") == "c"); | |
43 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c") == "."); | |
44 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x") == ".."); | |
45 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x/y") == "../.."); | |
46 | BOOST_TEST(path("a/b/c").lexically_relative("a/x") == "../b/c"); | |
47 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/x") == "../c"); | |
48 | BOOST_TEST(path("a/b/c").lexically_relative("a/x/y") == "../../b/c"); | |
49 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/x/y") == "../../c"); | |
50 | BOOST_TEST(path("a/b/c").lexically_relative("a/b/c/x/y/z") == "../../.."); | |
51 | ||
52 | // paths unrelated except first element, and first element is root directory | |
53 | BOOST_TEST(path("/a/b/c").lexically_relative("/x") == "../a/b/c"); | |
54 | BOOST_TEST(path("/a/b/c").lexically_relative("/x/y") == "../../a/b/c"); | |
55 | BOOST_TEST(path("/a/b/c").lexically_relative("/x/y/z") == "../../../a/b/c"); | |
56 | ||
57 | // paths unrelated | |
58 | BOOST_TEST(path("a/b/c").lexically_relative("x") == ""); | |
59 | BOOST_TEST(path("a/b/c").lexically_relative("x/y") == ""); | |
60 | BOOST_TEST(path("a/b/c").lexically_relative("x/y/z") == ""); | |
61 | BOOST_TEST(path("a/b/c").lexically_relative("/x") == ""); | |
62 | BOOST_TEST(path("a/b/c").lexically_relative("/x/y") == ""); | |
63 | BOOST_TEST(path("a/b/c").lexically_relative("/x/y/z") == ""); | |
64 | BOOST_TEST(path("a/b/c").lexically_relative("/a/b/c") == ""); | |
65 | ||
66 | // TODO: add some Windows-only test cases that probe presence or absence of | |
67 | // drive specifier-and root-directory | |
68 | ||
69 | // Some tests from Jamie Allsop's paper | |
70 | BOOST_TEST(path("/a/d").lexically_relative("/a/b/c") == "../../d"); | |
71 | BOOST_TEST(path("/a/b/c").lexically_relative("/a/d") == "../b/c"); | |
72 | #ifdef BOOST_WINDOWS_API | |
73 | BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == "../y"); | |
74 | #else | |
75 | BOOST_TEST(path("c:\\y").lexically_relative("c:\\x") == ""); | |
76 | #endif | |
77 | BOOST_TEST(path("d:\\y").lexically_relative("c:\\x") == ""); | |
78 | ||
79 | // From issue #1976 | |
80 | BOOST_TEST(path("/foo/new").lexically_relative("/foo/bar") == "../new"); | |
81 | } | |
82 | ||
83 | void lexically_proximate_test() | |
84 | { | |
85 | cout << "lexically_proximate_test..." << endl; | |
86 | // paths unrelated | |
87 | BOOST_TEST(path("a/b/c").lexically_proximate("x") == "a/b/c"); | |
88 | } | |
89 | } // unnamed namespace | |
90 | ||
91 | //--------------------------------------------------------------------------------------// | |
92 | // // | |
93 | // main // | |
94 | // // | |
95 | //--------------------------------------------------------------------------------------// | |
96 | ||
97 | int test_main(int, char*[]) | |
98 | { | |
99 | // document state of critical macros | |
100 | #ifdef BOOST_POSIX_API | |
101 | cout << "BOOST_POSIX_API" << endl; | |
102 | #endif | |
103 | #ifdef BOOST_WINDOWS_API | |
104 | cout << "BOOST_WINDOWS_API" << endl; | |
105 | #endif | |
106 | ||
107 | lexically_relative_test(); | |
108 | lexically_proximate_test(); | |
109 | ||
110 | return ::boost::report_errors(); | |
111 | } |