Lolly 1.4.27
Loading...
Searching...
No Matches
Functions
tm_ostream_test.cpp File Reference
#include "a_lolly_test.hpp"
#include "string.hpp"
#include "tm_ostream.hpp"
Include dependency graph for tm_ostream_test.cpp:

Go to the source code of this file.

Functions

bool test_same (tm_ostream &a, tm_ostream &b)
 
bool test_same (tm_ostream &a, string b)
 
TEST_MEMORY_LEAK_INIT TEST_CASE ("function is_writable")
 
 TEST_CASE ("function write and unbuffer")
 
 TEST_CASE ("function redirect")
 
 TEST_CASE ("operator <<")
 
 TEST_CASE ("cout/cerr")
 

Detailed Description

A unitest for tm_ostream.

Author
Paradisuman
Date
2023

Definition in file tm_ostream_test.cpp.

Function Documentation

◆ test_same() [1/2]

bool test_same ( tm_ostream & a,
tm_ostream & b )

Definition at line 13 of file tm_ostream_test.cpp.

13 {
14 string sa= a.unbuffer ();
15 string sb= b.unbuffer ();
16
17 return sa == sb;
18}
blackbox b[13]
The list class represents a linked list.
Definition list.hpp:48
string unbuffer()

◆ test_same() [2/2]

bool test_same ( tm_ostream & a,
string b )

Definition at line 21 of file tm_ostream_test.cpp.

21 {
22 string sa= a.unbuffer ();
23
24 return sa == b;
25}

◆ TEST_CASE() [1/5]

TEST_MEMORY_LEAK_INIT TEST_CASE ( "function is_writable" )

Definition at line 29 of file tm_ostream_test.cpp.

29 {
31 CHECK (t->is_writable () == true);
32
33 t.buffer ();
34 CHECK (t->is_writable () == true);
35}
blackbox t[13]

◆ TEST_CASE() [2/5]

TEST_CASE ( "function write and unbuffer" )

Definition at line 37 of file tm_ostream_test.cpp.

37 {
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}
bool test_same(tm_ostream &a, tm_ostream &b)

◆ TEST_CASE() [3/5]

TEST_CASE ( "function redirect" )

Definition at line 50 of file tm_ostream_test.cpp.

50 {
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}
blackbox t2
blackbox_rep * rep
Definition blackbox.hpp:27

◆ TEST_CASE() [4/5]

TEST_CASE ( "operator <<" )

Definition at line 67 of file tm_ostream_test.cpp.

67 {
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}
blackbox t1

◆ TEST_CASE() [5/5]

TEST_CASE ( "cout/cerr" )

Definition at line 184 of file tm_ostream_test.cpp.

184 {
185 cout << "Lolly" << LF;
186 cout << "棒棒糖" << LF;
187 cerr << "Lolly" << LF;
188 cerr << "棒棒糖" << LF;
189}
@ LF
Definition basic.hpp:287
tm_ostream & cerr
tm_ostream & cout