2 #include <gtest/gtest.h> 7 TEST(ByteOrder, compare_with_htons)
10 for(uint16_t host_num = 0; host_num < 50000; host_num += 71) {
11 uint16_t net_num = htons(host_num);
12 uint16_t memcpy_num = 0;
14 EXPECT_EQ(memcpy_num, net_num);
18 TEST(ByteOrder, compare_with_htonl)
20 for(uint32_t host_num = 0; host_num < 4000000000; host_num += 1299827) {
21 uint32_t net_num = htonl(host_num);
22 uint32_t memcpy_num = 0;
24 EXPECT_EQ(memcpy_num, net_num);
31 r.
write_raw(5,
"\x01\x02\x03\x04\x05\x06");
34 EXPECT_EQ(0x0102, u16.
get(0));
35 EXPECT_EQ(0x0304, u16.
get(1));
36 EXPECT_EQ(0x0506, u16.
get(2));
39 EXPECT_EQ(0x0506, u16n.get(0));
42 EXPECT_EQ(0x01020304, u32.get(0));
45 TEST(Accessor, basic_float)
48 r.
write_raw(10,
"\x01\x02\x03\x04\x05\x06\x07\x08");
56 EXPECT_FLOAT_EQ(val, f.
get(0));
58 EXPECT_FLOAT_EQ(val, f.
get(1));
66 const float scale(0.001);
68 EXPECT_FLOAT_EQ(scale * 0x0102, i16.
get_scaled(0));
69 EXPECT_FLOAT_EQ(scale * 0x0304, i16.
get_scaled(1));
81 EXPECT_FLOAT_EQ(0.123, check);
83 EXPECT_FLOAT_EQ(0.987, check);
85 EXPECT_FLOAT_EQ(0.555, check);
88 int main(
int argc,
char **argv)
90 testing::InitGoogleTest(&argc, argv);
91 return RUN_ALL_TESTS();
Provides the Registers class, which initializes with a suite of accessors suitable for reading and wr...
void set(uint8_t field, RegT value) const
void set_scaled(uint16_t field, double value) const
RegT get(uint8_t field) const
int main(int argc, char **argv)
TEST(ByteOrder, compare_with_htons)
void write_raw(uint8_t register_index, std::string data)
void memcpy_network(void *dest, void *src, size_t count)
const Accessor< float > mag_bias
double get_scaled(uint16_t field) const