network_interface_test.cpp
Go to the documentation of this file.
00001 #include <network_utils.h>
00002 #include <gtest/gtest.h>
00003 #include <stdio.h>
00004 
00005 TEST(TCPInterface, testReadBEFloat)
00006 {
00007   // 123.4567 as binary float
00008   uint8_t bytes[4] = { 0x42, 0xF6, 0xE9, 0xD5};
00009   ASSERT_EQ(123.45670318603515625, AS::Network::read_be<float>(bytes, 4, 0));
00010 }
00011 
00012 TEST(TCPInterface, testReadBEDouble)
00013 {
00014   // 123.4567 as binary double
00015   uint8_t bytes[8] = { 0x40, 0x5E, 0xDD, 0x3A, 0x92, 0xA3, 0x05, 0x53};
00016   ASSERT_EQ(123.4567, AS::Network::read_be<double>(bytes, 8, 0));
00017 }
00018 
00019 TEST(TCPInterface, testReadBEInt)
00020 {
00021   // 888888888 as  hex Int
00022   uint8_t bytes[4] = { 0x34, 0xFB, 0x5E, 0x38};
00023   ASSERT_EQ(888888888, AS::Network::read_be<uint32_t>(bytes, 4, 0));
00024 }
00025 
00026 TEST(TCPInterface, testReadLEFloat)
00027 {
00028   // 123.4567 as binary float
00029   uint8_t bytes[4] = { 0xD5, 0xE9, 0xF6, 0x42};
00030   ASSERT_EQ(123.45670318603515625, AS::Network::read_le<float>(bytes, 4, 0));
00031 }
00032 
00033 TEST(TCPInterface, testReadLEDouble)
00034 {
00035   // 123.4567 as binary double
00036   uint8_t bytes[8] = { 0x53, 0x05, 0xA3, 0x92, 0x3A, 0xDD, 0x5E, 0x40};
00037   ASSERT_EQ(123.4567, AS::Network::read_le<double>(bytes, 8, 0));
00038 }
00039 
00040 TEST(TCPInterface, testReadLEInt)
00041 {
00042   // 1234567891 as  hex Int
00043   uint8_t bytes[4] = { 0xD3, 0x02, 0x96, 0x49};
00044   ASSERT_EQ(1234567891, AS::Network::read_le<uint32_t>(bytes, 4, 0));
00045 }
00046 
00047 int main(int argc, char **argv)
00048 {
00049   testing::InitGoogleTest(&argc, argv);
00050   return RUN_ALL_TESTS();
00051 }


network_interface
Author(s): Joshua Whitley , Daniel Stanek , Joe Kale
autogenerated on Thu Jun 6 2019 21:43:30