src.dualinventive.com/fw/libdi_fw-tests/libdi/tests/can_rpc.cpp

79 lines
2.1 KiB
C++

/**
* @file tests/can_rpc.cpp
* @brief brief
* @date Aug 25, 2015
* @author rheijden
* @copyright 2015 Dual Inventive Technology Centre B.V.
*
* descr
*/
#include "fixtures/CANTest.hpp"
TEST_F(DI_CAN, rpc_send_device_info) {
struct di_rpc_device_info d;
char l[] = "testlabel";
d.version = NULL; // We let libdi generate the version for us :-)
d.revision = 123;
d.type = l;
ASSERT_EQ(DNOK, di_can_rpc_send(&_ctx, DI_CAN_TRANSFERTYPE_PUBLISH, DI_RPC_TYPE_DEVICE_INFO, &d, 1));
}
TEST_F(DI_CAN, rpc_send_sensor_info_bool) {
struct di_rpc_info info;
info.uid = 1;
info.label = "test-can-rpc-bool";
info.data_type = DI_RPC_DATA_TYPE_BOOL;
ASSERT_EQ(DNOK, di_can_rpc_send(&_ctx, DI_CAN_TRANSFERTYPE_PUBLISH, DI_RPC_TYPE_SENSOR_INFO, &info, 1));
}
TEST_F(DI_CAN, rpc_send_sensor_info_enum) {
struct di_rpc_info info;
struct di_rpc_enum elist[] = {
{ "empty", 0 },
{ "crit", 1 },
{ "low", 2 },
{ "half", 3 },
{ "full", 4 }
};
info.uid = 1;
info.label = "bat1-state";
info.data_type = DI_RPC_DATA_TYPE_ENUM;
info.enumerator.size = DI_ARRAY_SIZE(elist);
info.enumerator.begin = elist;
ASSERT_EQ(DNOK, di_can_rpc_send(&_ctx, DI_CAN_TRANSFERTYPE_PUBLISH, DI_RPC_TYPE_SENSOR_INFO, &info, 1));
}
TEST_F(DI_CAN, rpc_send_notify_info_single) {
struct di_rpc_info info;
info.uid = 1;
info.label = "wu-alarm-system";
info.data_type = DI_RPC_DATA_TYPE_BOOL;
ASSERT_EQ(DNOK, di_can_rpc_send(&_ctx, DI_CAN_TRANSFERTYPE_PUBLISH, DI_RPC_TYPE_NOTIFY_INFO, &info, 1));
}
TEST_F(DI_CAN, rpc_send_log_info_single) {
struct di_rpc_log log;
log.msg = "Hello World!";
ASSERT_EQ(DNOK, di_can_rpc_send(&_ctx, DI_CAN_TRANSFERTYPE_PUBLISH, DI_RPC_TYPE_LOG_INFO, &log, 1));
}
TEST_F(DI_CAN, rpc_send_device_ping) {
ASSERT_EQ(DNOK, di_can_rpc_send_device_ping(&_ctx, DI_CAN_TRANSFERTYPE_PUBLISH));
ASSERT_EQ(DNOK, di_can_rpc_send_device_ping(&_ctx, DI_CAN_TRANSFERTYPE_REPLY));
}
/** Send RPC reply on action:set with di_errno_t DNE_OPNOTSUPP (operation not supported) */
TEST_F(DI_CAN, rpc_send_errno) {
ASSERT_EQ(DNOK, di_can_rpc_send_errno(&_ctx, DI_CAN_TRANSFERTYPE_REPLY, DI_RPC_TYPE_ACTION_SET, DNE_OPNOTSUPP));
}