]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/filesystem/path/native/alloc.cc
PR libstdc++/90281 Fix string conversions for filesystem::path
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / filesystem / path / native / alloc.cc
CommitLineData
26b1320e
JW
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 "-lstdc++fs" }
19// { dg-do run { target c++11 } }
20// { dg-require-filesystem-ts "" }
21
22#include <experimental/filesystem>
23#include <string>
24#include <testsuite_hooks.h>
25#include <testsuite_allocator.h>
26
27template<typename C>
28 using alloc = __gnu_test::uneq_allocator<C>;
29
30void
31test01()
32{
33 using namespace std::experimental::filesystem;
34 path p;
35
36 auto str = p.string<char>(alloc<char>(1));
37 VERIFY( str == "" );
38 VERIFY( str.get_allocator() == alloc<char>(1) );
39
40#ifdef _GLIBCXX_USE_CHAR8_T
41 auto str8 = p.string<char8_t>(alloc<char8_t>(1));
42 VERIFY( str8 == u8"" );
43 VERIFY( str8.get_allocator() == alloc<char8_t>(1) );
44#endif
45
46 auto strw = p.string<wchar_t>(alloc<wchar_t>(2));
47 VERIFY( strw == L"" );
48 VERIFY( strw.get_allocator() == alloc<wchar_t>(2) );
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
59void
60test02()
61{
62 using namespace std::experimental::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 auto strw = p.string<wchar_t>(alloc<wchar_t>(2));
76 VERIFY( strw == L"abcdefghijklmnopqrstuvwxyz" );
77 VERIFY( strw.get_allocator() == alloc<wchar_t>(2) );
78
79 auto str16 = p.string<char16_t>(alloc<char16_t>(3));
80 VERIFY( str16 == u"abcdefghijklmnopqrstuvwxyz" );
81 VERIFY( str16.get_allocator() == alloc<char16_t>(3) );
82
83 auto str32 = p.string<char32_t>(alloc<char32_t>(4));
84 VERIFY( str32 == U"abcdefghijklmnopqrstuvwxyz" );
85 VERIFY( str32.get_allocator() == alloc<char32_t>(4) );
86}
87
88int
89main()
90{
91 test01();
92 test02();
93}