2 #include <gtest/gtest.h> 7 TEST(ByteOrder, compare_with_htons)
10 for(uint16_t host_num = 0; host_num < 50000; host_num += 71)
12 uint16_t net_num = htons(host_num);
13 uint16_t memcpy_num = 0;
15 EXPECT_EQ(memcpy_num, net_num);
19 TEST(ByteOrder, compare_with_htonl)
21 for(uint32_t host_num = 0; host_num < 4000000000; host_num += 1299827)
23 uint32_t net_num = htonl(host_num);
24 uint32_t memcpy_num = 0;
26 EXPECT_EQ(memcpy_num, net_num);
33 r.
write_raw(5,
"\x01\x02\x03\x04\x05\x06");
36 EXPECT_EQ(0x0102, u16.
get(0));
37 EXPECT_EQ(0x0304, u16.
get(1));
38 EXPECT_EQ(0x0506, u16.
get(2));
41 EXPECT_EQ(0x0506, u16n.get(0));
44 EXPECT_EQ(0x01020304, u32.get(0));
47 TEST(Accessor, basic_float)
50 r.
write_raw(10,
"\x01\x02\x03\x04\x05\x06\x07\x08");
59 EXPECT_FLOAT_EQ(val, f.
get(0));
61 EXPECT_FLOAT_EQ(val, f.
get(1));
69 const float scale(0.001);
71 EXPECT_FLOAT_EQ(scale * 0x0102, i16.
get_scaled(0));
72 EXPECT_FLOAT_EQ(scale * 0x0304, i16.
get_scaled(1));
84 EXPECT_FLOAT_EQ(0.123, check);
86 EXPECT_FLOAT_EQ(0.987, check);
88 EXPECT_FLOAT_EQ(0.555, check);
91 int main(
int argc,
char **argv)
93 testing::InitGoogleTest(&argc, argv);
94 return RUN_ALL_TESTS();
double get_scaled(uint16_t field) const
const Accessor< float > mag_ref
void write_raw(uint8_t register_index, std::string data)
Provides the Registers class, which initializes with a suite of accessors suitable for reading and wr...
int main(int argc, char **argv)
void memcpy_network(void *dest, void *src, size_t count)
void set_scaled(uint16_t field, double value) const
TEST(ByteOrder, compare_with_htons)
RegT get(uint8_t field) const
void set(uint8_t field, RegT value) const