18 #include <gtest/gtest.h> 21 #include <modbus/modbus.h> 43 static void SetUpTestCase();
44 void SetUp()
override;
45 void TearDown()
override;
51 static unsigned int testPort();
69 server_->startAsync(
LOCALHOST, testPort());
73 EXPECT_TRUE(client_.init(
LOCALHOST, testPort())) <<
"Server not present";
80 shutdownModbusServer(server_.get(), client_);
86 return PORTS_FOR_TEST_.at(ACTIVE_PORT_IDX_ % PORTS_FOR_TEST_.size());
91 std::iota(PORTS_FOR_TEST_.begin(), PORTS_FOR_TEST_.end(),
START_PORT);
97 RegCont reg_to_write_by_client{ 1 };
114 <<
"Unexpected reaction to proper connection (ip address and port number correct).";
124 EXPECT_FALSE(
checkIPConnection(
"192.192.192.192", testPort())) <<
"Unexpected reaction to incorrect ip address.";
129 ASSERT_NE(WRONG_PORT, testPort());
131 <<
"Unexpected reaction to incorrect port number and ip address.";
136 int main(
int argc,
char* argv[])
138 testing::InitGoogleTest(&argc, argv);
139 return RUN_ALL_TESTS();
Offers a modbus server and read/write functionality via subscription/publication. ...
constexpr unsigned int DEFAULT_REGISTER_SIZE
void shutdownModbusServer(PilzModbusServerMock *server, LibModbusClient &client)
std::vector< uint16_t > RegCont
Convenience data type defining the data type for a collection of registers.
constexpr unsigned int START_PORT
constexpr unsigned int DEFAULT_WRITE_IDX
constexpr unsigned int WRONG_PORT
static std::vector< unsigned int > PORTS_FOR_TEST_
static void SetUpTestCase()
constexpr unsigned int END_PORT
static unsigned int ACTIVE_PORT_IDX_
RegCont writeReadHoldingRegister(const int write_addr, const RegCont &write_reg, const int read_addr, const int read_nb) override
See base class.
TEST_F(ModbusConnectionCheckTestsuite, testReactionToCorrectConnection)
static unsigned int testPort()
int main(int argc, char *argv[])
void terminate()
Terminate the Server. Reading or connecting to it will fail.
bool checkIPConnection(const char *ip, const unsigned int &port)
Test the ip connection by connecting to the modbus server.
constexpr const char *const LOCALHOST
Wrapper around libmodbus, see https://libmodbus.org/.
Expection thrown by prbt_hardware_support::LibModbusClient::readHoldingRegister if a disconnect from ...