-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathSimulatorInterfaceTest.cpp
More file actions
59 lines (49 loc) · 2.52 KB
/
SimulatorInterfaceTest.cpp
File metadata and controls
59 lines (49 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2020 Charles Tytler
#include <gtest/gtest.h>
#include "SimulatorInterface/SimulatorInterface.h"
namespace test
{
class SimulatorInterfaceDerivedClass : public SimulatorInterface
{
using SimulatorInterface::SimulatorInterface;
// Implement pure virtual functions to allow testing of common functions.
void update_simulator_state(){};
void send_command(const std::string &address, const std::string &value){};
void send_reset_command(){};
std::optional<std::string> get_string_at_addr(const SimulatorAddress &address) const { return std::nullopt; }
std::optional<Decimal> get_value_at_addr(const SimulatorAddress &address) const { return std::nullopt; }
json get_current_state_as_json() const { return json{}; };
};
TEST(SimulatorInterfaceTest, invalid_connection_port_settings)
{
const SimulatorConnectionSettings connection_settings = {"19ab", "abc", "127.0.0.1", ""};
EXPECT_THROW(SimulatorInterfaceDerivedClass simulator_interface(connection_settings), std::runtime_error);
}
TEST(SimulatorInterfaceTest, udp_connect_on_construction_without_multicast)
{
const SimulatorConnectionSettings connection_settings = {"1908", "1909", "127.0.0.1", ""};
SimulatorInterfaceDerivedClass simulator_interface(connection_settings);
// Expect no errors thrown.
EXPECT_TRUE(simulator_interface.connection_settings_match(connection_settings));
}
TEST(SimulatorInterfaceTest, udp_connect_on_construction_with_multicast)
{
const SimulatorConnectionSettings connection_settings = {"1908", "1909", "0.0.0.0", "239.255.50.10"};
SimulatorInterfaceDerivedClass simulator_interface(connection_settings);
// Expect no errors thrown.
EXPECT_TRUE(simulator_interface.connection_settings_match(connection_settings));
}
TEST(SimulatorInterfaceTest, connection_settings_match_false)
{
const SimulatorConnectionSettings connection_settings = {"1908", "1909", "127.0.0.1", ""};
SimulatorInterfaceDerivedClass simulator_interface(connection_settings);
SimulatorConnectionSettings mismatched_connection_settings = {"1111", "2222", "127.0.0.1", ""};
EXPECT_FALSE(simulator_interface.connection_settings_match(mismatched_connection_settings));
}
TEST(SimulatorInterfaceTest, get_current_module_initial_value)
{
SimulatorInterfaceDerivedClass simulator_interface(SimulatorConnectionSettings{"1908", "1909", "127.0.0.1", ""});
// Test that the default value of an empty string is returned after initialization.
EXPECT_EQ("", simulator_interface.get_current_module());
}
} // namespace test