Lolly
1.4.28
Loading...
Searching...
No Matches
tests
Kernel
Abstractions
blackbox_test.cpp
Go to the documentation of this file.
1
/** \file blackbox_test.cpp
2
* \copyright GPLv3
3
* \details A unitest for blackbox.
4
* \author YuanYe
5
* \date 2023
6
*/
7
#include "
a_lolly_test.hpp
"
8
#include "
blackbox.hpp
"
9
#include "
string.hpp
"
10
#include <climits>
11
12
blackbox
b0
;
13
blackbox
b1
=
close_box<SI>
(-2147483648);
// int
14
blackbox
b2
=
close_box<SN>
(2147483647);
// unsigned int
15
blackbox
b3
=
close_box<HI>
(-32768);
// short
16
blackbox
b4
=
close_box<HN>
(32767);
// unsiened short
17
blackbox
b5
=
close_box<QI>
(
'`'
);
// char
18
blackbox
b6
=
close_box<QN>
(255);
// unsigned char
19
blackbox
b7
=
close_box<DI>
(
LLONG_MAX
);
// long long
20
blackbox
b8
=
close_box<DN>
(
ULLONG_MAX
);
// unsigned long long
21
blackbox
b9
=
close_box<pointer>
(
nullptr
);
// void*
22
blackbox
b10
=
close_box<float>
(3.14);
23
blackbox
b11
=
close_box<double>
(3.14159265);
24
blackbox
b12
=
close_box<long double>
(3.1415926535);
25
26
blackbox
t0
;
27
blackbox
t1
=
close_box<SI>
(1234);
// int
28
blackbox
t2
=
close_box<SN>
(5678);
// unsigned int
29
blackbox
t3
=
close_box<HI>
(123);
// short
30
blackbox
t4
=
close_box<HN>
(234);
// unsiened short
31
blackbox
t5
=
close_box<QI>
(
't'
);
// char
32
blackbox
t6
=
close_box<QN>
(23);
// unsigned char
33
blackbox
t7
=
close_box<DI>
(5678);
// long long
34
blackbox
t8
=
close_box<DN>
(0);
// unsigned long long
35
blackbox
t9
=
close_box<pointer>
(
nullptr
);
// void*
36
blackbox
t10
=
close_box<float>
(0.0);
37
blackbox
t11
=
close_box<double>
(8.567);
38
blackbox
t12
=
close_box<long double>
(7.345);
39
40
blackbox
t
[13] = {
t0
,
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
,
t8
,
t9
,
t10
,
t11
,
t12
};
41
blackbox
b
[13] = {
b0
,
b1
,
b2
,
b3
,
b4
,
b5
,
b6
,
b7
,
b8
,
b9
,
b10
,
b11
,
b12
};
42
string
bout
[13]= {
""
,
43
"-2147483648\0"
,
44
"2147483647"
,
45
"-32768\0"
,
46
"32767"
,
47
"`"
,
48
"255"
,
49
"9223372036854775807"
,
50
"18446744073709551615"
,
51
"false"
,
52
"3.14"
,
53
"3.14159"
,
54
"3.14159"
};
55
string
tout
[13]= {
""
,
56
"-2147483648\n"
,
57
"2147483647\t"
,
58
"-327680"
,
59
"32767 "
,
60
"`\n"
,
61
"0"
,
62
"9223372036854775807\n"
,
63
"18446744073709551615 "
,
64
"0"
,
65
"3.1415926"
,
66
"3.14159265"
,
67
"3.1415926535"
};
68
69
TEST_CASE
(
"test for get_type() and open_box()"
) {
70
CHECK
(
open_box<SI>
(
b1
) == -2147483648);
71
CHECK
(
open_box<SN>
(
b2
) == 2147483647);
72
CHECK
(
open_box<HI>
(
b3
) == -32768);
73
CHECK
(
open_box<HN>
(
b4
) == 32767);
74
CHECK
(
open_box<QI>
(
b5
) ==
'`'
);
75
CHECK
(
open_box<QN>
(
b6
) == 255);
76
CHECK
(
open_box<DI>
(
b7
) ==
LLONG_MAX
);
77
CHECK
(
open_box<DN>
(
b8
) ==
ULLONG_MAX
);
78
CHECK
(
open_box<pointer>
(
b9
) ==
nullptr
);
79
CHECK
(
open_box<float>
(
b10
) == (
float
) 3.14);
80
CHECK
(
open_box<double>
(
b11
) == 3.14159265);
81
CHECK
(
open_box<long double>
(
b12
) == 3.1415926535);
82
83
CHECK
(
open_box<SI>
(
t1
) == 1234);
84
CHECK
(
open_box<SN>
(
t2
) == 5678);
85
CHECK
(
open_box<HI>
(
t3
) == 123);
86
CHECK
(
open_box<HN>
(
t4
) == 234);
87
CHECK
(
open_box<QI>
(
t5
) ==
't'
);
88
CHECK
(
open_box<QN>
(
t6
) == 23);
89
CHECK
(
open_box<DI>
(
t7
) == 5678);
90
CHECK
(
open_box<DN>
(
t8
) == 0);
91
CHECK
(
open_box<pointer>
(
t9
) ==
nullptr
);
92
CHECK
(
open_box<float>
(
t10
) == 0.0);
93
CHECK
(
open_box<double>
(
t11
) == 8.567);
94
CHECK
(
open_box<long double>
(
t12
) == 7.345);
95
// If the incoming template type does not match, an exception will be thrown.
96
}
97
98
TEST_CASE
(
"test for equal(), operator== and operator!="
) {
99
SUBCASE
(
"test for operator=="
) {
100
for
(
int
i= 0; i < 13; i++) {
101
CHECK_EQ
(
t
[i] ==
t
[i],
true
);
102
}
103
}
104
105
SUBCASE
(
"test for operator!="
) {
106
for
(
int
i= 0; i < 13; i++) {
107
if
(i != 0 && i != 9)
CHECK_EQ
(
b
[i] !=
t
[i],
true
);
108
}
109
}
110
}
111
112
TEST_CASE
(
"Test fot display() and operator<<"
) {
113
tm_ostream
out;
114
string
str;
115
for
(
int
i= 0; i < 13; i++) {
116
out.
buffer
();
117
out <<
b
[i];
118
str= out.
unbuffer
();
119
CHECK_EQ
(str !=
tout
[i],
true
);
120
if
(i != 0)
CHECK_EQ
(str ==
bout
[i],
true
);
121
else
CHECK_EQ
(str !=
bout
[i],
true
);
122
}
123
}
a_lolly_test.hpp
blackbox.hpp
b12
blackbox b12
Definition
blackbox_test.cpp:24
t1
blackbox t1
Definition
blackbox_test.cpp:27
t5
blackbox t5
Definition
blackbox_test.cpp:31
b1
blackbox b1
Definition
blackbox_test.cpp:13
t3
blackbox t3
Definition
blackbox_test.cpp:29
b4
blackbox b4
Definition
blackbox_test.cpp:16
b0
blackbox b0
Definition
blackbox_test.cpp:12
t9
blackbox t9
Definition
blackbox_test.cpp:35
t8
blackbox t8
Definition
blackbox_test.cpp:34
b9
blackbox b9
Definition
blackbox_test.cpp:21
t7
blackbox t7
Definition
blackbox_test.cpp:33
bout
string bout[13]
Definition
blackbox_test.cpp:42
t2
blackbox t2
Definition
blackbox_test.cpp:28
t11
blackbox t11
Definition
blackbox_test.cpp:37
b10
blackbox b10
Definition
blackbox_test.cpp:22
t6
blackbox t6
Definition
blackbox_test.cpp:32
t10
blackbox t10
Definition
blackbox_test.cpp:36
t12
blackbox t12
Definition
blackbox_test.cpp:38
b2
blackbox b2
Definition
blackbox_test.cpp:14
b5
blackbox b5
Definition
blackbox_test.cpp:17
b
blackbox b[13]
Definition
blackbox_test.cpp:41
tout
string tout[13]
Definition
blackbox_test.cpp:55
t4
blackbox t4
Definition
blackbox_test.cpp:30
b3
blackbox b3
Definition
blackbox_test.cpp:15
b11
blackbox b11
Definition
blackbox_test.cpp:23
t
blackbox t[13]
Definition
blackbox_test.cpp:40
t0
blackbox t0
Definition
blackbox_test.cpp:26
b8
blackbox b8
Definition
blackbox_test.cpp:20
b7
blackbox b7
Definition
blackbox_test.cpp:19
b6
blackbox b6
Definition
blackbox_test.cpp:18
blackbox
Definition
blackbox.hpp:25
list
The list class represents a linked list.
Definition
list.hpp:48
tm_ostream
Definition
tm_ostream.hpp:36
tm_ostream::unbuffer
string unbuffer()
Definition
tm_ostream.cpp:198
tm_ostream::buffer
void buffer()
Definition
tm_ostream.cpp:192
TEST_CASE
TEST_CASE("test for operator+= and advance()")
Definition
parse_string_test.cpp:85
string.hpp
Generated by
1.10.0