61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
/**
|
|
* @file tests/device_state.cpp
|
|
* @brief brief
|
|
* @date Mar 14, 2016
|
|
* @author jjacobs
|
|
* @copyright 2016 Dual Inventive Technology Centre B.V.
|
|
*
|
|
* descr
|
|
*/
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <di/device.h>
|
|
|
|
/**
|
|
* Check if initial device state is set to DI_DEVICE_STATE_IDLE
|
|
*/
|
|
TEST(device_state, initial) {
|
|
EXPECT_EQ(DI_DEVICE_STATE_IDLE, di_device_state_get());
|
|
}
|
|
|
|
/**
|
|
* Check device state transitions and correct strings
|
|
*/
|
|
TEST(device_state, set_get_and_check_string) {
|
|
/* IDLE */
|
|
EXPECT_STREQ("idle", di_device_state_get_string());
|
|
|
|
/* IDLE -> ARMED */
|
|
EXPECT_EQ(DNOK, di_device_token_set(666));
|
|
EXPECT_EQ(DI_DEVICE_STATE_ARMED, di_device_state_get());
|
|
EXPECT_STREQ("armed", di_device_state_get_string());
|
|
|
|
/* ARMED -> ACTIVE */
|
|
EXPECT_EQ(DNOK, di_device_activate());
|
|
EXPECT_EQ(DI_DEVICE_STATE_ACTIVE, di_device_state_get());
|
|
EXPECT_STREQ("active", di_device_state_get_string());
|
|
|
|
/* Denied operation ACTIVE -> IDLE */
|
|
EXPECT_EQ(DNE_OPDENIED, di_device_state_set(DI_DEVICE_STATE_IDLE));
|
|
|
|
/* ACTIVE -> ARMED */
|
|
EXPECT_EQ(DNOK, di_device_deactivate());
|
|
EXPECT_EQ(DI_DEVICE_STATE_ARMED, di_device_state_get());
|
|
EXPECT_STREQ("armed", di_device_state_get_string());
|
|
|
|
/* ARMED -> IDLE */
|
|
EXPECT_EQ(DNOK, di_device_token_reset());
|
|
EXPECT_EQ(DI_DEVICE_STATE_IDLE, di_device_state_get());
|
|
EXPECT_STREQ("idle", di_device_state_get_string());
|
|
|
|
/* IDLE -> SERVICE */
|
|
EXPECT_EQ(DNOK, di_device_service_set(true));
|
|
EXPECT_EQ(DI_DEVICE_STATE_SERVICE, di_device_state_get());
|
|
EXPECT_STREQ("service", di_device_state_get_string());
|
|
|
|
/* SERVICE -> IDLE */
|
|
EXPECT_EQ(DNOK, di_device_service_set(false));
|
|
EXPECT_EQ(DI_DEVICE_STATE_IDLE, di_device_state_get());
|
|
EXPECT_STREQ("idle", di_device_state_get_string());
|
|
}
|