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)
5  2022, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/format-cout.hpp"
21 #include "lib/ios-savepoint.hpp"
22 
23 #include <iomanip>
24 #include <string>
25 
26 
27 using std::string;
28 
29 
30 namespace util {
31 namespace test {
32 
33 
34 
35 
36  /***************************************************************************/
41  : public Test
42  {
43  void
44  run (Arg)
45  {
46  switchToHex();
47  __verifySane();
48 
49  setFill();
50  __verifySane();
51 
52  nested();
53  __verifySane();
54 
55  try {
57  } catch(...){
58  cout << "Tilt" <<endl;
59  }
60  __verifySane();
61  }
62 
63 
65  void
67  {
68  cout << std::setw(10) << 42 <<endl;
69  }
70 
71 
73  void
75  {
76  IosSavepoint save{cout};
77  cout << std::hex
78  << std::showbase
79  << 42 <<endl;
80  }
81 
82 
84  void
86  {
87  IosSavepoint save{cout};
88  cout << std::setfill('*')
89  << std::setw(20)
90  << 42 <<endl;
91  }
92 
93 
95  void
97  {
98  IosSavepoint save{cout};
99  cout << std::hex << 42 <<endl;
100  {
101  IosSavepoint inner(cout);
102  cout << std::oct << std::showbase << 42 <<endl;
103  }
104  cout << 42 <<endl;
105  }
106 
107 
109  void
111  {
112  auto boom = []() -> float
113  { throw 42; };
114 
115  IosSavepoint save{cout};
116  cout << std::hexfloat
117  << 1234
118  << endl
119  << boom()
120  << endl;
121  }
122  };
123 
124  LAUNCHER (IosSavepoint_test, "unit common");
125 
126 
127 }} // namespace util::test
128 
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:40
Capture previous settings of an std::ostream and restore them when leaving scope. ...
Simplistic test class runner.
RAII helper to capture and restore output stream format settings.
void __verifySane()
verify that original state is restored