Lumiera  0.pre.03
»edit your freedom«
ios-savepoint-test.cpp
Go to the documentation of this file.
1 /*
2  IosSavepoint(Test) - manipulate and restore output stream formatting
3 
4  Copyright (C) Lumiera.org
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/format-cout.hpp"
30 #include "lib/ios-savepoint.hpp"
31 
32 #include <string>
33 
34 
35 using std::string;
36 
37 
38 namespace util {
39 namespace test {
40 
41 
42 
43 
44  /***************************************************************************/
49  : public Test
50  {
51  void
52  run (Arg)
53  {
54  switchToHex();
55  __verifySane();
56 
57  setFill();
58  __verifySane();
59 
60  nested();
61  __verifySane();
62 
63  try {
65  } catch(...){
66  cout << "Tilt" <<endl;
67  }
68  __verifySane();
69  }
70 
71 
73  void
75  {
76  cout << std::setw(10) << 42 <<endl;
77  }
78 
79 
81  void
83  {
84  IosSavepoint save{cout};
85  cout << std::hex
86  << std::showbase
87  << 42 <<endl;
88  }
89 
90 
92  void
94  {
95  IosSavepoint save{cout};
96  cout << std::setfill('*')
97  << std::setw(20)
98  << 42 <<endl;
99  }
100 
101 
103  void
105  {
106  IosSavepoint save{cout};
107  cout << std::hex << 42 <<endl;
108  {
109  IosSavepoint inner(cout);
110  cout << std::oct << std::showbase << 42 <<endl;
111  }
112  cout << 42 <<endl;
113  }
114 
115 
117  void
119  {
120  auto boom = []() -> float
121  { throw 42; };
122 
123  IosSavepoint save{cout};
124  cout << std::hexfloat
125  << 1234
126  << endl
127  << boom()
128  << endl;
129  }
130  };
131 
132  LAUNCHER (IosSavepoint_test, "unit common");
133 
134 
135 }} // namespace util::test
136 
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
Capture previous settings of an std::ostream and restore them when leaving scope. ...
Simple test class runner.
RAII helper to capture and restore output stream format settings.
void __verifySane()
verify that original state is restored