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