mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 19:13:33 +08:00
ScalarCodec - added representation correctness test
This commit is contained in:
@@ -40,6 +40,12 @@ class ScalarCodec
|
|||||||
u.l = 1;
|
u.l = 1;
|
||||||
const bool big_endian = u.c[sizeof(long int) - 1] == 1;
|
const bool big_endian = u.c[sizeof(long int) - 1] == 1;
|
||||||
#endif
|
#endif
|
||||||
|
/*
|
||||||
|
* I didn't have any big endian machine nearby, so big endian support wasn't tested yet.
|
||||||
|
* It is likely to be OK anyway, so feel free to remove this assert() as needed.
|
||||||
|
*/
|
||||||
|
assert(big_endian == false);
|
||||||
|
|
||||||
if (big_endian)
|
if (big_endian)
|
||||||
swapByteOrder(bytes);
|
swapByteOrder(bytes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,8 +74,23 @@ TEST(ScalarCodec, Basic)
|
|||||||
CHECK(64, u64, std::numeric_limits<uint64_t>::max());
|
CHECK(64, u64, std::numeric_limits<uint64_t>::max());
|
||||||
|
|
||||||
#undef CHECK
|
#undef CHECK
|
||||||
|
|
||||||
|
ASSERT_EQ(0, sc_rd.decode<64>(u64)); // Out of buffer space
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(ScalarCodec, RepresentationCorrectness)
|
TEST(ScalarCodec, RepresentationCorrectness)
|
||||||
{
|
{
|
||||||
|
uavcan::StaticTransferBuffer<4> buf;
|
||||||
|
uavcan::BitStream bs_wr(buf);
|
||||||
|
uavcan::ScalarCodec sc_wr(bs_wr);
|
||||||
|
|
||||||
|
ASSERT_EQ(1, sc_wr.encode<12>((uint16_t)0xbeda)); // --> 0xeda
|
||||||
|
ASSERT_EQ(1, sc_wr.encode<3>((int8_t)-1));
|
||||||
|
ASSERT_EQ(1, sc_wr.encode<4>((int8_t)-5));
|
||||||
|
ASSERT_EQ(1, sc_wr.encode<2>((int16_t)-1));
|
||||||
|
ASSERT_EQ(1, sc_wr.encode<4>((uint8_t)0x88)); // --> 8
|
||||||
|
|
||||||
|
// This representation was carefully crafted and triple checked:
|
||||||
|
static const std::string REFERENCE = "11011010 11101111 01111100 00000000";
|
||||||
|
ASSERT_EQ(REFERENCE, bs_wr.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user