Import Mbed OS hard-float snapshot
This commit is contained in:
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "gtest/gtest.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "CellularDevice.h"
|
||||
#include "FileHandle_stub.h"
|
||||
#include "myCellularDevice.h"
|
||||
#include "CellularStateMachine_stub.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
// AStyle ignored as the definition is not clear due to preprocessor usage
|
||||
// *INDENT-OFF*
|
||||
class TestCellularDevice : public testing::Test {
|
||||
protected:
|
||||
|
||||
void SetUp()
|
||||
{
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
CellularStateMachine_stub::get_current_target_state = STATE_INIT;
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_INIT;
|
||||
CellularStateMachine_stub::bool_value = false;
|
||||
}
|
||||
|
||||
void TearDown()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// *INDENT-ON*
|
||||
TEST_F(TestCellularDevice, test_create_delete)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
delete dev;
|
||||
dev = NULL;
|
||||
|
||||
CellularDevice *dev1 = CellularDevice::get_default_instance();
|
||||
EXPECT_FALSE(dev1);
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_set_sim_pin)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
// MAX_PIN_SIZE = 8; so let's try a longer one
|
||||
dev->set_sim_pin("123480375462074360276407");
|
||||
dev->set_sim_pin(NULL);
|
||||
dev->set_sim_pin("1234");
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_set_plmn)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
|
||||
// MAX_PLMN_SIZE = 16; so let's try a longer one
|
||||
dev->set_plmn("123480327465023746502734602736073264076340");
|
||||
dev->set_plmn("1234");
|
||||
dev->set_plmn(NULL);
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_set_device_ready)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_NO_MEMORY;
|
||||
ASSERT_EQ(dev->set_device_ready(), NSAPI_ERROR_NO_MEMORY);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->set_device_ready(), NSAPI_ERROR_OK);
|
||||
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_SIM_PIN;
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->set_device_ready(), NSAPI_ERROR_ALREADY);
|
||||
|
||||
CellularStateMachine_stub::bool_value = true;
|
||||
CellularStateMachine_stub::get_current_target_state = STATE_SIM_PIN;
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_POWER_ON;
|
||||
ASSERT_EQ(dev->set_device_ready(), NSAPI_ERROR_IN_PROGRESS);
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_set_sim_ready)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_NO_MEMORY;
|
||||
ASSERT_EQ(dev->set_sim_ready(), NSAPI_ERROR_NO_MEMORY);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->set_sim_ready(), NSAPI_ERROR_OK);
|
||||
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_REGISTERING_NETWORK;
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->set_sim_ready(), NSAPI_ERROR_ALREADY);
|
||||
|
||||
CellularStateMachine_stub::bool_value = true;
|
||||
CellularStateMachine_stub::get_current_target_state = STATE_REGISTERING_NETWORK;
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_POWER_ON;
|
||||
ASSERT_EQ(dev->set_sim_ready(), NSAPI_ERROR_IN_PROGRESS);
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_register_to_network)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_NO_MEMORY;
|
||||
ASSERT_EQ(dev->register_to_network(), NSAPI_ERROR_NO_MEMORY);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->register_to_network(), NSAPI_ERROR_OK);
|
||||
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_ATTACHING_NETWORK;
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->register_to_network(), NSAPI_ERROR_ALREADY);
|
||||
|
||||
CellularStateMachine_stub::bool_value = true;
|
||||
CellularStateMachine_stub::get_current_target_state = STATE_ATTACHING_NETWORK;
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_POWER_ON;
|
||||
ASSERT_EQ(dev->register_to_network(), NSAPI_ERROR_IN_PROGRESS);
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_attach_to_network)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_NO_MEMORY;
|
||||
ASSERT_EQ(dev->attach_to_network(), NSAPI_ERROR_NO_MEMORY);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->attach_to_network(), NSAPI_ERROR_OK);
|
||||
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_ATTACHING_NETWORK;
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->attach_to_network(), NSAPI_ERROR_ALREADY);
|
||||
|
||||
CellularStateMachine_stub::bool_value = true;
|
||||
CellularStateMachine_stub::get_current_target_state = STATE_ATTACHING_NETWORK;
|
||||
CellularStateMachine_stub::get_current_current_state = STATE_POWER_ON;
|
||||
ASSERT_EQ(dev->attach_to_network(), NSAPI_ERROR_IN_PROGRESS);
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_get_context_list)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
CellularContext *ctx = dev->create_context();
|
||||
EXPECT_TRUE(dev->get_context_list());
|
||||
delete dev;
|
||||
|
||||
dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
EXPECT_FALSE(dev->get_context_list());
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_cellular_callback)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
myCellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
ASSERT_EQ(dev->attach_to_network(), NSAPI_ERROR_OK);
|
||||
|
||||
cell_callback_data_t data;
|
||||
dev->cellular_callback((nsapi_event_t)CellularRegistrationStatusChanged, (intptr_t)&data);
|
||||
|
||||
data.error = NSAPI_ERROR_OK;
|
||||
dev->set_plmn("1234");
|
||||
dev->cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
||||
|
||||
dev->set_sim_pin("1234");
|
||||
data.status_data = CellularDevice::SimStatePinNeeded;
|
||||
dev->cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data);
|
||||
|
||||
CellularContext *ctx = dev->create_context();
|
||||
dev->cellular_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
|
||||
|
||||
delete dev;
|
||||
}
|
||||
|
||||
TEST_F(TestCellularDevice, test_shutdown)
|
||||
{
|
||||
FileHandle_stub fh1;
|
||||
CellularDevice *dev = new myCellularDevice(&fh1);
|
||||
EXPECT_TRUE(dev);
|
||||
|
||||
CellularStateMachine_stub::nsapi_error_value = NSAPI_ERROR_OK;
|
||||
ASSERT_EQ(dev->shutdown(), NSAPI_ERROR_OK);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
|
||||
####################
|
||||
# UNIT TESTS
|
||||
####################
|
||||
|
||||
# Add test specific include paths
|
||||
set(unittest-includes ${unittest-includes}
|
||||
../connectivity/cellular/include/cellular/framework/device/cellulardevice
|
||||
../connectivity/cellular/include/cellular/framework/device
|
||||
../connectivity/cellular/include/cellular/framework/common
|
||||
)
|
||||
|
||||
# Source files
|
||||
set(unittest-sources
|
||||
../connectivity/cellular/source/framework/device/CellularDevice.cpp
|
||||
)
|
||||
|
||||
# Test files
|
||||
set(unittest-test-sources
|
||||
${CMAKE_CURRENT_LIST_DIR}/cellulardevicetest.cpp
|
||||
stubs/FileHandle_stub.cpp
|
||||
stubs/CellularStateMachine_stub.cpp
|
||||
stubs/EventQueue_stub.cpp
|
||||
stubs/mbed_assert_stub.cpp
|
||||
stubs/BufferedSerial_stub.cpp
|
||||
stubs/SerialBase_stub.cpp
|
||||
stubs/ATHandler_stub.cpp
|
||||
stubs/AT_CellularNetwork_stub.cpp
|
||||
stubs/AT_CellularContext_stub.cpp
|
||||
stubs/AT_CellularDevice_stub.cpp
|
||||
stubs/Semaphore_stub.cpp
|
||||
stubs/NetworkInterface_stub.cpp
|
||||
stubs/NetworkInterfaceDefaults_stub.cpp
|
||||
stubs/CellularContext_stub.cpp
|
||||
stubs/ConditionVariable_stub.cpp
|
||||
stubs/Mutex_stub.cpp
|
||||
stubs/mbed_shared_queues_stub.cpp
|
||||
)
|
||||
|
||||
set(unittest-test-flags
|
||||
-DMDMRTS=PTC0
|
||||
-DMDMCTS=PTC1
|
||||
-DMDMTXD=NC
|
||||
-DMDMRXD=NC
|
||||
-DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200
|
||||
-DCELLULAR_DEVICE=myCellularDevice
|
||||
-DDEVICE_SERIAL_FC=1
|
||||
-DDEVICE_SERIAL=1
|
||||
-DDEVICE_INTERRUPTIN=1
|
||||
)
|
||||
Reference in New Issue
Block a user