API
Applications
Utilities
API
Handbook
GitHub
Home
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
17
namespace
libXWCTest
18
{
19
namespace
modbusTest
20
{
21
22
/// Verify the Modbus client throws instead of dying when the peer disappears.
23
TEST_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 Connect Exception.
Definition
modbus_exception.hpp:36
modbus
Modbus Operator Class.
Definition
modbus.hpp:53
modbus::modbus_read_input_registers
void modbus_read_input_registers(int address, int amount, uint16_t *buffer)
Definition
modbus.cpp:225
modbus::_connected
bool _connected
Definition
modbus.hpp:55
modbus::_socket
int _socket
Definition
modbus.hpp:57
libXWCTest::modbusTest::TEST_CASE
TEST_CASE("modbus reports a dropped peer as a connection exception", "[modbus]")
Verify the Modbus client throws instead of dying when the peer disappears.
Definition
modbus_test.cpp:23
libXWCTest
Namespace for all libXWC tests.
Definition
stdMotionStage_test.cpp:15
libMagAOX
modbus
tests
modbus_test.cpp
Generated by
1.9.8