TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
configurers_utils.test.cpp File Reference

Test configurers utilitary functions. More...

#include <ros/ros.h>
#include <gtest/gtest.h>
#include "travesim_adapters/configurers/configurers_utils.hpp"
Include dependency graph for configurers_utils.test.cpp:

Go to the source code of this file.

Functions

 TEST (configurers_utils, ipv4_string_to_uint)
 
 TEST (configurers_utils, check_valid_ip)
 
 TEST (configurers_utils, get_error_msg)
 
int main (int argc, char **argv)
 

Detailed Description

Test configurers utilitary functions.

Author
Lucas Haug lucas.nosp@m..hau.nosp@m.g@thu.nosp@m.nera.nosp@m.tz.or.nosp@m.g
Date
06/2021

Definition in file configurers_utils.test.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 99 of file configurers_utils.test.cpp.

99  {
100  testing::InitGoogleTest(&argc, argv);
101  return RUN_ALL_TESTS();
102 }

◆ TEST() [1/3]

TEST ( configurers_utils  ,
ipv4_string_to_uint   
)

Definition at line 23 of file configurers_utils.test.cpp.

24 {
25  uint ip_uint[4] = {0};
26 
27  EXPECT_TRUE(travesim::ipv4_string_to_uint("1.1.1.1", ip_uint));
28  EXPECT_TRUE(testing::internal::ArrayEq(ip_uint, {1, 1, 1, 1}));
29 
30  ip_uint[0] = 0;
31  ip_uint[1] = 0;
32  ip_uint[2] = 0;
33  ip_uint[3] = 0;
34 
35  EXPECT_TRUE(travesim::ipv4_string_to_uint("127.220.4.32", ip_uint));
36  EXPECT_TRUE(testing::internal::ArrayEq(ip_uint, {127, 220, 4, 32}));
37 
38  ip_uint[0] = 0;
39  ip_uint[1] = 0;
40  ip_uint[2] = 0;
41  ip_uint[3] = 0;
42 
43  EXPECT_FALSE(travesim::ipv4_string_to_uint("@.b.C.3", ip_uint));
44  EXPECT_TRUE(testing::internal::ArrayEq(ip_uint, {0, 0, 0, 0}));
45 
46  ip_uint[0] = 0;
47  ip_uint[1] = 0;
48  ip_uint[2] = 0;
49  ip_uint[3] = 0;
50 
51  EXPECT_FALSE(travesim::ipv4_string_to_uint("123,123,123,123", ip_uint));
52  EXPECT_TRUE(testing::internal::ArrayEq(ip_uint, {123, 0, 0, 0}));
53 
54  ip_uint[0] = 0;
55  ip_uint[1] = 0;
56  ip_uint[2] = 0;
57  ip_uint[3] = 0;
58 
59  EXPECT_FALSE(travesim::ipv4_string_to_uint("Test", ip_uint));
60  EXPECT_TRUE(testing::internal::ArrayEq(ip_uint, {0, 0, 0, 0}));
61 
62  ip_uint[0] = 0;
63  ip_uint[1] = 0;
64  ip_uint[2] = 0;
65  ip_uint[3] = 0;
66 
67  EXPECT_FALSE(travesim::ipv4_string_to_uint("239.64.73.Q", ip_uint));
68  EXPECT_TRUE(testing::internal::ArrayEq(ip_uint, {239, 64, 73, 0}));
69 }
bool ipv4_string_to_uint(std::string ip_string, uint *ip_uint)
Converts a IPv4 in a string to a array of unsigned integers, where the most significant byte of the I...

References travesim::ipv4_string_to_uint().

Here is the call graph for this function:

◆ TEST() [2/3]

TEST ( configurers_utils  ,
check_valid_ip   
)

Definition at line 71 of file configurers_utils.test.cpp.

72 {
73  using namespace travesim;
74 
75  EXPECT_EQ(check_valid_ip("127.0.0.2", "127.0.0.0", "127.255.255.0"), IPValidation::VALID);
76  EXPECT_EQ(check_valid_ip("225.0.64.2", "224.0.0.0", "239.255.34.255"), IPValidation::VALID);
77  EXPECT_EQ(check_valid_ip("227.0.0.2", "227.0.0.0", "A.255.255.0"), IPValidation::INVALID_FORMAT);
78  EXPECT_EQ(check_valid_ip("127.0.0,2", "127.0.0.0", "127.255.255.0"), IPValidation::INVALID_FORMAT);
79  EXPECT_EQ(check_valid_ip("127.0.512.2", "127.0.0.0", "127.255.255.0"), IPValidation::INVALID_NUMBERS);
80  EXPECT_EQ(check_valid_ip("1024.0.0.2", "127.0.0.0", "127.255.255.0"), IPValidation::INVALID_NUMBERS);
81  EXPECT_EQ(check_valid_ip("127.0.0.2", "127.0.0.255", "127.255.255.0"), IPValidation::OUT_OF_RANGE);
82  EXPECT_EQ(check_valid_ip("224.0.0.2", "127.0.0.0", "127.255.255.0"), IPValidation::OUT_OF_RANGE);
83 }
IPValidation check_valid_ip(std::string ip, std::string min_ip, std::string max_ip)
Checks if a IP is valid and is in the specified range.

References travesim::check_valid_ip(), travesim::INVALID_FORMAT, travesim::INVALID_NUMBERS, travesim::OUT_OF_RANGE, and travesim::VALID.

Here is the call graph for this function:

◆ TEST() [3/3]

TEST ( configurers_utils  ,
get_error_msg   
)

Definition at line 85 of file configurers_utils.test.cpp.

86 {
87  using namespace travesim;
88 
89  EXPECT_EQ(get_error_msg(IPValidation::VALID), "No error.");
90  EXPECT_EQ(get_error_msg(IPValidation::INVALID_FORMAT), "The IP string is wrong formatted.");
92  "The numbers on the ip are not representable by 8 bits.");
94  "The IP is not in the specified range. Hover over the parameterto see the range.");
95  EXPECT_EQ(get_error_msg(IPValidation(42)), "No error.");
96 }
IPValidation
Type used to validate a IP string.
std::string get_error_msg(IPValidation error)
Get the error msg based on the validation type.

References travesim::get_error_msg(), travesim::INVALID_FORMAT, travesim::INVALID_NUMBERS, travesim::OUT_OF_RANGE, and travesim::VALID.

Here is the call graph for this function: