Lolly 1.4.28
Loading...
Searching...
No Matches
tm_ostream_test.cpp
Go to the documentation of this file.
1/** \file tm_ostream_test.cpp
2 * \copyright GPLv3
3 * \details A unitest for tm_ostream.
4 * \author Paradisuman
5 * \date 2023
6 */
7
8#include "a_lolly_test.hpp"
9#include "string.hpp"
10#include "tm_ostream.hpp"
11
12bool
14 string sa= a.unbuffer ();
15 string sb= b.unbuffer ();
16
17 return sa == sb;
18}
19
20bool
21test_same (tm_ostream& a, string b) {
22 string sa= a.unbuffer ();
23
24 return sa == b;
25}
26
28
29TEST_CASE ("function is_writable") {
31 CHECK (t->is_writable () == true);
32
33 t.buffer ();
34 CHECK (t->is_writable () == true);
35}
36
37TEST_CASE ("function write and unbuffer") {
39
40 t.buffer ();
41 t->write ("abc");
42 CHECK (test_same (t, "abc"));
43
44 t.buffer ();
45 t->write ("abc");
46 t->write ("1234");
47 CHECK (test_same (t, "abc1234"));
48}
49
50TEST_CASE ("function redirect") {
52
53 SUBCASE ("redirect itself") {
54 auto tem= t;
55 t.redirect (t);
56 CHECK (t.rep == tem.rep);
57 }
58
59 SUBCASE ("redirect others") {
61 t.redirect (t2);
62
63 CHECK (t.rep == t2.rep);
64 }
65}
66
67TEST_CASE ("operator <<") {
69 t1.buffer ();
71 t2.buffer ();
72
73 SUBCASE ("test bool") {
74 t1 << true;
75 t2 << false;
76 CHECK (test_same (t1, "true"));
77 CHECK (test_same (t2, "false"));
78 }
79
80 SUBCASE ("test char") {
81 char val = 'A';
82 char val2= '1';
83 t1 << val;
84 t2 << val2;
85 CHECK (test_same (t1, "A"));
86 CHECK (test_same (t2, "1"));
87 }
88
89 SUBCASE ("test short") {
90 short val= 123;
91 t1 << val;
92 CHECK (test_same (t1, "123"));
93
94 short val_neg= -123;
95 t2 << val_neg;
96 CHECK (test_same (t2, "-123"));
97 }
98
99 SUBCASE ("test float") {
100 float val= 3.14f;
101 t1 << val;
102 CHECK (test_same (t1, "3.14"));
103
104 float val_neg= -3.14f;
105 t2 << val_neg;
106 CHECK (test_same (t2, "-3.14"));
107 }
108
109 SUBCASE ("test double") {
110 double val= 3.14159265;
111 t1 << val;
112 CHECK (test_same (t1, "3.14159"));
113
114 double val_neg= -3.14159265;
115 t2 << val_neg;
116 CHECK (test_same (t2, "-3.14159"));
117 }
118
119 SUBCASE ("test int") {
120 int val= 1000;
121 t1 << val;
122 CHECK (test_same (t1, "1000"));
123
124 int val_neg= -1000;
125 t2 << val_neg;
126 CHECK (test_same (t2, "-1000"));
127 }
128
129 SUBCASE ("test unsigned int") {
130 unsigned int val= 2000;
131 t1 << val;
132 CHECK (test_same (t1, "2000"));
133 }
134
135 SUBCASE ("test long") {
136 long val= 3000000L;
137 t1 << val;
138 CHECK (test_same (t1, "3000000"));
139
140 long val_neg= -3000000L;
141 t2 << val_neg;
142 CHECK (test_same (t2, "-3000000"));
143 }
144
145 SUBCASE ("test unsigned long") {
146 unsigned long val= 4000000UL;
147 t1 << val;
148 CHECK (test_same (t1, "4000000"));
149 }
150
151 SUBCASE ("test long long int") {
152 long long int val= 50000000000LL;
153 t1 << val;
154 CHECK (test_same (t1, "50000000000"));
155
156 long long int val_neg= -50000000000LL;
157 t2 << val_neg;
158 CHECK (test_same (t2, "-50000000000"));
159 }
160
161 SUBCASE ("test unsigned long long int") {
162 unsigned long long int val= 60000000000ULL;
163 t1 << val;
164 CHECK (test_same (t1, "60000000000"));
165 }
166
167 SUBCASE ("test long double") {
168 long double val= 3.141592653589793238L;
169 t1 << val;
170 CHECK (test_same (t1, "3.14159"));
171
172 long double val_neg= -3.141592653589793238L;
173 t2 << val_neg;
174 CHECK (test_same (t2, "-3.14159"));
175 }
176
177 SUBCASE ("test const char*") {
178 const char* val= "Hello, world!";
179 t1 << val;
180 CHECK (test_same (t1, "Hello, world!"));
181 }
182}
183
184TEST_CASE ("cout/cerr") {
185 cout << "Lolly" << LF;
186 cout << "棒棒糖" << LF;
187 cerr << "Lolly" << LF;
188 cerr << "棒棒糖" << LF;
189}
190
@ LF
Definition basic.hpp:287
blackbox t1
blackbox t2
blackbox b[13]
blackbox t[13]
blackbox_rep * rep
Definition blackbox.hpp:27
The list class represents a linked list.
Definition list.hpp:48
string unbuffer()
#define TEST_MEMORY_LEAK_INIT
#define TEST_MEMORY_LEAK_ALL
TEST_CASE("test for operator+= and advance()")
tm_ostream & cerr
tm_ostream & cout
bool test_same(tm_ostream &a, tm_ostream &b)