API
 
Loading...
Searching...
No Matches
modbus_test.cpp
Go to the documentation of this file.
1/** \file modbus_test.cpp
2 * \brief Catch2 tests for the MagAO-X Modbus transport.
3 *
4 * \author Jared R. Males (jaredmales@gmail.com)
5 */
6
7#include "../../../tests/catch2/catch.hpp"
8
9#include <sys/socket.h>
10#include <unistd.h>
11
12#define private public
13#include "../modbus.hpp"
14#undef private
15#include "../modbus_exception.hpp"
16
17namespace libXWCTest
18{
19namespace modbusTest
20{
21
22/// Verify the Modbus client throws instead of dying when the peer disappears.
23TEST_CASE( "modbus reports a dropped peer as a connection exception", "[modbus]" )
24{
25 int socketPair[2];
26 REQUIRE( ::socketpair( AF_UNIX, SOCK_STREAM, 0, socketPair ) == 0 );
27
28 modbus mb( "127.0.0.1", 502 );
29 mb._socket = socketPair[0];
30 mb._connected = true;
31
32 REQUIRE( ::close( socketPair[1] ) == 0 );
33
34 uint16_t inputRegs[1]{ 0 };
35
36 REQUIRE_THROWS_AS( mb.modbus_read_input_registers( 0, 1, inputRegs ), modbus_connect_exception );
37 REQUIRE( mb._connected == false );
38}
39
40} // namespace modbusTest
41} // namespace libXWCTest
Modbus Connect Exception.
Modbus Operator Class.
Definition modbus.hpp:53
void modbus_read_input_registers(int address, int amount, uint16_t *buffer)
Definition modbus.cpp:225
bool _connected
Definition modbus.hpp:55
int _socket
Definition modbus.hpp:57
TEST_CASE("modbus reports a dropped peer as a connection exception", "[modbus]")
Verify the Modbus client throws instead of dying when the peer disappears.
Namespace for all libXWC tests.