F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FormatTest.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title FormatTest.cpp
3// \author T. Chieu
4// \brief cpp file for FormatTest class
5//
6// \copyright
7// Copyright (C) 2009-2022 California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10//
11// ======================================================================
12
13#include "FppTest/array/FormatBoolArrayAc.hpp"
14#include "FppTest/array/FormatU8ArrayAc.hpp"
15#include "FppTest/array/FormatU16DecArrayAc.hpp"
16#include "FppTest/array/FormatU32OctArrayAc.hpp"
17#include "FppTest/array/FormatU64HexArrayAc.hpp"
18#include "FppTest/array/FormatI8ArrayAc.hpp"
19#include "FppTest/array/FormatI16DecArrayAc.hpp"
20#include "FppTest/array/FormatI32OctArrayAc.hpp"
21#include "FppTest/array/FormatI64HexArrayAc.hpp"
22#include "FppTest/array/FormatF32eArrayAc.hpp"
23#include "FppTest/array/FormatF32fArrayAc.hpp"
24#include "FppTest/array/FormatF64gArrayAc.hpp"
25#include "FppTest/array/FormatStringArrayAc.hpp"
26#include "FppTest/array/FormatCharArrayAc.hpp"
28
29#include "gtest/gtest.h"
30
31#include <sstream>
32#include <limits>
33
34// Tests FPP format strings
35class FormatTest : public ::testing::Test {
36protected:
37 void SetUp() override {
38 buf2 << "[ ";
39 }
40
41 std::stringstream buf1, buf2;
42};
43
45 bool testVals[FormatBool::SIZE] = {true, true, false};
46 FormatBool a(testVals);
47
48 buf1 << a;
49 for (U32 i = 0; i < FormatBool::SIZE; i++) {
50 buf2 << "a " << testVals[i] << " b ";
51 }
52 buf2 << "]";
53
54 ASSERT_STREQ(
55 buf1.str().c_str(),
56 buf2.str().c_str()
57 );
58}
59
61 U8 testVals[FormatU8::SIZE] = {0, 100, std::numeric_limits<U8>::max()};
62 FormatU8 a(testVals);
63
64 buf1 << a;
65 for (U32 i = 0; i < FormatU8::SIZE; i++) {
66 buf2 << "a " << (U16) testVals[i] << " b ";
67 }
68 buf2 << "]";
69
70 ASSERT_STREQ(
71 buf1.str().c_str(),
72 buf2.str().c_str()
73 );
74}
75
77 U16 testVals[FormatU16Dec::SIZE] = {0, 100, std::numeric_limits<U16>::max()};
78 FormatU16Dec a(testVals);
79
80 buf1 << a;
81 for (U32 i = 0; i < FormatU16Dec::SIZE; i++) {
82 buf2 << "a " << std::dec << testVals[i] << " b ";
83 }
84 buf2 << "]";
85
86 ASSERT_STREQ(
87 buf1.str().c_str(),
88 buf2.str().c_str()
89 );
90}
91
93 U32 testVals[FormatU32Oct::SIZE] = {0, 100, std::numeric_limits<U32>::max()};
94 FormatU32Oct a(testVals);
95
96 buf1 << a;
97 for (U32 i = 0; i < FormatU32Oct::SIZE; i++) {
98 buf2 << "a " << std::oct << testVals[i] << " b ";
99 }
100 buf2 << "]";
101
102 ASSERT_STREQ(
103 buf1.str().c_str(),
104 buf2.str().c_str()
105 );
106}
107
109 U64 testVals[FormatU64Hex::SIZE] =
110 {0, 100, std::numeric_limits<U64>::max()};
111 FormatU64Hex a(testVals);
112
113 buf1 << a;
114 for (U32 i = 0; i < FormatU64Hex::SIZE; i++) {
115 buf2 << "a " << std::hex << testVals[i] << " b ";
116 }
117 buf2 << "]";
118
119 ASSERT_STREQ(
120 buf1.str().c_str(),
121 buf2.str().c_str()
122 );
123}
124
126 I8 testVals[FormatI8::SIZE] =
127 {std::numeric_limits<I8>::min(), 0, std::numeric_limits<I8>::max()};
128 FormatI8 a(testVals);
129
130 buf1 << a;
131 for (U32 i = 0; i < FormatI8::SIZE; i++) {
132 buf2 << "a " << (I16) testVals[i] << " b ";
133 }
134 buf2 << "]";
135
136 ASSERT_STREQ(
137 buf1.str().c_str(),
138 buf2.str().c_str()
139 );
140}
141
143 I16 testVals[FormatI16Dec::SIZE] =
144 {std::numeric_limits<I16>::min(), 0, std::numeric_limits<I16>::max()};
145 FormatI16Dec a(testVals);
146
147 buf1 << a;
148 for (U32 i = 0; i < FormatI16Dec::SIZE; i++) {
149 buf2 << "a " << std::dec << testVals[i] << " b ";
150 }
151 buf2 << "]";
152
153 ASSERT_STREQ(
154 buf1.str().c_str(),
155 buf2.str().c_str()
156 );
157}
158
160 I32 testVals[FormatI32Oct::SIZE] =
161 {std::numeric_limits<I32>::min(), 0, std::numeric_limits<I32>::max()};
162 FormatI32Oct a(testVals);
163
164 buf1 << a;
165 for (U32 i = 0; i < FormatI32Oct::SIZE; i++) {
166 buf2 << "a " << std::oct << testVals[i] << " b ";
167 }
168 buf2 << "]";
169
170 ASSERT_STREQ(
171 buf1.str().c_str(),
172 buf2.str().c_str()
173 );
174
175}
176
178 I64 testVals[FormatI64Hex::SIZE] =
179 {std::numeric_limits<I64>::min(), 0, std::numeric_limits<I64>::max()};
180 FormatI64Hex a(testVals);
181
182 buf1 << a;
183 for (U32 i = 0; i < FormatI64Hex::SIZE; i++) {
184 buf2 << "a " << std::hex << testVals[i] << " b ";
185 }
186 buf2 << "]";
187
188 ASSERT_STREQ(
189 buf1.str().c_str(),
190 buf2.str().c_str()
191 );
192}
193
195 F32 testVals[FormatF32e::SIZE] =
196 {std::numeric_limits<F32>::min(), 0.0, std::numeric_limits<F32>::max()};
197 FormatF32e a(testVals);
198
199 buf1 << a;
200 for (U32 i = 0; i < FormatF32e::SIZE; i++) {
201 buf2 << "a " << std::setprecision(1) << std::scientific << testVals[i] << " b ";
202 }
203 buf2 << "]";
204
205 ASSERT_STREQ(
206 buf1.str().c_str(),
207 buf2.str().c_str()
208 );
209}
210
212 F32 testVals[FormatF32f::SIZE] =
213 {std::numeric_limits<F32>::min(), 0.0, std::numeric_limits<F32>::max()};
214 FormatF32f a(testVals);
215
216 buf1 << a;
217 for (U32 i = 0; i < FormatF32f::SIZE; i++) {
218 buf2 << "a " << std::setprecision(2) << std::fixed << testVals[i] << " b ";
219 }
220 buf2 << "]";
221
222 ASSERT_STREQ(
223 buf1.str().c_str(),
224 buf2.str().c_str()
225 );
226}
227
229 F64 testVals[FormatF64g::SIZE] =
230 {std::numeric_limits<F64>::min(), 0.0, std::numeric_limits<F64>::max()};
231 FormatF64g a(testVals);
232
233 buf1 << a;
234 for (U32 i = 0; i < FormatF64g::SIZE; i++) {
235 buf2 << "a " << std::setprecision(3) << testVals[i] << " b ";
236 }
237 buf2 << "]";
238
239 ASSERT_STREQ(
240 buf1.str().c_str(),
241 buf2.str().c_str()
242 );
243}
244
246 FormatString::StringSize80 testVals[FormatString::SIZE];
247 char buf[80];
248 for (U32 i = 0; i < FormatString::SIZE; i++) {
249 FppTest::Utils::setString(buf, sizeof(buf));
250 testVals[i] = buf;
251 }
252
253 FormatString a(testVals);
254
255 buf1 << a;
256 for (U32 i = 0; i < FormatString::SIZE; i++) {
257 buf2 << "% " << testVals[i].toChar() << " ";
258 }
259 buf2 << "]";
260
261 ASSERT_STREQ(
262 buf1.str().c_str(),
263 buf2.str().c_str()
264 );
265}
266
268 U8 testVals[FormatChar::SIZE] =
270 FormatChar a(testVals);
271
272 buf1 << a;
273 for (U32 i = 0; i < FormatChar::SIZE; i++) {
274 buf2 << "a " << testVals[i] << " b ";
275 }
276 buf2 << "]";
277
278 ASSERT_STREQ(
279 buf1.str().c_str(),
280 buf2.str().c_str()
281 );
282}
int8_t I8
8-bit signed integer
Definition BasicTypes.h:25
float F32
32-bit floating point
Definition BasicTypes.h:45
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
TEST_F(FormatTest, Bool)
void SetUp() override
std::stringstream buf2
std::stringstream buf1
void setString(char *buf, U32 size)
Definition Utils.cpp:41
U8 getNonzeroU8()
Definition Utils.cpp:23
#define U64(C)
Definition sha.h:176