| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14 |
| 10 | // UNSUPPORTED: availability-filesystem-missing |
| 11 | |
| 12 | // <filesystem> |
| 13 | |
| 14 | // class path |
| 15 | |
| 16 | // path& make_preferred() |
| 17 | |
| 18 | #include <filesystem> |
| 19 | #include <cassert> |
| 20 | #include <string> |
| 21 | #include <type_traits> |
| 22 | |
| 23 | #include "test_iterators.h" |
| 24 | #include "count_new.h" |
| 25 | namespace fs = std::filesystem; |
| 26 | |
| 27 | struct MakePreferredTestcase { |
| 28 | const char* value; |
| 29 | const char* expected_posix; |
| 30 | const char* expected_windows; |
| 31 | }; |
| 32 | |
| 33 | const MakePreferredTestcase TestCases[] = |
| 34 | { |
| 35 | {.value: "" , .expected_posix: "" , .expected_windows: "" } |
| 36 | , {.value: "hello_world" , .expected_posix: "hello_world" , .expected_windows: "hello_world" } |
| 37 | , {.value: "/" , .expected_posix: "/" , .expected_windows: "\\" } |
| 38 | , {.value: "/foo/bar/baz/" , .expected_posix: "/foo/bar/baz/" , .expected_windows: "\\foo\\bar\\baz\\" } |
| 39 | , {.value: "\\" , .expected_posix: "\\" , .expected_windows: "\\" } |
| 40 | , {.value: "\\foo\\bar\\baz\\" , .expected_posix: "\\foo\\bar\\baz\\" , .expected_windows: "\\foo\\bar\\baz\\" } |
| 41 | , {.value: "\\foo\\/bar\\/baz\\" , .expected_posix: "\\foo\\/bar\\/baz\\" , .expected_windows: "\\foo\\\\bar\\\\baz\\" } |
| 42 | }; |
| 43 | |
| 44 | int main(int, char**) |
| 45 | { |
| 46 | // This operation is an identity operation on linux. |
| 47 | // On windows, compare with preferred_win, if set. |
| 48 | using namespace fs; |
| 49 | for (auto const & TC : TestCases) { |
| 50 | path p(TC.value); |
| 51 | assert(p == TC.value); |
| 52 | path& Ref = (p.make_preferred()); |
| 53 | #ifdef _WIN32 |
| 54 | std::string s(TC.expected_windows); |
| 55 | #else |
| 56 | std::string s(TC.expected_posix); |
| 57 | #endif |
| 58 | assert(p.string() == s); |
| 59 | assert(&Ref == &p); |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |