| 1 | // Copyright (C) 2016-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // { dg-do run { target c++17 } } |
| 19 | |
| 20 | #include <filesystem> |
| 21 | #include <string> |
| 22 | #include <testsuite_hooks.h> |
| 23 | #include <testsuite_allocator.h> |
| 24 | |
| 25 | template<typename C> |
| 26 | using alloc = __gnu_test::uneq_allocator<C>; |
| 27 | |
| 28 | void |
| 29 | test01() |
| 30 | { |
| 31 | using namespace std::filesystem; |
| 32 | path p; |
| 33 | |
| 34 | auto str = p.string<char>(alloc<char>(1)); |
| 35 | VERIFY( str == "" ); |
| 36 | VERIFY( str.get_allocator() == alloc<char>(1) ); |
| 37 | |
| 38 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 39 | auto str8 = p.string<char8_t>(alloc<char8_t>(1)); |
| 40 | VERIFY( str8 == u8"" ); |
| 41 | VERIFY( str8.get_allocator() == alloc<char8_t>(1) ); |
| 42 | #endif |
| 43 | |
| 44 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 45 | auto strw = p.string<wchar_t>(alloc<wchar_t>(2)); |
| 46 | VERIFY( strw == L"" ); |
| 47 | VERIFY( strw.get_allocator() == alloc<wchar_t>(2) ); |
| 48 | #endif |
| 49 | |
| 50 | auto str16 = p.string<char16_t>(alloc<char16_t>(3)); |
| 51 | VERIFY( str16 == u"" ); |
| 52 | VERIFY( str16.get_allocator() == alloc<char16_t>(3) ); |
| 53 | |
| 54 | auto str32 = p.string<char32_t>(alloc<char32_t>(4)); |
| 55 | VERIFY( str32 == U"" ); |
| 56 | VERIFY( str32.get_allocator() == alloc<char32_t>(4) ); |
| 57 | } |
| 58 | |
| 59 | void |
| 60 | test02() |
| 61 | { |
| 62 | using namespace std::filesystem; |
| 63 | path p = "abcdefghijklmnopqrstuvwxyz"; |
| 64 | |
| 65 | auto str = p.string<char>(alloc<char>(1)); |
| 66 | VERIFY( str == "abcdefghijklmnopqrstuvwxyz" ); |
| 67 | VERIFY( str.get_allocator() == alloc<char>(1) ); |
| 68 | |
| 69 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 70 | auto str8 = p.string<char8_t>(alloc<char8_t>(1)); |
| 71 | VERIFY( str8 == u8"abcdefghijklmnopqrstuvwxyz" ); |
| 72 | VERIFY( str8.get_allocator() == alloc<char8_t>(1) ); |
| 73 | #endif |
| 74 | |
| 75 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 76 | auto strw = p.string<wchar_t>(alloc<wchar_t>(2)); |
| 77 | VERIFY( strw == L"abcdefghijklmnopqrstuvwxyz" ); |
| 78 | VERIFY( strw.get_allocator() == alloc<wchar_t>(2) ); |
| 79 | #endif |
| 80 | |
| 81 | auto str16 = p.string<char16_t>(alloc<char16_t>(3)); |
| 82 | VERIFY( str16 == u"abcdefghijklmnopqrstuvwxyz" ); |
| 83 | VERIFY( str16.get_allocator() == alloc<char16_t>(3) ); |
| 84 | |
| 85 | auto str32 = p.string<char32_t>(alloc<char32_t>(4)); |
| 86 | VERIFY( str32 == U"abcdefghijklmnopqrstuvwxyz" ); |
| 87 | VERIFY( str32.get_allocator() == alloc<char32_t>(4) ); |
| 88 | } |
| 89 | |
| 90 | int |
| 91 | main() |
| 92 | { |
| 93 | test01(); |
| 94 | test02(); |
| 95 | } |