#include #include #include TEST(rpc, type_to_str) { static struct expect { const char *str; enum di_rpc_types type; } expect[] = { { "notify:info", DI_RPC_TYPE_NOTIFY_INFO }, { "notify:data", DI_RPC_TYPE_NOTIFY_DATA }, { "action:info", DI_RPC_TYPE_ACTION_INFO }, { "action:get", DI_RPC_TYPE_ACTION_GET }, { "action:set", DI_RPC_TYPE_ACTION_SET }, { "sensor:info", DI_RPC_TYPE_SENSOR_INFO }, { "sensor:data", DI_RPC_TYPE_SENSOR_DATA }, { "config:info", DI_RPC_TYPE_CONFIG_INFO }, { "config:get", DI_RPC_TYPE_CONFIG_GET }, { "config:set", DI_RPC_TYPE_CONFIG_SET }, { "device:ping", DI_RPC_TYPE_DEVICE_PING }, { "device:info", DI_RPC_TYPE_DEVICE_INFO }, { "device:data", DI_RPC_TYPE_DEVICE_DATA }, { "device:reset", DI_RPC_TYPE_DEVICE_RESET }, { "device:errors", DI_RPC_TYPE_DEVICE_ERRORS }, { "dncm:status", DI_RPC_TYPE_DNCM_STATUS }, { "dncm:modem", DI_RPC_TYPE_DNCM_MODEM }, { "unknown", DI_RPC_TYPE_UNKNOWN } }; const size_t size = sizeof(expect)/sizeof(expect[0]); /* di_rpc_str */ for (size_t n = 0; n < size; n++) ASSERT_STREQ(expect[n].str, di_rpc_to_str(expect[n].type)); /* di_rpc_types_to_str */ for (size_t n = 0; n < size; n++) ASSERT_STREQ(expect[n].str, di_rpc_types_to_str(expect[n].type)); /* di_rpc_types_from_str */ for (size_t n = 0; n < size; n++) ASSERT_EQ(expect[n].type, di_rpc_types_from_str(expect[n].str)); } TEST(rpc, data_type_to_str) { ASSERT_STREQ("bool", di_rpc_data_type_to_str(DI_RPC_DATA_TYPE_BOOL)); ASSERT_STREQ("number", di_rpc_data_type_to_str(DI_RPC_DATA_TYPE_NUMBER)); ASSERT_STREQ("enum", di_rpc_data_type_to_str(DI_RPC_DATA_TYPE_ENUM)); ASSERT_STREQ("gps", di_rpc_data_type_to_str(DI_RPC_DATA_TYPE_GPS)); ASSERT_STREQ("string", di_rpc_data_type_to_str(DI_RPC_DATA_TYPE_STRING)); } TEST(rpc, msg_type_to_str) { ASSERT_STREQ("unknown", di_rpc_msg_type_to_str(DI_RPC_MSG_TYPE_UNKNOWN)); ASSERT_STREQ("req", di_rpc_msg_type_to_str(DI_RPC_MSG_TYPE_REQUEST)); ASSERT_STREQ("rep", di_rpc_msg_type_to_str(DI_RPC_MSG_TYPE_REPLY)); ASSERT_STREQ("pub", di_rpc_msg_type_to_str(DI_RPC_MSG_TYPE_PUBLISH)); } TEST(rpc, msg_reset) { struct di_rpc_msg msg; /* Initial reset */ di_rpc_msg_reset(&msg, di_device_uid_get()); ASSERT_EQ(1U, DI_RPC_VERSION); ASSERT_EQ(DI_RPC_VERSION, msg.dinetrpc); ASSERT_EQ(DI_RPC_MSG_TYPE_UNKNOWN, msg.msg_type); ASSERT_EQ(DI_RPC_TYPE_UNKNOWN, msg.type); ASSERT_STREQ("00000000000000000000000000000000", msg.device_uid); ASSERT_EQ(0U, msg.id); ASSERT_EQ(DNOK, msg.err); /* Modify */ msg.dinetrpc = 12; msg.msg_type = DI_RPC_MSG_TYPE_PUBLISH; msg.type = DI_RPC_TYPE_DEVICE_PING; msg.id = 1234; msg.err = DNE_PARAM; /* Initialized device_uid */ di_rpc_msg_reset(&msg, di_device_uid_get()); ASSERT_EQ(1U, DI_RPC_VERSION); ASSERT_EQ(DI_RPC_VERSION, msg.dinetrpc); ASSERT_EQ(DI_RPC_MSG_TYPE_UNKNOWN, msg.msg_type); ASSERT_EQ(DI_RPC_TYPE_UNKNOWN, msg.type); ASSERT_STREQ("00000000000000000000000000000000", msg.device_uid); ASSERT_EQ(0U, msg.id); ASSERT_EQ(DNOK, msg.err); }