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 10 11 // <filesystem> 12 13 // class path 14 15 // path& make_preferred() 16 17 #include "filesystem_include.h" 18 #include <type_traits> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "test_iterators.h" 23 #include "count_new.h" 24 #include "filesystem_test_helper.h" 25 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 {"", "", ""} 36 , {"hello_world", "hello_world", "hello_world"} 37 , {"/", "/", "\\"} 38 , {"/foo/bar/baz/", "/foo/bar/baz/", "\\foo\\bar\\baz\\"} 39 , {"\\", "\\", "\\"} 40 , {"\\foo\\bar\\baz\\", "\\foo\\bar\\baz\\", "\\foo\\bar\\baz\\"} 41 , {"\\foo\\/bar\\/baz\\", "\\foo\\/bar\\/baz\\", "\\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