2013-11-21 Edward Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libstdc++-v3 / testsuite / experimental / string_view / cons / wchar_t / 1.cc
blobeb115fd55283dfde0faa5425834a7d14a748556a
1 // { dg-options "-std=gnu++1y" }
3 // Copyright (C) 2013 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // basic_string_view constructors.
22 #include <experimental/string_view>
23 #include <string>
24 #include <cwchar>
25 #include <testsuite_hooks.h>
27 void
28 test01()
30 bool test [[gnu::unused]] = true;
31 typedef std::experimental::wstring_view::size_type csize_type;
33 // basic_string_view()
34 const std::experimental::wstring_view str00{};
35 VERIFY( str00.length() == 0 );
36 VERIFY( str00.data() != nullptr );
38 // basic_string_view(const char*)
39 const wchar_t str_lit01[] = L"rodeo beach, marin";
40 const std::experimental::wstring_view str01{str_lit01};
41 VERIFY( str01.length() == 18 );
42 VERIFY( str01.data() == str_lit01 );
43 const std::experimental::wstring_view str02{L"baker beach, san francisco"};
44 VERIFY( str02.length() == 26 );
46 // basic_string_view(const string_view&)
47 std::experimental::wstring_view str04{str01};
48 VERIFY( str04.length() == str01.length() );
49 VERIFY( str04.data() == str01.data() );
51 // basic_string_view(const char* s)
52 csize_type len_lit01 = wcslen(str_lit01);
53 std::experimental::wstring_view str05{str_lit01, len_lit01};
54 VERIFY( str05.length() == len_lit01 );
55 VERIFY( str05.data() == str_lit01 );
57 // basic_string_view(const wchar_t* s, std::size_t l)
58 std::experimental::wstring_view str06{nullptr, len_lit01};
59 VERIFY( str06.length() == 0 );
60 VERIFY( str06.data() != nullptr );
62 // basic_string_view(basic_string& s)
63 std::wstring istr07(10, L'z');
64 std::experimental::wstring_view str07{istr07};
65 VERIFY( str07.length() == 10 );
68 int
69 main()
71 test01();
73 return 0;