]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/manipulators/standard/char/quoted.cc
3041d18d83ff2370a8bf094bde8ef0f63b6beb58
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / manipulators / standard / char / quoted.cc
1 // { dg-do run { target c++14 } }
2
3 // Copyright (C) 2013-2016 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.
10
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.
15
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/>.
19
20 // 27.7.6 - Quoted manipulators [quoted.manip]
21
22 #include <string>
23 #include <sstream>
24 #include <iomanip>
25 #include <testsuite_hooks.h>
26
27 void
28 test01()
29 {
30 // Basic test from paper.
31 bool test [[gnu::unused]] = true;
32 std::stringstream ss;
33 std::string original = "foolish me";
34 std::string round_trip;
35 ss << std::quoted(original);
36 ss >> std::quoted(round_trip);
37 VERIFY( original == round_trip );
38 }
39
40 void
41 test02()
42 {
43 // Test skipws correctness.
44 bool test [[gnu::unused]] = true;
45 std::stringstream ss;
46 ss << std::quoted("Hello Goodbye") << ' ' << 1 << ' ' << 2;
47 std::string song;
48 int thing1, thing2;
49 ss >> std::quoted(song) >> thing1 >> thing2;
50 VERIFY( song == "Hello Goodbye" );
51 VERIFY( thing1 == 1 );
52 VERIFY( thing2 == 2 );
53 }
54
55 void
56 test03()
57 {
58 // Test read of unquoted string.
59 bool test [[gnu::unused]] = true;
60 std::stringstream ss;
61 ss << "Alpha Omega";
62 std::string testit;
63 ss >> std::quoted(testit);
64 VERIFY( testit == "Alpha" );
65 }
66
67 auto
68 test04(const std::string& message)
69 {
70 // Test 'const basic_string&'
71 bool test [[gnu::unused]] = true;
72 std::stringstream ss;
73 ss << "** Error: " << std::quoted(message) << " **";
74 return ss.str();
75 }
76
77 int
78 main()
79 {
80 test01();
81 test02();
82 test03();
83 auto ss = test04("My biscuits are burnin'!");
84 VERIFY( ss == "** Error: \"My biscuits are burnin'!\" **" );
85
86 return 0;
87 }