]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/filesystem/path/native/alloc.cc
PR libstdc++/90281 Fix string conversions for filesystem::path
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / filesystem / path / native / alloc.cc
1 // Copyright (C) 2016-2019 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-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
20
21 #include <filesystem>
22 #include <string>
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
25
26 template<typename C>
27 using alloc = __gnu_test::uneq_allocator<C>;
28
29 void
30 test01()
31 {
32 using namespace std::filesystem;
33 path p;
34
35 auto str = p.string<char>(alloc<char>(1));
36 VERIFY( str == "" );
37 VERIFY( str.get_allocator() == alloc<char>(1) );
38
39 #ifdef _GLIBCXX_USE_CHAR8_T
40 auto str8 = p.string<char8_t>(alloc<char8_t>(1));
41 VERIFY( str8 == u8"" );
42 VERIFY( str8.get_allocator() == alloc<char8_t>(1) );
43 #endif
44
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
49 auto str16 = p.string<char16_t>(alloc<char16_t>(3));
50 VERIFY( str16 == u"" );
51 VERIFY( str16.get_allocator() == alloc<char16_t>(3) );
52
53 auto str32 = p.string<char32_t>(alloc<char32_t>(4));
54 VERIFY( str32 == U"" );
55 VERIFY( str32.get_allocator() == alloc<char32_t>(4) );
56 }
57
58 void
59 test02()
60 {
61 using namespace std::filesystem;
62 path p = "abcdefghijklmnopqrstuvwxyz";
63
64 auto str = p.string<char>(alloc<char>(1));
65 VERIFY( str == "abcdefghijklmnopqrstuvwxyz" );
66 VERIFY( str.get_allocator() == alloc<char>(1) );
67
68 #ifdef _GLIBCXX_USE_CHAR8_T
69 auto str8 = p.string<char8_t>(alloc<char8_t>(1));
70 VERIFY( str8 == u8"abcdefghijklmnopqrstuvwxyz" );
71 VERIFY( str8.get_allocator() == alloc<char8_t>(1) );
72 #endif
73
74 auto strw = p.string<wchar_t>(alloc<wchar_t>(2));
75 VERIFY( strw == L"abcdefghijklmnopqrstuvwxyz" );
76 VERIFY( strw.get_allocator() == alloc<wchar_t>(2) );
77
78 auto str16 = p.string<char16_t>(alloc<char16_t>(3));
79 VERIFY( str16 == u"abcdefghijklmnopqrstuvwxyz" );
80 VERIFY( str16.get_allocator() == alloc<char16_t>(3) );
81
82 auto str32 = p.string<char32_t>(alloc<char32_t>(4));
83 VERIFY( str32 == U"abcdefghijklmnopqrstuvwxyz" );
84 VERIFY( str32.get_allocator() == alloc<char32_t>(4) );
85 }
86
87 int
88 main()
89 {
90 test01();
91 test02();
92 }