3 #include "gtest/gtest.h" 9 typedef ::testing::Types<bool, uint8_t, uint16_t, uint32_t, int8_t, int16_t,
10 int32_t, float,
double>
15 typedef ::testing::Types<uint8_t, uint16_t, uint32_t, int8_t, int16_t, int32_t>
22 EXPECT_EQ(std::size_t(0), b.size());
30 EXPECT_TRUE(b.
pack(ref));
31 EXPECT_EQ(
sizeof(TypeParam), b.size());
32 EXPECT_TRUE(b.
unpack(ref));
33 EXPECT_EQ(TypeParam(0), ref);
39 EXPECT_TRUE(b.
pack(ref));
40 EXPECT_EQ(
sizeof(TypeParam), b.size());
41 EXPECT_TRUE(b.
unpack(ref));
42 EXPECT_EQ(TypeParam(1), ref);
47 TypeParam ref = std::numeric_limits<TypeParam>::max();
48 EXPECT_TRUE(b.
pack(ref));
49 EXPECT_EQ(
sizeof(TypeParam), b.size());
50 EXPECT_TRUE(b.
unpack(ref));
51 EXPECT_EQ(std::numeric_limits<TypeParam>::max(), ref);
56 TypeParam ref = std::numeric_limits<TypeParam>::min();
57 EXPECT_TRUE(b.
pack(ref));
58 EXPECT_EQ(
sizeof(TypeParam), b.size());
59 EXPECT_TRUE(b.
unpack(ref));
60 EXPECT_EQ(std::numeric_limits<TypeParam>::min(), ref);
68 EXPECT_TRUE(b.
pack(v));
69 EXPECT_EQ(
sizeof(TypeParam), b.size());
79 EXPECT_TRUE(b.
pack(v));
80 EXPECT_EQ(
sizeof(TypeParam), b.size());
88 TypeParam ref = std::numeric_limits<TypeParam>::max();
90 EXPECT_TRUE(b.
pack(v));
91 EXPECT_EQ(
sizeof(TypeParam), b.size());
99 TypeParam ref = std::numeric_limits<TypeParam>::min();
101 EXPECT_TRUE(b.
pack(v));
102 EXPECT_EQ(
sizeof(TypeParam), b.size());
110 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(ref));
111 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
112 for(
int i = 0; i < 10; ++i) {
113 EXPECT_TRUE(b.
unpack(ref));
114 EXPECT_EQ(TypeParam(0), ref);
121 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(ref));
122 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
123 for(
int i = 0; i < 10; ++i) {
124 EXPECT_TRUE(b.
unpack(ref));
125 EXPECT_EQ(TypeParam(1), ref);
131 TypeParam ref = std::numeric_limits<TypeParam>::max();
132 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(ref));
133 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
134 for(
int i = 0; i < 10; ++i) {
135 EXPECT_TRUE(b.
unpack(ref));
136 EXPECT_EQ(std::numeric_limits<TypeParam>::max(), ref);
142 TypeParam ref = std::numeric_limits<TypeParam>::min();
143 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(ref));
144 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
145 for(
int i = 0; i < 10; ++i) {
146 EXPECT_TRUE(b.
unpack(ref));
147 EXPECT_EQ(std::numeric_limits<TypeParam>::min(), ref);
156 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(v));
157 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
158 for(
int i = 0; i < 10; ++i) {
169 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(v));
170 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
171 for(
int i = 0; i < 10; ++i) {
180 TypeParam ref = std::numeric_limits<TypeParam>::max();
182 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(v));
183 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
184 for(
int i = 0; i < 10; ++i) {
193 TypeParam ref = std::numeric_limits<TypeParam>::min();
195 for(
int i = 0; i < 10; ++i) EXPECT_TRUE(b.
pack(v));
196 EXPECT_EQ(10 *
sizeof(TypeParam), b.size());
197 for(
int i = 0; i < 10; ++i) {
206 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
207 EXPECT_EQ(
sizeof(TypeParam), b.size());
208 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
209 EXPECT_DOUBLE_EQ(0, ref);
215 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
216 EXPECT_EQ(
sizeof(TypeParam), b.size());
217 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
218 EXPECT_DOUBLE_EQ(10.f, ref);
223 double ref = (double)std::numeric_limits<TypeParam>::max() + 1.0;
224 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
225 EXPECT_EQ(
sizeof(TypeParam), b.size());
226 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
227 EXPECT_DOUBLE_EQ(std::numeric_limits<TypeParam>::max(), ref);
232 double ref = (double)std::numeric_limits<TypeParam>::min() - 1.0;
233 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
234 EXPECT_EQ(
sizeof(TypeParam), b.size());
235 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
236 EXPECT_DOUBLE_EQ(std::numeric_limits<TypeParam>::min(), ref);
242 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
243 EXPECT_EQ(
sizeof(TypeParam), b.size());
244 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
245 EXPECT_FLOAT_EQ(0.f, ref);
251 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
252 EXPECT_EQ(
sizeof(TypeParam), b.size());
253 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
254 EXPECT_FLOAT_EQ(10.f, ref);
259 float ref = (float)std::numeric_limits<TypeParam>::max() + 1.0;
260 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
261 EXPECT_EQ(
sizeof(TypeParam), b.size());
262 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
263 EXPECT_FLOAT_EQ(std::numeric_limits<TypeParam>::max(), ref);
268 float ref = (float)std::numeric_limits<TypeParam>::min() - 1.0;
269 EXPECT_TRUE(b.
pack<TypeParam>(ref, 1));
270 EXPECT_EQ(
sizeof(TypeParam), b.size());
271 EXPECT_TRUE(b.
unpack<TypeParam>(ref, 1));
272 EXPECT_FLOAT_EQ(std::numeric_limits<TypeParam>::min(), ref);
277 int main(
int argc,
char **argv) {
278 ::testing::InitGoogleTest(&argc, argv);
279 return RUN_ALL_TESTS();
::testing::Types< uint8_t, uint16_t, uint32_t, int8_t, int16_t, int32_t > scaleOutputTypes
bool unpack(T &val) const
Extracts little endian integers from the ByteVector. Consumes a number of bytes matching sizeof(T)...
TYPED_TEST_CASE(ByteVectorBasicTest, basicTypes)
::testing::Types< bool, uint8_t, uint16_t, uint32_t, int8_t, int16_t, int32_t, float, double > basicTypes
TEST(ByteVectorBasicTest, Initialzation)
bool pack(const T &val)
Packs integer types into the ByteVector. Ensures little endian packing.
TYPED_TEST(ByteVectorBasicTest, Pack1zero)
std::size_t unpacking_remaining() const
Returns the number of bytes still avialable for unpacking.
std::size_t unpacking_offset() const
Gives the number of bytes which have already been consumed by unpack operations.
int main(int argc, char **argv)