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 #ifdef _GLIBCXX_USE_WCHAR_T 52 auto strw = p.string<wchar_t>(); 53 VERIFY( strw == L"abc" ); 54 VERIFY( strw == p.wstring() ); 55 #endif 56 57 auto str16 = p.string<char16_t>(); 58 VERIFY( str16 == u"abc" ); 59 VERIFY( str16 == p.u16string() ); 60 61 auto str32 = p.string<char32_t>(); 62 VERIFY( str32 == U"abc" ); 63 VERIFY( str32 == p.u32string() ); 64 } 65 66 void test03()67test03() 68 { 69 std::filesystem::path p; 70 auto str8 = p.u8string(); 71 VERIFY( str8 == u8"" ); 72 auto str16 = p.u16string(); 73 VERIFY( str16 == u"" ); 74 auto str32 = p.u32string(); 75 VERIFY( str32 == U"" ); 76 } 77 78 void test04()79test04() 80 { 81 // PR libstdc++/90281 82 auto p = std::filesystem::u8path("\xf0\x9d\x84\x9e"); 83 auto str8 = p.u8string(); 84 VERIFY( str8 == u8"\U0001D11E" ); 85 auto str16 = p.u16string(); 86 VERIFY( str16 == u"\U0001D11E" ); 87 auto str32 = p.u32string(); 88 VERIFY( str32 == U"\U0001D11E" ); 89 } 90 91 int main()92main() 93 { 94 test01(); 95 test02(); 96 test03(); 97 test04(); 98 } 99