mirror of https://github.com/ARMmbed/mbed-os.git
UT for CellularDevice get/set timeouts methods
parent
ce3d41433e
commit
da77cdc52e
|
@ -240,3 +240,35 @@ TEST_F(TestCellularDevice, test_shutdown)
|
|||
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_timeout_array)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
myCellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
|
||||
// Max size
|
||||
uint16_t set_timeouts[CELLULAR_RETRY_ARRAY_SIZE + 1];
|
||||
for (int i = 0; i < CELLULAR_RETRY_ARRAY_SIZE; i++) {
|
||||
set_timeouts[i] = i + 100;
|
||||
}
|
||||
dev->set_retry_timeout_array(set_timeouts, CELLULAR_RETRY_ARRAY_SIZE);
|
||||
|
||||
uint16_t verify_timeouts[CELLULAR_RETRY_ARRAY_SIZE + 1];
|
||||
for (int i = 0; i < CELLULAR_RETRY_ARRAY_SIZE; i++) {
|
||||
verify_timeouts[i] = i + 100;
|
||||
}
|
||||
dev->verify_timeout_array(verify_timeouts, CELLULAR_RETRY_ARRAY_SIZE);
|
||||
|
||||
// Empty
|
||||
dev->set_retry_timeout_array(NULL, 0);
|
||||
dev->verify_timeout_array(NULL, 0);
|
||||
|
||||
// Oversize (returns only CELLULAR_RETRY_ARRAY_SIZE)
|
||||
dev->set_retry_timeout_array(set_timeouts, CELLULAR_RETRY_ARRAY_SIZE + 1);
|
||||
dev->verify_timeout_array(verify_timeouts, CELLULAR_RETRY_ARRAY_SIZE);
|
||||
|
||||
delete dev;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,12 @@ nsapi_error_t CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
|||
CellularStubState CellularStateMachine_stub::get_current_target_state = STATE_INIT;
|
||||
CellularStubState CellularStateMachine_stub::get_current_current_state = STATE_INIT;
|
||||
bool CellularStateMachine_stub::bool_value = false;
|
||||
std::vector<uint16_t> CellularStateMachine_stub::timeouts;
|
||||
|
||||
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue, CellularNetwork &nw) :
|
||||
_cellularDevice(device), _network(nw), _queue(queue)
|
||||
{
|
||||
CellularStateMachine_stub::timeouts.clear();
|
||||
}
|
||||
|
||||
CellularStateMachine::~CellularStateMachine()
|
||||
|
@ -77,11 +79,21 @@ void CellularStateMachine::cellular_event_changed(nsapi_event_t ev, intptr_t ptr
|
|||
|
||||
void CellularStateMachine::get_retry_timeout_array(uint16_t *timeout, int &array_len) const
|
||||
{
|
||||
|
||||
const int array_size = CellularStateMachine_stub::timeouts.size();
|
||||
for (int i = 0; i < array_size; i++) {
|
||||
timeout[i] = CellularStateMachine_stub::timeouts[i];
|
||||
}
|
||||
array_len = array_size;
|
||||
}
|
||||
|
||||
void CellularStateMachine::set_retry_timeout_array(const uint16_t timeout[], int array_len)
|
||||
{
|
||||
CellularStateMachine_stub::timeouts.clear();
|
||||
|
||||
const int real_size = array_len > CELLULAR_RETRY_ARRAY_SIZE ? CELLULAR_RETRY_ARRAY_SIZE : array_len;
|
||||
for (int i = 0; i < real_size; i++) {
|
||||
CellularStateMachine_stub::timeouts.push_back(timeout[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CellularStateMachine::set_timeout(int timeout)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define CELLULARSTATEMACHINE_STUB_H_
|
||||
|
||||
#include "CellularStateMachine.h"
|
||||
#include <vector>
|
||||
|
||||
enum CellularStubState {
|
||||
STATE_INIT = 0,
|
||||
|
@ -35,6 +36,7 @@ extern nsapi_error_t nsapi_error_value;
|
|||
extern CellularStubState get_current_target_state;
|
||||
extern CellularStubState get_current_current_state;
|
||||
extern bool bool_value;
|
||||
extern std::vector<uint16_t> timeouts;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "FileHandle_stub.h"
|
||||
#include "ATHandler_stub.h"
|
||||
#include "AT_CellularContext.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace events;
|
||||
|
||||
|
@ -175,6 +176,24 @@ public:
|
|||
{
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
void verify_timeout_array(const uint16_t timeout[], int array_len)
|
||||
{
|
||||
if (array_len > CELLULAR_RETRY_ARRAY_SIZE) {
|
||||
FAIL();
|
||||
}
|
||||
uint16_t get_timeouts[CELLULAR_RETRY_ARRAY_SIZE];
|
||||
int get_timeouts_len = 0;
|
||||
|
||||
get_retry_timeout_array(get_timeouts, get_timeouts_len);
|
||||
|
||||
EXPECT_EQ(array_len, get_timeouts_len);
|
||||
|
||||
for (int i = 0; i < array_len; i++) {
|
||||
EXPECT_EQ(timeout[i], get_timeouts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
AT_CellularNetwork *_network;
|
||||
AT_CellularContext *_context_list;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue