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 // These tests require locale for non-char paths 12 // UNSUPPORTED: no-localization 13 14 // <filesystem> 15 16 // class path 17 18 // std::string generic_string() const; 19 // std::wstring generic_wstring() const; 20 // std::u8string generic_u8string() const; 21 // std::u16string generic_u16string() const; 22 // std::u32string generic_u32string() const; 23 24 25 #include "filesystem_include.h" 26 #include <type_traits> 27 #include <cassert> 28 29 #include "test_macros.h" 30 #include "test_iterators.h" 31 #include "count_new.h" 32 #include "min_allocator.h" 33 #include "filesystem_test_helper.h" 34 35 MultiStringType input = MKSTR("c:\\foo\\bar"); 36 #ifdef _WIN32 37 // On windows, the generic_* accessors return a path with forward slashes 38 MultiStringType ref = MKSTR("c:/foo/bar"); 39 #else 40 // On posix, the input string is returned as-is 41 MultiStringType ref = MKSTR("c:\\foo\\bar"); 42 #endif 43 main(int,char **)44int main(int, char**) 45 { 46 using namespace fs; 47 auto const& MS = ref; 48 const char* value = input; 49 const path p(value); 50 { 51 std::string s = p.generic_string(); 52 assert(s == (const char*)MS); 53 } 54 { 55 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 56 ASSERT_SAME_TYPE(decltype(p.generic_u8string()), std::u8string); 57 std::u8string s = p.generic_u8string(); 58 assert(s == (const char8_t*)MS); 59 #else 60 ASSERT_SAME_TYPE(decltype(p.generic_u8string()), std::string); 61 std::string s = p.generic_u8string(); 62 assert(s == (const char*)MS); 63 #endif 64 } 65 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 66 { 67 std::wstring s = p.generic_wstring(); 68 assert(s == (const wchar_t*)MS); 69 } 70 #endif 71 { 72 std::u16string s = p.generic_u16string(); 73 assert(s == (const char16_t*)MS); 74 } 75 { 76 std::u32string s = p.generic_u32string(); 77 assert(s == (const char32_t*)MS); 78 } 79 80 return 0; 81 } 82