network_interface_test.cpp
Go to the documentation of this file.
1 #include <network_utils.h>
2 #include <gtest/gtest.h>
3 #include <stdio.h>
4 
5 TEST(TCPInterface, testReadBEFloat)
6 {
7  // 123.4567 as binary float
8  uint8_t bytes[4] = { 0x42, 0xF6, 0xE9, 0xD5};
9  ASSERT_EQ(123.45670318603515625, AS::Network::read_be<float>(bytes, 4, 0));
10 }
11 
12 TEST(TCPInterface, testReadBEDouble)
13 {
14  // 123.4567 as binary double
15  uint8_t bytes[8] = { 0x40, 0x5E, 0xDD, 0x3A, 0x92, 0xA3, 0x05, 0x53};
16  ASSERT_EQ(123.4567, AS::Network::read_be<double>(bytes, 8, 0));
17 }
18 
19 TEST(TCPInterface, testReadBEInt)
20 {
21  // 888888888 as hex Int
22  uint8_t bytes[4] = { 0x34, 0xFB, 0x5E, 0x38};
23  ASSERT_EQ(888888888, AS::Network::read_be<uint32_t>(bytes, 4, 0));
24 }
25 
26 TEST(TCPInterface, testReadLEFloat)
27 {
28  // 123.4567 as binary float
29  uint8_t bytes[4] = { 0xD5, 0xE9, 0xF6, 0x42};
30  ASSERT_EQ(123.45670318603515625, AS::Network::read_le<float>(bytes, 4, 0));
31 }
32 
33 TEST(TCPInterface, testReadLEDouble)
34 {
35  // 123.4567 as binary double
36  uint8_t bytes[8] = { 0x53, 0x05, 0xA3, 0x92, 0x3A, 0xDD, 0x5E, 0x40};
37  ASSERT_EQ(123.4567, AS::Network::read_le<double>(bytes, 8, 0));
38 }
39 
40 TEST(TCPInterface, testReadLEInt)
41 {
42  // 1234567891 as hex Int
43  uint8_t bytes[4] = { 0xD3, 0x02, 0x96, 0x49};
44  ASSERT_EQ(1234567891, AS::Network::read_le<uint32_t>(bytes, 4, 0));
45 }
46 
47 int main(int argc, char **argv)
48 {
49  testing::InitGoogleTest(&argc, argv);
50  return RUN_ALL_TESTS();
51 }
int main(int argc, char **argv)
TEST(TCPInterface, testReadBEFloat)


network_interface
Author(s): Joshua Whitley , Daniel Stanek , Joe Kale
autogenerated on Sat Sep 7 2019 03:30:10