1 // Copyright (C) 2016-2021 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 24 void test01()25test01() 26 { 27 using namespace std::filesystem; 28 using string_type = std::basic_string<path::value_type>; 29 const string_type s{ 'a', 'b', 'c' }; 30 path p(s); 31 32 VERIFY( p.native() == s ); 33 VERIFY( p.c_str() == s ); 34 VERIFY( static_cast<string_type>(p) == s ); 35 36 string_type s2 = p; // implicit conversion 37 VERIFY( s2 == p.native() ); 38 } 39 40 void test02()41test02() 42 { 43 using namespace std::filesystem; 44 const char* s = "abc"; 45 path p(s); 46 47 auto str = p.string<char>(); 48 VERIFY( str == "abc" ); 49 VERIFY( str == p.string() ); 50 51 auto strw = p.string<wchar_t>(); 52 VERIFY( strw == L"abc" ); 53 VERIFY( strw == p.wstring() ); 54 55 auto str16 = p.string<char16_t>(); 56 VERIFY( str16 == u"abc" ); 57 VERIFY( str16 == p.u16string() ); 58 59 auto str32 = p.string<char32_t>(); 60 VERIFY( str32 == U"abc" ); 61 VERIFY( str32 == p.u32string() ); 62 } 63 64 void test03()65test03() 66 { 67 std::filesystem::path p; 68 auto str8 = p.u8string(); 69 VERIFY( str8 == u8"" ); 70 auto str16 = p.u16string(); 71 VERIFY( str16 == u"" ); 72 auto str32 = p.u32string(); 73 VERIFY( str32 == U"" ); 74 } 75 76 void test04()77test04() 78 { 79 // PR libstdc++/90281 80 auto p = std::filesystem::u8path("\xf0\x9d\x84\x9e"); 81 auto str8 = p.u8string(); 82 VERIFY( str8 == u8"\U0001D11E" ); 83 auto str16 = p.u16string(); 84 VERIFY( str16 == u"\U0001D11E" ); 85 auto str32 = p.u32string(); 86 VERIFY( str32 == U"\U0001D11E" ); 87 } 88 89 int main()90main() 91 { 92 test01(); 93 test02(); 94 test03(); 95 test04(); 96 } 97