From 9f9aa4a21090fa6d900899b4ed95d8b70e2faa9c Mon Sep 17 00:00:00 2001 From: Antti Kauppila Date: Thu, 30 Aug 2018 13:29:42 +0300 Subject: [PATCH 1/4] cellular unittests ported to googletest framework --- UNITTESTS/CMakeLists.txt | 21 +- .../AT_CellularBase/at_cellularbasetest.cpp | 49 - .../AT_CellularBase/test_at_cellularbase.cpp | 59 - .../at_cellularbase/at_cellularbasetest.cpp | 137 ++ .../unittest.cmake | 3 +- .../at_cellulardevicetest.cpp | 261 ++++ .../AT/at_cellulardevice/unittest.cmake | 38 + .../at_cellularinformationtest.cpp | 155 +++ .../AT/at_cellularinformation/unittest.cmake | 31 + .../at_cellularnetworktest.cpp | 1167 +++++++++++++++++ .../AT/at_cellularnetwork/unittest.cmake | 37 + .../at_cellularpower/at_cellularpowertest.cpp | 201 +++ .../AT/at_cellularpower/unittest.cmake | 31 + .../AT/at_cellularsim/at_cellularsimtest.cpp | 204 +++ .../AT/at_cellularsim/unittest.cmake | 32 + .../AT/at_cellularsms/at_cellularsmstest.cpp | 203 +++ .../AT/at_cellularsms/unittest.cmake | 33 + .../at_cellularstack/at_cellularstacktest.cpp | 377 ++++++ .../AT/at_cellularstack/unittest.cmake | 34 + .../framework/AT/athandler/athandlertest.cpp | 1022 +++++++++++++++ .../framework/AT/athandler/unittest.cmake | 41 + .../framework/common/util/test_util.cpp | 179 --- .../framework/common/util/unittest.cmake | 3 +- .../framework/common/util/utiltest.cpp | 162 ++- UNITTESTS/stubs/ATCmdParser_stub.cpp | 420 ++++++ UNITTESTS/stubs/ATHandler_stub.cpp | 82 +- UNITTESTS/stubs/ATHandler_stub.h | 22 +- UNITTESTS/stubs/AT_CellularBase_stub.cpp | 48 + UNITTESTS/stubs/AT_CellularBase_stub.h | 25 + UNITTESTS/stubs/AT_CellularDevice_stub.cpp | 91 ++ .../stubs/AT_CellularInformation_stub.cpp | 49 + .../stubs/AT_CellularMultiplexer_stub.cpp | 35 + UNITTESTS/stubs/AT_CellularNetwork_stub.cpp | 256 ++++ UNITTESTS/stubs/AT_CellularPower_stub.cpp | 81 ++ UNITTESTS/stubs/AT_CellularSIM_stub.cpp | 59 + UNITTESTS/stubs/AT_CellularSMS_stub.cpp | 190 +++ UNITTESTS/stubs/AT_CellularStack_stub.cpp | 90 ++ UNITTESTS/stubs/BufferedBlockDevice_stub.cpp | 104 ++ UNITTESTS/stubs/CellularUtil_stub.cpp | 113 ++ UNITTESTS/stubs/ChainingBlockDevice_stub.cpp | 88 ++ UNITTESTS/stubs/EventFlags_stub.cpp | 1 + .../stubs/ExhaustibleBlockDevice_stub.cpp | 88 ++ UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp | 97 ++ UNITTESTS/stubs/HeapBlockDevice_stub.cpp | 82 ++ UNITTESTS/stubs/Kernel_stub.cpp | 25 + UNITTESTS/stubs/MBRBlockDevice_stub.cpp | 156 +++ UNITTESTS/stubs/NetworkInterface_stub.cpp | 89 ++ UNITTESTS/stubs/NetworkStack_stub.cpp | 95 ++ UNITTESTS/stubs/ObservingBlockDevice_stub.cpp | 100 ++ UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp | 101 ++ UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp | 95 ++ UNITTESTS/stubs/Semaphore_stub.cpp | 57 + UNITTESTS/stubs/SlicingBlockDevice_stub.cpp | 83 ++ UNITTESTS/stubs/SocketAddress_stub.cpp | 145 ++ UNITTESTS/stubs/Thread_stub.cpp | 27 + UNITTESTS/stubs/Timer_stub.cpp | 74 ++ UNITTESTS/stubs/Timer_stub.h | 24 + UNITTESTS/stubs/equeue_stub.c | 85 +- UNITTESTS/stubs/mbed_assert_stub.cpp | 24 + UNITTESTS/stubs/mbed_critical_stub.c | 115 ++ .../mbed_poll_stub.cpp} | 23 +- UNITTESTS/stubs/mbed_poll_stub.h | 27 + UNITTESTS/stubs/mbed_wait_api_stub.cpp | 30 + UNITTESTS/stubs/randLIB_stub.cpp | 27 + UNITTESTS/stubs/us_ticker_stub.cpp | 54 + UNITTESTS/target_h/ATCmdParser.h | 33 + UNITTESTS/target_h/arm_math.h | 16 + UNITTESTS/target_h/cmsis.h | 16 + UNITTESTS/target_h/cmsis_compiler.h | 16 + .../util/test_util.h => target_h/cmsis_os.h} | 25 +- UNITTESTS/target_h/cmsis_os2.h | 78 ++ UNITTESTS/target_h/mbed.h | 3 +- UNITTESTS/target_h/mbed_rtos1_types.h | 1 + UNITTESTS/target_h/mbed_rtos_storage.h | 16 +- UNITTESTS/target_h/mbed_rtx.h | 16 + UNITTESTS/target_h/mbed_rtx_conf.h | 20 + UNITTESTS/target_h/nsapi_ppp.h | 16 + UNITTESTS/target_h/platform/mbed_power_mgmt.h | 17 + UNITTESTS/target_h/platform/mbed_retarget.h | 79 ++ UNITTESTS/target_h/randLIB.h | 27 + UNITTESTS/target_h/rtos/Mutex.h | 48 + UNITTESTS/target_h/rtos/Semaphore.h | 18 + UNITTESTS/target_h/rtx_lib.h | 25 + UNITTESTS/target_h/rtx_os.h | 70 + UNITTESTS/target_h/sys/syslimits.h | 17 + 85 files changed, 8140 insertions(+), 374 deletions(-) delete mode 100644 UNITTESTS/features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp delete mode 100644 UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp rename UNITTESTS/features/cellular/framework/AT/{AT_CellularBase => at_cellularbase}/unittest.cmake (84%) create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake create mode 100644 UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp create mode 100644 UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake delete mode 100644 UNITTESTS/features/cellular/framework/common/util/test_util.cpp create mode 100644 UNITTESTS/stubs/ATCmdParser_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularBase_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularBase_stub.h create mode 100644 UNITTESTS/stubs/AT_CellularDevice_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularInformation_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularNetwork_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularPower_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularSIM_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularSMS_stub.cpp create mode 100644 UNITTESTS/stubs/AT_CellularStack_stub.cpp create mode 100644 UNITTESTS/stubs/BufferedBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/CellularUtil_stub.cpp create mode 100644 UNITTESTS/stubs/ChainingBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/ExhaustibleBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/HeapBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/Kernel_stub.cpp create mode 100644 UNITTESTS/stubs/MBRBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/NetworkInterface_stub.cpp create mode 100644 UNITTESTS/stubs/NetworkStack_stub.cpp create mode 100644 UNITTESTS/stubs/ObservingBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/Semaphore_stub.cpp create mode 100644 UNITTESTS/stubs/SlicingBlockDevice_stub.cpp create mode 100644 UNITTESTS/stubs/SocketAddress_stub.cpp create mode 100644 UNITTESTS/stubs/Thread_stub.cpp create mode 100644 UNITTESTS/stubs/Timer_stub.cpp create mode 100644 UNITTESTS/stubs/Timer_stub.h create mode 100644 UNITTESTS/stubs/mbed_assert_stub.cpp create mode 100644 UNITTESTS/stubs/mbed_critical_stub.c rename UNITTESTS/{features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.h => stubs/mbed_poll_stub.cpp} (63%) create mode 100644 UNITTESTS/stubs/mbed_poll_stub.h create mode 100644 UNITTESTS/stubs/mbed_wait_api_stub.cpp create mode 100644 UNITTESTS/stubs/randLIB_stub.cpp create mode 100644 UNITTESTS/stubs/us_ticker_stub.cpp create mode 100644 UNITTESTS/target_h/ATCmdParser.h create mode 100644 UNITTESTS/target_h/arm_math.h create mode 100644 UNITTESTS/target_h/cmsis.h create mode 100644 UNITTESTS/target_h/cmsis_compiler.h rename UNITTESTS/{features/cellular/framework/common/util/test_util.h => target_h/cmsis_os.h} (61%) create mode 100644 UNITTESTS/target_h/cmsis_os2.h create mode 100644 UNITTESTS/target_h/mbed_rtx.h create mode 100644 UNITTESTS/target_h/mbed_rtx_conf.h create mode 100644 UNITTESTS/target_h/nsapi_ppp.h create mode 100644 UNITTESTS/target_h/platform/mbed_power_mgmt.h create mode 100644 UNITTESTS/target_h/randLIB.h create mode 100644 UNITTESTS/target_h/rtos/Mutex.h create mode 100644 UNITTESTS/target_h/rtos/Semaphore.h create mode 100644 UNITTESTS/target_h/rtx_lib.h create mode 100644 UNITTESTS/target_h/rtx_os.h create mode 100644 UNITTESTS/target_h/sys/syslimits.h diff --git a/UNITTESTS/CMakeLists.txt b/UNITTESTS/CMakeLists.txt index 5b28cd46b6..76a0fddf4a 100644 --- a/UNITTESTS/CMakeLists.txt +++ b/UNITTESTS/CMakeLists.txt @@ -90,17 +90,35 @@ endif(COVERAGE) set(unittest-includes-base "${PROJECT_SOURCE_DIR}/target_h" "${PROJECT_SOURCE_DIR}/target_h/events" + "${PROJECT_SOURCE_DIR}/target_h/events/equeue" + "${PROJECT_SOURCE_DIR}/target_h/platform" "${PROJECT_SOURCE_DIR}/stubs" "${PROJECT_SOURCE_DIR}/.." "${PROJECT_SOURCE_DIR}/../features" + "${PROJECT_SOURCE_DIR}/../features/netsocket" "${PROJECT_SOURCE_DIR}/../platform" "${PROJECT_SOURCE_DIR}/../drivers" "${PROJECT_SOURCE_DIR}/../hal" "${PROJECT_SOURCE_DIR}/../events" + "${PROJECT_SOURCE_DIR}/../events/equeue" + "${PROJECT_SOURCE_DIR}/../rtos" "${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX" "${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX/rtx5/Include" "${PROJECT_SOURCE_DIR}/../cmsis" - "${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice/" + "${PROJECT_SOURCE_DIR}/../features/frameworks" + "${PROJECT_SOURCE_DIR}/../features/frameworks/mbed-trace" + "${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice" + "${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice" + "${PROJECT_SOURCE_DIR}/../features/filesystem/fat" + "${PROJECT_SOURCE_DIR}/../features/filesystem/fat/ChaN" + "${PROJECT_SOURCE_DIR}/../features/filesystem/bd" + "${PROJECT_SOURCE_DIR}/../features/filesystem/" + "${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs" + "${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs" + "${PROJECT_SOURCE_DIR}/../features/cellular/framework/API" + "${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT" + "${PROJECT_SOURCE_DIR}/../features/cellular/framework" + "${PROJECT_SOURCE_DIR}/../features/cellular/framework/common" ) # Create a list for test suites. @@ -168,3 +186,4 @@ foreach(testfile ${unittest-file-list}) message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n") endif(unittest-test-sources) endforeach(testfile) + diff --git a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp b/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp deleted file mode 100644 index 08ec439c7f..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 "test_at_cellularbase.h" -#include "AT_CellularBase.h" - -class TestAT_CellularBase : public testing::Test { -protected: - Test_AT_CellularBase *unit; - - virtual void SetUp() - { - unit = new Test_AT_CellularBase(); - } - - virtual void TearDown() - { - delete unit; - } -}; - -TEST_F(TestAT_CellularBase, Create) -{ - EXPECT_TRUE(unit); -} - -TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler) -{ - unit->test_AT_CellularBase_get_at_handler(); -} - -TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error) -{ - unit->test_AT_CellularBase_get_device_error(); -} diff --git a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp b/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp deleted file mode 100644 index 11d28a225c..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 "test_at_cellularbase.h" -#include "EventQueue.h" -#include "AT_CellularBase.h" -#include "ATHandler_stub.h" -#include "FileHandle_stub.h" -#include - -using namespace mbed; -using namespace events; - -Test_AT_CellularBase::Test_AT_CellularBase() -{ - -} - -Test_AT_CellularBase::~Test_AT_CellularBase() -{ -} - -void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 100, ","); - AT_CellularBase at(ah); - - EXPECT_EQ(&ah, &at.get_at_handler()); -} - -void Test_AT_CellularBase::test_AT_CellularBase_get_device_error() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - AT_CellularBase at(ah); - - ATHandler_stub::device_err_value.errCode = 8; - - EXPECT_EQ(8, at.get_device_error().errCode); - - ATHandler_stub::device_err_value.errCode = 0; -} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp new file mode 100644 index 0000000000..3537aa9c8a --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp @@ -0,0 +1,137 @@ +/* + * 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 "AT_CellularBase.h" +#include "EventQueue.h" +#include "AT_CellularBase.h" +#include "ATHandler_stub.h" +#include "FileHandle_stub.h" +#include + +using namespace mbed; +using namespace events; + +class my_base : public AT_CellularBase { +public: + my_base(ATHandler &at) : AT_CellularBase(at) + { + } + bool check_not_supported() + { + static const AT_CellularBase::SupportedFeature unsupported_features[] = { + AT_CellularBase::AT_CGSN_WITH_TYPE, + AT_CellularBase::SUPPORTED_FEATURE_END_MARK + }; + set_unsupported_features(unsupported_features); + return is_supported(AT_CGSN_WITH_TYPE); + } + + bool check_supported() + { + set_unsupported_features(NULL); + return is_supported(AT_CGSN_WITH_TYPE); + } + + bool check_supported_not_found() + { + static const AT_CellularBase::SupportedFeature unsupported_features[] = { + AT_CellularBase::AT_CGSN_WITH_TYPE, + AT_CellularBase::SUPPORTED_FEATURE_END_MARK + }; + set_unsupported_features(unsupported_features); + return is_supported(SUPPORTED_FEATURE_END_MARK); + } +}; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularBase : public testing::Test { +protected: + + void SetUp() + { + } + + void TearDown() + { + } +}; +// *INDENT-ON* + +TEST_F(TestAT_CellularBase, Create) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 100, ","); + AT_CellularBase *unit = new AT_CellularBase(ah); + + EXPECT_TRUE(unit != NULL); + + delete unit; +} + +TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 100, ","); + AT_CellularBase at(ah); + + EXPECT_TRUE(&ah == &at.get_at_handler()); +} + +TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularBase at(ah); + + ATHandler_stub::device_err_value.errCode = 8; + + EXPECT_EQ(8, at.get_device_error().errCode); + + ATHandler_stub::device_err_value.errCode = 0; +} + +TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularBase at(ah); + + static const AT_CellularBase::SupportedFeature unsupported_features[] = { + AT_CellularBase::AT_CGSN_WITH_TYPE, + AT_CellularBase::SUPPORTED_FEATURE_END_MARK + }; + + at.set_unsupported_features(unsupported_features); +} + +TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + my_base my_at(ah); + + EXPECT_TRUE(true == my_at.check_supported()); + EXPECT_TRUE(true == my_at.check_supported_not_found()); + EXPECT_TRUE(false == my_at.check_not_supported()); +} diff --git a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake similarity index 84% rename from UNITTESTS/features/cellular/framework/AT/AT_CellularBase/unittest.cmake rename to UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake index 8229144a79..b842f53743 100644 --- a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake @@ -23,10 +23,9 @@ set(unittest-sources # Test files set(unittest-test-sources + features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp stubs/mbed_assert_stub.c stubs/ATHandler_stub.cpp stubs/EventQueue_stub.cpp stubs/FileHandle_stub.cpp - features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp - features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp ) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp new file mode 100644 index 0000000000..98eae84cd7 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -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 "AT_CellularDevice.h" +#include "ATHandler_stub.h" +#include "AT_CellularBase_stub.h" +#include + +using namespace mbed; +using namespace events; + +class TestAT_CellularDevice : public testing::Test { +protected: + + void SetUp() { + } + + void TearDown() { + } +}; + +TEST_F(TestAT_CellularDevice, Create) +{ + EventQueue que; + AT_CellularDevice dev(que); + + CellularDevice *dev2 = new AT_CellularDevice(que); + + EXPECT_TRUE(dev2 != NULL); + delete dev2; +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + FileHandle_stub fh2; + FileHandle_stub fh3; + + EXPECT_TRUE(dev.open_network(&fh1)); + EXPECT_TRUE(dev.open_sms(&fh2)); + AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; + EXPECT_TRUE(dev.open_sim(&fh3)); + ATHandler_stub::fh_value = &fh1; + EXPECT_TRUE(dev.open_power(&fh1)); + + ATHandler_stub::fh_value = NULL; +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + + EXPECT_TRUE(!dev.open_network(NULL)); + EXPECT_TRUE(dev.open_network(&fh1)); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + + EXPECT_TRUE(!dev.open_sms(NULL)); + EXPECT_TRUE(dev.open_sms(&fh1)); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + + EXPECT_TRUE(!dev.open_power(NULL)); + EXPECT_TRUE(dev.open_power(&fh1)); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + + EXPECT_TRUE(! dev.open_sim(NULL)); + EXPECT_TRUE(dev.open_sim(&fh1)); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + + EXPECT_TRUE(!dev.open_information(NULL)); + EXPECT_TRUE(dev.open_information(&fh1)); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::ref_count = 0; + + EXPECT_TRUE(dev.open_network(&fh1)); + EXPECT_TRUE(ATHandler_stub::ref_count == 1); + + dev.close_network(); + EXPECT_TRUE(ATHandler_stub::ref_count == 0); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::ref_count = 0; + + EXPECT_TRUE(dev.open_sms(&fh1)); + EXPECT_TRUE(ATHandler_stub::ref_count == 1); + + dev.close_sms(); + EXPECT_TRUE(ATHandler_stub::ref_count == 0); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::ref_count = 0; + + EXPECT_TRUE(dev.open_power(&fh1)); + EXPECT_TRUE(ATHandler_stub::ref_count == 1); + + dev.close_power(); + EXPECT_TRUE(ATHandler_stub::ref_count == 0); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::ref_count = 0; + + + EXPECT_TRUE(dev.open_sim(&fh1)); + dev.close_sms(); // this should not affect to refcount as it's not opened + EXPECT_TRUE(ATHandler_stub::ref_count == 1); + + dev.close_sim(); + EXPECT_TRUE(ATHandler_stub::ref_count == 0); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::int_value = 0; + + EXPECT_TRUE(dev.open_information(&fh1)); + + ATHandler_stub::fh_value = NULL; + AT_CellularBase_stub::handler_value = NULL; + dev.close_information(); + + ATHandler_stub::fh_value = &fh1; + ATHandler at(&fh1, que, 0, ","); + AT_CellularBase_stub::handler_value = &at; + + EXPECT_TRUE(dev.open_information(&fh1)); + AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; + + dev.close_information(); + + ATHandler_stub::fh_value = NULL; +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::timeout = 0; + ATHandler_stub::default_timeout = false; + + // no interfaces open so settings timeout should not change anything + dev.set_timeout(5000); + EXPECT_TRUE(ATHandler_stub::timeout == 0); + EXPECT_TRUE(ATHandler_stub::default_timeout == false); + + EXPECT_TRUE(dev.open_sim(&fh1)); + EXPECT_TRUE(ATHandler_stub::ref_count == 1); + + dev.set_timeout(5000); + EXPECT_TRUE(ATHandler_stub::timeout == 5000); + EXPECT_TRUE(ATHandler_stub::default_timeout == true); + + dev.close_sim(); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + ATHandler_stub::debug_on = false; + + // no interfaces open so debug toggling should not affect + dev.modem_debug_on(true); + EXPECT_TRUE(ATHandler_stub::debug_on == false); + + EXPECT_TRUE(dev.open_sim(&fh1)); + EXPECT_TRUE(ATHandler_stub::ref_count == 1); + + dev.modem_debug_on(true); + EXPECT_TRUE(ATHandler_stub::debug_on == true); + + dev.close_sim(); +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_stack) +{ + EventQueue que; + AT_CellularDevice dev(que); + FileHandle_stub fh1; + + NetworkStack *stack = dev.get_stack(); + EXPECT_TRUE(stack == NULL); + + EXPECT_TRUE(dev.open_network(&fh1)); + + stack = dev.get_stack(); + EXPECT_TRUE(stack == NULL); // Not in PPP so also null but this is got from the network class +} + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) +{ + EventQueue que; + AT_CellularDevice dev(que); + EXPECT_TRUE(0 == dev.get_send_delay()); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake new file mode 100644 index 0000000000..36b69e0dbe --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -0,0 +1,38 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_device_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + stubs/randLIB_stub.c + ../features/cellular/framework/AT/AT_CellularDevice.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp + stubs/AT_CellularNetwork_stub.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularSMS_stub.cpp + stubs/AT_CellularSIM_stub.cpp + stubs/AT_CellularPower_stub.cpp + stubs/AT_CellularInformation_stub.cpp + stubs/CellularUtil_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/NetworkInterface_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/mbed_assert_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp new file mode 100644 index 0000000000..4f2be58fbe --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp @@ -0,0 +1,155 @@ +/* + * 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 +#include "ATHandler_stub.h" +#include "EventQueue.h" +#include "FileHandle_stub.h" +#include "AT_CellularBase_stub.h" +#include "ATHandler.h" +#include "AT_CellularInformation.h" +#include "AT_CellularBase.h" + +using namespace mbed; +using namespace events; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularInformation : public testing::Test { +protected: + + void SetUp() + { + } + + void TearDown() + { + } +}; +// *INDENT-ON* + +TEST_F(TestAT_CellularInformation, Create) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation *unit = new AT_CellularInformation(ah); + EXPECT_TRUE(unit != NULL); + delete unit; +} + +TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_manufacturer) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "some"; + ATHandler_stub::ssize_value = 4; + + char buf[8]; + EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_manufacturer(buf, 8)); + EXPECT_TRUE(strcmp("some", buf) == 0); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::ssize_value = -1; + buf[0] = 0; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8)); + EXPECT_TRUE(strlen(buf) == 0); +} + +TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_model) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "model"; + ATHandler_stub::ssize_value = 5; + char buf[8]; + EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_model(buf, 8)); + EXPECT_TRUE(strcmp("model", buf) == 0); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::ssize_value = -1; + buf[0] = 0; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8)); + EXPECT_TRUE(strlen(buf) == 0); +} + +TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + + //Used heap var here to visit heap constructor + AT_CellularInformation *aci = new AT_CellularInformation(ah); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "revision"; + ATHandler_stub::ssize_value = 8; + + char buf[9]; + EXPECT_TRUE(NSAPI_ERROR_OK == aci->get_revision(buf, 9)); + EXPECT_TRUE(strcmp("revision", buf) == 0); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::ssize_value = -1; + buf[0] = 0; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8)); + EXPECT_TRUE(strlen(buf) == 0); + + delete aci; +} + +TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "1234567"; + ATHandler_stub::ssize_value = 7; + char buf[8]; + + EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::SN)); + EXPECT_TRUE(strcmp("1234567", buf) == 0); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::ssize_value = -1; + buf[0] = 0; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_serial_number(buf, 8, CellularInformation::SN)); + EXPECT_TRUE(strlen(buf) == 0); + + AT_CellularBase_stub::supported_bool = false; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); + EXPECT_TRUE(strlen(buf) == 0); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "1234567"; + ATHandler_stub::ssize_value = 7; + AT_CellularBase_stub::supported_bool = true; + EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); + EXPECT_TRUE(strcmp("1234567", buf) == 0); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake new file mode 100644 index 0000000000..0a64cf5242 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake @@ -0,0 +1,31 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_information_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + stubs/randLIB_stub.c + ../features/cellular/framework/AT/AT_CellularInformation.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT//at_cellularinformation/at_cellularinformationtest.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/mbed_assert_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp new file mode 100644 index 0000000000..4ff0837b16 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp @@ -0,0 +1,1167 @@ +/* + * 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 +#include "AT_CellularNetwork.h" +#include "EventQueue.h" +#include "ATHandler.h" +#include "AT_CellularDevice.h" +#include "FileHandle_stub.h" +#include "CellularLog.h" +#include "ATHandler_stub.h" +#include "AT_CellularStack.h" + +using namespace mbed; +using namespace events; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularNetwork : public testing::Test { +protected: + + void SetUp() + { + ATHandler_stub::int_count = kRead_int_table_size; + ATHandler_stub::read_string_index = kRead_string_table_size; + ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::int_value = -1; + } + + void TearDown() + { + } +}; +// *INDENT-ON* +class my_stack : public AT_CellularStack { +public: + my_stack(ATHandler &atHandler) : AT_CellularStack(atHandler, 1, IPV4_STACK) {} + virtual int get_max_socket_count() + { + return 1; + } + virtual int get_max_packet_size() + { + return 200; + } + virtual bool is_protocol_supported(nsapi_protocol_t protocol) + { + return true; + } + virtual nsapi_error_t socket_close_impl(int sock_id) + { + return NSAPI_ERROR_OK; + } + virtual nsapi_error_t create_socket_impl(CellularSocket *socket) + { + return NSAPI_ERROR_OK; + } + virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, + const void *data, nsapi_size_t size) + { + return 100; + } + virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, + void *buffer, nsapi_size_t size) + { + return 100; + } +}; + +class my_AT_CN : public AT_CellularNetwork { +public: + my_AT_CN(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {} + virtual ~my_AT_CN() {} + NetworkStack *get_stack() + { + if (!_stack) { + return new my_stack(get_at_handler()); + } else { + return _stack; + } + } + virtual AT_CellularNetwork::RegistrationMode has_registration(RegistrationType reg_type) + { + if (reg_type == C_GREG) { + return RegistrationModeDisable; + } + return RegistrationModeEnable; + } + virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat) + { + return NSAPI_ERROR_OK; + } + virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack) + { + if (requested_stack == IPV4_STACK || requested_stack == DEFAULT_STACK) { + return true; + } + return false; + } +}; + +class my_AT_CNipv6 : public AT_CellularNetwork { +public: + my_AT_CNipv6(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {} + virtual ~my_AT_CNipv6() {} + NetworkStack *get_stack() + { + if (!_stack) { + return new my_stack(get_at_handler()); + } else { + return _stack; + } + } + virtual AT_CellularNetwork::RegistrationMode has_registration(RegistrationType reg_type) + { + if (reg_type == C_GREG) { + return RegistrationModeDisable; + } + return RegistrationModeEnable; + } + virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat) + { + return NSAPI_ERROR_OK; + } + virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack) + { + if (requested_stack == IPV6_STACK || requested_stack == DEFAULT_STACK) { + return true; + } + return false; + } +}; + +static int network_cb_count; +static void network_cb(nsapi_event_t ev, intptr_t intptr) +{ + network_cb_count++; +} + +TEST_F(TestAT_CellularNetwork, Create) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork *cn = new AT_CellularNetwork(at); + EXPECT_TRUE(cn != NULL); + delete cn; +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_init) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + AT_CellularNetwork cn(at); + + EXPECT_TRUE(NSAPI_ERROR_OK == cn.init()); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_NO_MEMORY; + EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == cn.init()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_credentials) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork *cnn = new AT_CellularNetwork(at); + delete cnn; + + AT_CellularNetwork cn(at); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn")); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, NULL, NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, NULL, "passwd")); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user")); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", NULL, NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", NULL, "passwd")); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", "user", NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", "user")); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", "user", "passwd")); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_activate_context) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + my_AT_CN my_cn(at); + my_AT_CNipv6 my_cnipv6(at); + + // get_context return true and new context created. But now stack and so error. + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); + + // get_context return true and new context created, also do_user_authentication called with success. + // But now stack and so error. + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); + + // get_context return true and new context created, also do_user_authentication called with failure. + ATHandler_stub::resp_stop_success_count = 2; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == cn.activate_context()); + + + // get_context return true and new context created, also do_user_authentication called with success. + // Now there is stack. + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); + + // get_context return true and new context created, test delete context + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); + + + + // get_context pdp type gives zero len, fails with no stack + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 1; + ATHandler_stub::read_string_table[0] = ""; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); + + // get_context pdp type gives proper type, apn reading fails + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 1; + ATHandler_stub::read_string_table[0] = "IPV6"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_NO_CONNECTION == cn.activate_context()); + + // get_context pdp type gives proper type, apn does not match, now other contexts so new one created + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IP"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); + + // get_context pdp type gives proper type, apn match + ATHandler_stub::resp_info_true_counter = 2; // set to 2 so cgact will give that this context is active + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IPV4V6"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(IPV4_STACK)); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); + + // get_context pdp type gives proper type, apn match + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IPV6"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(IPV6_STACK)); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.activate_context()); + + // get_context pdp type gives proper type, apn match + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IPV4V6"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(DEFAULT_STACK)); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); + + // get_context pdp type gives proper type, apn match + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IPV4V6"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(DEFAULT_STACK)); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.activate_context()); + + // get_context pdp type gives proper type, apn match + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IPV6"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(DEFAULT_STACK)); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cnipv6.activate_context()); + + // get_context pdp type gives proper type, apn match + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[0] = "internet"; + ATHandler_stub::read_string_table[1] = "IP"; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(DEFAULT_STACK)); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.activate_context()); + + // get_context pdp type gives proper type, apn match. Test Delete the created context. + ATHandler_stub::resp_info_true_counter = 0; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::int_value = 1; + //ATHandler_stub::nsapi_error_ok_counter = 2; + ATHandler_stub::resp_stop_success_count = 2; + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_credentials(NULL, NULL, NULL)); + EXPECT_TRUE(NSAPI_ERROR_NO_CONNECTION == my_cn.activate_context()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_connect) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + // no stack so will fail + cn.attach(&network_cb); + network_cb_count = 0; + + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.connect("APN", "a", "b")); + EXPECT_TRUE(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); + EXPECT_TRUE(network_cb_count == 2); + + network_cb_count = 0; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_NO_CONNECTION == cn.connect("APN")); + EXPECT_TRUE(network_cb_count == 2); + EXPECT_TRUE(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); + + my_AT_CN my_cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + cn.set_stack_type(IPV4_STACK); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.connect()); + EXPECT_TRUE(network_cb_count == 2); + EXPECT_TRUE(NSAPI_STATUS_GLOBAL_UP == my_cn.get_connection_status()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_disconnect) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.disconnect()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_stack) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + my_AT_CN my_cn(at); + my_stack *mystack = (my_stack *)my_cn.get_stack(); + EXPECT_TRUE(mystack); + delete mystack; +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_registration) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration()); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration()); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration("12345")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration("12345")); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_registration_status) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::int_value = 3; + CellularNetwork::RegistrationStatus stat = CellularNetwork::NotRegistered; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_EREG, stat)); + EXPECT_TRUE(stat == CellularNetwork::RegistrationDenied); + stat = CellularNetwork::NotRegistered; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_GREG, stat)); + EXPECT_TRUE(stat == CellularNetwork::RegistrationDenied); + + my_AT_CN nw(at); + stat = CellularNetwork::NotRegistered; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.get_registration_status(CellularNetwork::C_GREG, stat)); + EXPECT_TRUE(stat == CellularNetwork::NotRegistered); + EXPECT_TRUE(NSAPI_ERROR_OK == nw.get_registration_status(CellularNetwork::C_EREG, stat)); + EXPECT_TRUE(stat == CellularNetwork::RegistrationDenied); + + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + stat = CellularNetwork::NotRegistered; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_status(CellularNetwork::C_EREG, stat)); + EXPECT_TRUE(stat == -1); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_status(CellularNetwork::C_GREG, stat)); + EXPECT_TRUE(stat == -1); + + stat = CellularNetwork::NotRegistered; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.get_registration_status(CellularNetwork::C_GREG, stat)); + EXPECT_TRUE(stat == CellularNetwork::NotRegistered); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.get_registration_status(CellularNetwork::C_EREG, stat)); + EXPECT_TRUE(stat == -1); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_network_registering_mode) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + + ATHandler_stub::int_value = 0; + CellularNetwork::NWRegisteringMode mode = CellularNetwork::NWModeManual; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_network_registering_mode(mode)); + EXPECT_TRUE(mode == CellularNetwork::NWModeAutomatic); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + mode = CellularNetwork::NWModeManual; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_network_registering_mode(mode)); + EXPECT_TRUE(mode == -1); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_registration_urc) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + + CellularNetwork::RegistrationType type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); + + my_AT_CN nw(at); + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, true)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, true)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, true)); + + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); + + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, false)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, false)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_OK == nw.set_registration_urc(type, false)); + + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); + + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, true)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, true)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, true)); + + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); + + type = CellularNetwork::C_EREG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, false)); + type = CellularNetwork::C_GREG; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, false)); + type = CellularNetwork::C_REG; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, false)); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_attach) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::int_value = 0; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_attach()); + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_attach()); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_attach()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_attach) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::AttachStatus stat = CellularNetwork::Detached; + ATHandler_stub::int_value = 1; + ATHandler_stub::bool_value = true; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_attach(stat)); + EXPECT_TRUE(stat == CellularNetwork::Attached); + + ATHandler_stub::int_value = 0; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_attach(stat)); + EXPECT_TRUE(stat == CellularNetwork::Detached); + + stat = CellularNetwork::Attached; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_attach(stat)); + EXPECT_TRUE(stat == CellularNetwork::Detached); + + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_attach(stat)); + EXPECT_TRUE(stat == CellularNetwork::Detached); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_attach(stat)); + EXPECT_TRUE(stat == CellularNetwork::Detached); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_detach) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + my_AT_CN cn(at); + + EXPECT_TRUE(NSAPI_ERROR_OK == cn.detach()); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.detach()); + + // connect so we can test callback in detach + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + cn.set_stack_type(IPV4_STACK); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.connect()); + EXPECT_TRUE(NSAPI_STATUS_GLOBAL_UP == cn.get_connection_status()); + // attach callback + cn.attach(&network_cb); + network_cb_count = 0; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.detach()); + EXPECT_TRUE(network_cb_count == 1); + EXPECT_TRUE(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_rate_control) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + int ur = -1; + CellularNetwork::RateControlExceptionReports reports = CellularNetwork::NotAllowedToBeSent; + CellularNetwork::RateControlUplinkTimeUnit timeUnit = CellularNetwork::Unrestricted; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); + EXPECT_TRUE(reports == CellularNetwork::NotAllowedToBeSent); + EXPECT_TRUE(timeUnit == CellularNetwork::Unrestricted); + EXPECT_TRUE(ur == -1); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::int_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_rate_control(reports, timeUnit, ur)); + EXPECT_TRUE(reports == CellularNetwork::AllowedToBeSent); + EXPECT_TRUE(timeUnit == CellularNetwork::Minute); + EXPECT_TRUE(ur == 1); + + // test second if in get_rate_control + reports = CellularNetwork::NotAllowedToBeSent; + timeUnit = CellularNetwork::Unrestricted; + ur = -1; + + ATHandler_stub::int_count = 1; + ATHandler_stub::int_valid_count_table[0] = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); + EXPECT_TRUE(reports == CellularNetwork::NotAllowedToBeSent); + EXPECT_TRUE(timeUnit == CellularNetwork::Unrestricted); + EXPECT_TRUE(ur == -1); + + // test second if in get_rate_control + ATHandler_stub::int_count = 2; + ATHandler_stub::int_valid_count_table[0] = 1; + ATHandler_stub::int_valid_count_table[1] = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); + EXPECT_TRUE(reports == CellularNetwork::AllowedToBeSent); + EXPECT_TRUE(timeUnit == CellularNetwork::Unrestricted); + EXPECT_TRUE(ur == -1); + + // test third if in get_rate_control + ATHandler_stub::int_count = 3; + ATHandler_stub::int_valid_count_table[0] = 3; + ATHandler_stub::int_valid_count_table[1] = 1; + ATHandler_stub::int_valid_count_table[2] = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); + EXPECT_TRUE(reports == CellularNetwork::AllowedToBeSent); + EXPECT_TRUE(timeUnit == CellularNetwork::Day); + EXPECT_TRUE(ur == -1); + + ATHandler_stub::int_count = 4; + ATHandler_stub::int_valid_count_table[0] = 5; + ATHandler_stub::int_valid_count_table[1] = 3; + ATHandler_stub::int_valid_count_table[2] = 1; + ATHandler_stub::int_valid_count_table[3] = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_rate_control(reports, timeUnit, ur)); + EXPECT_TRUE(reports == CellularNetwork::AllowedToBeSent); + EXPECT_TRUE(timeUnit == CellularNetwork::Day); + EXPECT_TRUE(ur == 5); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_apn_backoff_timer) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + int time = -1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == cn.get_apn_backoff_timer(time)); + EXPECT_TRUE(time == -1); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == cn.get_apn_backoff_timer(time)); + EXPECT_TRUE(time == -1); + + ATHandler_stub::resp_info_true_counter = 0; + ATHandler_stub::bool_value = false; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + cn.set_credentials("internet", NULL, NULL); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_apn_backoff_timer(time)); + EXPECT_TRUE(time == -1); + + ATHandler_stub::resp_info_true_counter = 0; + ATHandler_stub::bool_value = true; + ATHandler_stub::int_value = 55; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + cn.set_credentials("internet", NULL, NULL); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_apn_backoff_timer(time)); + EXPECT_TRUE(time == 55); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_ip_address) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + EXPECT_TRUE(!cn.get_ip_address()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_access_technology) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_UNKNOWN)); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_GSM_COMPACT)); + + my_AT_CN my_cn(at); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_access_technology(CellularNetwork::RAT_GSM_COMPACT)); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_access_technology) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::RadioAccessTechnology rat; + + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_access_technology(rat)); + EXPECT_TRUE(CellularNetwork::RAT_UNKNOWN == rat); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_scan_plmn) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + int c = -1; + CellularNetwork::operList_t ops; + ATHandler_stub::bool_value = false; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.scan_plmn(ops, c)); + EXPECT_TRUE(c == 0); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); + EXPECT_TRUE(c == 0); + + + ATHandler_stub::read_string_index = 3; + ATHandler_stub::read_string_table[0] = "44444"; + ATHandler_stub::read_string_table[1] = "33333"; + ATHandler_stub::read_string_table[2] = "12345"; + ATHandler_stub::int_value = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::info_elem_true_counter = 1; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); + EXPECT_TRUE(c == 1); + EXPECT_TRUE(ops.get_head() != NULL); + CellularNetwork::operator_t *op = ops.get_head(); + EXPECT_TRUE(op->op_status == CellularNetwork::operator_t::Available); + EXPECT_TRUE(strcmp(op->op_long, "12345") == 0); + EXPECT_TRUE(strcmp(op->op_short, "33333") == 0); + EXPECT_TRUE(strcmp(op->op_num, "44444") == 0); + ops.delete_all(); + + ATHandler_stub::read_string_index = 3; + ATHandler_stub::int_value = 6; // RAT_HSDPA_HSUPA + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::info_elem_true_counter = 1; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_UTRAN)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); + EXPECT_TRUE(c == 0); + EXPECT_TRUE(ops.get_head() == NULL); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_ciot_optimization_config) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE)); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_ciot_optimization_config) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::Supported_UE_Opt sup = CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT; + CellularNetwork::Preferred_UE_Opt pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; + ATHandler_stub::int_value = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_ciot_optimization_config(sup, pref)); + EXPECT_TRUE(sup == CellularNetwork::SUPPORTED_UE_OPT_CONTROL_PLANE); + EXPECT_TRUE(pref == CellularNetwork::PREFERRED_UE_OPT_CONTROL_PLANE); + + sup = CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT; + pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; + ATHandler_stub::int_value = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_ciot_optimization_config(sup, pref)); + EXPECT_TRUE(sup == CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT); + EXPECT_TRUE(pref == CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_set_stack_type) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == cn.set_stack_type(IPV4_STACK)); + + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_stack_type(DEFAULT_STACK)); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_stack_type) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + EXPECT_TRUE(DEFAULT_STACK == cn.get_stack_type()); + + my_AT_CN my_cn(at); + EXPECT_TRUE(DEFAULT_STACK == my_cn.get_stack_type()); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.set_stack_type(IPV4_STACK)); + EXPECT_TRUE(DEFAULT_STACK == my_cn.get_stack_type()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_pdpcontext_params) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::pdpContextList_t list; + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_pdpcontext_params(list)); + + // don't got to while loop + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + ATHandler_stub::resp_info_true_counter = 0; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list)); + EXPECT_TRUE(NULL == list.get_head()); + + // go to while loop and check values + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::int_count = 9; + ATHandler_stub::int_valid_count_table[8] = 1; + ATHandler_stub::int_valid_count_table[7] = 2; + ATHandler_stub::int_valid_count_table[6] = 3; + ATHandler_stub::int_valid_count_table[5] = 4; + ATHandler_stub::int_valid_count_table[4] = 5; + ATHandler_stub::int_valid_count_table[3] = 6; + ATHandler_stub::int_valid_count_table[2] = 7; + ATHandler_stub::int_valid_count_table[1] = 8; + ATHandler_stub::int_valid_count_table[0] = 9; + + ATHandler_stub::read_string_index = 7; + ATHandler_stub::read_string_table[6] = "internet"; + ATHandler_stub::read_string_table[5] = "1.2.3.4.5.6.7.8.9.10.11.112.13.14.15.16.1.2.3.44.55.6.7.8.9.10.11.12.13.14.15.16"; + ATHandler_stub::read_string_table[4] = "23.33.44.1.2.3.55.123.225.34.11.1.0.0.123.234"; + ATHandler_stub::read_string_table[3] = "1.2.3.4"; + ATHandler_stub::read_string_table[2] = "0.255.0.255"; + ATHandler_stub::read_string_table[1] = "25.66.77.88"; + ATHandler_stub::read_string_table[0] = "004.003.002.001"; + + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list)); + CellularNetwork::pdpcontext_params_t *params = list.get_head(); + EXPECT_TRUE(params != NULL); + EXPECT_TRUE(params->next == NULL); + EXPECT_TRUE(params->cid == 1); + EXPECT_TRUE(params->bearer_id == 2); + EXPECT_TRUE(params->im_signalling_flag == 3); + EXPECT_TRUE(params->lipa_indication == 4); + EXPECT_TRUE(params->ipv4_mtu == 5); + EXPECT_TRUE(params->wlan_offload == 6); + EXPECT_TRUE(params->local_addr_ind == 7); + EXPECT_TRUE(params->non_ip_mtu == 8); + EXPECT_TRUE(params->serving_plmn_rate_control_value == 9); + EXPECT_TRUE(strcmp(params->apn, "internet") == 0); + EXPECT_TRUE(strcmp(params->local_addr, "102:304:506:708:90A:B70:D0E:F10") == 0); + EXPECT_TRUE(strcmp(params->local_subnet_mask, "102:32C:3706:708:90A:B0C:D0E:F10") == 0); + EXPECT_TRUE(strcmp(params->gateway_addr, "1721:2C01:203:377B:E122:B01:000:7BEA") == 0); + EXPECT_TRUE(strcmp(params->dns_primary_addr, "1.2.3.4") == 0); + EXPECT_TRUE(strcmp(params->dns_secondary_addr, "0.255.0.255") == 0); + EXPECT_TRUE(strcmp(params->p_cscf_prim_addr, "25.66.77.88") == 0); + EXPECT_TRUE(strcmp(params->p_cscf_sec_addr, "004.003.002.001") == 0); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_extended_signal_quality) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + int rx = -1, be = -1, rs = -1, ec = -1, rsrq = -1, rsrp = -1; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_extended_signal_quality(rx, be, rs, ec, rsrq, rsrp)); + EXPECT_TRUE(rx == -1 && be == -1 && rs == -1 && ec == -1 && rsrq == -1 && rsrp == -1); + + ATHandler_stub::int_value = 5; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_extended_signal_quality(rx, be, rs, ec, rsrq, rsrp)); + EXPECT_TRUE(rx == 5 && be == 5 && rs == 5 && ec == 5 && rsrq == 5 && rsrp == 5); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + int rs = -1, ber = -1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_signal_quality(rs, ber)); + EXPECT_TRUE(rs == -1 && ber == -1); + + ATHandler_stub::int_value = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_signal_quality(rs, ber)); + EXPECT_TRUE(rs == 1 && ber == 1); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_cell_id) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + int id = 0; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_cell_id(id)); + EXPECT_TRUE(id == -1); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_cell_id(id)); + EXPECT_TRUE(id == -1); + + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[1] = "00C3"; + ATHandler_stub::read_string_table[0] = "1234FFC1"; //== cellid and in dec: 305463233 + ATHandler_stub::int_value = 1; + // Get registration status to modify cell_id + CellularNetwork::RegistrationType type; + CellularNetwork::RegistrationStatus status; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_EREG, status)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_cell_id(id)); + EXPECT_TRUE(id == 305463233); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_3gpp_error) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::int_value = 8; + EXPECT_TRUE(8 == cn.get_3gpp_error()); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_operator_params) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + int format; + CellularNetwork::operator_t ops; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_operator_params(format, ops)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::int_value = 0; + ATHandler_stub::read_string_index = 1; + ATHandler_stub::read_string_table[0] = "12345"; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); + EXPECT_TRUE(format == 0); + EXPECT_TRUE(strcmp(ops.op_long, "12345") == 0); + EXPECT_TRUE(strlen(ops.op_short) == 0); + EXPECT_TRUE(strlen(ops.op_num) == 0); + EXPECT_TRUE(ops.op_rat == CellularNetwork::RAT_GSM); + + ops.op_long[0] = 0; + ATHandler_stub::int_value = 1; + ATHandler_stub::read_string_index = 1; + ATHandler_stub::read_string_table[0] = "12345"; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); + EXPECT_TRUE(format == 1); + EXPECT_TRUE(strlen(ops.op_long) == 0); + EXPECT_TRUE(strcmp(ops.op_short, "12345") == 0); + EXPECT_TRUE(strlen(ops.op_num) == 0); + EXPECT_TRUE(ops.op_rat == CellularNetwork::RAT_GSM_COMPACT); + + ops.op_short[0] = 0; + ATHandler_stub::int_value = 2; + ATHandler_stub::read_string_index = 1; + ATHandler_stub::read_string_table[0] = "12345"; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); + EXPECT_TRUE(format == 2); + EXPECT_TRUE(strlen(ops.op_long) == 0); + EXPECT_TRUE(strlen(ops.op_short) == 0); + EXPECT_TRUE(strcmp(ops.op_num, "12345") == 0); + EXPECT_TRUE(ops.op_rat == CellularNetwork::RAT_UTRAN); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_get_operator_names) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + CellularNetwork::operator_names_list name_list; + + ATHandler_stub::resp_info_true_counter = 0; + ATHandler_stub::bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_names(name_list)); + EXPECT_TRUE(name_list.get_head() == NULL); + + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == cn.get_operator_names(name_list)); + EXPECT_TRUE(name_list.get_head() != NULL); + EXPECT_TRUE(name_list.get_head()->next == NULL); + + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_index = 2; + ATHandler_stub::read_string_table[1] = "12345"; + ATHandler_stub::read_string_table[0] = "56789"; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + name_list.delete_all(); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.get_operator_names(name_list)); + CellularNetwork::operator_names_t *op_names = name_list.get_head(); + EXPECT_TRUE(op_names != NULL); + EXPECT_TRUE(op_names->next == NULL); + EXPECT_TRUE(strcmp(op_names->numeric, "12345") == 0); + EXPECT_TRUE(strcmp(op_names->alpha, "56789") == 0); +} + +TEST_F(TestAT_CellularNetwork, test_AT_CellularNetwork_attach) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + network_cb_count = 0; + cn.attach(&network_cb); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.connect()); + EXPECT_TRUE(network_cb_count == 2); // check that attached callback was called twice +} + +TEST_F(TestAT_CellularNetwork, test_get_connection_status) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + network_cb_count = 0; + cn.attach(&network_cb); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == cn.connect()); + EXPECT_TRUE(network_cb_count == 2); // check that attached callback was called twice + EXPECT_TRUE(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); + + my_AT_CN my_cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::bool_value = false; + cn.set_stack_type(IPV4_STACK); + EXPECT_TRUE(NSAPI_ERROR_OK == my_cn.connect()); + EXPECT_TRUE(network_cb_count == 2); + EXPECT_TRUE(NSAPI_STATUS_GLOBAL_UP == my_cn.get_connection_status()); +} + +TEST_F(TestAT_CellularNetwork, test_set_blocking) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularNetwork cn(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_blocking(false)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_blocking(true)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_blocking(false)); + EXPECT_TRUE(NSAPI_ERROR_OK == cn.set_blocking(true)); +} + diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake new file mode 100644 index 0000000000..e41cf3c6de --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake @@ -0,0 +1,37 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_network_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + ../features/cellular/framework/AT/AT_CellularNetwork.cpp + ../features/cellular/framework/AT/AT_CellularStack.cpp + ../features/cellular/framework/common/CellularUtil.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/NetworkInterface_stub.cpp + stubs/NetworkStack_stub.cpp + stubs/us_ticker_stub.cpp + stubs/mbed_assert_stub.cpp + stubs/SocketAddress_stub.cpp + stubs/randLIB_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp new file mode 100644 index 0000000000..48b67abd2f --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp @@ -0,0 +1,201 @@ +/* + * 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 +#include "AT_CellularNetwork.h" +#include "EventQueue.h" +#include "ATHandler.h" +#include "AT_CellularPower.h" +#include "FileHandle_stub.h" +#include "ATHandler_stub.h" + +using namespace mbed; +using namespace events; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularPower : public testing::Test { +protected: + + void SetUp() { + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + } + + void TearDown() { + } +}; +// *INDENT-ON* + + +static void device_ready_cb() +{ +} + +TEST_F(TestAT_CellularPower, Create) +{ + + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower *pow = new AT_CellularPower(at); + + EXPECT_TRUE(pow != NULL); + + delete pow; +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_on) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.on()); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_off) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off()); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_at_mode) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_at_mode()); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode()); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(6)); + EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 1)); + EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 0)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6)); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == pow.reset()); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_power_save_mode) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345)); + + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0)); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_receive_period) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3)); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready()); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb)); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL)); +} + +TEST_F(TestAT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularPower pow(at); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb)); + + pow.remove_device_ready_urc_cb(NULL); + pow.remove_device_ready_urc_cb(&device_ready_cb); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake new file mode 100644 index 0000000000..118bdac47c --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake @@ -0,0 +1,31 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_power_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + ../features/cellular/framework/AT/AT_CellularPower.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/CellularUtil_stub.cpp + stubs/mbed_assert_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp new file mode 100644 index 0000000000..eb82bc6c9a --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp @@ -0,0 +1,204 @@ +/* + * 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 "ATHandler_stub.h" +#include +#include "AT_CellularNetwork.h" +#include "EventQueue.h" +#include "ATHandler.h" +#include "AT_CellularSIM.h" +#include "FileHandle_stub.h" +#include "CellularLog.h" +#include "ATHandler_stub.h" + +using namespace mbed; +using namespace events; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularSIM : public testing::Test { +protected: + + void SetUp() + { + ATHandler_stub::read_string_index = kRead_string_table_size; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = 0; + } + + void TearDown() + { + } +}; +// *INDENT-ON* + +TEST_F(TestAT_CellularSIM, Create) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSIM *sim = new AT_CellularSIM(at); + + EXPECT_TRUE(sim != NULL); + delete sim; +} + +TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSIM sim(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "READY"; + ATHandler_stub::ssize_value = 5; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); + + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin(NULL)); +} + +TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_change_pin) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSIM sim(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", "34")); + EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, "34")); + EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", NULL)); + EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, NULL)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34")); +} + +TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin_query) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSIM sim(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", true)); + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, true)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", false)); + EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true)); +} + +TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSIM sim(at); + CellularSIM::SimState state; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::read_string_value = NULL; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); + EXPECT_TRUE(CellularSIM::SimStateUnknown == state); + + ATHandler_stub::read_string_value = "READY"; + ATHandler_stub::ssize_value = 5; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); + EXPECT_TRUE(CellularSIM::SimStateReady == state); + + ATHandler_stub::read_string_value = "SIM PIN"; + ATHandler_stub::ssize_value = 7; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); + EXPECT_TRUE(CellularSIM::SimStatePinNeeded == state); + + ATHandler_stub::read_string_value = "SIM PUK"; + ATHandler_stub::ssize_value = 7; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); + EXPECT_TRUE(CellularSIM::SimStatePukNeeded == state); + + ATHandler_stub::read_string_value = "SOME CRAP"; + ATHandler_stub::ssize_value = 9; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); + EXPECT_TRUE(CellularSIM::SimStateUnknown == state); +} + +TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + char imsi[16]; + AT_CellularSIM sim(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "123456789012345"; + ATHandler_stub::ssize_value = 15; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_imsi(imsi)); + EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, imsi) == 0); + + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::read_string_index = -1; + imsi[0] = 0; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi)); + EXPECT_TRUE(strlen(imsi) == 0); + + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL)); + + // this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation. + // Now we have improved documentation that that the given imsi buffer size must be over 15. + //char imsi2[5]; + //EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2)); +} + +TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + char buf[16]; + AT_CellularSIM sim(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = "123456789012345"; + ATHandler_stub::ssize_value = 15; + EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_iccid(buf, 16)); + EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, buf) == 0); + + buf[0] = 0; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = -1; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16)); + EXPECT_TRUE(strlen(buf) == 0); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake new file mode 100644 index 0000000000..ab4f3c0763 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake @@ -0,0 +1,32 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_sim_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + ../features/cellular/framework/AT/AT_CellularSIM.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/CellularUtil_stub.cpp + stubs/us_ticker_stub.cpp + stubs/mbed_assert_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp new file mode 100644 index 0000000000..a586c2e652 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp @@ -0,0 +1,203 @@ +/* + * 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 +#include "AT_CellularNetwork.h" +#include "EventQueue.h" +#include "ATHandler.h" +#include "ATHandler_stub.h" +#include "AT_CellularSMS.h" +#include "FileHandle_stub.h" +#include "CellularLog.h" + +using namespace mbed; +using namespace events; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularSMS : public testing::Test { +protected: + + void SetUp() + { + ATHandler_stub::return_given_size = false; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + } + + void TearDown() + { + } +}; +// *INDENT-ON* + +TEST_F(TestAT_CellularSMS, Create) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS *sms = new AT_CellularSMS(at); + + EXPECT_TRUE(sms != NULL); + delete sms; +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText)); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_send_sms) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + EXPECT_EQ(NSAPI_ERROR_PARAMETER, sms.send_sms(NULL, "2", 1)); + + sms.initialize(CellularSMS::CellularSMSMmodeText); + ATHandler_stub::size_value = 1; + EXPECT_EQ(1, sms.send_sms("1", "22", 2)); + + ATHandler_stub::size_value = 2; + EXPECT_EQ(2, sms.send_sms("1", "22", 2)); + + ATHandler_stub::return_given_size = true; // PDU mode write is much longer than than msg len + sms.initialize(CellularSMS::CellularSMSMmodePDU); + EXPECT_EQ(2, sms.send_sms("1", "23", 2));; + + ATHandler_stub::nsapi_error_ok_counter = 1; + ATHandler_stub::size_value = 32; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8)); + + ATHandler_stub::nsapi_error_ok_counter = 2; + ATHandler_stub::size_value = 32; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + char table[] = "232323232323232323232323232323232323232323232323232323\ + 232323232323232323232323232323232323232323232323232323\ + 232323232323232323232323232323232323232323232323232323\ + 23232323232323232323232323232323232323\0"; + + EXPECT_EQ(strlen(table), sms.send_sms("1", table, strlen(table))); + EXPECT_EQ(strlen(table), sms.send_sms("12", table, strlen(table))); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_get_sms) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + char buf[16]; + char phone[21]; + char stamp[21]; + int size; + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size)); + + ATHandler_stub::resp_info_true_counter = 1; + ATHandler_stub::int_value = 0; + EXPECT_TRUE(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); + + ATHandler_stub::resp_info_true_counter = 2; + ATHandler_stub::int_value = 11; + EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); + //TODO: Should make add_info to happen, before calling get_sms! + + ATHandler_stub::resp_info_true_counter = 2; + ATHandler_stub::int_value = 11; + sms.initialize(CellularSMS::CellularSMSMmodePDU); + EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_sms_callback) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + sms.set_sms_callback(NULL); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cpms) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4")); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_csca) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1)); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cscs) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2")); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_delete_all_messages) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; + EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages()); +} + +TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_extra_sim_wait_time) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + AT_CellularSMS sms(at); + sms.set_extra_sim_wait_time(56); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake new file mode 100644 index 0000000000..ba6c5b52c8 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake @@ -0,0 +1,33 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_sms_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + ../features/cellular/framework/AT/AT_CellularSMS.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/CellularUtil_stub.cpp + stubs/us_ticker_stub.cpp + stubs/mbed_assert_stub.cpp + stubs/mbed_wait_api_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp new file mode 100644 index 0000000000..40e2aebe9c --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp @@ -0,0 +1,377 @@ +/* + * 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 "AT_CellularStack.h" +#include +#include "AT_CellularNetwork.h" +#include "EventQueue.h" +#include "ATHandler.h" +#include "AT_CellularStack.h" +#include "FileHandle_stub.h" +#include "CellularLog.h" +#include "ATHandler_stub.h" +#include "SocketAddress.h" + +using namespace mbed; +using namespace events; + +class MyStack : public AT_CellularStack { +public: + bool bool_value; + bool max_sock_value; + nsapi_error_t create_error; + CellularSocket socket; + + MyStack(ATHandler &atr, int cid, nsapi_ip_stack_t typ) : AT_CellularStack(atr, cid, typ) + { + bool_value = false; + max_sock_value = 0; + create_error = NSAPI_ERROR_OK; + } + + virtual int get_max_socket_count() + { + return max_sock_value; + } + + virtual bool is_protocol_supported(nsapi_protocol_t protocol) + { + return bool_value; + } + + virtual nsapi_error_t socket_close_impl(int sock_id) + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t create_socket_impl(CellularSocket *socket) + { + return create_error; + } + + virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, + const void *data, nsapi_size_t size) + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, + void *buffer, nsapi_size_t size) + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) + { + return AT_CellularStack::socket_open(handle, proto); + } + + virtual nsapi_error_t socket_close(nsapi_socket_t handle) + { + return AT_CellularStack::socket_close(handle); + } + + virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) + { + return AT_CellularStack::socket_bind(handle, address); + } + + virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) + { + return AT_CellularStack::socket_listen(handle, backlog); + } + + virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) + { + return AT_CellularStack::socket_connect(handle, address); + } + + virtual nsapi_error_t socket_accept(nsapi_socket_t server, + nsapi_socket_t *handle, SocketAddress *address = 0) + { + return AT_CellularStack::socket_accept(server, handle, address); + } + + virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, + const void *data, nsapi_size_t size) + { + return AT_CellularStack::socket_send(handle, data, size); + } + + virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, + void *data, nsapi_size_t size) + { + return AT_CellularStack::socket_recv(handle, data, size); + } + + virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, + const void *data, nsapi_size_t size) + { + return AT_CellularStack::socket_sendto(handle, address, data, size); + } + + virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, + void *buffer, nsapi_size_t size) + { + return AT_CellularStack::socket_recvfrom(handle, address, buffer, size); + } + + virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) + { + return AT_CellularStack::socket_attach(handle, callback, data); + } +}; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestAT_CellularStack : public testing::Test { +protected: + + void SetUp() + { + ATHandler_stub::return_given_size = false; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::ssize_value = 0; + ATHandler_stub::bool_value = false; + ATHandler_stub::read_string_value = NULL; + } + + void TearDown() + { + } +}; +// *INDENT-ON* + +TEST_F(TestAT_CellularStack, Create) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack *st = new MyStack(at, 0, IPV4_STACK); + + EXPECT_TRUE(st != NULL); + delete st; +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_get_ip_address) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + EXPECT_TRUE(0 == strlen(st.get_ip_address())); + + char table[] = "1.2.3.4.5.65.7.8.9.10.11\0"; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::bool_value = true; + ATHandler_stub::read_string_value = table; + EXPECT_TRUE(NULL == st.get_ip_address()); + + ATHandler_stub::ssize_value = strlen(table); + ATHandler_stub::bool_value = true; + ATHandler_stub::read_string_value = table; + EXPECT_TRUE(st.get_ip_address()); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + st.bool_value = false; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP)); + + st.bool_value = true; + st.max_sock_value = 0; + nsapi_socket_t sock = &st.socket; + EXPECT_TRUE(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP)); + + MyStack st2(at, 0, IPV6_STACK); + st2.bool_value = true; + st2.max_sock_value = 1; + sock = &st2.socket; + EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(&st.socket)); + + nsapi_socket_t sock = &st.socket; + st.bool_value = true; + st.max_sock_value = 1; + EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP)); + st.max_sock_value = 0; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock)); + + MyStack st2(at, 0, IPV6_STACK); + st2.max_sock_value = 1; + st2.bool_value = true; + sock = &st2.socket; + EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP)); + EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_close(sock)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_bind) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + SocketAddress addr; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_ALREADY; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr)); + + EXPECT_TRUE(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_listen) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_connect) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + SocketAddress addr; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr)); + + EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_accept) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + nsapi_socket_t sock = &st.socket; + EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4)); + + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4)); + + SocketAddress addr; + st.max_sock_value = 1; + st.bool_value = true; + nsapi_socket_t sock = &st.socket; + st.socket_open(&sock, NSAPI_TCP); + st.socket_connect(sock, addr); + EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_send(sock, "addr", 4)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + + SocketAddress addr; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4)); + + st.max_sock_value = 1; + st.bool_value = true; + nsapi_socket_t sock = &st.socket; + st.socket_open(&sock, NSAPI_TCP); + st.socket_connect(sock, addr); + st.create_error = NSAPI_ERROR_CONNECTION_LOST; + EXPECT_TRUE(NSAPI_ERROR_CONNECTION_LOST == st.socket_sendto(sock, addr, "addr", 4)); + + st.create_error = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recv) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + char table[4]; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + char table[4]; + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4)); + + SocketAddress addr; + st.max_sock_value = 1; + st.bool_value = true; + nsapi_socket_t sock = &st.socket; + st.socket_open(&sock, NSAPI_TCP); + st.socket_connect(sock, addr); + st.create_error = NSAPI_ERROR_CONNECTION_LOST; + EXPECT_TRUE(NSAPI_ERROR_CONNECTION_LOST == st.socket_recvfrom(sock, &addr, table, 4)); + + st.create_error = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4)); +} + +TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach) +{ + EventQueue que; + FileHandle_stub fh1; + ATHandler at(&fh1, que, 0, ","); + + MyStack st(at, 0, IPV6_STACK); + + st.socket_attach(NULL, NULL, NULL); + st.max_sock_value = 1; + st.bool_value = true; + nsapi_socket_t sock = &st.socket; + st.socket_open(&sock, NSAPI_TCP); + st.socket_attach(sock, NULL, NULL); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake new file mode 100644 index 0000000000..32ed822154 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake @@ -0,0 +1,34 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_cellular_stack_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + ../features/cellular/framework/AT/AT_CellularStack.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp + stubs/ATHandler_stub.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/CellularUtil_stub.cpp + stubs/us_ticker_stub.cpp + stubs/NetworkStack_stub.cpp + stubs/SocketAddress_stub.cpp + stubs/mbed_assert_stub.cpp +) diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp new file mode 100644 index 0000000000..df0780cfc5 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -0,0 +1,1022 @@ +/* + * 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 +#include "AT_CellularNetwork.h" +#include "EventQueue.h" +#include "ATHandler.h" +#include "AT_CellularStack.h" +#include "FileHandle_stub.h" +#include "CellularLog.h" +#include "mbed_poll_stub.h" + +#include "Timer_stub.h" + +using namespace mbed; +using namespace events; + +void urc_callback() +{ +} + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class TestATHandler : public testing::Test { +protected: + + void SetUp() + { + } + + void TearDown() + { + } +}; +// *INDENT-ON* + +TEST_F(TestATHandler, Create) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler *at = new ATHandler(&fh1, que, 0, ","); + + delete at; + + at = new ATHandler(&fh1, que, 0, NULL); + + EXPECT_TRUE(at != NULL); + delete at; +} + +TEST_F(TestATHandler, test_ATHandler_get_file_handle) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_EQ(&fh1, at.get_file_handle()); +} + +TEST_F(TestATHandler, test_ATHandler_set_file_handle) +{ + EventQueue que; + FileHandle_stub fh1, fh2; + + ATHandler at(&fh1, que, 0, ","); + + at.set_file_handle(&fh2); +} + +TEST_F(TestATHandler, test_ATHandler_lock) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + + at.lock(); +} + +TEST_F(TestATHandler, test_ATHandler_unlock) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + filehandle_stub_short_value_counter = 1; + fh1.short_value = POLLIN; + at.unlock(); +} + +TEST_F(TestATHandler, test_ATHandler_unlock_return_error) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(NSAPI_ERROR_OK == at.unlock_return_error()); +} + +TEST_F(TestATHandler, test_ATHandler_set_urc_handler) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + const char ch[] = "testtesttesttest"; + at.set_urc_handler(ch, &urc_callback); +} + +TEST_F(TestATHandler, test_ATHandler_get_last_error) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error()); +} + +TEST_F(TestATHandler, test_ATHandler_get_last_device_error) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(0 == at.get_last_device_error().errCode); +} + +TEST_F(TestATHandler, test_ATHandler_inc_ref_count) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.inc_ref_count(); +} + +TEST_F(TestATHandler, test_ATHandler_dec_ref_count) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.dec_ref_count(); +} + +TEST_F(TestATHandler, test_ATHandler_get_ref_count) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(1 == at.get_ref_count()); + + at.inc_ref_count(); + EXPECT_TRUE(2 == at.get_ref_count()); + + at.inc_ref_count(); + EXPECT_TRUE(3 == at.get_ref_count()); + + at.dec_ref_count(); + at.dec_ref_count(); + EXPECT_TRUE(1 == at.get_ref_count()); +} + +TEST_F(TestATHandler, test_ATHandler_set_at_timeout) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.set_at_timeout(8); + + at.set_at_timeout(80, true); +} + +TEST_F(TestATHandler, test_ATHandler_restore_at_timeout) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.set_at_timeout(80, true); + at.set_at_timeout(800); + at.restore_at_timeout(); +} + +TEST_F(TestATHandler, test_ATHandler_clear_error) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.clear_error(); +} + +TEST_F(TestATHandler, test_ATHandler_process_oob) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + filehandle_stub_short_value_counter = 1; + fh1.short_value = POLLIN; + at.set_urc_handler("s", &urc_callback); + at.process_oob(); + + filehandle_stub_short_value_counter = 2; + at.process_oob(); + + //at.fill_buffer(); + uint8_t buf[5]; + at.clear_error(); + char table[] = "ssssssssssssssssssssssssssssssss\0"; + filehandle_stub_table = table; + filehandle_stub_table_pos = 0; + at.read_bytes(buf, 5); + + filehandle_stub_short_value_counter = 2; + at.process_oob(); + + at.clear_error(); + timer_stub_value = 0; + filehandle_stub_table_pos = 0; + at.read_bytes(buf, 5); + + filehandle_stub_short_value_counter = 1; + at.process_oob(); + + char table2[4]; + table2[0] = '\r'; + table2[1] = '\r'; + table2[2] = '\n'; + table2[3] = 0; + filehandle_stub_table = table2; + + at.clear_error(); + timer_stub_value = 0; + filehandle_stub_table_pos = 0; + at.read_bytes(buf, 1); + + filehandle_stub_short_value_counter = 1; + at.process_oob(); + + + filehandle_stub_table = table; + + + filehandle_stub_short_value_counter = 0; + filehandle_stub_table_pos = 0; + filehandle_stub_table = NULL; +} + +TEST_F(TestATHandler, test_ATHandler_set_filehandle_sigio) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.set_filehandle_sigio(); +} + +TEST_F(TestATHandler, test_ATHandler_flush) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + filehandle_stub_short_value_counter = 1; + fh1.short_value = POLLIN; + at.flush(); +} + +TEST_F(TestATHandler, test_ATHandler_cmd_start) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + mbed_poll_stub::revents_value = POLLOUT; + mbed_poll_stub::int_value = 1; + fh1.size_value = 3; + at.cmd_start("s"); + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 0; + + at.cmd_start("s"); + + at.cmd_start("s"); +} + +TEST_F(TestATHandler, test_ATHandler_write_int) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + fh1.size_value = -1; + at.write_int(4); + + at.clear_error(); + mbed_poll_stub::revents_value = POLLOUT; + mbed_poll_stub::int_value = 1; + fh1.size_value = 6; + at.write_int(4); + + at.write_int(2147483647); + + at.write_int(2147483647 + 1); + +// at.at_error(0, DeviceErrorType(0)); +// at.write_int(4); +} + +TEST_F(TestATHandler, test_ATHandler_write_string) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + fh1.size_value = -1; + at.write_string("help"); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + + at.clear_error(); + mbed_poll_stub::revents_value = POLLOUT; + mbed_poll_stub::int_value = 1; + fh1.size_value = -1; + at.cmd_start("s"); + at.write_string("help", true); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + + at.clear_error(); + mbed_poll_stub::revents_value = POLLOUT; + mbed_poll_stub::int_value = 1; + fh1.size_value = -1; + at.write_string("help", true); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + + at.clear_error(); + mbed_poll_stub::revents_value = POLLOUT; + mbed_poll_stub::int_value = 1; + fh1.size_value = 7; + at.write_string("help", true); + EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error()); +} + +TEST_F(TestATHandler, test_ATHandler_cmd_stop) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + fh1.size_value = -1; + at.cmd_stop(); + + at.write_string("help", true); + + at.cmd_stop(); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); +} + +TEST_F(TestATHandler, test_ATHandler_write_bytes) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + fh1.size_value = -1; + uint8_t data[] = "data"; + at.write_bytes(data, 4); + + at.write_bytes(data, 4); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); +} + +TEST_F(TestATHandler, test_ATHandler_set_stop_tag) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.set_stop_tag("s"); +} + +TEST_F(TestATHandler, test_ATHandler_set_delimiter) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.set_delimiter('+'); +} + +TEST_F(TestATHandler, test_ATHandler_skip_param) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.skip_param(); + + char table[] = "ssssssssssssssssssssssssssssOK\r\n\0"; + filehandle_stub_table = table; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + at.skip_param(); + EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR); + + char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0"; + filehandle_stub_table = table1; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + at.skip_param(); + + char table2[] = "sssOK\r\n\0"; + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + at.skip_param(); + + char table3[] = "sssssssOK\nssss\0"; + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + + //Need to create a new instance because stop tag already found + ATHandler at2(&fh1, que, 0, ","); + at2.flush(); + at2.clear_error(); + at2.resp_start(); + at2.skip_param(); + + at2.skip_param(4, 3); + + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + + at2.flush(); + at2.clear_error(); + at2.resp_start(); + at2.skip_param(4, 3); + + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + + at2.flush(); + at2.clear_error(); + at2.resp_start(); + at2.skip_param(24, 17); +} + +TEST_F(TestATHandler, test_ATHandler_read_bytes) +{ + EventQueue que; + FileHandle_stub fh1; + filehandle_stub_table = NULL; + filehandle_stub_table_pos = 0; + + ATHandler at(&fh1, que, 0, ","); + uint8_t buf[5]; + + // TEST EMPTY BUFFER + // Shouldn't read any byte since buffer is empty + EXPECT_TRUE(-1 == at.read_bytes(buf, 1)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + // Return error due to error set to at handler by the above call on empty buffer + EXPECT_TRUE(-1 == at.read_bytes(buf, 1)); + + // TEST DATA IN BUFFER + at.clear_error(); + char table1[] = "1234512345678OK\r\n\0"; + filehandle_stub_table = table1; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1;; + + // Read 5 bytes + EXPECT_TRUE(5 == at.read_bytes(buf, 5)); + EXPECT_TRUE(!memcmp(buf, table1, 5)); + // get_char triggered above should have filled in the whole reading buffer(fill_buffer()) + EXPECT_TRUE(filehandle_stub_table_pos == (strlen(table1) - 1)); + // Read another 8 bytes + EXPECT_TRUE(8 == at.read_bytes(buf, 8) && !memcmp(buf, table1 + 5, 8)); + // Reading more than the 4 bytes left -> ERROR + EXPECT_TRUE(-1 == at.read_bytes(buf, 5)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); +} + +TEST_F(TestATHandler, test_ATHandler_read_string) +{ + EventQueue que; + FileHandle_stub fh1; + filehandle_stub_table = NULL; + filehandle_stub_table_pos = 0; + + ATHandler at(&fh1, que, 0, ","); + + // *** EMPTY *** + at.clear_error(); + char table1[] = ""; + at.flush(); + filehandle_stub_table = table1; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf1[1]; + // No _stop_tag set without resp_start + EXPECT_TRUE(-1 == at.read_string(buf1, 1)); + at.clear_error(); + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + // Device error because buffer is empty + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + at.clear_error(); + // Device error because empty buffer and attempt to fill_buffer by consume_char('\"') + EXPECT_TRUE(-1 == at.read_string(buf1, 1)); + + // *** 1 BYTE *** + at.clear_error(); + char table2[] = "s\0"; + at.flush(); + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf2[1]; + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + // Device error because no CRLF and no more data to read + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + at.clear_error(); + EXPECT_TRUE(0 == at.read_string(buf2, 1)); + + // *** CRLF *** + at.clear_error(); + char table3[] = "\r\ns\r\n\0"; + at.flush(); + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf3[1]; + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + // OK because after CRLF matched there is more data to read ending in CRLF + EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error()); + // To read 0 bytes from: s\r\n + EXPECT_TRUE(0 == at.read_string(buf3, 0 + 1/*for NULL*/)); + // To read 1 byte from: s\r\n -> read s + EXPECT_TRUE(1 == at.read_string(buf3, 1 + 1/*for NULL*/)); + + // *** Reading more than available in buffer *** + at.clear_error(); + char table4[] = "\"s,\"OK\r\n\0"; + at.flush(); + filehandle_stub_table = table4; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf4[7]; + uint8_t buf5[5]; + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read 5 bytes from: "s,"OK\r\n -> read "s,"O + at.read_bytes(buf5, 5); + // K\r\n left to be read -> reading more than 3 + 1(for NULL) -> ERROR + EXPECT_TRUE(-1 == at.read_string(buf4, 4 + 1/*for NULL*/)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + + // *** Encountering delimiter after reading 1 byte *** + at.clear_error(); + at.flush(); + filehandle_stub_table = table4; + filehandle_stub_table_pos = 0; + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read 1 byte from: "s,"OK\r\n -> read " + at.read_bytes(buf5, 1); + // TO read max 4 from: s,"OK\r\n -> read s and stop on , + EXPECT_TRUE(1 == at.read_string(buf4, 4 + 1/*for NULL*/)); + + // *** Encountering delimiter as first char in buffer *** + at.clear_error(); + at.flush(); + filehandle_stub_table = table4; + filehandle_stub_table_pos = 0; + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read 2 bytes from: "s,"OK\r\n -> read "s + at.read_bytes(buf5, 2); + // TO read max 4 bytes from: ,"OK\r\n -> stop on , + EXPECT_TRUE(0 == at.read_string(buf4, 4 + 1/*for NULL*/)); + + // *** Read as much as buffer size is without encountering any delimiter " or OKCRLF *** + at.clear_error(); + char table5[] = "\"s\"OK\r\nabcd\0"; + at.flush(); + filehandle_stub_table = table5; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read 1 byte from: "s"OK\r\n -> read " + at.read_bytes(buf5, 1); + // TO read max 1 byte from: s"OK\r\n -> read s + EXPECT_TRUE(1 == at.read_string(buf4, 1 + 1/*for NULL*/)); + + // *** Consume " and run into OKCRLF *** + // TO read max 1 byte from: "OK\r\n -> consume " and find stop tag OKCRLF + EXPECT_TRUE(0 == at.read_string(buf4, 1 + 1/*for NULL*/)); + + // *** Try to read after stop tag was found *** + // stop tag found do not read further + EXPECT_TRUE(-1 == at.read_string(buf4, 1 + 1/*for NULL*/)); + + // *** Try to read after stop tag was found when parameter allows it *** + // stop tag found but flag indicates to read despite stop_tag found + EXPECT_TRUE(4 == at.read_string(buf4, 4 + 1/*for NULL*/, true)); + + // *** Read as much as buffer size is without encountering any delimiter " or OKCRLF *** + at.clear_error(); + char table6[] = "sss\rsss\0"; + at.flush(); + filehandle_stub_table = table6; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + at.resp_start("s"); + // TO read from: ss\rsss -> read all 6 chars ss\rsss + EXPECT_TRUE(6 == at.read_string(buf4, 6 + 1/*for NULL*/)); + + // *** Reading when buffer only has " *** + at.clear_error(); + char table7[] = "s\"\0"; + at.flush(); + filehandle_stub_table = table7; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + at.resp_start("s"); + // TO read from buffer having only " -> consume " -> trying to read when nothing in buffer + EXPECT_TRUE(-1 == at.read_string(buf4, 5)); + EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); + + // *** Reading through partially matching stop tag *** + at.clear_error(); + char table8[] = "\"s\"OK\rabcd\r\n\0"; + at.flush(); + filehandle_stub_table = table8; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf8[9]; + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read from + EXPECT_TRUE(8 == at.read_string(buf8, 8 + 1/*for NULL*/)); + + // *** Reading through partially matching stop tag *** + at.clear_error(); + char table9[] = "\"s\"Oabcd\r\n\0"; + at.flush(); + filehandle_stub_table = table9; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf9[5]; + + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read from + EXPECT_TRUE(6 == at.read_string(buf9, 6 + 1/*for NULL*/)); + + // *** CRLF part of the string *** + at.clear_error(); + char table10[] = "\"s\"\r\nOK\r\n\0"; + at.flush(); + filehandle_stub_table = table10; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf10[10]; + + // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read + at.resp_start(); + // TO read from + EXPECT_TRUE(3 == at.read_string(buf10, 9 + 1/*for NULL*/)); +} + +TEST_F(TestATHandler, test_ATHandler_read_hex_string) +{ + EventQueue que; + FileHandle_stub fh1; + filehandle_stub_table = NULL; + filehandle_stub_table_pos = 0; + + ATHandler at(&fh1, que, 0, ","); + + // *** Read up to delimiter, even length *** + at.clear_error(); + char table1[] = "68656C6C6F,"; + at.flush(); + filehandle_stub_table = table1; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf1[10]; + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + EXPECT_TRUE(5 == at.read_hex_string(buf1, 5)); + EXPECT_TRUE(!strncmp(buf1, "hello", 5)); + + // *** Read up to delimiter, odd length *** + at.clear_error(); + char table2[] = "68656C6C6F7,"; + at.flush(); + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf2[10]; + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + EXPECT_TRUE(5 == at.read_hex_string(buf2, 6)); + EXPECT_TRUE(!strncmp(buf2, "hello", 5)); + + // *** Read with stop tag, even length *** + at.clear_error(); + char table3[] = "6865OK\r\n"; + at.flush(); + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf3[6]; + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + EXPECT_TRUE(2 == at.read_hex_string(buf3, 2 + 1/*get to stop tag match*/)); + EXPECT_TRUE(!strncmp(buf3, "he", 2)); + at.resp_stop(); + + // *** Read with stop tag, odd length *** + at.clear_error(); + char table4[] = "686OK\r\n"; + at.flush(); + filehandle_stub_table = table4; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + char buf4[6]; + // Set _stop_tag to resp_stop(OKCRLF) + at.resp_start(); + EXPECT_TRUE(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/)); + EXPECT_TRUE(!strncmp(buf4, "h", 1)); +} + +TEST_F(TestATHandler, test_ATHandler_read_int) +{ + EventQueue que; + FileHandle_stub fh1; + filehandle_stub_table = NULL; + filehandle_stub_table_pos = 0; + + ATHandler at(&fh1, que, 0, ","); + + int32_t ret = at.read_int(); + EXPECT_TRUE(-1 == ret); + at.clear_error(); + + char table[] = "\",\"OK\r\n\0"; + filehandle_stub_table = table; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = strlen(table); + + at.resp_start(); + + ret = at.read_int(); + EXPECT_TRUE(-1 == ret); + at.flush(); + at.clear_error(); + + char table2[] = "\"2,\"OK\r\n\0"; + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = strlen(table2); + + at.resp_start(); + + ret = at.read_int(); + EXPECT_TRUE(2 == ret); +} + +TEST_F(TestATHandler, test_ATHandler_resp_start) +{ + EventQueue que; + FileHandle_stub fh1; + + filehandle_stub_table = NULL; + filehandle_stub_table_pos = 0; + + ATHandler at(&fh1, que, 0, ","); + at.resp_start(); + at.resp_start(); + + char table2[] = "\"2,\"OK\r\n\0"; + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start("ssssaaaassssaaaassss"); //too long prefix + + char table3[] = "+CME ERROR: 108\0"; + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + + char table4[] = "+CMS ERROR: 6\0"; + filehandle_stub_table = table4; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + + char table5[] = "ERROR\r\n\0"; + filehandle_stub_table = table5; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + + char table6[] = "OK\r\n\0"; + filehandle_stub_table = table6; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + + char table7[] = "ssssss\0"; + filehandle_stub_table = table7; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.set_urc_handler("ss", NULL); + at.resp_start(); +} + +TEST_F(TestATHandler, test_ATHandler_resp_stop) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + + char table[] = "21 OK\r\n\0"; + filehandle_stub_table = table; + filehandle_stub_table_pos = 0; + + at.info_elem('2'); + at.set_stop_tag("OK\r\n"); + at.resp_stop(); + + char table3[] = "+CME ERROR: 108\0"; + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start(); + + at.resp_stop(); + + char table7[] = "ssssss\0"; + filehandle_stub_table = table7; + filehandle_stub_table_pos = 0; + + at.flush(); + at.clear_error(); + at.resp_start("ss", false); + at.resp_stop(); +} + +TEST_F(TestATHandler, test_ATHandler_info_resp) +{ + EventQueue que; + FileHandle_stub fh1; + + filehandle_stub_table = NULL; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(at.info_resp()); + + at.resp_start(); + EXPECT_TRUE(!at.info_resp()); + + at.flush(); + at.clear_error(); + + char table2[] = "21 OK\r\n\0"; + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = strlen(table2); + + at.resp_start("21"); + EXPECT_TRUE(at.info_resp()); + + EXPECT_TRUE(!at.info_resp()); + + at.flush(); + at.clear_error(); + + char table3[] = "21 OK\r\n\0"; + filehandle_stub_table = table3; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = strlen(table3); + + EXPECT_TRUE(at.info_resp()); +} + +TEST_F(TestATHandler, test_ATHandler_info_elem) +{ + EventQueue que; + FileHandle_stub fh1; + + char table[] = "21 OK\r\n\0"; + filehandle_stub_table = table; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = strlen(table); + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(!at.info_elem('O')); + at.flush(); + + char table2[] = "21 OK\r\n\0"; + filehandle_stub_table = table2; + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = strlen(table2); + + at.clear_error(); + at.resp_start("21"); + EXPECT_TRUE(at.info_elem('O')); + at.flush(); + + filehandle_stub_table = NULL; + filehandle_stub_table_pos = 0; + + at.clear_error(); + at.resp_start("21"); + EXPECT_TRUE(!at.info_elem('2')); +} + +TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + EXPECT_TRUE(at.consume_to_stop_tag()); +} + +TEST_F(TestATHandler, test_ATHandler_set_debug) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.set_debug(true); + + at.set_debug(false); +} + +TEST_F(TestATHandler, test_ATHandler_get_3gpp_error) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + at.get_3gpp_error(); +} diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake new file mode 100644 index 0000000000..6f9c05df34 --- /dev/null +++ b/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake @@ -0,0 +1,41 @@ + +#################### +# UNIT TESTS +#################### + +# Unit test suite name +set(TEST_SUITE_NAME "at_handler_unit") + +# Add test specific include paths +set(unittest-includes ${unittest-includes} + features/cellular/framework/common/util + ../features/cellular/framework/common + ../features/cellular/framework/AT + ../features/frameworks/mbed-client-randlib/mbed-client-randlib +) + +# Source files +set(unittest-sources + ../features/cellular/framework/AT/ATHandler.cpp + ../features/cellular/framework/common/CellularUtil.cpp +) + +# Test files +set(unittest-test-sources + features/cellular/framework/AT/athandler/athandlertest.cpp + stubs/AT_CellularBase_stub.cpp + stubs/EventQueue_stub.cpp + stubs/FileHandle_stub.cpp + stubs/us_ticker_stub.cpp + stubs/mbed_wait_api_stub.cpp + stubs/mbed_assert_stub.cpp + stubs/mbed_poll_stub.cpp + stubs/Timer_stub.cpp + stubs/equeue_stub.c + stubs/Kernel_stub.cpp + stubs/Thread_stub.cpp + stubs/randLIB_stub.cpp +) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048") diff --git a/UNITTESTS/features/cellular/framework/common/util/test_util.cpp b/UNITTESTS/features/cellular/framework/common/util/test_util.cpp deleted file mode 100644 index 49aebf90b0..0000000000 --- a/UNITTESTS/features/cellular/framework/common/util/test_util.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * 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 "test_util.h" -#include -#include "CellularUtil.h" -#include - -using namespace mbed_cellular_util; - -Test_util::Test_util() -{ - -} - -Test_util::~Test_util() -{ -} - -void Test_util::test_util_uint_to_binary_string() -{ - char str[33]; - uint_to_binary_str(15, str, 33, 32); - str[32] = '\0'; - // 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111" - EXPECT_STREQ("00000000000000000000000000001111", str); - - // test NULL pointer - uint_to_binary_str(15, NULL, 0, 32); - - // test give too small buffer - char too_small[5]; - uint_to_binary_str(15, too_small, 5, 6); -} - -void Test_util::test_util_char_str_to_hex() -{ - // basic conversion test, happy days - char hex_buf[50]; - uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf); - hex_buf[number_of_hex_chars] = '\0'; - EXPECT_STREQ("31323334", hex_buf); - EXPECT_EQ(8, number_of_hex_chars); - - number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf); - hex_buf[number_of_hex_chars] = '\0'; - EXPECT_STREQ("7775687575", hex_buf); - EXPECT_EQ(10, number_of_hex_chars); - - // First don't omit the leading zero and then omit and check that leading zero is missing - number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf); - hex_buf[number_of_hex_chars] = '\0'; - EXPECT_STREQ("0A7775687575", hex_buf); - EXPECT_EQ(12, number_of_hex_chars); - - number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true); - hex_buf[number_of_hex_chars] = '\0'; - EXPECT_STREQ("A7775687575", hex_buf); - EXPECT_EQ(11, number_of_hex_chars); - - // test giving a null pointer - number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf); - EXPECT_EQ(0, number_of_hex_chars); - number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL); - EXPECT_EQ(0, number_of_hex_chars); -} - -void Test_util::test_util_convert_ipv6() -{ - // leading zeros omitted - char ipv6[64]; - strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64); - convert_ipv6(ipv6); - EXPECT_STREQ("101:101:101:101:101:101:101:101", ipv6); - EXPECT_EQ(31, strlen(ipv6)); - - // some omitted and some not so much - strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64); - convert_ipv6(ipv6); - EXPECT_STREQ("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6); - EXPECT_EQ(38, strlen(ipv6)); - - // test giving a null pointer - convert_ipv6(NULL); -} - -void Test_util::test_util_prefer_ipv6() -{ - char tt[20] = "62.241.198.246"; - char temp[64] = "2001:14B8:1000:000:000:000:000:002"; - - // not enough space to swap, arrays should stay the same - prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp)); - EXPECT_STREQ("62.241.198.246", tt); - EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", temp); - - // should swap as first one was ip4 and later was ipv6 and enough space - char tt2[64] = "62.241.198.246"; - prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp)); - EXPECT_STREQ("62.241.198.246", temp); - EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", tt2); -} - -void Test_util::test_util_separate_ip_addresses() -{ - char *s = (char *)calloc(128, 1); - - char ip[64] = {0}; - char subnet[64] = {0}; - - strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip); - EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet); - - strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip); - EXPECT_STREQ("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4\0", 8); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("1.2.3.4", ip); - EXPECT_STREQ("", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4.5.6.7.8\0", 16); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("1.2.3.4", ip); - EXPECT_STREQ("5.6.7.8", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("102:304:506:708:90A:B0C:D0E:F10", ip); - EXPECT_STREQ("", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip); - EXPECT_STREQ("", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("1.2.3.4", ip); - EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - EXPECT_STREQ("1.2.3.4", ip); - EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet); - EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s); - - free(s); -} diff --git a/UNITTESTS/features/cellular/framework/common/util/unittest.cmake b/UNITTESTS/features/cellular/framework/common/util/unittest.cmake index b1d43bac34..cefe41bb1c 100644 --- a/UNITTESTS/features/cellular/framework/common/util/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/common/util/unittest.cmake @@ -20,7 +20,6 @@ set(unittest-sources # Test files set(unittest-test-sources - stubs/randLIB_stub.c - features/cellular/framework/common/util/test_util.cpp features/cellular/framework/common/util/utiltest.cpp + stubs/randLIB_stub.cpp ) diff --git a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp index deaa0c5690..237316608b 100644 --- a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp +++ b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Arm Limited and affiliates + * Copyright (c) 2018, Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,49 +15,167 @@ * limitations under the License. */ #include "gtest/gtest.h" -#include "test_util.h" +#include +#include "CellularUtil.h" -class TestUtil : public testing::Test { +using namespace mbed_cellular_util; + +// AStyle ignored as the definition is not clear due to preprocessor usage +// *INDENT-OFF* +class Testutil : public testing::Test { protected: - Test_util *unit; - virtual void SetUp() + void SetUp() { - unit = new Test_util(); } - virtual void TearDown() + void TearDown() { - delete unit; } }; +// *INDENT-ON* -TEST_F(TestUtil, Create) +TEST_F(Testutil, test_util_uint_to_binary_string) { - EXPECT_TRUE(unit); + char str[33]; + uint_to_binary_str(15, str, 33, 32); + str[32] = '\0'; + // 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111" + EXPECT_STREQ("00000000000000000000000000001111", str); + + // test NULL pointer + uint_to_binary_str(15, NULL, 0, 32); + + // test give too small buffer + char too_small[5]; + uint_to_binary_str(15, too_small, 5, 6); } -TEST_F(TestUtil, test_util_uint_to_binary_string) +TEST_F(Testutil, char_str_to_hex) { - unit->test_util_uint_to_binary_string(); + // basic conversion test, happy days + char hex_buf[50]; + uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf); + hex_buf[number_of_hex_chars] = '\0'; + EXPECT_STREQ("31323334", hex_buf); + EXPECT_EQ(8, number_of_hex_chars); + + number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf); + hex_buf[number_of_hex_chars] = '\0'; + EXPECT_STREQ("7775687575", hex_buf); + EXPECT_EQ(10, number_of_hex_chars); + + // First don't omit the leading zero and then omit and check that leading zero is missing + number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf); + hex_buf[number_of_hex_chars] = '\0'; + EXPECT_STREQ("0A7775687575", hex_buf); + EXPECT_EQ(12, number_of_hex_chars); + + number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true); + hex_buf[number_of_hex_chars] = '\0'; + EXPECT_STREQ("A7775687575", hex_buf); + EXPECT_EQ(11, number_of_hex_chars); + + // test giving a null pointer + number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf); + EXPECT_EQ(0, number_of_hex_chars); + number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL); + EXPECT_EQ(0, number_of_hex_chars); } -TEST_F(TestUtil, char_str_to_hex) +TEST_F(Testutil, convert_ipv6) { - unit->test_util_char_str_to_hex(); + // leading zeros omitted + char ipv6[64]; + strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64); + convert_ipv6(ipv6); + EXPECT_STREQ("101:101:101:101:101:101:101:101", ipv6); + EXPECT_EQ(31, strlen(ipv6)); + + // some omitted and some not so much + strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64); + convert_ipv6(ipv6); + EXPECT_STREQ("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6); + EXPECT_EQ(38, strlen(ipv6)); + + // test giving a null pointer + convert_ipv6(NULL); } -TEST_F(TestUtil, convert_ipv6) +TEST_F(Testutil, prefer_ipv6) { - unit->test_util_convert_ipv6(); + char tt[20] = "62.241.198.246"; + char temp[64] = "2001:14B8:1000:000:000:000:000:002"; + + // not enough space to swap, arrays should stay the same + prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp)); + EXPECT_STREQ("62.241.198.246", tt); + EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", temp); + + // should swap as first one was ip4 and later was ipv6 and enough space + char tt2[64] = "62.241.198.246"; + prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp)); + EXPECT_STREQ("62.241.198.246", temp); + EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", tt2); } -TEST_F(TestUtil, prefer_ipv6) +TEST_F(Testutil, separate_ip_addresses) { - unit->test_util_prefer_ipv6(); -} + char *s = (char *)malloc(128); -TEST_F(TestUtil, separate_ip_addresses) -{ - unit->test_util_separate_ip_addresses(); + char ip[64] = {0}; + char subnet[64] = {0}; + + strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip); + EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet); + + strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip); + EXPECT_STREQ("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet); + + ip[0] = '\0'; + subnet[0] = '\0'; + strncpy(s, "1.2.3.4\0", 8); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("1.2.3.4", ip); + EXPECT_STREQ("", subnet); + + ip[0] = '\0'; + subnet[0] = '\0'; + strncpy(s, "1.2.3.4.5.6.7.8\0", 16); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("1.2.3.4", ip); + EXPECT_STREQ("5.6.7.8", subnet); + + ip[0] = '\0'; + subnet[0] = '\0'; + strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("102:304:506:708:90A:B0C:D0E:F10", ip); + EXPECT_STREQ("", subnet); + + ip[0] = '\0'; + subnet[0] = '\0'; + strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip); + EXPECT_STREQ("", subnet); + + ip[0] = '\0'; + subnet[0] = '\0'; + strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("1.2.3.4", ip); + EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet); + + ip[0] = '\0'; + subnet[0] = '\0'; + strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); + EXPECT_STREQ("1.2.3.4", ip); + EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet); + EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s); } diff --git a/UNITTESTS/stubs/ATCmdParser_stub.cpp b/UNITTESTS/stubs/ATCmdParser_stub.cpp new file mode 100644 index 0000000000..d9157ec848 --- /dev/null +++ b/UNITTESTS/stubs/ATCmdParser_stub.cpp @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2017, 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 "ATCmdParser.h" +#include "mbed_poll.h" +#include "mbed_debug.h" + +#ifdef LF +#undef LF +#define LF 10 +#else +#define LF 10 +#endif + +#ifdef CR +#undef CR +#define CR 13 +#else +#define CR 13 +#endif + +// getc/putc handling with timeouts +int ATCmdParser::putc(char c) +{ + pollfh fhs; + fhs.fh = _fh; + fhs.events = POLLOUT; + + int count = poll(&fhs, 1, _timeout); + if (count > 0 && (fhs.revents & POLLOUT)) { + return _fh->write(&c, 1) == 1 ? 0 : -1; + } else { + return -1; + } +} + +int ATCmdParser::getc() +{ + pollfh fhs; + fhs.fh = _fh; + fhs.events = POLLIN; + + int count = poll(&fhs, 1, _timeout); + if (count > 0 && (fhs.revents & POLLIN)) { + unsigned char ch; + return _fh->read(&ch, 1) == 1 ? ch : -1; + } else { + return -1; + } +} + +void ATCmdParser::flush() +{ + while (_fh->readable()) { + unsigned char ch; + _fh->read(&ch, 1); + } +} + + +// read/write handling with timeouts +int ATCmdParser::write(const char *data, int size) +{ + int i = 0; + for (; i < size; i++) { + if (putc(data[i]) < 0) { + return -1; + } + } + return i; +} + +int ATCmdParser::read(char *data, int size) +{ + int i = 0; + for (; i < size; i++) { + int c = getc(); + if (c < 0) { + return -1; + } + data[i] = c; + } + return i; +} + + +// printf/scanf handling +int ATCmdParser::vprintf(const char *format, va_list args) +{ + + if (vsprintf(_buffer, format, args) < 0) { + return false; + } + + int i = 0; + for (; _buffer[i]; i++) { + if (putc(_buffer[i]) < 0) { + return -1; + } + } + return i; +} + +int ATCmdParser::vscanf(const char *format, va_list args) +{ + // Since format is const, we need to copy it into our buffer to + // add the line's null terminator and clobber value-matches with asterisks. + // + // We just use the beginning of the buffer to avoid unnecessary allocations. + int i = 0; + int offset = 0; + + while (format[i]) { + if (format[i] == '%' && format[i + 1] != '%' && format[i + 1] != '*') { + _buffer[offset++] = '%'; + _buffer[offset++] = '*'; + i++; + } else { + _buffer[offset++] = format[i++]; + } + } + + // Scanf has very poor support for catching errors + // fortunately, we can abuse the %n specifier to determine + // if the entire string was matched. + _buffer[offset++] = '%'; + _buffer[offset++] = 'n'; + _buffer[offset++] = 0; + + // To workaround scanf's lack of error reporting, we actually + // make two passes. One checks the validity with the modified + // format string that only stores the matched characters (%n). + // The other reads in the actual matched values. + // + // We keep trying the match until we succeed or some other error + // derails us. + int j = 0; + + while (true) { + // Ran out of space + if (j + 1 >= _buffer_size - offset) { + return false; + } + // Recieve next character + int c = getc(); + if (c < 0) { + return -1; + } + _buffer[offset + j++] = c; + _buffer[offset + j] = 0; + + // Check for match + int count = -1; + sscanf(_buffer + offset, _buffer, &count); + + // We only succeed if all characters in the response are matched + if (count == j) { + // Store the found results + vsscanf(_buffer + offset, format, args); + return j; + } + } +} + + +// Command parsing with line handling +bool ATCmdParser::vsend(const char *command, va_list args) +{ + // Create and send command + if (vsprintf(_buffer, command, args) < 0) { + return false; + } + + for (int i = 0; _buffer[i]; i++) { + if (putc(_buffer[i]) < 0) { + return false; + } + } + + // Finish with newline + for (size_t i = 0; _output_delimiter[i]; i++) { + if (putc(_output_delimiter[i]) < 0) { + return false; + } + } + + debug_if(_dbg_on, "AT> %s\n", _buffer); + return true; +} + +bool ATCmdParser::vrecv(const char *response, va_list args) +{ +restart: + _aborted = false; + // Iterate through each line in the expected response + while (response[0]) { + // Since response is const, we need to copy it into our buffer to + // add the line's null terminator and clobber value-matches with asterisks. + // + // We just use the beginning of the buffer to avoid unnecessary allocations. + int i = 0; + int offset = 0; + bool whole_line_wanted = false; + + while (response[i]) { + if (response[i] == '%' && response[i + 1] != '%' && response[i + 1] != '*') { + _buffer[offset++] = '%'; + _buffer[offset++] = '*'; + i++; + } else { + _buffer[offset++] = response[i++]; + // Find linebreaks, taking care not to be fooled if they're in a %[^\n] conversion specification + if (response[i - 1] == '\n' && !(i >= 3 && response[i - 3] == '[' && response[i - 2] == '^')) { + whole_line_wanted = true; + break; + } + } + } + + // Scanf has very poor support for catching errors + // fortunately, we can abuse the %n specifier to determine + // if the entire string was matched. + _buffer[offset++] = '%'; + _buffer[offset++] = 'n'; + _buffer[offset++] = 0; + + debug_if(_dbg_on, "AT? %s\n", _buffer); + // To workaround scanf's lack of error reporting, we actually + // make two passes. One checks the validity with the modified + // format string that only stores the matched characters (%n). + // The other reads in the actual matched values. + // + // We keep trying the match until we succeed or some other error + // derails us. + int j = 0; + + while (true) { + // Receive next character + int c = getc(); + if (c < 0) { + debug_if(_dbg_on, "AT(Timeout)\n"); + return false; + } + // Simplify newlines (borrowed from retarget.cpp) + if ((c == CR && _in_prev != LF) || + (c == LF && _in_prev != CR)) { + _in_prev = c; + c = '\n'; + } else if ((c == CR && _in_prev == LF) || + (c == LF && _in_prev == CR)) { + _in_prev = c; + // onto next character + continue; + } else { + _in_prev = c; + } + _buffer[offset + j++] = c; + _buffer[offset + j] = 0; + + // Check for oob data + for (struct oob *oob = _oobs; oob; oob = oob->next) { + if ((unsigned)j == oob->len && memcmp( + oob->prefix, _buffer + offset, oob->len) == 0) { + debug_if(_dbg_on, "AT! %s\n", oob->prefix); + oob->cb(); + + if (_aborted) { + debug_if(_dbg_on, "AT(Aborted)\n"); + return false; + } + // oob may have corrupted non-reentrant buffer, + // so we need to set it up again + goto restart; + } + } + + // Check for match + int count = -1; + if (whole_line_wanted && c != '\n') { + // Don't attempt scanning until we get delimiter if they included it in format + // This allows recv("Foo: %s\n") to work, and not match with just the first character of a string + // (scanf does not itself match whitespace in its format string, so \n is not significant to it) + } else { + sscanf(_buffer + offset, _buffer, &count); + } + + // We only succeed if all characters in the response are matched + if (count == j) { + debug_if(_dbg_on, "AT= %s\n", _buffer + offset); + // Reuse the front end of the buffer + memcpy(_buffer, response, i); + _buffer[i] = 0; + + // Store the found results + vsscanf(_buffer + offset, _buffer, args); + + // Jump to next line and continue parsing + response += i; + break; + } + + // Clear the buffer when we hit a newline or ran out of space + // running out of space usually means we ran into binary data + if (c == '\n' || j + 1 >= _buffer_size - offset) { + debug_if(_dbg_on, "AT< %s", _buffer + offset); + j = 0; + } + } + } + + return true; +} + +// Mapping to vararg functions +int ATCmdParser::printf(const char *format, ...) +{ + va_list args; + va_start(args, format); + int res = vprintf(format, args); + va_end(args); + return res; +} + +int ATCmdParser::scanf(const char *format, ...) +{ + va_list args; + va_start(args, format); + int res = vscanf(format, args); + va_end(args); + return res; +} + +bool ATCmdParser::send(const char *command, ...) +{ + va_list args; + va_start(args, command); + bool res = vsend(command, args); + va_end(args); + return res; +} + +bool ATCmdParser::recv(const char *response, ...) +{ + va_list args; + va_start(args, response); + bool res = vrecv(response, args); + va_end(args); + return res; +} + +// oob registration +void ATCmdParser::oob(const char *prefix, Callback cb) +{ + struct oob *oob = new struct oob; + oob->len = strlen(prefix); + oob->prefix = prefix; + oob->cb = cb; + oob->next = _oobs; + _oobs = oob; +} + +void ATCmdParser::abort() +{ + _aborted = true; +} + +bool ATCmdParser::process_oob() +{ + if (!_fh->readable()) { + return false; + } + + int i = 0; + while (true) { + // Receive next character + int c = getc(); + if (c < 0) { + return false; + } + _buffer[i++] = c; + _buffer[i] = 0; + + // Check for oob data + struct oob *oob = _oobs; + while (oob) { + if (i == (int)oob->len && memcmp( + oob->prefix, _buffer, oob->len) == 0) { + debug_if(_dbg_on, "AT! %s\r\n", oob->prefix); + oob->cb(); + return true; + } + oob = oob->next; + } + + // Clear the buffer when we hit a newline or ran out of space + // running out of space usually means we ran into binary data + if (i + 1 >= _buffer_size || + strcmp(&_buffer[i - _output_delim_size], _output_delimiter) == 0) { + + debug_if(_dbg_on, "AT< %s", _buffer); + i = 0; + } + } +} + + diff --git a/UNITTESTS/stubs/ATHandler_stub.cpp b/UNITTESTS/stubs/ATHandler_stub.cpp index cee8e30579..3daf8da115 100644 --- a/UNITTESTS/stubs/ATHandler_stub.cpp +++ b/UNITTESTS/stubs/ATHandler_stub.cpp @@ -31,6 +31,10 @@ const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds nsapi_error_t ATHandler_stub::nsapi_error_value = 0; uint8_t ATHandler_stub::nsapi_error_ok_counter = 0; int ATHandler_stub::int_value = -1; +int ATHandler_stub::ref_count = 0; +int ATHandler_stub::timeout = 0; +bool ATHandler_stub::default_timeout = 0; +bool ATHandler_stub::debug_on = 0; ssize_t ATHandler_stub::ssize_value = 0; char *ATHandler_stub::read_string_value = NULL; size_t ATHandler_stub::size_value = 0; @@ -41,28 +45,45 @@ FileHandle_stub *ATHandler_stub::fh_value = NULL; device_err_t ATHandler_stub::device_err_value; Callback ATHandler_stub::callback = NULL; uint8_t ATHandler_stub::resp_info_true_counter = false; +uint8_t ATHandler_stub::info_elem_true_counter = false; +int ATHandler_stub::int_valid_count_table[kRead_int_table_size]; +int ATHandler_stub::int_count = kRead_int_table_size; -ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) : _nextATHandler(0), +int ATHandler_stub::read_string_index = kRead_string_table_size; +char *ATHandler_stub::read_string_table[kRead_string_table_size]; +int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; + +ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) : + _nextATHandler(0), _fileHandle(fh), _queue(queue) { + ATHandler_stub::ref_count = 1; +} + +void ATHandler::set_debug(bool debug_on) +{ + ATHandler_stub::debug_on = debug_on; } ATHandler::~ATHandler() { + ATHandler_stub::ref_count = -909; } void ATHandler::inc_ref_count() { + ATHandler_stub::ref_count++; } void ATHandler::dec_ref_count() { + ATHandler_stub::ref_count--; } int ATHandler::get_ref_count() { - return ATHandler_stub::int_value; + return ATHandler_stub::ref_count; } FileHandle *ATHandler::get_file_handle() @@ -77,7 +98,7 @@ void ATHandler::set_file_handle(FileHandle *fh) nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback cb) { ATHandler_stub::callback = cb; - return NSAPI_ERROR_OK; + return ATHandler_stub::nsapi_error_value; } void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback callback) @@ -108,6 +129,8 @@ nsapi_error_t ATHandler::unlock_return_error() void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout) { + ATHandler_stub::timeout = timeout_milliseconds; + ATHandler_stub::default_timeout = default_timeout; } void ATHandler::restore_at_timeout() @@ -120,10 +143,12 @@ void ATHandler::process_oob() void ATHandler::clear_error() { + ATHandler_stub::nsapi_error_ok_counter++; } void ATHandler::skip_param(uint32_t count) { + } void ATHandler::skip_param(ssize_t len, uint32_t count) @@ -137,15 +162,44 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len) ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag) { - if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) { - memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value); + + if (ATHandler_stub::read_string_index == kRead_string_table_size) { + if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) { + memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value + 1); + } + return ATHandler_stub::ssize_value; } - return ATHandler_stub::ssize_value; + + ATHandler_stub::read_string_index--; + if (ATHandler_stub::read_string_index >= 0) { + char *tmp = ATHandler_stub::read_string_table[ATHandler_stub::read_string_index]; + ssize_t len = strlen(tmp); + memcpy(buf, tmp, len + 1); + return len; + } + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + return -1; } -int ATHandler::read_int() +int32_t ATHandler::read_int() { - return ATHandler_stub::int_value; + if (ATHandler_stub::nsapi_error_value != NSAPI_ERROR_OK) { + return -1; + } + + if (ATHandler_stub::int_count == kRead_int_table_size) { + return ATHandler_stub::int_value; + } + + //printf("ATHandler_stub::int_count: %d", ATHandler_stub::int_count); + ATHandler_stub::int_count--; + if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) { + return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count]; + } + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + return -1; } void ATHandler::set_delimiter(char delimiter) @@ -180,6 +234,10 @@ bool ATHandler::info_resp() bool ATHandler::info_elem(char start_tag) { + if (ATHandler_stub::info_elem_true_counter) { + ATHandler_stub::info_elem_true_counter--; + return true; + } return ATHandler_stub::bool_value; } @@ -190,13 +248,18 @@ bool ATHandler::consume_to_stop_tag() void ATHandler::resp_stop() { + if (ATHandler_stub::resp_stop_success_count > 0) { + ATHandler_stub::resp_stop_success_count--; + return; + } + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; } void ATHandler::cmd_start(const char *cmd) { } -void ATHandler::write_int(int param) +void ATHandler::write_int(int32_t param) { } @@ -223,4 +286,5 @@ device_err_t ATHandler::get_last_device_error() const void ATHandler::flush() { + } diff --git a/UNITTESTS/stubs/ATHandler_stub.h b/UNITTESTS/stubs/ATHandler_stub.h index 6ea956601a..d259938488 100644 --- a/UNITTESTS/stubs/ATHandler_stub.h +++ b/UNITTESTS/stubs/ATHandler_stub.h @@ -23,21 +23,37 @@ #include "FileHandle_stub.h" #include "Callback.h" -namespace ATHandler_stub -{ +#ifndef __AT_HANDLER_STUB_H__ +#define __AT_HANDLER_STUB_H__ +static const int kRead_string_table_size = 100; +static const int kRead_int_table_size = 100; +static const int kResp_stop_count_default = 100; + +namespace ATHandler_stub { extern nsapi_error_t nsapi_error_value; extern uint8_t nsapi_error_ok_counter; extern int int_value; +extern int ref_count; +extern int timeout; +extern bool default_timeout; +extern bool debug_on; extern ssize_t ssize_value; extern char *read_string_value; extern size_t size_value; extern size_t return_given_size; extern bool bool_value; extern uint8_t resp_info_true_counter; +extern uint8_t info_elem_true_counter; extern uint8_t uint8_value; extern mbed::FileHandle_stub *fh_value; extern mbed::device_err_t device_err_value; extern mbed::Callback callback; +extern char *read_string_table[kRead_string_table_size]; +extern int read_string_index; +extern int int_valid_count_table[kRead_int_table_size]; +extern int int_count; +extern int resp_stop_success_count; +} -} // namespace ATHandler_stub +#endif diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.cpp b/UNITTESTS/stubs/AT_CellularBase_stub.cpp new file mode 100644 index 0000000000..e1f8526f5f --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularBase_stub.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 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 "nsapi_types.h" +#include "AT_CellularBase.h" +#include "AT_CellularBase_stub.h" + + +using namespace mbed; + +ATHandler *AT_CellularBase_stub::handler_value = NULL; +ATHandler *AT_CellularBase_stub::handler_at_constructor_value = NULL; +device_err_t AT_CellularBase_stub::device_err_value; +bool AT_CellularBase_stub::supported_bool = true; + +AT_CellularBase::AT_CellularBase(ATHandler &at) : _at(at) +{ + AT_CellularBase_stub::handler_at_constructor_value = &_at; +} + +ATHandler &AT_CellularBase::get_at_handler() +{ + return *AT_CellularBase_stub::handler_value; +} + +device_err_t AT_CellularBase::get_device_error() const +{ + return AT_CellularBase_stub::device_err_value; +} + +bool AT_CellularBase::is_supported(SupportedFeature feature) +{ + return AT_CellularBase_stub::supported_bool; +} diff --git a/UNITTESTS/stubs/AT_CellularBase_stub.h b/UNITTESTS/stubs/AT_CellularBase_stub.h new file mode 100644 index 0000000000..f7d117d192 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularBase_stub.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2017, 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 "ATHandler.h" + +namespace AT_CellularBase_stub { +extern mbed::ATHandler *handler_value; +extern mbed::ATHandler *handler_at_constructor_value; +extern mbed::device_err_t device_err_value; +extern bool supported_bool; +} diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp new file mode 100644 index 0000000000..2010018ced --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017, 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 "AT_CellularDevice.h" + +AT_CellularDevice::AT_CellularDevice(EventQueue &queue) : + _atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _multiplexer(0), _information(0), _queue(queue) +{ +} + +AT_CellularDevice::~AT_CellularDevice() +{ +} + +ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) +{ + return NULL; +} + +void AT_CellularDevice::release_at_handler(ATHandler *at_handler) +{ + +} + +CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) +{ + return NULL; +} + +CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) +{ + return NULL; +} + +CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) +{ + return NULL; +} + +CellularPower *AT_CellularDevice::open_power(FileHandle *fh) +{ + return NULL; +} + +CellularMultiplexer *AT_CellularDevice::open_multiplexer(FileHandle *fh) +{ + return NULL; +} + +CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) +{ + return NULL; +} + +void AT_CellularDevice::close_network() +{ +} + +void AT_CellularDevice::close_sms() +{ +} + +void AT_CellularDevice::close_power() +{ +} + +void AT_CellularDevice::close_sim() +{ +} + +void AT_CellularDevice::close_multiplexer() +{ +} + +void AT_CellularDevice::close_information() +{ +} diff --git a/UNITTESTS/stubs/AT_CellularInformation_stub.cpp b/UNITTESTS/stubs/AT_CellularInformation_stub.cpp new file mode 100644 index 0000000000..a41b3080d5 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularInformation_stub.cpp @@ -0,0 +1,49 @@ +/* + * 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 "AT_CellularInformation.h" +#include "nsapi_types.h" + +using namespace mbed; + +AT_CellularInformation::AT_CellularInformation(ATHandler &at) : AT_CellularBase(at) +{ +} + +AT_CellularInformation::~AT_CellularInformation() +{ +} + +nsapi_error_t AT_CellularInformation::get_manufacturer(char *buf, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularInformation::get_model(char *buf, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp b/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp new file mode 100644 index 0000000000..c397d5fb38 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, 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 "AT_CellularMultiplexer.h" +#include "CellularLog.h" +#include "nsapi_types.h" + +using namespace mbed; + +AT_CellularMultiplexer::AT_CellularMultiplexer(ATHandler &at) : AT_CellularBase(at) +{ +} + +AT_CellularMultiplexer::~AT_CellularMultiplexer() +{ +} + +nsapi_error_t AT_CellularMultiplexer::multiplexer_mode_start() +{ + return 0; +} diff --git a/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp new file mode 100644 index 0000000000..c4ba878439 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2017, 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 "AT_CellularNetwork.h" +#include "CellularNetwork.h" +#include "CellularUtil.h" +#include "CellularLog.h" +#include "FileHandle.h" +#include "nsapi_types.h" + +using namespace mbed; +using namespace mbed_cellular_util; + +AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler) +{ +} + +AT_CellularNetwork::~AT_CellularNetwork() +{ +} + +nsapi_error_t AT_CellularNetwork::init() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn, + const char *username, const char *password) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn, + AuthenticationType type, const char *username, const char *password) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::connect(const char *apn, + const char *username, const char *password) +{ + return connect(); +} + +nsapi_error_t AT_CellularNetwork::connect() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::activate_context() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::open_data_channel() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::disconnect() +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularNetwork::attach(Callback status_cb) +{ +} + +nsapi_connection_status_t AT_CellularNetwork::get_connection_status() const +{ + return NSAPI_STATUS_LOCAL_UP; +} + +nsapi_error_t AT_CellularNetwork::set_blocking(bool blocking) +{ + return NSAPI_ERROR_OK;; +} + +nsapi_ip_stack_t AT_CellularNetwork::string_to_stack_type(const char *pdp_type) +{ + return IPV4_STACK; +} + +nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bool urc_on) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_network_registering_mode(NWRegisteringMode &mode) +{ + mode = NWModeAutomatic; + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type, RegistrationStatus &status) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_cell_id(int &cell_id) +{ + return NSAPI_ERROR_OK; +} + +AT_CellularNetwork::RegistrationMode AT_CellularNetwork::has_registration(RegistrationType reg_type) +{ + return RegistrationModeDisable; +} + +nsapi_error_t AT_CellularNetwork::set_attach(int timeout) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::detach() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoffTime) +{ + return NSAPI_ERROR_OK; +} + +NetworkStack *AT_CellularNetwork::get_stack() +{ + return NULL; +} + +const char *AT_CellularNetwork::get_ip_address() +{ + return NULL; +} + +nsapi_error_t AT_CellularNetwork::set_stack_type(nsapi_ip_stack_t stack_type) +{ + return NSAPI_ERROR_OK; +} + +nsapi_ip_stack_t AT_CellularNetwork::get_stack_type() +{ + return IPV4_STACK; +} + +bool AT_CellularNetwork::get_modem_stack_type(nsapi_ip_stack_t requested_stack) +{ + return false; +} + +void AT_CellularNetwork::urc_no_carrier() +{ + +} + +nsapi_error_t AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::set_access_technology(RadioAccessTechnology opAct) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_access_technology(RadioAccessTechnology &rat) +{ + rat = RAT_CATM1; + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt supported_opt, + Preferred_UE_Opt preferred_opt) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt &supported_opt, + Preferred_UE_Opt &preferred_opt) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_rate_control( + CellularNetwork::RateControlExceptionReports &reports, + CellularNetwork::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate) +{ + return NSAPI_ERROR_OK; +} + + +nsapi_error_t AT_CellularNetwork::get_pdpcontext_params(pdpContextList_t ¶ms_list) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::get_operator_params(int &format, operator_t &operator_params) +{ + return NSAPI_ERROR_OK; +} + +int AT_CellularNetwork::get_3gpp_error() +{ + return 0; +} + +nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_names) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularNetwork::do_user_authentication() +{ + return NSAPI_ERROR_OK; +} + + + diff --git a/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/UNITTESTS/stubs/AT_CellularPower_stub.cpp new file mode 100644 index 0000000000..3459088ce5 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularPower_stub.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017, 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 "AT_CellularPower.h" +#include "CellularUtil.h" +#include "CellularLog.h" + +using namespace mbed_cellular_util; +using namespace mbed; + +AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at) +{ +} + +AT_CellularPower::~AT_CellularPower() +{ +} + +nsapi_error_t AT_CellularPower::on() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::off() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::set_at_mode() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::reset() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int active_time) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback callback) +{ + +} + +nsapi_error_t AT_CellularPower::is_device_ready() +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularSIM_stub.cpp b/UNITTESTS/stubs/AT_CellularSIM_stub.cpp new file mode 100644 index 0000000000..fc4be35b94 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularSIM_stub.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, 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 "AT_CellularSIM.h" +#include "CellularLog.h" + +using namespace mbed; + +AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at) +{ +} + +AT_CellularSIM::~AT_CellularSIM() +{ +} + +nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSIM::get_imsi(char *imsi) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularSMS_stub.cpp b/UNITTESTS/stubs/AT_CellularSMS_stub.cpp new file mode 100644 index 0000000000..66456d7295 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularSMS_stub.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2017, 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 +#include "AT_CellularSMS.h" +#include "CellularLog.h" + +using namespace mbed; + +#define CTRL_Z "\x1a" +#define ESC "\x1b" + +const int SMS_STATUS_SIZE = 12 + 1; +const int FIRST_OCTET_DELIVER_SUBMIT = 17; +const int TP_VALIDITY_PERIOD_24_HOURS = 167; +const int TP_PROTOCOL_IDENTIFIER = 0; +const int SMS_DATA_CODING_SCHEME = 0; + +const uint16_t SMS_MAX_8BIT_CONCATENATED_SINGLE_SMS_SIZE = 134; +const uint16_t SMS_MAX_GSM7_CONCATENATED_SINGLE_SMS_SIZE = 153; + + +AT_CellularSMS::AT_CellularSMS(ATHandler &at) : AT_CellularBase(at), _cb(0), _mode(CellularSMSMmodeText), + _use_8bit_encoding(false), _sim_wait_time(0), _sms_message_ref_number(1), _sms_info(NULL) +{ +} + +AT_CellularSMS::~AT_CellularSMS() +{ +} + +void AT_CellularSMS::cmt_urc() +{ +} + +void AT_CellularSMS::cmti_urc() +{ +} + +nsapi_error_t AT_CellularSMS::set_cnmi() +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSMS::set_csdh(int show_header) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode) +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularSMS::set_extra_sim_wait_time(int sim_wait_time) +{ +} + +char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message, uint8_t message_length, uint8_t msg_parts, + uint8_t msg_part_number, uint8_t &header_size) +{ + return NULL; +} + +nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const char *message, int msg_len) +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularSMS::set_sms_callback(Callback func) +{ +} + +nsapi_error_t AT_CellularSMS::set_cpms(const char *memr, const char *memw, const char *mems) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSMS::set_csca(const char *sca, int type) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularSMS::set_cscs(const char *chr_set) +{ + return NSAPI_ERROR_OK; +} + +//nsapi_error_t AT_CellularSMS::set_csms(int msg_service) +//{ +// return NSAPI_ERROR_OK; +//} + +nsapi_error_t AT_CellularSMS::delete_sms(sms_info_t *sms) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularSMS::delete_all_messages() +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char *buf, uint16_t len, char *phone_num, char *time_stamp) +{ + return NSAPI_ERROR_OK; +} + +// read msg in PDU mode +nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char *phone_num, char *time_stamp) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *phone_num, uint16_t phone_len, + char *time_stamp, uint16_t time_len, int *buf_size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularSMS::get_data_from_pdu(const char *pdu, sms_info_t *info, int *part_number, char *phone_number, char *msg) +{ + return NSAPI_ERROR_OK; +} + +// read params from User DEfined Header +int AT_CellularSMS::read_udh_from_pdu(const char *pdu, sms_info_t *info, int &part_number, int &padding_bits) +{ + return 0; +} + +nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload(const char *pdu, int msg_len, int scheme, char *msg, int padding_bits) +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularSMS::free_linked_list() +{ +} + +void AT_CellularSMS::add_info(sms_info_t *info, int index, int part_number) +{ +} + +// reads all the messages to the linked list AT_CellularSMS::_sms_info +nsapi_error_t AT_CellularSMS::list_messages() +{ + return NSAPI_ERROR_OK; +} + +AT_CellularSMS::sms_info_t *AT_CellularSMS::get_oldest_sms_index() +{ + return NULL; +} + +// if time_string_1 is greater (more fresh date) then return 1, same 0, smaller -1. Error -2 +int AT_CellularSMS::compare_time_strings(const char *time_string_1, const char *time_string_2) +{ + return 0; +} + +bool AT_CellularSMS::create_time(const char *time_string, time_t *time) +{ + return 0; +} + diff --git a/UNITTESTS/stubs/AT_CellularStack_stub.cpp b/UNITTESTS/stubs/AT_CellularStack_stub.cpp new file mode 100644 index 0000000000..640d8c1b68 --- /dev/null +++ b/UNITTESTS/stubs/AT_CellularStack_stub.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2017, 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 "AT_CellularStack.h" +#include "CellularUtil.h" +#include "CellularLog.h" + +using namespace mbed_cellular_util; + +AT_CellularStack::AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : _at(atHandler), _socket(NULL), _cid(cid), _stack_type(stack_type) +{ +} + +AT_CellularStack::~AT_CellularStack() +{ +} + +const char *AT_CellularStack::get_ip_address() +{ + return NULL; +} + +nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularStack::socket_close(nsapi_socket_t handle) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularStack::socket_bind(nsapi_socket_t handle, const SocketAddress &addr) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularStack::socket_listen(nsapi_socket_t handle, int backlog) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularStack::socket_send(nsapi_socket_t handle, const void *data, unsigned size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &addr, const void *data, unsigned size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularStack::socket_recv(nsapi_socket_t handle, void *data, unsigned size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t AT_CellularStack::socket_recvfrom(nsapi_socket_t handle, SocketAddress *addr, void *buffer, unsigned size) +{ + return NSAPI_ERROR_OK; +} + +void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) +{ +} + diff --git a/UNITTESTS/stubs/BufferedBlockDevice_stub.cpp b/UNITTESTS/stubs/BufferedBlockDevice_stub.cpp new file mode 100644 index 0000000000..9c9fabea1f --- /dev/null +++ b/UNITTESTS/stubs/BufferedBlockDevice_stub.cpp @@ -0,0 +1,104 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * 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 "BufferedBlockDevice.h" +#include "mbed_assert.h" +#include "mbed_critical.h" +#include +#include + +static inline uint32_t align_down(bd_size_t val, bd_size_t size) +{ + return 0; +} + +BufferedBlockDevice::BufferedBlockDevice(BlockDevice *bd) +{ +} + +BufferedBlockDevice::~BufferedBlockDevice() +{ +} + +int BufferedBlockDevice::init() +{ + return 0; +} + +int BufferedBlockDevice::deinit() +{ + return 0; +} + +int BufferedBlockDevice::flush() +{ + return 0; +} + +int BufferedBlockDevice::sync() +{ + return 0; +} + +int BufferedBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int BufferedBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int BufferedBlockDevice::trim(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t BufferedBlockDevice::get_read_size() const +{ + return 1; +} + +bd_size_t BufferedBlockDevice::get_program_size() const +{ + return 1; +} + +bd_size_t BufferedBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t BufferedBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int BufferedBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t BufferedBlockDevice::size() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/CellularUtil_stub.cpp b/UNITTESTS/stubs/CellularUtil_stub.cpp new file mode 100644 index 0000000000..d4bcaf4916 --- /dev/null +++ b/UNITTESTS/stubs/CellularUtil_stub.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) , 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 "CellularUtil.h" +#include +#include +#include + +namespace mbed_cellular_util { + +#define MAX_STRING_LEN 200 + +void str_copy_skip_char(char *dest, uint16_t dest_size, const char *src, char c) +{ +} + +void str_remove_char(char *src, char c) +{ +} + +void uint_to_binary_str(uint32_t num, char *str, uint8_t str_size, uint8_t bit_cnt) +{ +} + +// converts the given str to hex string to buf +uint16_t char_str_to_hex(const char *str, uint16_t len, char *buf, bool omit_leading_zero) +{ + return 0; +} + +void convert_ipv6(char *ip) +{ + +} + +char *find_dot_number(char *str, int dot_number) +{ + return NULL; +} + +void separate_ip4like_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size) +{ +} + +void separate_ip_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size) +{ +} + +void prefer_ipv6(char *ip, size_t ip_size, char *ip2, size_t ip2_size) +{ +} + +void int_to_hex_str(uint8_t num, char *buf) +{ + buf[0] = '0'; + buf[1] = '2'; +} + +int hex_str_to_int(const char *hex_string, int hex_string_length) +{ + return 0; +} + +int hex_str_to_char_str(const char *str, uint16_t len, char *buf) +{ + return 0; +} + +void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt) +{ + +} + +int char_str_to_hex_str(const char *str, uint16_t len, char *buf, bool omit_leading_zero) +{ + //The code is dependent on this, so this is easiest just to put here + if (!str || !buf) { + return 0; + } + + char *ptr = buf; + int i = 0; + while (i < len) { + if (omit_leading_zero == true && i == 0 && !(str[i] >> 4 & 0x0F)) { + *ptr++ = hex_values[(str[i]) & 0x0F]; + } else { + *ptr++ = hex_values[((str[i]) >> 4) & 0x0F]; + *ptr++ = hex_values[(str[i]) & 0x0F]; + } + i++; + } + return ptr - buf; +} + +uint16_t get_dynamic_ip_port() +{ + return 0; +} + +} // namespace mbed_cellular_util diff --git a/UNITTESTS/stubs/ChainingBlockDevice_stub.cpp b/UNITTESTS/stubs/ChainingBlockDevice_stub.cpp new file mode 100644 index 0000000000..51134b3553 --- /dev/null +++ b/UNITTESTS/stubs/ChainingBlockDevice_stub.cpp @@ -0,0 +1,88 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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 "ChainingBlockDevice.h" +#include "mbed_critical.h" + + +ChainingBlockDevice::ChainingBlockDevice(BlockDevice **bds, size_t bd_count) +{ +} + +static bool is_aligned(uint64_t x, uint64_t alignment) +{ + return true; +} + +int ChainingBlockDevice::init() +{ + return 0; +} + +int ChainingBlockDevice::deinit() +{ + return 0; +} + +int ChainingBlockDevice::sync() +{ + return 0; +} + +int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ChainingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ChainingBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t ChainingBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t ChainingBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t ChainingBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t ChainingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int ChainingBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t ChainingBlockDevice::size() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/EventFlags_stub.cpp b/UNITTESTS/stubs/EventFlags_stub.cpp index 95762b8b83..5e5b0736e5 100644 --- a/UNITTESTS/stubs/EventFlags_stub.cpp +++ b/UNITTESTS/stubs/EventFlags_stub.cpp @@ -15,6 +15,7 @@ * limitations under the License. */ +#include #include "rtos/EventFlags.h" rtos::EventFlags::EventFlags() {} diff --git a/UNITTESTS/stubs/ExhaustibleBlockDevice_stub.cpp b/UNITTESTS/stubs/ExhaustibleBlockDevice_stub.cpp new file mode 100644 index 0000000000..36cdb1cfac --- /dev/null +++ b/UNITTESTS/stubs/ExhaustibleBlockDevice_stub.cpp @@ -0,0 +1,88 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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 "ExhaustibleBlockDevice.h" +#include "mbed.h" +#include "mbed_critical.h" + + +ExhaustibleBlockDevice::ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles) +{ +} + +ExhaustibleBlockDevice::~ExhaustibleBlockDevice() +{ +} + +int ExhaustibleBlockDevice::init() +{ + return 0; +} + +int ExhaustibleBlockDevice::deinit() +{ + return 0; +} + +int ExhaustibleBlockDevice::sync() +{ + return 0; +} + +int ExhaustibleBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t ExhaustibleBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t ExhaustibleBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t ExhaustibleBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t ExhaustibleBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int ExhaustibleBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t ExhaustibleBlockDevice::size() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp b/UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp new file mode 100644 index 0000000000..bbc9db57ce --- /dev/null +++ b/UNITTESTS/stubs/FlashSimBlockDevice_stub.cpp @@ -0,0 +1,97 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * 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 "FlashSimBlockDevice.h" +#include "mbed_assert.h" +#include "mbed_critical.h" +#include +#include +#include + +static const bd_size_t min_blank_buf_size = 32; + +static inline uint32_t align_up(bd_size_t val, bd_size_t size) +{ + return (((val - 1) / size) + 1) * size; +} + +FlashSimBlockDevice::FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value) +{ +} + +FlashSimBlockDevice::~FlashSimBlockDevice() +{ +} + +int FlashSimBlockDevice::init() +{ + return 0; +} + +int FlashSimBlockDevice::deinit() +{ + return 0; +} + +int FlashSimBlockDevice::sync() +{ + return 0; +} + +bd_size_t FlashSimBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t FlashSimBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t FlashSimBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t FlashSimBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +bd_size_t FlashSimBlockDevice::size() const +{ + return 0; +} + +int FlashSimBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int FlashSimBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int FlashSimBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int FlashSimBlockDevice::get_erase_value() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/HeapBlockDevice_stub.cpp b/UNITTESTS/stubs/HeapBlockDevice_stub.cpp new file mode 100644 index 0000000000..afa6e9bbbc --- /dev/null +++ b/UNITTESTS/stubs/HeapBlockDevice_stub.cpp @@ -0,0 +1,82 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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 "HeapBlockDevice.h" +#include "mbed_critical.h" + + +HeapBlockDevice::HeapBlockDevice(bd_size_t size, bd_size_t block) +{ +} + +HeapBlockDevice::HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase) +{ +} + +HeapBlockDevice::~HeapBlockDevice() +{ +} + +int HeapBlockDevice::init() +{ + return 0; +} + +int HeapBlockDevice::deinit() +{ + return 0; +} + +bd_size_t HeapBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t HeapBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t HeapBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t HeapBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +bd_size_t HeapBlockDevice::size() const +{ + return 0; +} + +int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + diff --git a/UNITTESTS/stubs/Kernel_stub.cpp b/UNITTESTS/stubs/Kernel_stub.cpp new file mode 100644 index 0000000000..ecfa1d80af --- /dev/null +++ b/UNITTESTS/stubs/Kernel_stub.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) , 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 "Kernel.h" + +namespace rtos { + +uint64_t Kernel::get_ms_count() +{ + return 20; +} +} diff --git a/UNITTESTS/stubs/MBRBlockDevice_stub.cpp b/UNITTESTS/stubs/MBRBlockDevice_stub.cpp new file mode 100644 index 0000000000..1e12f59cee --- /dev/null +++ b/UNITTESTS/stubs/MBRBlockDevice_stub.cpp @@ -0,0 +1,156 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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 "MBRBlockDevice.h" +#include "mbed_critical.h" +#include + + +// On disk structures, all entries are little endian +MBED_PACKED(struct) mbr_entry { + uint8_t status; + uint8_t chs_start[3]; + uint8_t type; + uint8_t chs_stop[3]; + uint32_t lba_offset; + uint32_t lba_size; +}; + +MBED_PACKED(struct) mbr_table { + struct mbr_entry entries[4]; + uint8_t signature[2]; +}; + +// Little-endian conversion, should compile to noop +// if system is little-endian +static inline uint32_t tole32(uint32_t a) +{ + return 0; +} + +static inline uint32_t fromle32(uint32_t a) +{ + return 0; +} + +static void tochs(uint32_t lba, uint8_t chs[3]) +{ +} + + +// Partition after address are turned into absolute +// addresses, assumes bd is initialized +static int partition_absolute( + BlockDevice *bd, int part, uint8_t type, + bd_size_t offset, bd_size_t size) +{ + return 0; +} + +int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type, bd_addr_t start) +{ + return 0; +} + +int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type, + bd_addr_t start, bd_addr_t stop) +{ + return 0; +} + +MBRBlockDevice::MBRBlockDevice(BlockDevice *bd, int part) +{ +} + +int MBRBlockDevice::init() +{ + return 0; +} + +int MBRBlockDevice::deinit() +{ + return 0; +} + +int MBRBlockDevice::sync() +{ + return 0; +} + +int MBRBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int MBRBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int MBRBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t MBRBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t MBRBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t MBRBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t MBRBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int MBRBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t MBRBlockDevice::size() const +{ + return 0; +} + +bd_size_t MBRBlockDevice::get_partition_start() const +{ + return 0; +} + +bd_size_t MBRBlockDevice::get_partition_stop() const +{ + return 0; +} + +uint8_t MBRBlockDevice::get_partition_type() const +{ + return 0; +} + +int MBRBlockDevice::get_partition_number() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/NetworkInterface_stub.cpp b/UNITTESTS/stubs/NetworkInterface_stub.cpp new file mode 100644 index 0000000000..0e8eaa15a9 --- /dev/null +++ b/UNITTESTS/stubs/NetworkInterface_stub.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2015, 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 "netsocket/NetworkInterface.h" +#include "netsocket/NetworkStack.h" +#include + + +// Default network-interface state +const char *NetworkInterface::get_mac_address() +{ + return 0; +} + +const char *NetworkInterface::get_ip_address() +{ + return 0; +} + +const char *NetworkInterface::get_netmask() +{ + return 0; +} + +const char *NetworkInterface::get_gateway() +{ + return 0; +} + +nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::set_dhcp(bool dhcp) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +// DNS operations go through the underlying stack by default +nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +void NetworkInterface::attach(mbed::Callback status_cb) +{ + +} + +nsapi_connection_status_t NetworkInterface::get_connection_status() const +{ + return NSAPI_STATUS_LOCAL_UP; +} + +nsapi_error_t NetworkInterface::set_blocking(bool blocking) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_value_or_error_t NetworkInterface::gethostbyname_async(char const *, mbed::Callback, nsapi_version) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + diff --git a/UNITTESTS/stubs/NetworkStack_stub.cpp b/UNITTESTS/stubs/NetworkStack_stub.cpp new file mode 100644 index 0000000000..372812effb --- /dev/null +++ b/UNITTESTS/stubs/NetworkStack_stub.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2015, 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 "NetworkStack.h" +#include "nsapi_dns.h" +#include "mbed.h" +#include "stddef.h" +#include + +// Default NetworkStack operations +nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t NetworkStack::get_dns_server(int index, SocketAddress *address) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +// Conversion function for network stacks +NetworkStack *nsapi_create_stack(nsapi_stack_t *stack) +{ + return NULL; +} + +NetworkStack *nsapi_create_stack(NetworkStack *stack) +{ + return NULL; +} + +nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *host, hostbyname_cb_t callback, + nsapi_version_t version) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +call_in_callback_cb_t NetworkStack::get_call_in_callback() +{ + return NULL; +} + +nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback func) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +const char *NetworkStack::get_ip_address() +{ + return NULL; +} diff --git a/UNITTESTS/stubs/ObservingBlockDevice_stub.cpp b/UNITTESTS/stubs/ObservingBlockDevice_stub.cpp new file mode 100644 index 0000000000..ffd9450a83 --- /dev/null +++ b/UNITTESTS/stubs/ObservingBlockDevice_stub.cpp @@ -0,0 +1,100 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017-2017 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "ObservingBlockDevice.h" +#include "ReadOnlyBlockDevice.h" +#include "mbed.h" + + +ObservingBlockDevice::ObservingBlockDevice(BlockDevice *bd) +{ + // Does nothing +} + +ObservingBlockDevice::~ObservingBlockDevice() +{ + // Does nothing +} + +void ObservingBlockDevice::attach(Callback cb) +{ +} + +int ObservingBlockDevice::init() +{ + return 0; +} + +int ObservingBlockDevice::deinit() +{ + return 0; +} + +int ObservingBlockDevice::sync() +{ + return 0; +} + +int ObservingBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ObservingBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ObservingBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t ObservingBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t ObservingBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t ObservingBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t ObservingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int ObservingBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t ObservingBlockDevice::size() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp b/UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp new file mode 100644 index 0000000000..df41cb1da5 --- /dev/null +++ b/UNITTESTS/stubs/ProfilingBlockDevice_stub.cpp @@ -0,0 +1,101 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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 "ProfilingBlockDevice.h" + + +ProfilingBlockDevice::ProfilingBlockDevice(BlockDevice *bd) +{ +} + +int ProfilingBlockDevice::init() +{ + return 0; +} + +int ProfilingBlockDevice::deinit() +{ + return 0; +} + +int ProfilingBlockDevice::sync() +{ + return 0; +} + +int ProfilingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ProfilingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ProfilingBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int ProfilingBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::size() const +{ + return 0; +} + +void ProfilingBlockDevice::reset() +{ +} + +bd_size_t ProfilingBlockDevice::get_read_count() const +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::get_program_count() const +{ + return 0; +} + +bd_size_t ProfilingBlockDevice::get_erase_count() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp b/UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp new file mode 100644 index 0000000000..13e20d934e --- /dev/null +++ b/UNITTESTS/stubs/ReadOnlyBlockDevice_stub.cpp @@ -0,0 +1,95 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017-2017 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "ReadOnlyBlockDevice.h" +#include "mbed_error.h" + + +ReadOnlyBlockDevice::ReadOnlyBlockDevice(BlockDevice *bd) +{ + // Does nothing +} + +ReadOnlyBlockDevice::~ReadOnlyBlockDevice() +{ + // Does nothing +} + +int ReadOnlyBlockDevice::init() +{ + return 0; +} + +int ReadOnlyBlockDevice::deinit() +{ + return 0; +} + +int ReadOnlyBlockDevice::sync() +{ + return 0; +} + +int ReadOnlyBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ReadOnlyBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int ReadOnlyBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t ReadOnlyBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t ReadOnlyBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t ReadOnlyBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t ReadOnlyBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int ReadOnlyBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t ReadOnlyBlockDevice::size() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/Semaphore_stub.cpp b/UNITTESTS/stubs/Semaphore_stub.cpp new file mode 100644 index 0000000000..ada09df114 --- /dev/null +++ b/UNITTESTS/stubs/Semaphore_stub.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) , 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 "Semaphore.h" + +namespace rtos { + +Semaphore::Semaphore(int32_t count) +{ + +} + +Semaphore::Semaphore(int32_t count, uint16_t max_count) +{ + +} + +void Semaphore::constructor(int32_t count, uint16_t max_count) +{ + +} + +int32_t Semaphore::wait(uint32_t millisec) +{ + return 0; +} + +int32_t Semaphore::wait_until(uint64_t millisec) +{ + return 0; +} + +osStatus Semaphore::release(void) +{ + return 0; +} + +Semaphore::~Semaphore() +{ + +} + +} diff --git a/UNITTESTS/stubs/SlicingBlockDevice_stub.cpp b/UNITTESTS/stubs/SlicingBlockDevice_stub.cpp new file mode 100644 index 0000000000..6b4fbabdcf --- /dev/null +++ b/UNITTESTS/stubs/SlicingBlockDevice_stub.cpp @@ -0,0 +1,83 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * + * 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 "SlicingBlockDevice.h" + + +SlicingBlockDevice::SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr_t stop) +{ + +} + +int SlicingBlockDevice::init() +{ + return 0; +} + +int SlicingBlockDevice::deinit() +{ + return 0; +} + +int SlicingBlockDevice::sync() +{ + return 0; +} + +int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int SlicingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +int SlicingBlockDevice::erase(bd_addr_t addr, bd_size_t size) +{ + return 0; +} + +bd_size_t SlicingBlockDevice::get_read_size() const +{ + return 0; +} + +bd_size_t SlicingBlockDevice::get_program_size() const +{ + return 0; +} + +bd_size_t SlicingBlockDevice::get_erase_size() const +{ + return 0; +} + +bd_size_t SlicingBlockDevice::get_erase_size(bd_addr_t addr) const +{ + return 0; +} + +int SlicingBlockDevice::get_erase_value() const +{ + return 0; +} + +bd_size_t SlicingBlockDevice::size() const +{ + return 0; +} diff --git a/UNITTESTS/stubs/SocketAddress_stub.cpp b/UNITTESTS/stubs/SocketAddress_stub.cpp new file mode 100644 index 0000000000..76e02aa12b --- /dev/null +++ b/UNITTESTS/stubs/SocketAddress_stub.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015, 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 "SocketAddress.h" +#include "NetworkInterface.h" +#include "NetworkStack.h" +#include +#include "mbed.h" + + +static bool ipv4_is_valid(const char *addr) +{ + return false; +} + +static bool ipv6_is_valid(const char *addr) +{ + return false; +} + +static void ipv4_from_address(uint8_t *bytes, const char *addr) +{ + +} + +static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk) +{ + return 0; +} + +static void ipv6_from_address(uint8_t *bytes, const char *addr) +{ + +} + +static void ipv4_to_address(char *addr, const uint8_t *bytes) +{ + +} + +static void ipv6_to_address(char *addr, const uint8_t *bytes) +{ +} + + +SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port) +{ +} + +SocketAddress::SocketAddress(const char *addr, uint16_t port) +{ +} + +SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port) +{ +} + +SocketAddress::SocketAddress(const SocketAddress &addr) +{ +} + +SocketAddress::~SocketAddress() +{ +} + +bool SocketAddress::set_ip_address(const char *addr) +{ + return false; +} + +void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version) +{ +} + +void SocketAddress::set_addr(nsapi_addr_t addr) +{ +} + +void SocketAddress::set_port(uint16_t port) +{ +} + +const char *SocketAddress::get_ip_address() const +{ + return NULL; +} + +const void *SocketAddress::get_ip_bytes() const +{ + return NULL; +} + +nsapi_version_t SocketAddress::get_ip_version() const +{ + nsapi_version_t ver = NSAPI_IPv6; + return ver; +} + +nsapi_addr_t SocketAddress::get_addr() const +{ + nsapi_addr_t addr; + addr.version = NSAPI_IPv6; + return _addr; +} + +uint16_t SocketAddress::get_port() const +{ + return 0; +} + +SocketAddress::operator bool() const +{ + return false; +} + +SocketAddress &SocketAddress::operator=(const SocketAddress &addr) +{ + set_addr(addr.get_addr()); + set_port(addr.get_port()); + return *this; +} + +bool operator==(const SocketAddress &a, const SocketAddress &b) +{ + return false; +} + +bool operator!=(const SocketAddress &a, const SocketAddress &b) +{ + return false; +} diff --git a/UNITTESTS/stubs/Thread_stub.cpp b/UNITTESTS/stubs/Thread_stub.cpp new file mode 100644 index 0000000000..8eed1e7f2a --- /dev/null +++ b/UNITTESTS/stubs/Thread_stub.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) , 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 "Thread.h" + +namespace rtos { + +osStatus Thread::wait_until(uint64_t millisec) +{ + return 0; +} + +} diff --git a/UNITTESTS/stubs/Timer_stub.cpp b/UNITTESTS/stubs/Timer_stub.cpp new file mode 100644 index 0000000000..2e20c161ae --- /dev/null +++ b/UNITTESTS/stubs/Timer_stub.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) , 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 "Timer.h" +#include "Timer_stub.h" + +namespace mbed { + +Timer::Timer() +{ +} + +Timer::Timer(const ticker_data_t *data) +{ +} + +Timer::~Timer() +{ +} + +void Timer::start() +{ +} + +void Timer::stop() +{ + ; +} + +int Timer::read_us() +{ + return 0; +} + +float Timer::read() +{ + return 0; +} + +int Timer::read_ms() +{ + timer_stub_value += timer_stub_step; + return timer_stub_value; +} + +us_timestamp_t Timer::read_high_resolution_us() +{ + return 0; +} + +void Timer::reset() +{ +} + +Timer::operator float() +{ + return 0; +} + +} // namespace mbed diff --git a/UNITTESTS/stubs/Timer_stub.h b/UNITTESTS/stubs/Timer_stub.h new file mode 100644 index 0000000000..699fdd0c53 --- /dev/null +++ b/UNITTESTS/stubs/Timer_stub.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) , 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. + */ +#ifndef TIMER_STUB_H +#define TIMER_STUB_H + + +static uint16_t timer_stub_value = 0; +static uint16_t timer_stub_step = 20; + +#endif diff --git a/UNITTESTS/stubs/equeue_stub.c b/UNITTESTS/stubs/equeue_stub.c index bd9852bec2..55a52174e7 100644 --- a/UNITTESTS/stubs/equeue_stub.c +++ b/UNITTESTS/stubs/equeue_stub.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Arm Limited and affiliates. + * Copyright (c) , Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,25 +15,90 @@ * limitations under the License. */ -#include "equeue/equeue.h" +#include "equeue.h" -void *equeue_alloc(equeue_t *q, size_t size) -{ -} - -int equeue_post(equeue_t *q, void (*cb)(void *), void *p) +int equeue_create(equeue_t *queue, size_t size) { return 0; } -void equeue_event_delay(void *p, int ms) +int equeue_create_inplace(equeue_t *queue, size_t size, void *buffer) { + return 0; } -void equeue_event_period(void *p, int ms) +void equeue_destroy(equeue_t *queue) { + } -void equeue_event_dtor(void *p, void (*dtor)(void *)) +void equeue_dispatch(equeue_t *queue, int ms) { + +} + +void equeue_break(equeue_t *queue) +{ + +} + +int equeue_call(equeue_t *queue, void (*cb)(void *), void *data) +{ + return 0; +} + +int equeue_call_in(equeue_t *queue, int ms, void (*cb)(void *), void *data) +{ + return 0; +} + +int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data) +{ + return 0; +} + +void *equeue_alloc(equeue_t *queue, size_t size) +{ + return NULL; +} + +void equeue_dealloc(equeue_t *queue, void *event) +{ + +} + +void equeue_event_delay(void *event, int ms) +{ + +} + +void equeue_event_period(void *event, int ms) +{ + +} + +void equeue_event_dtor(void *event, void (*dtor)(void *)) +{ + +} + +int equeue_post(equeue_t *queue, void (*cb)(void *), void *event) +{ + return 0; +} + +void equeue_cancel(equeue_t *queue, int id) +{ + +} + +void equeue_background(equeue_t *queue, + void (*update)(void *timer, int ms), void *timer) +{ + +} + +void equeue_chain(equeue_t *queue, equeue_t *target) +{ + } diff --git a/UNITTESTS/stubs/mbed_assert_stub.cpp b/UNITTESTS/stubs/mbed_assert_stub.cpp new file mode 100644 index 0000000000..341881a7f5 --- /dev/null +++ b/UNITTESTS/stubs/mbed_assert_stub.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) , 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 "mbed_assert.h" + +void mbed_assert_internal(const char *expr, const char *file, int line) +{ + +} + diff --git a/UNITTESTS/stubs/mbed_critical_stub.c b/UNITTESTS/stubs/mbed_critical_stub.c new file mode 100644 index 0000000000..f812764382 --- /dev/null +++ b/UNITTESTS/stubs/mbed_critical_stub.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved + * 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. + */ + +/* Declare __STDC_LIMIT_MACROS so stdint.h defines UINT32_MAX when using C++ */ +#define __STDC_LIMIT_MACROS +#include "hal/critical_section_api.h" + +#include "cmsis.h" +#include "platform/mbed_assert.h" +#include "platform/mbed_critical.h" +#include "platform/mbed_toolchain.h" + +static volatile uint32_t critical_section_reentrancy_counter = 0; + +bool core_util_are_interrupts_enabled(void) +{ + return false; +} + +bool core_util_is_isr_active(void) +{ + return false; +} + +bool core_util_in_critical_section(void) +{ + return false; +} + +void core_util_critical_section_enter(void) +{ +} + +void core_util_critical_section_exit(void) +{ +} + +bool core_util_atomic_cas_u8(volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue) +{ + return false; +} + +bool core_util_atomic_cas_u16(volatile uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue) +{ + return false; +} + + +bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) +{ + return false; +} + + +uint8_t core_util_atomic_incr_u8(volatile uint8_t *valuePtr, uint8_t delta) +{ + return 0; +} + +uint16_t core_util_atomic_incr_u16(volatile uint16_t *valuePtr, uint16_t delta) +{ + return 0; +} + +uint32_t core_util_atomic_incr_u32(volatile uint32_t *valuePtr, uint32_t delta) +{ + return 0; +} + + +uint8_t core_util_atomic_decr_u8(volatile uint8_t *valuePtr, uint8_t delta) +{ + return 0; +} + +uint16_t core_util_atomic_decr_u16(volatile uint16_t *valuePtr, uint16_t delta) +{ + return 0; +} + +uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta) +{ + return 0; +} + + +bool core_util_atomic_cas_ptr(void *volatile *ptr, void **expectedCurrentValue, void *desiredValue) +{ + return false; +} + +void *core_util_atomic_incr_ptr(void *volatile *valuePtr, ptrdiff_t delta) +{ + return NULL; +} + +void *core_util_atomic_decr_ptr(void *volatile *valuePtr, ptrdiff_t delta) +{ + return NULL; +} + diff --git a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.h b/UNITTESTS/stubs/mbed_poll_stub.cpp similarity index 63% rename from UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.h rename to UNITTESTS/stubs/mbed_poll_stub.cpp index 3091dadb83..1914399d2a 100644 --- a/UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.h +++ b/UNITTESTS/stubs/mbed_poll_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Arm Limited and affiliates. + * Copyright (c) , Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,18 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef TEST_AT_CELLULARBASE_H -#define TEST_AT_CELLULARBASE_H -class Test_AT_CellularBase { -public: - Test_AT_CellularBase(); +#include "mbed_poll.h" +#include "mbed_poll_stub.h" - virtual ~Test_AT_CellularBase(); +int mbed_poll_stub::revents_value = POLLOUT; +int mbed_poll_stub::int_value = 0; - void test_AT_CellularBase_get_at_handler(); +namespace mbed { - void test_AT_CellularBase_get_device_error(); -}; +int poll(pollfh fhs[], unsigned nfhs, int timeout) +{ + fhs->revents = mbed_poll_stub::revents_value; + return mbed_poll_stub::int_value; +} -#endif // TEST_AT_CELLULARBASE_H +} diff --git a/UNITTESTS/stubs/mbed_poll_stub.h b/UNITTESTS/stubs/mbed_poll_stub.h new file mode 100644 index 0000000000..6c0a4327a9 --- /dev/null +++ b/UNITTESTS/stubs/mbed_poll_stub.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) , 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. + */ +#ifndef __MBED_POLL_STUB_H__ +#define __MBED_POLL_STUB_H__ + +#include + +namespace mbed_poll_stub { +extern int revents_value; +extern int int_value; +} + +#endif diff --git a/UNITTESTS/stubs/mbed_wait_api_stub.cpp b/UNITTESTS/stubs/mbed_wait_api_stub.cpp new file mode 100644 index 0000000000..f8b240544d --- /dev/null +++ b/UNITTESTS/stubs/mbed_wait_api_stub.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) , 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 "mbed_wait_api.h" + +void wait(float s) +{ +} + +void wait_ms(int ms) +{ +} + +void wait_us(int us) +{ +} diff --git a/UNITTESTS/stubs/randLIB_stub.cpp b/UNITTESTS/stubs/randLIB_stub.cpp new file mode 100644 index 0000000000..61cd893d0e --- /dev/null +++ b/UNITTESTS/stubs/randLIB_stub.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017, 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 "randLIB.h" + +void randLIB_seed_random(void) +{ +} + +uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max) +{ + return min; +} + diff --git a/UNITTESTS/stubs/us_ticker_stub.cpp b/UNITTESTS/stubs/us_ticker_stub.cpp new file mode 100644 index 0000000000..69c96accee --- /dev/null +++ b/UNITTESTS/stubs/us_ticker_stub.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) , 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 "stdlib.h" +#include "us_ticker_api.h" + +const ticker_data_t *get_us_ticker_data(void) +{ + return NULL; +} + +void us_ticker_irq_handler(void) +{ +} + +void us_ticker_init(void) +{ +} + +uint32_t us_ticker_read(void) +{ + return 0; +} + +void us_ticker_set_interrupt(timestamp_t timestamp) +{ +} + +void us_ticker_disable_interrupt(void) +{ +} + +void us_ticker_clear_interrupt(void) +{ +} + +void us_ticker_fire_interrupt(void) +{ +} diff --git a/UNITTESTS/target_h/ATCmdParser.h b/UNITTESTS/target_h/ATCmdParser.h new file mode 100644 index 0000000000..c1994cc2af --- /dev/null +++ b/UNITTESTS/target_h/ATCmdParser.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) , 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. + */ +#ifndef __AT_CMD_PARSER_H__ +#define __AT_CMD_PARSER_H__ + +#include "mbed.h" +#include +#include "FileHandle.h" + +class ATCmdParser { +public: + ATCmdParser(mbed::FileHandle *fh, const char *output_delimiter = "\r", + int buffer_size = 256, int timeout = 8000, bool debug = false) {} + + ~ATCmdParser() {} +}; + +#endif //__AT_CMD_PARSER_H__ + diff --git a/UNITTESTS/target_h/arm_math.h b/UNITTESTS/target_h/arm_math.h new file mode 100644 index 0000000000..a431b392e7 --- /dev/null +++ b/UNITTESTS/target_h/arm_math.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) , 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. + */ diff --git a/UNITTESTS/target_h/cmsis.h b/UNITTESTS/target_h/cmsis.h new file mode 100644 index 0000000000..a431b392e7 --- /dev/null +++ b/UNITTESTS/target_h/cmsis.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) , 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. + */ diff --git a/UNITTESTS/target_h/cmsis_compiler.h b/UNITTESTS/target_h/cmsis_compiler.h new file mode 100644 index 0000000000..a431b392e7 --- /dev/null +++ b/UNITTESTS/target_h/cmsis_compiler.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) , 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. + */ diff --git a/UNITTESTS/features/cellular/framework/common/util/test_util.h b/UNITTESTS/target_h/cmsis_os.h similarity index 61% rename from UNITTESTS/features/cellular/framework/common/util/test_util.h rename to UNITTESTS/target_h/cmsis_os.h index bb968ef5f4..a40ab9e73b 100644 --- a/UNITTESTS/features/cellular/framework/common/util/test_util.h +++ b/UNITTESTS/target_h/cmsis_os.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Arm Limited and affiliates. + * Copyright (c) , Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,24 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef TEST_UTIL_H -#define TEST_UTIL_H -class Test_util { -public: - Test_util(); +#ifndef CMSIS_OS_H_ +#define CMSIS_OS_H_ - virtual ~Test_util(); +#include "cmsis_os2.h" - void test_util_uint_to_binary_string(); +#define osPriority osPriority_t - void test_util_char_str_to_hex(); +#define osThreadId osThreadId_t - void test_util_convert_ipv6(); +typedef struct { +} osEvent; - void test_util_prefer_ipv6(); - - void test_util_separate_ip_addresses(); -}; - -#endif // TEST_UTIL_H +#endif diff --git a/UNITTESTS/target_h/cmsis_os2.h b/UNITTESTS/target_h/cmsis_os2.h new file mode 100644 index 0000000000..c2a601fb16 --- /dev/null +++ b/UNITTESTS/target_h/cmsis_os2.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) , 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. + */ + +#ifndef __CMSIS_OS2_H__ +#define __CMSIS_OS2_H__ + +#include + +//If conflicts, then remove these, copied from cmsis_os.h +typedef int32_t osStatus; + +#define osOK 0 + + + +//These are from cmsis_os2.h +typedef void *osSemaphoreId_t; + +typedef struct { + const char *name; ///< name of the semaphore + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block +} osSemaphoreAttr_t; + +//Thread +typedef enum { + osPriorityNormal = 24 ///< Priority: normal +} osPriority_t; + +typedef void *osThreadId_t; + +typedef void *osEventFlagsId_t; + +/// Attributes structure for thread. +typedef struct { +} osThreadAttr_t; + +#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. + +// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait). +#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default). +#define osFlagsWaitAll 0x00000001U ///< Wait for all flags. +#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for. + +// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx). +#define osFlagsError 0x80000000U ///< Error indicator. +#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1). +#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2). +#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3). +#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4). +#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6). + +// Thread attributes (attr_bits in \ref osThreadAttr_t). +#define osThreadDetached 0x00000000U ///< Thread created in detached mode (default) +#define osThreadJoinable 0x00000001U ///< Thread created in joinable mode + +// Mutex attributes (attr_bits in \ref osMutexAttr_t). +#define osMutexRecursive 0x00000001U ///< Recursive mutex. +#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol. +#define osMutexRobust 0x00000008U ///< Robust mutex. + + +#endif diff --git a/UNITTESTS/target_h/mbed.h b/UNITTESTS/target_h/mbed.h index 1f88324deb..276aebc58b 100644 --- a/UNITTESTS/target_h/mbed.h +++ b/UNITTESTS/target_h/mbed.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Arm Limited and affiliates. + * Copyright (c) 2018, Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,7 @@ #include #include "events/mbed_events.h" +#include "events/mbed_shared_queues.h" namespace mbed { #include "platform/Callback.h" diff --git a/UNITTESTS/target_h/mbed_rtos1_types.h b/UNITTESTS/target_h/mbed_rtos1_types.h index e200f189f2..4ff0189351 100644 --- a/UNITTESTS/target_h/mbed_rtos1_types.h +++ b/UNITTESTS/target_h/mbed_rtos1_types.h @@ -18,6 +18,7 @@ #ifndef MBED_RTOS1_TYPES_H #define MBED_RTOS1_TYPES_H +#include "cmsis_os.h" #include "mbed_rtos_storage.h" #endif // MBED_RTOS1_TYPES_H diff --git a/UNITTESTS/target_h/mbed_rtos_storage.h b/UNITTESTS/target_h/mbed_rtos_storage.h index 48923f2a23..e1b1276138 100644 --- a/UNITTESTS/target_h/mbed_rtos_storage.h +++ b/UNITTESTS/target_h/mbed_rtos_storage.h @@ -23,17 +23,13 @@ extern "C" { #endif #include "cmsis_os2.h" +#include "rtx_os.h" +#include "rtx_lib.h" +#include "mbed_rtx_conf.h" -typedef osMutexId_t mbed_rtos_storage_mutex_t; -typedef osSemaphoreId_t mbed_rtos_storage_semaphore_t; -typedef osThreadId_t mbed_rtos_storage_thread_t; -typedef osThreadId_t osThreadId; -typedef osMemoryPoolId_t mbed_rtos_storage_mem_pool_t; -typedef osMessageQueueId_t mbed_rtos_storage_msg_queue_t; -typedef osEventFlagsId_t mbed_rtos_storage_event_flags_t; -typedef void *mbed_rtos_storage_message_t; -typedef osTimerId_t mbed_rtos_storage_timer_t; -typedef osStatus_t osStatus; +typedef os_semaphore_t mbed_rtos_storage_semaphore_t; +typedef os_thread_t mbed_rtos_storage_thread_t; +typedef osRtxEventFlags_t mbed_rtos_storage_event_flags_t; #ifdef __cplusplus } diff --git a/UNITTESTS/target_h/mbed_rtx.h b/UNITTESTS/target_h/mbed_rtx.h new file mode 100644 index 0000000000..a431b392e7 --- /dev/null +++ b/UNITTESTS/target_h/mbed_rtx.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) , 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. + */ diff --git a/UNITTESTS/target_h/mbed_rtx_conf.h b/UNITTESTS/target_h/mbed_rtx_conf.h new file mode 100644 index 0000000000..17620e86e8 --- /dev/null +++ b/UNITTESTS/target_h/mbed_rtx_conf.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) , 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. + */ + +#ifndef OS_STACK_SIZE +#define OS_STACK_SIZE 0 +#endif diff --git a/UNITTESTS/target_h/nsapi_ppp.h b/UNITTESTS/target_h/nsapi_ppp.h new file mode 100644 index 0000000000..a431b392e7 --- /dev/null +++ b/UNITTESTS/target_h/nsapi_ppp.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) , 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. + */ diff --git a/UNITTESTS/target_h/platform/mbed_power_mgmt.h b/UNITTESTS/target_h/platform/mbed_power_mgmt.h new file mode 100644 index 0000000000..2810b22dae --- /dev/null +++ b/UNITTESTS/target_h/platform/mbed_power_mgmt.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) , 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. + */ + diff --git a/UNITTESTS/target_h/platform/mbed_retarget.h b/UNITTESTS/target_h/platform/mbed_retarget.h index 0c513f53e3..b379eb0de3 100644 --- a/UNITTESTS/target_h/platform/mbed_retarget.h +++ b/UNITTESTS/target_h/platform/mbed_retarget.h @@ -18,7 +18,15 @@ #ifndef RETARGET_H #define RETARGET_H +#include #include +#include + +#include + +namespace mbed { + +#define NAME_MAX 255 #undef EPERM #define EPERM 1 /* Operation not permitted */ @@ -283,4 +291,75 @@ #undef ENOTRECOVERABLE #define ENOTRECOVERABLE 131 /* State not recoverable */ +#define _IFMT 0170000 //< type of file +#define _IFSOCK 0140000 //< socket +#define _IFLNK 0120000 //< symbolic link +#define _IFREG 0100000 //< regular +#define _IFBLK 0060000 //< block special +#define _IFDIR 0040000 //< directory +#define _IFCHR 0020000 //< character special +#define _IFIFO 0010000 //< fifo special + + +#define O_RDONLY 0 ///< Open for reading +#define O_WRONLY 1 ///< Open for writing +#define O_RDWR 2 ///< Open for reading and writing +#define O_NONBLOCK 0x0004 ///< Non-blocking mode +#define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write +#define O_CREAT 0x0200 ///< Create file if it does not exist +#define O_TRUNC 0x0400 ///< Truncate file to zero length +#define O_EXCL 0x0800 ///< Fail if file exists +#define O_BINARY 0x8000 ///< Open file in binary mode + +#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) + +#define NAME_MAX 255 ///< Maximum size of a name in a file path + +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 + + +struct statvfs { + unsigned long f_bsize; ///< Filesystem block size + unsigned long f_frsize; ///< Fragment size (block size) + + fsblkcnt_t f_blocks; ///< Number of blocks + fsblkcnt_t f_bfree; ///< Number of free blocks + fsblkcnt_t f_bavail; ///< Number of free blocks for unprivileged users + + unsigned long f_fsid; ///< Filesystem ID + + unsigned long f_namemax; ///< Maximum filename length +}; + + +struct dirent { + char d_name[NAME_MAX + 1]; ///< Name of file + uint8_t d_type; ///< Type of file +}; + +enum { + DT_UNKNOWN, ///< The file type could not be determined. + DT_FIFO, ///< This is a named pipe (FIFO). + DT_CHR, ///< This is a character device. + DT_DIR, ///< This is a directory. + DT_BLK, ///< This is a block device. + DT_REG, ///< This is a regular file. + DT_LNK, ///< This is a symbolic link. + DT_SOCK, ///< This is a UNIX domain socket. +}; + +/* fcntl.h defines */ +#define F_GETFL 3 +#define F_SETFL 4 + +struct pollfd { + int fd; + short events; + short revents; +}; + +} + #endif //RETARGET_H diff --git a/UNITTESTS/target_h/randLIB.h b/UNITTESTS/target_h/randLIB.h new file mode 100644 index 0000000000..a621be3688 --- /dev/null +++ b/UNITTESTS/target_h/randLIB.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017, 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. + */ +#ifndef FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ +#define FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ + +#include + +extern void randLIB_seed_random(void); + +uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max); + + +#endif /* FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ */ diff --git a/UNITTESTS/target_h/rtos/Mutex.h b/UNITTESTS/target_h/rtos/Mutex.h new file mode 100644 index 0000000000..a804e17212 --- /dev/null +++ b/UNITTESTS/target_h/rtos/Mutex.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) , 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. + */ +#ifndef __MUTEX_H__ +#define __MUTEX_H__ + +#include +#include "cmsis_os2.h" + +namespace rtos { + +class Mutex { +public: + Mutex(); + + Mutex(const char *name); + + osStatus lock(uint32_t millisec=osWaitForever); + + bool trylock(); + + bool trylock_for(uint32_t millisec); + + bool trylock_until(uint64_t millisec); + + osStatus unlock(); + + osThreadId_t get_owner(); + + ~Mutex(); +}; + +} + +#endif diff --git a/UNITTESTS/target_h/rtos/Semaphore.h b/UNITTESTS/target_h/rtos/Semaphore.h new file mode 100644 index 0000000000..34e472dea6 --- /dev/null +++ b/UNITTESTS/target_h/rtos/Semaphore.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) , 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. + */ + +typedef void *Semaphore; diff --git a/UNITTESTS/target_h/rtx_lib.h b/UNITTESTS/target_h/rtx_lib.h new file mode 100644 index 0000000000..2b2368f0a6 --- /dev/null +++ b/UNITTESTS/target_h/rtx_lib.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) , 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. + */ +#ifndef __RTX_LIB_H__ +#define __RTX_LIB_H__ + +#include "rtx_os.h" + +#define os_semaphore_t osRtxSemaphore_t +#define os_thread_t osRtxThread_t + +#endif diff --git a/UNITTESTS/target_h/rtx_os.h b/UNITTESTS/target_h/rtx_os.h new file mode 100644 index 0000000000..dfa7082fa1 --- /dev/null +++ b/UNITTESTS/target_h/rtx_os.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) , 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. + */ + +#ifndef __RTX_OS__ +#define __RTX_OS__ + +#include "inttypes.h" + +typedef struct osRtxSemaphore_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + uint16_t tokens; ///< Current number of tokens + uint16_t max_tokens; ///< Maximum number of tokens +} osRtxSemaphore_t; + +typedef struct osRtxThread_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t attr; ///< Object Attributes + const char *name; ///< Object Name + struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list + struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list + struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list + struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list + struct osRtxThread_s *thread_join; ///< Thread waiting to Join + uint32_t delay; ///< Delay Time + int8_t priority; ///< Thread Priority + int8_t priority_base; ///< Base Priority + uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0]) + uint8_t flags_options; ///< Thread/Event Flags Options + uint32_t wait_flags; ///< Waiting Thread/Event Flags + uint32_t thread_flags; ///< Thread Flags + struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes + void *stack_mem; ///< Stack Memory + uint32_t stack_size; ///< Stack Size + uint32_t sp; ///< Current Stack Pointer + uint32_t thread_addr; ///< Thread entry address + uint32_t tz_memory; ///< TrustZone Memory Identifier + void *context; ///< Context for OsEventObserver objects +} osRtxThread_t; + +typedef struct { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Waiting Threads List + uint32_t event_flags; ///< Event Flags +} osRtxEventFlags_t; + +#endif diff --git a/UNITTESTS/target_h/sys/syslimits.h b/UNITTESTS/target_h/sys/syslimits.h new file mode 100644 index 0000000000..5c90b373f1 --- /dev/null +++ b/UNITTESTS/target_h/sys/syslimits.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) , 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. + */ +#define NAME_MAX 255 From adc4ce438548926a39b974d65716d83c3218dc8f Mon Sep 17 00:00:00 2001 From: Antti Kauppila Date: Fri, 31 Aug 2018 13:30:53 +0300 Subject: [PATCH 2/4] Old Cellular UNITTESTS removed --- .../at_cellulardevicetest.cpp | 6 + UNITTESTS/stubs/ATHandler_stub.cpp | 2 +- UNITTESTS/stubs/ATHandler_stub.h | 2 + UNITTESTS/stubs/SocketAddress_stub.cpp | 24 - features/cellular/UNITTESTS/Makefile | 19 - features/cellular/UNITTESTS/MakefileWorker.mk | 562 -------- .../UNITTESTS/at/at_cellularbase/Makefile | 21 - .../at_cellularbase/at_cellularbasetest.cpp | 62 - .../UNITTESTS/at/at_cellularbase/main.cpp | 28 - .../at_cellularbase/test_at_cellularbase.cpp | 119 -- .../at/at_cellularbase/test_at_cellularbase.h | 36 - .../UNITTESTS/at/at_cellulardevice/Makefile | 29 - .../at_cellulardevicetest.cpp | 116 -- .../UNITTESTS/at/at_cellulardevice/main.cpp | 28 - .../test_at_cellulardevice.h | 60 - .../at/at_cellularinformation/Makefile | 22 - .../at_cellularinformationtest.cpp | 61 - .../at/at_cellularinformation/main.cpp | 28 - .../test_at_cellularinformation.cpp | 141 -- .../test_at_cellularinformation.h | 36 - .../UNITTESTS/at/at_cellularnetwork/Makefile | 29 - .../at_cellularnetworktest.cpp | 216 --- .../UNITTESTS/at/at_cellularnetwork/main.cpp | 28 - .../test_at_cellularnetwork.cpp | 1160 ----------------- .../test_at_cellularnetwork.h | 96 -- .../UNITTESTS/at/at_cellularpower/Makefile | 23 - .../at_cellularpower/at_cellularpowertest.cpp | 94 -- .../UNITTESTS/at/at_cellularpower/main.cpp | 28 - .../test_at_cellularpower.cpp | 193 --- .../at_cellularpower/test_at_cellularpower.h | 50 - .../UNITTESTS/at/at_cellularsim/Makefile | 24 - .../at/at_cellularsim/at_cellularsimtest.cpp | 78 -- .../UNITTESTS/at/at_cellularsim/main.cpp | 28 - .../at/at_cellularsim/test_at_cellularsim.cpp | 195 --- .../at/at_cellularsim/test_at_cellularsim.h | 42 - .../UNITTESTS/at/at_cellularsms/Makefile | 25 - .../at/at_cellularsms/at_cellularsmstest.cpp | 91 -- .../UNITTESTS/at/at_cellularsms/main.cpp | 28 - .../at/at_cellularsms/test_at_cellularsms.cpp | 206 --- .../at/at_cellularsms/test_at_cellularsms.h | 48 - .../UNITTESTS/at/at_cellularstack/Makefile | 26 - .../at_cellularstack/at_cellularstacktest.cpp | 107 -- .../UNITTESTS/at/at_cellularstack/main.cpp | 28 - .../test_at_cellularstack.cpp | 367 ------ .../at_cellularstack/test_at_cellularstack.h | 54 - .../cellular/UNITTESTS/at/athandler/Makefile | 30 - .../UNITTESTS/at/athandler/athandlertest.cpp | 226 ---- .../cellular/UNITTESTS/at/athandler/main.cpp | 28 - .../UNITTESTS/at/athandler/test_athandler.cpp | 1016 --------------- .../UNITTESTS/at/athandler/test_athandler.h | 102 -- .../cellular/UNITTESTS/common/util/Makefile | 18 - .../cellular/UNITTESTS/common/util/main.cpp | 28 - .../UNITTESTS/common/util/test_util.cpp | 177 --- .../UNITTESTS/common/util/test_util.h | 38 - .../UNITTESTS/common/util/utiltest.cpp | 66 - .../cellular/UNITTESTS/makefile_defines.txt | 32 - features/cellular/UNITTESTS/run_tests | 48 - .../cellular/UNITTESTS/stubs/ATCmdParser.cpp | 420 ------ .../UNITTESTS/stubs/AT_CellularBase_stub.cpp | 48 - .../UNITTESTS/stubs/AT_CellularBase_stub.h | 25 - .../stubs/AT_CellularDevice_stub.cpp | 91 -- .../stubs/AT_CellularInformation_stub.cpp | 49 - .../stubs/AT_CellularMultiplexer_stub.cpp | 35 - .../stubs/AT_CellularNetwork_stub.cpp | 256 ---- .../UNITTESTS/stubs/AT_CellularPower_stub.cpp | 81 -- .../UNITTESTS/stubs/AT_CellularSIM_stub.cpp | 59 - .../UNITTESTS/stubs/AT_CellularSMS_stub.cpp | 190 --- .../UNITTESTS/stubs/AT_CellularStack_stub.cpp | 90 -- .../UNITTESTS/stubs/CellularUtil_stub.cpp | 113 -- .../UNITTESTS/stubs/EventQueue_stub.cpp | 58 - .../UNITTESTS/stubs/FileHandle_stub.cpp | 32 - .../UNITTESTS/stubs/FileHandle_stub.h | 94 -- features/cellular/UNITTESTS/stubs/Kernel.cpp | 25 - .../UNITTESTS/stubs/NetworkInterface_stub.cpp | 89 -- .../UNITTESTS/stubs/NetworkStack_stub.cpp | 95 -- .../UNITTESTS/stubs/Semaphore_stub.cpp | 57 - .../UNITTESTS/stubs/SocketAddress_stub.cpp | 121 -- .../cellular/UNITTESTS/stubs/Thread_stub.cpp | 27 - .../cellular/UNITTESTS/stubs/Timer_stub.cpp | 74 -- .../cellular/UNITTESTS/stubs/Timer_stub.h | 24 - .../cellular/UNITTESTS/stubs/equeue_stub.c | 104 -- .../UNITTESTS/stubs/mbed_assert_stub.cpp | 24 - .../UNITTESTS/stubs/mbed_poll_stub.cpp | 32 - .../cellular/UNITTESTS/stubs/mbed_poll_stub.h | 27 - .../UNITTESTS/stubs/mbed_wait_api_stub.cpp | 30 - .../cellular/UNITTESTS/stubs/randLIB_stub.cpp | 27 - .../UNITTESTS/stubs/us_ticker_stub.cpp | 54 - .../cellular/UNITTESTS/target_h/ATCmdParser.h | 33 - .../UNITTESTS/target_h/PeripheralNames.h | 16 - .../cellular/UNITTESTS/target_h/PinNames.h | 27 - .../cellular/UNITTESTS/target_h/arm_math.h | 16 - features/cellular/UNITTESTS/target_h/cmsis.h | 16 - .../UNITTESTS/target_h/cmsis_compiler.h | 16 - .../cellular/UNITTESTS/target_h/cmsis_os.h | 30 - .../cellular/UNITTESTS/target_h/cmsis_os2.h | 52 - features/cellular/UNITTESTS/target_h/device.h | 16 - .../target_h/mbed-trace/mbed_trace.h | 27 - features/cellular/UNITTESTS/target_h/mbed.h | 24 - .../UNITTESTS/target_h/mbed_rtos1_types.h | 18 - .../UNITTESTS/target_h/mbed_rtos_storage.h | 24 - .../cellular/UNITTESTS/target_h/mbed_rtx.h | 16 - .../UNITTESTS/target_h/mbed_rtx_conf.h | 18 - .../cellular/UNITTESTS/target_h/nsapi_ppp.h | 16 - .../target_h/platform/mbed_power_mgmt.h | 17 - .../target_h/platform/mbed_retarget.h | 20 - .../cellular/UNITTESTS/target_h/randLIB.h | 27 - .../cellular/UNITTESTS/target_h/rtos/Mutex.h | 18 - .../UNITTESTS/target_h/rtos/Semaphore.h | 18 - .../cellular/UNITTESTS/target_h/rtx_lib.h | 25 - features/cellular/UNITTESTS/target_h/rtx_os.h | 60 - .../UNITTESTS/target_h/sys/syslimits.h | 17 - 111 files changed, 9 insertions(+), 9484 deletions(-) delete mode 100755 features/cellular/UNITTESTS/Makefile delete mode 100755 features/cellular/UNITTESTS/MakefileWorker.mk delete mode 100644 features/cellular/UNITTESTS/at/at_cellularbase/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularbase/at_cellularbasetest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularbase/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellulardevice/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellulardevice/at_cellulardevicetest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellulardevice/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellulardevice/test_at_cellulardevice.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellularinformation/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularinformation/at_cellularinformationtest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularinformation/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellularnetwork/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularnetwork/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellularpower/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularpower/at_cellularpowertest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularpower/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsim/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsim/at_cellularsimtest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsim/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsms/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsms/at_cellularsmstest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsms/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.h delete mode 100644 features/cellular/UNITTESTS/at/at_cellularstack/Makefile delete mode 100644 features/cellular/UNITTESTS/at/at_cellularstack/at_cellularstacktest.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularstack/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.cpp delete mode 100644 features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.h delete mode 100644 features/cellular/UNITTESTS/at/athandler/Makefile delete mode 100644 features/cellular/UNITTESTS/at/athandler/athandlertest.cpp delete mode 100644 features/cellular/UNITTESTS/at/athandler/main.cpp delete mode 100644 features/cellular/UNITTESTS/at/athandler/test_athandler.cpp delete mode 100644 features/cellular/UNITTESTS/at/athandler/test_athandler.h delete mode 100644 features/cellular/UNITTESTS/common/util/Makefile delete mode 100644 features/cellular/UNITTESTS/common/util/main.cpp delete mode 100644 features/cellular/UNITTESTS/common/util/test_util.cpp delete mode 100644 features/cellular/UNITTESTS/common/util/test_util.h delete mode 100644 features/cellular/UNITTESTS/common/util/utiltest.cpp delete mode 100755 features/cellular/UNITTESTS/makefile_defines.txt delete mode 100755 features/cellular/UNITTESTS/run_tests delete mode 100644 features/cellular/UNITTESTS/stubs/ATCmdParser.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.h delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularDevice_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularInformation_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularPower_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularSIM_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularSMS_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/AT_CellularStack_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/CellularUtil_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/EventQueue_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/FileHandle_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/FileHandle_stub.h delete mode 100644 features/cellular/UNITTESTS/stubs/Kernel.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/NetworkInterface_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/NetworkStack_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/Semaphore_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/SocketAddress_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/Thread_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/Timer_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/Timer_stub.h delete mode 100644 features/cellular/UNITTESTS/stubs/equeue_stub.c delete mode 100644 features/cellular/UNITTESTS/stubs/mbed_assert_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/mbed_poll_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/mbed_poll_stub.h delete mode 100644 features/cellular/UNITTESTS/stubs/mbed_wait_api_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/randLIB_stub.cpp delete mode 100644 features/cellular/UNITTESTS/stubs/us_ticker_stub.cpp delete mode 100644 features/cellular/UNITTESTS/target_h/ATCmdParser.h delete mode 100644 features/cellular/UNITTESTS/target_h/PeripheralNames.h delete mode 100644 features/cellular/UNITTESTS/target_h/PinNames.h delete mode 100644 features/cellular/UNITTESTS/target_h/arm_math.h delete mode 100644 features/cellular/UNITTESTS/target_h/cmsis.h delete mode 100644 features/cellular/UNITTESTS/target_h/cmsis_compiler.h delete mode 100644 features/cellular/UNITTESTS/target_h/cmsis_os.h delete mode 100644 features/cellular/UNITTESTS/target_h/cmsis_os2.h delete mode 100644 features/cellular/UNITTESTS/target_h/device.h delete mode 100644 features/cellular/UNITTESTS/target_h/mbed-trace/mbed_trace.h delete mode 100644 features/cellular/UNITTESTS/target_h/mbed.h delete mode 100644 features/cellular/UNITTESTS/target_h/mbed_rtos1_types.h delete mode 100644 features/cellular/UNITTESTS/target_h/mbed_rtos_storage.h delete mode 100644 features/cellular/UNITTESTS/target_h/mbed_rtx.h delete mode 100644 features/cellular/UNITTESTS/target_h/mbed_rtx_conf.h delete mode 100644 features/cellular/UNITTESTS/target_h/nsapi_ppp.h delete mode 100644 features/cellular/UNITTESTS/target_h/platform/mbed_power_mgmt.h delete mode 100644 features/cellular/UNITTESTS/target_h/platform/mbed_retarget.h delete mode 100644 features/cellular/UNITTESTS/target_h/randLIB.h delete mode 100644 features/cellular/UNITTESTS/target_h/rtos/Mutex.h delete mode 100644 features/cellular/UNITTESTS/target_h/rtos/Semaphore.h delete mode 100644 features/cellular/UNITTESTS/target_h/rtx_lib.h delete mode 100644 features/cellular/UNITTESTS/target_h/rtx_os.h delete mode 100644 features/cellular/UNITTESTS/target_h/sys/syslimits.h diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 98eae84cd7..33f47399af 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -120,6 +120,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network) ATHandler_stub::ref_count = 0; EXPECT_TRUE(dev.open_network(&fh1)); + AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.close_network(); @@ -134,6 +135,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) ATHandler_stub::ref_count = 0; EXPECT_TRUE(dev.open_sms(&fh1)); + AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.close_sms(); @@ -148,6 +150,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) ATHandler_stub::ref_count = 0; EXPECT_TRUE(dev.open_power(&fh1)); + AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.close_power(); @@ -163,6 +166,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) EXPECT_TRUE(dev.open_sim(&fh1)); + AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; + dev.close_sms(); // this should not affect to refcount as it's not opened EXPECT_TRUE(ATHandler_stub::ref_count == 1); @@ -191,6 +196,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; dev.close_information(); + EXPECT_TRUE(ATHandler_stub::ref_count == 1); ATHandler_stub::fh_value = NULL; } diff --git a/UNITTESTS/stubs/ATHandler_stub.cpp b/UNITTESTS/stubs/ATHandler_stub.cpp index 3daf8da115..81267d0b44 100644 --- a/UNITTESTS/stubs/ATHandler_stub.cpp +++ b/UNITTESTS/stubs/ATHandler_stub.cpp @@ -68,7 +68,7 @@ void ATHandler::set_debug(bool debug_on) ATHandler::~ATHandler() { - ATHandler_stub::ref_count = -909; + ATHandler_stub::ref_count = kATHandler_destructor_ref_ount; } void ATHandler::inc_ref_count() diff --git a/UNITTESTS/stubs/ATHandler_stub.h b/UNITTESTS/stubs/ATHandler_stub.h index d259938488..856ed9cb7d 100644 --- a/UNITTESTS/stubs/ATHandler_stub.h +++ b/UNITTESTS/stubs/ATHandler_stub.h @@ -29,6 +29,8 @@ static const int kRead_string_table_size = 100; static const int kRead_int_table_size = 100; static const int kResp_stop_count_default = 100; +// set reference count to -909 to separate it from zero so we can test that ATHandler is really deleted. +static const int kATHandler_destructor_ref_ount = -909; namespace ATHandler_stub { extern nsapi_error_t nsapi_error_value; diff --git a/UNITTESTS/stubs/SocketAddress_stub.cpp b/UNITTESTS/stubs/SocketAddress_stub.cpp index 76e02aa12b..9ed53f03cf 100644 --- a/UNITTESTS/stubs/SocketAddress_stub.cpp +++ b/UNITTESTS/stubs/SocketAddress_stub.cpp @@ -22,40 +22,16 @@ #include "mbed.h" -static bool ipv4_is_valid(const char *addr) -{ - return false; -} - static bool ipv6_is_valid(const char *addr) { return false; } -static void ipv4_from_address(uint8_t *bytes, const char *addr) -{ - -} - static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk) { return 0; } -static void ipv6_from_address(uint8_t *bytes, const char *addr) -{ - -} - -static void ipv4_to_address(char *addr, const uint8_t *bytes) -{ - -} - -static void ipv6_to_address(char *addr, const uint8_t *bytes) -{ -} - SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port) { diff --git a/features/cellular/UNITTESTS/Makefile b/features/cellular/UNITTESTS/Makefile deleted file mode 100755 index 1327cf4601..0000000000 --- a/features/cellular/UNITTESTS/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -#scan for folders having "Makefile" in them and remove 'this' to prevent loop -DIRS := $(filter-out ./, $(sort $(dir $(shell find . -name 'Makefile')))) - -all: - for dir in $(DIRS); do \ - cd $$dir; make gcov; cd ..; cd ..;\ - done - -clean: - for dir in $(DIRS); do \ - cd $$dir; make clean; cd ..; cd ..;\ - done - rm -rf ../source/*gcov ../source/*gcda ../source/*o - rm -rf stubs/*gcov stubs/*gcda stubs/*o - rm -rf results/* - rm -rf coverages/* - rm -rf results - rm -rf coverages - diff --git a/features/cellular/UNITTESTS/MakefileWorker.mk b/features/cellular/UNITTESTS/MakefileWorker.mk deleted file mode 100755 index 2096ced036..0000000000 --- a/features/cellular/UNITTESTS/MakefileWorker.mk +++ /dev/null @@ -1,562 +0,0 @@ -#--------- -# -# MakefileWorker.mk -# -# Include this helper file in your makefile -# It makes -# A static library -# A test executable -# -# See this example for parameter settings -# examples/Makefile -# -#---------- -# Inputs - these variables describe what to build -# -# INCLUDE_DIRS - Directories used to search for include files. -# This generates a -I for each directory -# SRC_DIRS - Directories containing source file to built into the library -# SRC_FILES - Specific source files to build into library. Helpful when not all code -# in a directory can be built for test (hopefully a temporary situation) -# TEST_SRC_DIRS - Directories containing unit test code build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# TEST_SRC_FILES - Specific source files to build into the unit test runner -# These do not go in a library. They are explicitly included in the test runner -# MOCKS_SRC_DIRS - Directories containing mock source files to build into the test runner -# These do not go in a library. They are explicitly included in the test runner -#---------- -# You can adjust these variables to influence how to build the test target -# and where to put and name outputs -# See below to determine defaults -# COMPONENT_NAME - the name of the thing being built -# TEST_TARGET - name the test executable. By default it is -# $(COMPONENT_NAME)_tests -# Helpful if you want 1 > make files in the same directory with different -# executables as output. -# CPPUTEST_HOME - where CppUTest home dir found -# TARGET_PLATFORM - Influences how the outputs are generated by modifying the -# CPPUTEST_OBJS_DIR and CPPUTEST_LIB_DIR to use a sub-directory under the -# normal objs and lib directories. Also modifies where to search for the -# CPPUTEST_LIB to link against. -# CPPUTEST_OBJS_DIR - a directory where o and d files go -# CPPUTEST_LIB_DIR - a directory where libs go -# CPPUTEST_ENABLE_DEBUG - build for debug -# CPPUTEST_USE_MEM_LEAK_DETECTION - Links with overridden new and delete -# CPPUTEST_USE_STD_CPP_LIB - Set to N to keep the standard C++ library out -# of the test harness -# CPPUTEST_USE_GCOV - Turn on coverage analysis -# Clean then build with this flag set to Y, then 'make gcov' -# CPPUTEST_MAPFILE - generate a map file -# CPPUTEST_WARNINGFLAGS - overly picky by default -# OTHER_MAKEFILE_TO_INCLUDE - a hook to use this makefile to make -# other targets. Like CSlim, which is part of fitnesse -# CPPUTEST_USE_VPATH - Use Make's VPATH functionality to support user -# specification of source files and directories that aren't below -# the user's Makefile in the directory tree, like: -# SRC_DIRS += ../../lib/foo -# It defaults to N, and shouldn't be necessary except in the above case. -#---------- -# -# Other flags users can initialize to sneak in their settings -# CPPUTEST_CXXFLAGS - flags for the C++ compiler -# CPPUTEST_CPPFLAGS - flags for the C++ AND C preprocessor -# CPPUTEST_CFLAGS - flags for the C complier -# CPPUTEST_LDFLAGS - Linker flags -#---------- - -# Some behavior is weird on some platforms. Need to discover the platform. - -# Platforms -UNAME_OUTPUT = "$(shell uname -a)" -MACOSX_STR = Darwin -MINGW_STR = MINGW -CYGWIN_STR = CYGWIN -LINUX_STR = Linux -SUNOS_STR = SunOS -UNKNWOWN_OS_STR = Unknown - -# Compilers -CC_VERSION_OUTPUT ="$(shell $(CXX) -v 2>&1)" -CLANG_STR = clang -SUNSTUDIO_CXX_STR = SunStudio - -UNAME_OS = $(UNKNWOWN_OS_STR) - -ifeq ($(findstring $(MINGW_STR),$(UNAME_OUTPUT)),$(MINGW_STR)) - UNAME_OS = $(MINGW_STR) -endif - -ifeq ($(findstring $(CYGWIN_STR),$(UNAME_OUTPUT)),$(CYGWIN_STR)) - UNAME_OS = $(CYGWIN_STR) -endif - -ifeq ($(findstring $(LINUX_STR),$(UNAME_OUTPUT)),$(LINUX_STR)) - UNAME_OS = $(LINUX_STR) -endif - -ifeq ($(findstring $(MACOSX_STR),$(UNAME_OUTPUT)),$(MACOSX_STR)) - UNAME_OS = $(MACOSX_STR) -#lion has a problem with the 'v' part of -a - UNAME_OUTPUT = "$(shell uname -pmnrs)" -endif - -ifeq ($(findstring $(SUNOS_STR),$(UNAME_OUTPUT)),$(SUNOS_STR)) - UNAME_OS = $(SUNOS_STR) - - SUNSTUDIO_CXX_ERR_STR = CC -flags -ifeq ($(findstring $(SUNSTUDIO_CXX_ERR_STR),$(CC_VERSION_OUTPUT)),$(SUNSTUDIO_CXX_ERR_STR)) - CC_VERSION_OUTPUT ="$(shell $(CXX) -V 2>&1)" - COMPILER_NAME = $(SUNSTUDIO_CXX_STR) -endif -endif - -ifeq ($(findstring $(CLANG_STR),$(CC_VERSION_OUTPUT)),$(CLANG_STR)) - COMPILER_NAME = $(CLANG_STR) -endif - -#Kludge for mingw, it does not have cc.exe, but gcc.exe will do -ifeq ($(UNAME_OS),$(MINGW_STR)) - CC := gcc -endif - -#And another kludge. Exception handling in gcc 4.6.2 is broken when linking the -# Standard C++ library as a shared library. Unbelievable. -ifeq ($(UNAME_OS),$(MINGW_STR)) - CPPUTEST_LDFLAGS += -static -endif -ifeq ($(UNAME_OS),$(CYGWIN_STR)) - CPPUTEST_LDFLAGS += -static -endif - - -#Kludge for MacOsX gcc compiler on Darwin9 who can't handle pendantic -ifeq ($(UNAME_OS),$(MACOSX_STR)) -ifeq ($(findstring Version 9,$(UNAME_OUTPUT)),Version 9) - CPPUTEST_PEDANTIC_ERRORS = N -endif -endif - -ifndef COMPONENT_NAME - COMPONENT_NAME = name_this_in_the_makefile -endif - -# Debug on by default -ifndef CPPUTEST_ENABLE_DEBUG - CPPUTEST_ENABLE_DEBUG = Y -endif - -# new and delete for memory leak detection on by default -ifndef CPPUTEST_USE_MEM_LEAK_DETECTION - CPPUTEST_USE_MEM_LEAK_DETECTION = Y -endif - -# Use the standard C library -ifndef CPPUTEST_USE_STD_C_LIB - CPPUTEST_USE_STD_C_LIB = Y -endif - -# Use the standard C++ library -ifndef CPPUTEST_USE_STD_CPP_LIB - CPPUTEST_USE_STD_CPP_LIB = Y -endif - -# Use gcov, off by default -ifndef CPPUTEST_USE_GCOV - CPPUTEST_USE_GCOV = N -endif - -ifndef CPPUTEST_PEDANTIC_ERRORS - CPPUTEST_PEDANTIC_ERRORS = Y -endif - -# Default warnings -ifndef CPPUTEST_WARNINGFLAGS - CPPUTEST_WARNINGFLAGS = -Wall -Wextra -Wshadow -Wswitch-default -Wswitch-enum -Wconversion -ifeq ($(CPPUTEST_PEDANTIC_ERRORS), Y) -# CPPUTEST_WARNINGFLAGS += -pedantic-errors - CPPUTEST_WARNINGFLAGS += -pedantic -endif -ifeq ($(UNAME_OS),$(LINUX_STR)) - CPPUTEST_WARNINGFLAGS += -Wsign-conversion -endif - CPPUTEST_CXX_WARNINGFLAGS = -Woverloaded-virtual - CPPUTEST_C_WARNINGFLAGS = -Wstrict-prototypes -endif - -#Wonderful extra compiler warnings with clang -ifeq ($(COMPILER_NAME),$(CLANG_STR)) -# -Wno-disabled-macro-expansion -> Have to disable the macro expansion warning as the operator new overload warns on that. -# -Wno-padded -> I sort-of like this warning but if there is a bool at the end of the class, it seems impossible to remove it! (except by making padding explicit) -# -Wno-global-constructors Wno-exit-time-destructors -> Great warnings, but in CppUTest it is impossible to avoid as the automatic test registration depends on the global ctor and dtor -# -Wno-weak-vtables -> The TEST_GROUP macro declares a class and will automatically inline its methods. Thats ok as they are only in one translation unit. Unfortunately, the warning can't detect that, so it must be disabled. - CPPUTEST_CXX_WARNINGFLAGS += -Weverything -Wno-disabled-macro-expansion -Wno-padded -Wno-global-constructors -Wno-exit-time-destructors -Wno-weak-vtables - CPPUTEST_C_WARNINGFLAGS += -Weverything -Wno-padded -endif - -# Uhm. Maybe put some warning flags for SunStudio here? -ifeq ($(COMPILER_NAME),$(SUNSTUDIO_CXX_STR)) - CPPUTEST_CXX_WARNINGFLAGS = - CPPUTEST_C_WARNINGFLAGS = -endif - -# Default dir for temporary files (d, o) -ifndef CPPUTEST_OBJS_DIR -ifndef TARGET_PLATFORM - CPPUTEST_OBJS_DIR = objs -else - CPPUTEST_OBJS_DIR = objs/$(TARGET_PLATFORM) -endif -endif - -# Default dir for the outout library -ifndef CPPUTEST_LIB_DIR -ifndef TARGET_PLATFORM - CPPUTEST_LIB_DIR = lib -else - CPPUTEST_LIB_DIR = lib/$(TARGET_PLATFORM) -endif -endif - -# No map by default -ifndef CPPUTEST_MAP_FILE - CPPUTEST_MAP_FILE = N -endif - -# No extentions is default -ifndef CPPUTEST_USE_EXTENSIONS - CPPUTEST_USE_EXTENSIONS = N -endif - -# No VPATH is default -ifndef CPPUTEST_USE_VPATH - CPPUTEST_USE_VPATH := N -endif -# Make empty, instead of 'N', for usage in $(if ) conditionals -ifneq ($(CPPUTEST_USE_VPATH), Y) - CPPUTEST_USE_VPATH := -endif - -ifndef TARGET_PLATFORM -#CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib -CPPUTEST_LIB_LINK_DIR = /usr/lib/x86_64-linux-gnu -else -CPPUTEST_LIB_LINK_DIR = $(CPPUTEST_HOME)/lib/$(TARGET_PLATFORM) -endif - -# -------------------------------------- -# derived flags in the following area -# -------------------------------------- - -# Without the C library, we'll need to disable the C++ library and ... -ifeq ($(CPPUTEST_USE_STD_C_LIB), N) - CPPUTEST_USE_STD_CPP_LIB = N - CPPUTEST_USE_MEM_LEAK_DETECTION = N - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_C_LIB_DISABLED - CPPUTEST_CPPFLAGS += -nostdinc -endif - -CPPUTEST_CPPFLAGS += -DCPPUTEST_COMPILATION - -ifeq ($(CPPUTEST_USE_MEM_LEAK_DETECTION), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_MEM_LEAK_DETECTION_DISABLED -else - ifndef CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorNewMacros.h - endif - ifndef CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE - CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE = -include $(CPPUTEST_HOME)/include/CppUTest/MemoryLeakDetectorMallocMacros.h - endif -endif - -ifeq ($(CPPUTEST_ENABLE_DEBUG), Y) - CPPUTEST_CXXFLAGS += -g - CPPUTEST_CFLAGS += -g - CPPUTEST_LDFLAGS += -g -endif - -ifeq ($(CPPUTEST_USE_STD_CPP_LIB), N) - CPPUTEST_CPPFLAGS += -DCPPUTEST_STD_CPP_LIB_DISABLED -ifeq ($(CPPUTEST_USE_STD_C_LIB), Y) - CPPUTEST_CXXFLAGS += -nostdinc++ -endif -endif - -ifdef $(GMOCK_HOME) - GTEST_HOME = $(GMOCK_HOME)/gtest - CPPUTEST_CPPFLAGS += -I$(GMOCK_HOME)/include - GMOCK_LIBRARY = $(GMOCK_HOME)/lib/.libs/libgmock.a - LD_LIBRARIES += $(GMOCK_LIBRARY) - CPPUTEST_CPPFLAGS += -DINCLUDE_GTEST_TESTS - CPPUTEST_WARNINGFLAGS = - CPPUTEST_CPPFLAGS += -I$(GTEST_HOME)/include -I$(GTEST_HOME) - GTEST_LIBRARY = $(GTEST_HOME)/lib/.libs/libgtest.a - LD_LIBRARIES += $(GTEST_LIBRARY) -endif - - -ifeq ($(CPPUTEST_USE_GCOV), Y) - CPPUTEST_CXXFLAGS += -fprofile-arcs -ftest-coverage - CPPUTEST_CFLAGS += -fprofile-arcs -ftest-coverage -endif - -CPPUTEST_CXXFLAGS += $(CPPUTEST_WARNINGFLAGS) $(CPPUTEST_CXX_WARNINGFLAGS) -CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS) -CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE) -CPPUTEST_CPPFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE) -CPPUTEST_CFLAGS += $(CPPUTEST_C_WARNINGFLAGS) - -TARGET_MAP = $(COMPONENT_NAME).map.txt -ifeq ($(CPPUTEST_MAP_FILE), Y) - CPPUTEST_LDFLAGS += -Wl,-map,$(TARGET_MAP) -endif - -# Link with CppUTest lib -CPPUTEST_LIB = $(CPPUTEST_LIB_LINK_DIR)/libCppUTest.a - -ifeq ($(CPPUTEST_USE_EXTENSIONS), Y) -CPPUTEST_LIB += $(CPPUTEST_LIB_LINK_DIR)/libCppUTestExt.a -endif - -ifdef CPPUTEST_STATIC_REALTIME - LD_LIBRARIES += -lrt -endif - -TARGET_LIB = \ - $(CPPUTEST_LIB_DIR)/lib$(COMPONENT_NAME).a - -ifndef TEST_TARGET - ifndef TARGET_PLATFORM - TEST_TARGET = $(COMPONENT_NAME)_tests - else - TEST_TARGET = $(COMPONENT_NAME)_$(TARGET_PLATFORM)_tests - endif -endif - -#Helper Functions -get_src_from_dir = $(wildcard $1/*.cpp) $(wildcard $1/*.cc) $(wildcard $1/*.c) -get_dirs_from_dirspec = $(wildcard $1) -get_src_from_dir_list = $(foreach dir, $1, $(call get_src_from_dir,$(dir))) -__src_to = $(subst .c,$1, $(subst .cc,$1, $(subst .cpp,$1,$(if $(CPPUTEST_USE_VPATH),$(notdir $2),$2)))) -src_to = $(addprefix $(CPPUTEST_OBJS_DIR)/,$(call __src_to,$1,$2)) -src_to_o = $(call src_to,.o,$1) -src_to_d = $(call src_to,.d,$1) -src_to_gcda = $(call src_to,.gcda,$1) -src_to_gcno = $(call src_to,.gcno,$1) -time = $(shell date +%s) -delta_t = $(eval minus, $1, $2) -debug_print_list = $(foreach word,$1,echo " $(word)";) echo; - -#Derived -STUFF_TO_CLEAN += $(TEST_TARGET) $(TEST_TARGET).exe $(TARGET_LIB) $(TARGET_MAP) - -SRC += $(call get_src_from_dir_list, $(SRC_DIRS)) $(SRC_FILES) -OBJ = $(call src_to_o,$(SRC)) - -STUFF_TO_CLEAN += $(OBJ) - -TEST_SRC += $(call get_src_from_dir_list, $(TEST_SRC_DIRS)) $(TEST_SRC_FILES) -TEST_OBJS = $(call src_to_o,$(TEST_SRC)) -STUFF_TO_CLEAN += $(TEST_OBJS) - - -MOCKS_SRC += $(call get_src_from_dir_list, $(MOCKS_SRC_DIRS)) -MOCKS_OBJS = $(call src_to_o,$(MOCKS_SRC)) -STUFF_TO_CLEAN += $(MOCKS_OBJS) - -ALL_SRC = $(SRC) $(TEST_SRC) $(MOCKS_SRC) - -# If we're using VPATH -ifeq ($(CPPUTEST_USE_VPATH), Y) -# gather all the source directories and add them - VPATH += $(sort $(dir $(ALL_SRC))) -# Add the component name to the objs dir path, to differentiate between same-name objects - CPPUTEST_OBJS_DIR := $(addsuffix /$(COMPONENT_NAME),$(CPPUTEST_OBJS_DIR)) -endif - -#Test coverage with gcov -GCOV_OUTPUT = gcov_output.txt -GCOV_REPORT = gcov_report.txt -GCOV_ERROR = gcov_error.txt -GCOV_GCDA_FILES = $(call src_to_gcda, $(ALL_SRC)) -GCOV_GCNO_FILES = $(call src_to_gcno, $(ALL_SRC)) -TEST_OUTPUT = $(TEST_TARGET).txt -STUFF_TO_CLEAN += \ - $(GCOV_OUTPUT)\ - $(GCOV_REPORT)\ - $(GCOV_REPORT).html\ - $(GCOV_ERROR)\ - $(GCOV_GCDA_FILES)\ - $(GCOV_GCNO_FILES)\ - $(TEST_OUTPUT) - -#The gcda files for gcov need to be deleted before each run -#To avoid annoying messages. -GCOV_CLEAN = $(SILENCE)rm -f $(GCOV_GCDA_FILES) $(GCOV_OUTPUT) $(GCOV_REPORT) $(GCOV_ERROR) -RUN_TEST_TARGET = $(SILENCE) $(GCOV_CLEAN) ; echo "Running $(TEST_TARGET)"; ./$(TEST_TARGET) $(CPPUTEST_EXE_FLAGS) -ojunit - -ifeq ($(CPPUTEST_USE_GCOV), Y) - - ifeq ($(COMPILER_NAME),$(CLANG_STR)) - LD_LIBRARIES += --coverage - else - LD_LIBRARIES += -lgcov - endif -endif - - -INCLUDES_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(INCLUDE_DIRS)) -INCLUDES += $(foreach dir, $(INCLUDES_DIRS_EXPANDED), -I$(dir)) -MOCK_DIRS_EXPANDED = $(call get_dirs_from_dirspec, $(MOCKS_SRC_DIRS)) -INCLUDES += $(foreach dir, $(MOCK_DIRS_EXPANDED), -I$(dir)) - -CPPUTEST_CPPFLAGS += $(INCLUDES) $(CPPUTESTFLAGS) - -DEP_FILES = $(call src_to_d, $(ALL_SRC)) -STUFF_TO_CLEAN += $(DEP_FILES) $(PRODUCTION_CODE_START) $(PRODUCTION_CODE_END) -STUFF_TO_CLEAN += $(STDLIB_CODE_START) $(MAP_FILE) cpputest_*.xml junit_run_output - -# We'll use the CPPUTEST_CFLAGS etc so that you can override AND add to the CppUTest flags -CFLAGS = $(CPPUTEST_CFLAGS) $(CPPUTEST_ADDITIONAL_CFLAGS) -CPPFLAGS = $(CPPUTEST_CPPFLAGS) $(CPPUTEST_ADDITIONAL_CPPFLAGS) -CXXFLAGS = $(CPPUTEST_CXXFLAGS) $(CPPUTEST_ADDITIONAL_CXXFLAGS) -LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS) - -# Don't consider creating the archive a warning condition that does STDERR output -ARFLAGS := $(ARFLAGS)c - -DEP_FLAGS=-MMD -MP - -# Some macros for programs to be overridden. For some reason, these are not in Make defaults -RANLIB = ranlib - -# Targets - -.PHONY: all -all: start $(TEST_TARGET) - $(RUN_TEST_TARGET) - -.PHONY: start -start: $(TEST_TARGET) - $(SILENCE)START_TIME=$(call time) - -.PHONY: all_no_tests -all_no_tests: $(TEST_TARGET) - -.PHONY: flags -flags: - @echo - @echo "OS ${UNAME_OS}" - @echo "Compile C and C++ source with CPPFLAGS:" - @$(call debug_print_list,$(CPPFLAGS)) - @echo "Compile C++ source with CXXFLAGS:" - @$(call debug_print_list,$(CXXFLAGS)) - @echo "Compile C source with CFLAGS:" - @$(call debug_print_list,$(CFLAGS)) - @echo "Link with LDFLAGS:" - @$(call debug_print_list,$(LDFLAGS)) - @echo "Link with LD_LIBRARIES:" - @$(call debug_print_list,$(LD_LIBRARIES)) - @echo "Create libraries with ARFLAGS:" - @$(call debug_print_list,$(ARFLAGS)) - -TEST_DEPS = $(TEST_OBJS) $(MOCKS_OBJS) $(PRODUCTION_CODE_START) $(TARGET_LIB) $(USER_LIBS) $(PRODUCTION_CODE_END) $(CPPUTEST_LIB) $(STDLIB_CODE_START) -test-deps: $(TEST_DEPS) - -$(TEST_TARGET): $(TEST_DEPS) - @echo Linking $@ - $(SILENCE)$(CXX) -o $@ $^ $(LD_LIBRARIES) $(LDFLAGS) - -$(TARGET_LIB): $(OBJ) - @echo Building archive $@ - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(AR) $(ARFLAGS) $@ $^ - $(SILENCE)$(RANLIB) $@ - -test: $(TEST_TARGET) - $(RUN_TEST_TARGET) | tee $(TEST_OUTPUT) - -vtest: $(TEST_TARGET) - $(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT) - -$(CPPUTEST_OBJS_DIR)/%.o: %.cc - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.cpp - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.cpp) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -$(CPPUTEST_OBJS_DIR)/%.o: %.c - @echo compiling $(notdir $<) - $(SILENCE)mkdir -p $(dir $@) - $(SILENCE)$(COMPILE.c) $(DEP_FLAGS) $(OUTPUT_OPTION) $< - -ifneq "$(MAKECMDGOALS)" "clean" --include $(DEP_FILES) -endif - -.PHONY: clean -clean: - @echo Making clean - $(SILENCE)$(RM) $(STUFF_TO_CLEAN) - $(SILENCE)rm -rf gcov objs #$(CPPUTEST_OBJS_DIR) - $(SILENCE)rm -rf $(CPPUTEST_LIB_DIR) - $(SILENCE)find . -name "*.gcno" | xargs rm -f - $(SILENCE)find . -name "*.gcda" | xargs rm -f - -#realclean gets rid of all gcov, o and d files in the directory tree -#not just the ones made by this makefile -.PHONY: realclean -realclean: clean - $(SILENCE)rm -rf gcov - $(SILENCE)find . -name "*.gdcno" | xargs rm -f - $(SILENCE)find . -name "*.[do]" | xargs rm -f - -gcov: test -ifeq ($(CPPUTEST_USE_VPATH), Y) - $(SILENCE)gcov --object-directory $(CPPUTEST_OBJS_DIR) $(SRC) >> $(GCOV_OUTPUT) 2>> $(GCOV_ERROR) -else - $(SILENCE)for d in $(SRC_DIRS) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$d $$d/*.c $$d/*.cpp >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done - $(SILENCE)for f in $(SRC_FILES) ; do \ - gcov --object-directory $(CPPUTEST_OBJS_DIR)/$$f $$f >> $(GCOV_OUTPUT) 2>>$(GCOV_ERROR) ; \ - done -endif -# $(CPPUTEST_HOME)/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - /usr/share/cpputest/scripts/filterGcov.sh $(GCOV_OUTPUT) $(GCOV_ERROR) $(GCOV_REPORT) $(TEST_OUTPUT) - $(SILENCE)cat $(GCOV_REPORT) - $(SILENCE)mkdir -p gcov - $(SILENCE)mv *.gcov gcov - $(SILENCE)mv gcov_* gcov - @echo "See gcov directory for details" - -.PHONEY: format -format: - $(CPPUTEST_HOME)/scripts/reformat.sh $(PROJECT_HOME_DIR) - -.PHONEY: debug -debug: - @echo - @echo "Target Source files:" - @$(call debug_print_list,$(SRC)) - @echo "Target Object files:" - @$(call debug_print_list,$(OBJ)) - @echo "Test Source files:" - @$(call debug_print_list,$(TEST_SRC)) - @echo "Test Object files:" - @$(call debug_print_list,$(TEST_OBJS)) - @echo "Mock Source files:" - @$(call debug_print_list,$(MOCKS_SRC)) - @echo "Mock Object files:" - @$(call debug_print_list,$(MOCKS_OBJS)) - @echo "All Input Dependency files:" - @$(call debug_print_list,$(DEP_FILES)) - @echo Stuff to clean: - @$(call debug_print_list,$(STUFF_TO_CLEAN)) - @echo Includes: - @$(call debug_print_list,$(INCLUDES)) - --include $(OTHER_MAKEFILE_TO_INCLUDE) diff --git a/features/cellular/UNITTESTS/at/at_cellularbase/Makefile b/features/cellular/UNITTESTS/at/at_cellularbase/Makefile deleted file mode 100644 index 119b84aae9..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularbase/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularBase_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularBase.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularbasetest.cpp \ - test_at_cellularbase.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularbase/at_cellularbasetest.cpp b/features/cellular/UNITTESTS/at/at_cellularbase/at_cellularbasetest.cpp deleted file mode 100644 index 0c7ff37f60..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularbase/at_cellularbasetest.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularbase.h" -#include "AT_CellularBase.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularBase) -{ - Test_AT_CellularBase *unit; - - void setup() - { - unit = new Test_AT_CellularBase(); - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularBase, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularBase, test_AT_CellularBase_get_at_handler) -{ - unit->test_AT_CellularBase_get_at_handler(); -} - -TEST(AT_CellularBase, test_AT_CellularBase_get_device_error) -{ - unit->test_AT_CellularBase_get_device_error(); -} - -TEST(AT_CellularBase, test_AT_CellularBase_set_unsupported_features) -{ - unit->test_AT_CellularBase_set_unsupported_features(); -} - -TEST(AT_CellularBase, test_AT_CellularBase_is_supported) -{ - unit->test_AT_CellularBase_is_supported(); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularbase/main.cpp b/features/cellular/UNITTESTS/at/at_cellularbase/main.cpp deleted file mode 100644 index 2c5e6a6356..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularbase/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularBase); - diff --git a/features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.cpp b/features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.cpp deleted file mode 100644 index e69af7f28f..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularbase.h" -#include "EventQueue.h" -#include "AT_CellularBase.h" -#include "ATHandler_stub.h" -#include "FileHandle_stub.h" -#include - -using namespace mbed; -using namespace events; - -class my_base : public AT_CellularBase { -public: - my_base(ATHandler &at) : AT_CellularBase(at) - { - } - bool check_not_supported() - { - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK - }; - set_unsupported_features(unsupported_features); - return is_supported(AT_CGSN_WITH_TYPE); - } - - bool check_supported() - { - set_unsupported_features(NULL); - return is_supported(AT_CGSN_WITH_TYPE); - } - - bool check_supported_not_found() - { - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK - }; - set_unsupported_features(unsupported_features); - return is_supported(SUPPORTED_FEATURE_END_MARK); - } -}; - -Test_AT_CellularBase::Test_AT_CellularBase() -{ - -} - -Test_AT_CellularBase::~Test_AT_CellularBase() -{ -} - -void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 100, ","); - AT_CellularBase at(ah); - - CHECK(&ah == &at.get_at_handler()); -} - -void Test_AT_CellularBase::test_AT_CellularBase_get_device_error() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - AT_CellularBase at(ah); - - ATHandler_stub::device_err_value.errCode = 8; - - CHECK_EQUAL(8, at.get_device_error().errCode); - - ATHandler_stub::device_err_value.errCode = 0; -} - -void Test_AT_CellularBase::test_AT_CellularBase_set_unsupported_features() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - AT_CellularBase at(ah); - - static const AT_CellularBase::SupportedFeature unsupported_features[] = { - AT_CellularBase::AT_CGSN_WITH_TYPE, - AT_CellularBase::SUPPORTED_FEATURE_END_MARK - }; - - at.set_unsupported_features(unsupported_features); -} - -void Test_AT_CellularBase::test_AT_CellularBase_is_supported() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - my_base my_at(ah); - - CHECK(true == my_at.check_supported()); - CHECK(true == my_at.check_supported_not_found()); - CHECK(false == my_at.check_not_supported()); - -} diff --git a/features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.h b/features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.h deleted file mode 100644 index 57dab4ea2d..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularbase/test_at_cellularbase.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARBASE_H -#define TEST_AT_CELLULARBASE_H - -class Test_AT_CellularBase { -public: - Test_AT_CellularBase(); - - virtual ~Test_AT_CellularBase(); - - void test_AT_CellularBase_get_at_handler(); - - void test_AT_CellularBase_get_device_error(); - - void test_AT_CellularBase_set_unsupported_features(); - - void test_AT_CellularBase_is_supported(); -}; - -#endif // TEST_AT_CELLULARBASE_H - diff --git a/features/cellular/UNITTESTS/at/at_cellulardevice/Makefile b/features/cellular/UNITTESTS/at/at_cellulardevice/Makefile deleted file mode 100644 index cdc3e27799..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellulardevice/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularDevice_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularDevice.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellulardevicetest.cpp \ - test_at_cellulardevice.cpp \ - ../../stubs/AT_CellularNetwork_stub.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularSMS_stub.cpp \ - ../../stubs/AT_CellularSIM_stub.cpp \ - ../../stubs/AT_CellularPower_stub.cpp \ - ../../stubs/AT_CellularInformation_stub.cpp \ - ../../stubs/CellularUtil_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/NetworkInterface_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellulardevice/at_cellulardevicetest.cpp b/features/cellular/UNITTESTS/at/at_cellulardevice/at_cellulardevicetest.cpp deleted file mode 100644 index 8dae6677a0..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellulardevice/at_cellulardevicetest.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellulardevice.h" - -TEST_GROUP(AT_CellularDevice) -{ - Test_AT_CellularDevice *unit; - - void setup() { - unit = new Test_AT_CellularDevice(); - } - - void teardown() { - delete unit; - } -}; - -TEST(AT_CellularDevice, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_constructor) -{ - unit->test_AT_CellularDevice_constructor(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_get_at_handler) -{ - unit->test_AT_CellularDevice_get_at_handler(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_open_network) -{ - unit->test_AT_CellularDevice_open_network(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_open_sms) -{ - unit->test_AT_CellularDevice_open_sms(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_open_power) -{ - unit->test_AT_CellularDevice_open_power(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_open_sim) -{ - unit->test_AT_CellularDevice_open_sim(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_open_information) -{ - unit->test_AT_CellularDevice_open_information(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_close_network) -{ - unit->test_AT_CellularDevice_close_network(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_close_sms) -{ - unit->test_AT_CellularDevice_close_sms(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_close_power) -{ - unit->test_AT_CellularDevice_close_power(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_close_sim) -{ - unit->test_AT_CellularDevice_close_sim(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_close_information) -{ - unit->test_AT_CellularDevice_close_information(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_set_timeout) -{ - unit->test_AT_CellularDevice_set_timeout(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_modem_debug_on) -{ - unit->test_AT_CellularDevice_modem_debug_on(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_get_stack) -{ - unit->test_AT_CellularDevice_get_stack(); -} - -TEST(AT_CellularDevice, test_AT_CellularDevice_get_send_delay) -{ - unit->test_AT_CellularDevice_get_send_delay(); -} diff --git a/features/cellular/UNITTESTS/at/at_cellulardevice/main.cpp b/features/cellular/UNITTESTS/at/at_cellulardevice/main.cpp deleted file mode 100644 index 827f00e9d4..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellulardevice/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularDevice); - diff --git a/features/cellular/UNITTESTS/at/at_cellulardevice/test_at_cellulardevice.h b/features/cellular/UNITTESTS/at/at_cellulardevice/test_at_cellulardevice.h deleted file mode 100644 index 6bc72d20ad..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellulardevice/test_at_cellulardevice.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARDEVICE_H -#define TEST_AT_CELLULARDEVICE_H - -class Test_AT_CellularDevice { -public: - Test_AT_CellularDevice(); - - virtual ~Test_AT_CellularDevice(); - - void test_AT_CellularDevice_constructor(); - - void test_AT_CellularDevice_get_at_handler(); //tests also releasing of those - - void test_AT_CellularDevice_open_network(); - - void test_AT_CellularDevice_open_sms(); - - void test_AT_CellularDevice_open_power(); - - void test_AT_CellularDevice_open_sim(); - - void test_AT_CellularDevice_open_information(); - - void test_AT_CellularDevice_close_network(); - - void test_AT_CellularDevice_close_sms(); - - void test_AT_CellularDevice_close_power(); - - void test_AT_CellularDevice_close_sim(); - - void test_AT_CellularDevice_close_information(); - - void test_AT_CellularDevice_set_timeout(); - - void test_AT_CellularDevice_modem_debug_on(); - - void test_AT_CellularDevice_get_stack(); - - void test_AT_CellularDevice_get_send_delay(); -}; - -#endif // TEST_AT_CELLULARDEVICE_H - diff --git a/features/cellular/UNITTESTS/at/at_cellularinformation/Makefile b/features/cellular/UNITTESTS/at/at_cellularinformation/Makefile deleted file mode 100644 index cd74bc1b01..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularinformation/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularInformation_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularInformation.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularinformationtest.cpp \ - test_at_cellularinformation.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularinformation/at_cellularinformationtest.cpp b/features/cellular/UNITTESTS/at/at_cellularinformation/at_cellularinformationtest.cpp deleted file mode 100644 index 25581e69b1..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularinformation/at_cellularinformationtest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularinformation.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularInformation) -{ - Test_AT_CellularInformation *unit; - - void setup() - { - unit = new Test_AT_CellularInformation(); - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularInformation, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularInformation, test_AT_CellularInformation_get_manufacturer) -{ - unit->test_AT_CellularInformation_get_manufacturer(); -} - -TEST(AT_CellularInformation, test_AT_CellularInformation_get_model) -{ - unit->test_AT_CellularInformation_get_model(); -} - -TEST(AT_CellularInformation, test_AT_CellularInformation_get_revision) -{ - unit->test_AT_CellularInformation_get_revision(); -} - -TEST(AT_CellularInformation, test_AT_CellularInformation_get_serial_number) -{ - unit->test_AT_CellularInformation_get_serial_number(); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularinformation/main.cpp b/features/cellular/UNITTESTS/at/at_cellularinformation/main.cpp deleted file mode 100644 index bba3df884f..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularinformation/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularInformation); - diff --git a/features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.cpp b/features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.cpp deleted file mode 100644 index 221ee054f9..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularinformation.h" -#include -#include "ATHandler_stub.h" -#include "EventQueue.h" -#include "FileHandle_stub.h" -#include "AT_CellularBase_stub.h" -#include "ATHandler.h" -#include "AT_CellularInformation.h" -#include "AT_CellularBase.h" - -using namespace mbed; -using namespace events; - -Test_AT_CellularInformation::Test_AT_CellularInformation() -{ - -} - -Test_AT_CellularInformation::~Test_AT_CellularInformation() -{ -} - -void Test_AT_CellularInformation::test_AT_CellularInformation_get_manufacturer() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - AT_CellularInformation aci(ah); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "some"; - ATHandler_stub::ssize_value = 4; - - char buf[8]; - CHECK(NSAPI_ERROR_OK == aci.get_manufacturer(buf, 8)); - CHECK(strcmp("some", buf) == 0); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::ssize_value = -1; - buf[0] = 0; - CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8)); - CHECK(strlen(buf) == 0); -} - -void Test_AT_CellularInformation::test_AT_CellularInformation_get_model() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - AT_CellularInformation aci(ah); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "model"; - ATHandler_stub::ssize_value = 5; - char buf[8]; - CHECK(NSAPI_ERROR_OK == aci.get_model(buf, 8)); - CHECK(strcmp("model", buf) == 0); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::ssize_value = -1; - buf[0] = 0; - CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8)); - CHECK(strlen(buf) == 0); -} - -void Test_AT_CellularInformation::test_AT_CellularInformation_get_revision() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - - //Used heap var here to visit heap constructor - AT_CellularInformation *aci = new AT_CellularInformation(ah); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "revision"; - ATHandler_stub::ssize_value = 8; - - char buf[9]; - CHECK(NSAPI_ERROR_OK == aci->get_revision(buf, 9)); - CHECK(strcmp("revision", buf) == 0); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::ssize_value = -1; - buf[0] = 0; - CHECK(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8)); - CHECK(strlen(buf) == 0); - - delete aci; -} - -void Test_AT_CellularInformation::test_AT_CellularInformation_get_serial_number() -{ - EventQueue eq; - FileHandle_stub fh; - ATHandler ah(&fh, eq, 0, ","); - AT_CellularInformation aci(ah); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "1234567"; - ATHandler_stub::ssize_value = 7; - char buf[8]; - - CHECK(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::SN)); - CHECK(strcmp("1234567", buf) == 0); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::ssize_value = -1; - buf[0] = 0; - CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_serial_number(buf, 8, CellularInformation::SN)); - CHECK(strlen(buf) == 0); - - AT_CellularBase_stub::supported_bool = false; - CHECK(NSAPI_ERROR_UNSUPPORTED == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); - CHECK(strlen(buf) == 0); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "1234567"; - ATHandler_stub::ssize_value = 7; - AT_CellularBase_stub::supported_bool = true; - CHECK(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); - CHECK(strcmp("1234567", buf) == 0); -} - diff --git a/features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.h b/features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.h deleted file mode 100644 index 64fabbb4d5..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularinformation/test_at_cellularinformation.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARINFORMATION_H -#define TEST_AT_CELLULARINFORMATION_H - -class Test_AT_CellularInformation { -public: - Test_AT_CellularInformation(); - - virtual ~Test_AT_CellularInformation(); - - void test_AT_CellularInformation_get_manufacturer(); - - void test_AT_CellularInformation_get_model(); - - void test_AT_CellularInformation_get_revision(); - - void test_AT_CellularInformation_get_serial_number(); -}; - -#endif // TEST_AT_CELLULARINFORMATION_H - diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/Makefile b/features/cellular/UNITTESTS/at/at_cellularnetwork/Makefile deleted file mode 100644 index f834d5787f..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularNetwork_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularNetwork.cpp \ - ../../../framework/AT/AT_CellularStack.cpp \ - ../../../framework/common/CellularUtil.cpp \ - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularnetworktest.cpp \ - test_at_cellularnetwork.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/NetworkInterface_stub.cpp \ - ../../stubs/NetworkStack_stub.cpp \ - ../../stubs/us_ticker_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - ../../stubs/SocketAddress_stub.cpp \ - ../../stubs/randLIB_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp b/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp deleted file mode 100644 index 538c527544..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/at_cellularnetworktest.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularnetwork.h" -#include "ATHandler_stub.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularNetwork) -{ - Test_AT_CellularNetwork *unit; - - void setup() - { - unit = new Test_AT_CellularNetwork(); - ATHandler_stub::int_count = kRead_int_table_size; - ATHandler_stub::read_string_index = kRead_string_table_size; - ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularNetwork, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_constructor) -{ - unit->test_AT_CellularNetwork_constructor(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_init) -{ - unit->test_AT_CellularNetwork_init(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_credentials) -{ - unit->test_AT_CellularNetwork_set_credentials(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_activate_context) -{ - unit->test_AT_CellularNetwork_activate_context(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_connect) -{ - unit->test_AT_CellularNetwork_connect(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_disconnect) -{ - unit->test_AT_CellularNetwork_disconnect(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_stack) -{ - unit->test_AT_CellularNetwork_get_stack(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_registration) -{ - unit->test_AT_CellularNetwork_set_registration(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_registration_status) -{ - unit->test_AT_CellularNetwork_get_registration_status(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_network_registering_mode) -{ - unit->test_AT_CellularNetwork_get_network_registering_mode(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_registration_urc) -{ - unit->test_AT_CellularNetwork_set_registration_urc(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_attach) -{ - unit->test_AT_CellularNetwork_set_attach(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_attach) -{ - unit->test_AT_CellularNetwork_get_attach(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_detach) -{ - unit->test_AT_CellularNetwork_detach(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_rate_control) -{ - unit->test_AT_CellularNetwork_get_rate_control(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_apn_backoff_timer) -{ - unit->test_AT_CellularNetwork_get_apn_backoff_timer(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_ip_address) -{ - unit->test_AT_CellularNetwork_get_ip_address(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_access_technology) -{ - unit->test_AT_CellularNetwork_set_access_technology(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_access_technology) -{ - unit->test_AT_CellularNetwork_get_access_technology(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_scan_plmn) -{ - unit->test_AT_CellularNetwork_scan_plmn(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_ciot_optimization_config) -{ - unit->test_AT_CellularNetwork_set_ciot_optimization_config(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_ciot_optimization_config) -{ - unit->test_AT_CellularNetwork_get_ciot_optimization_config(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_set_stack_type) -{ - unit->test_AT_CellularNetwork_set_stack_type(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_stack_type) -{ - unit->test_AT_CellularNetwork_get_stack_type(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_pdpcontext_params) -{ - unit->test_AT_CellularNetwork_get_pdpcontext_params(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_extended_signal_quality) -{ - unit->test_AT_CellularNetwork_get_extended_signal_quality(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_signal_quality) -{ - unit->test_AT_CellularNetwork_get_signal_quality(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_cell_id) -{ - unit->test_AT_CellularNetwork_get_cell_id(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_3gpp_error) -{ - unit->test_AT_CellularNetwork_get_3gpp_error(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_operator_params) -{ - unit->test_AT_CellularNetwork_get_operator_params(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_get_operator_names) -{ - unit->test_AT_CellularNetwork_get_operator_names(); -} - -TEST(AT_CellularNetwork, test_AT_CellularNetwork_attach) -{ - unit->test_AT_CellularNetwork_attach(); -} - -TEST(AT_CellularNetwork, test_get_connection_status) -{ - unit->test_get_connection_status(); -} - -TEST(AT_CellularNetwork, test_set_blocking) -{ - unit->test_set_blocking(); -} - diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/main.cpp b/features/cellular/UNITTESTS/at/at_cellularnetwork/main.cpp deleted file mode 100644 index aec2c257bd..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularNetwork); - diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp b/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp deleted file mode 100644 index 4dd3bbd2af..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.cpp +++ /dev/null @@ -1,1160 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularnetwork.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularDevice.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" -#include "ATHandler_stub.h" -#include "AT_CellularStack.h" - -using namespace mbed; -using namespace events; - -class my_stack : public AT_CellularStack { -public: - my_stack(ATHandler &atHandler) : AT_CellularStack(atHandler, 1, IPV4_STACK) {} - virtual int get_max_socket_count() - { - return 1; - } - virtual int get_max_packet_size() - { - return 200; - } - virtual bool is_protocol_supported(nsapi_protocol_t protocol) - { - return true; - } - virtual nsapi_error_t socket_close_impl(int sock_id) - { - return NSAPI_ERROR_OK; - } - virtual nsapi_error_t create_socket_impl(CellularSocket *socket) - { - return NSAPI_ERROR_OK; - } - virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, - const void *data, nsapi_size_t size) - { - return 100; - } - virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, - void *buffer, nsapi_size_t size) - { - return 100; - } -}; - -class my_AT_CN : public AT_CellularNetwork { -public: - my_AT_CN(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {} - virtual ~my_AT_CN() {} - NetworkStack *get_stack() - { - if (!_stack) { - return new my_stack(get_at_handler()); - } else { - return _stack; - } - } - virtual AT_CellularNetwork::RegistrationMode has_registration(RegistrationType reg_type) - { - if (reg_type == C_GREG) { - return RegistrationModeDisable; - } - return RegistrationModeLAC; - } - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat) - { - return NSAPI_ERROR_OK; - } - virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack) - { - if (requested_stack == IPV4_STACK || requested_stack == DEFAULT_STACK) { - return true; - } - return false; - } -}; - -class my_AT_CNipv6 : public AT_CellularNetwork { -public: - my_AT_CNipv6(ATHandler &atHandler) : AT_CellularNetwork(atHandler) {} - virtual ~my_AT_CNipv6() {} - NetworkStack *get_stack() - { - if (!_stack) { - return new my_stack(get_at_handler()); - } else { - return _stack; - } - } - virtual AT_CellularNetwork::RegistrationMode has_registration(RegistrationType reg_type) - { - if (reg_type == C_GREG) { - return RegistrationModeDisable; - } - return RegistrationModeLAC; - } - virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat) - { - return NSAPI_ERROR_OK; - } - virtual bool get_modem_stack_type(nsapi_ip_stack_t requested_stack) - { - if (requested_stack == IPV6_STACK || requested_stack == DEFAULT_STACK) { - return true; - } - return false; - } -}; - -static int network_cb_count; -static void network_cb(nsapi_event_t ev, intptr_t intptr) -{ - network_cb_count++; -} - -Test_AT_CellularNetwork::Test_AT_CellularNetwork() -{ - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::int_value = -1; -} - -Test_AT_CellularNetwork::~Test_AT_CellularNetwork() -{ -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_constructor() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork *cn = new AT_CellularNetwork(at); - - delete cn; -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_init() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - AT_CellularNetwork cn(at); - - CHECK(NSAPI_ERROR_OK == cn.init()); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_NO_MEMORY; - CHECK(NSAPI_ERROR_NO_MEMORY == cn.init()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_credentials() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn")); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, NULL)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, NULL, NULL)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, NULL, "passwd")); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", NULL)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user")); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", NULL)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", NULL, NULL)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", NULL, "passwd")); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", "user", NULL)); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", "user")); - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", "user", "passwd")); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_activate_context() -{ - - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - my_AT_CN my_cn(at); - my_AT_CNipv6 my_cnipv6(at); - - // get_context return true and new context created. But now stack and so error. - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); - - // get_context return true and new context created, also do_user_authentication called with success. - // But now stack and so error. - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); - - // get_context return true and new context created, also do_user_authentication called with failure. - ATHandler_stub::resp_stop_success_count = 2; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_OK == cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); - CHECK(NSAPI_ERROR_AUTH_FAILURE == cn.activate_context()); - - - // get_context return true and new context created, also do_user_authentication called with success. - // Now there is stack. - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); - CHECK(NSAPI_ERROR_OK == my_cn.activate_context()); - - // get_context return true and new context created, test delete context - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::resp_stop_success_count = kResp_stop_count_default; - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); - CHECK(NSAPI_ERROR_OK == my_cn.activate_context()); - - - - // get_context pdp type gives zero len, fails with no stack - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = ""; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.activate_context()); - - // get_context pdp type gives proper type, apn reading fails - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "IPV6"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_NO_CONNECTION == cn.activate_context()); - - // get_context pdp type gives proper type, apn does not match, now other contexts so new one created - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IP"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials("apn", CellularNetwork::CHAP, "user", "passwd")); - CHECK(NSAPI_ERROR_OK == my_cn.activate_context()); - - // get_context pdp type gives proper type, apn match - ATHandler_stub::resp_info_true_counter = 2; // set to 2 so cgact will give that this context is active - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV4V6"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cn.set_stack_type(IPV4_STACK)); - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); - CHECK(NSAPI_ERROR_OK == my_cn.activate_context()); - - // get_context pdp type gives proper type, apn match - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV6"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(IPV6_STACK)); - CHECK(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); - CHECK(NSAPI_ERROR_OK == my_cnipv6.activate_context()); - - // get_context pdp type gives proper type, apn match - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV4V6"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cn.set_stack_type(DEFAULT_STACK)); - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); - CHECK(NSAPI_ERROR_OK == my_cn.activate_context()); - - // get_context pdp type gives proper type, apn match - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV4V6"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(DEFAULT_STACK)); - CHECK(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); - CHECK(NSAPI_ERROR_OK == my_cnipv6.activate_context()); - - // get_context pdp type gives proper type, apn match - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IPV6"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cnipv6.set_stack_type(DEFAULT_STACK)); - CHECK(NSAPI_ERROR_OK == my_cnipv6.set_credentials("internet")); - CHECK(NSAPI_ERROR_OK == my_cnipv6.activate_context()); - - // get_context pdp type gives proper type, apn match - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[0] = "internet"; - ATHandler_stub::read_string_table[1] = "IP"; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == my_cn.set_stack_type(DEFAULT_STACK)); - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials("internet")); - CHECK(NSAPI_ERROR_OK == my_cn.activate_context()); - - // get_context pdp type gives proper type, apn match. Test Delete the created context. - ATHandler_stub::resp_info_true_counter = 0; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::int_value = 1; - //ATHandler_stub::nsapi_error_ok_counter = 2; - ATHandler_stub::resp_stop_success_count = 2; - CHECK(NSAPI_ERROR_OK == my_cn.set_credentials(NULL, NULL, NULL)); - CHECK(NSAPI_ERROR_NO_CONNECTION == my_cn.activate_context()); - -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_connect() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - // no stack so will fail - cn.attach(&network_cb); - network_cb_count = 0; - - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.connect("APN", "a", "b")); - CHECK(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); - CHECK(network_cb_count == 2); - - network_cb_count = 0; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_NO_CONNECTION == cn.connect("APN")); - CHECK(network_cb_count == 2); - CHECK(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); - - my_AT_CN my_cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - cn.set_stack_type(IPV4_STACK); - CHECK(NSAPI_ERROR_OK == my_cn.connect()); - CHECK(network_cb_count == 2); - CHECK(NSAPI_STATUS_GLOBAL_UP == my_cn.get_connection_status()); - -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_disconnect() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CHECK(NSAPI_ERROR_OK == cn.disconnect()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_stack() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - my_AT_CN my_cn(at); - my_stack *mystack = (my_stack *)my_cn.get_stack(); - CHECK(mystack); - delete mystack; -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_registration() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.set_registration()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration("12345")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.set_registration("12345")); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_registration_status() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::int_value = 3; - CellularNetwork::RegistrationStatus stat = CellularNetwork::NotRegistered; - CHECK(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_EREG, stat)); - CHECK(stat == CellularNetwork::RegistrationDenied); - stat = CellularNetwork::NotRegistered; - CHECK(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_GREG, stat)); - CHECK(stat == CellularNetwork::RegistrationDenied); - - my_AT_CN nw(at); - stat = CellularNetwork::NotRegistered; - CHECK(NSAPI_ERROR_UNSUPPORTED == nw.get_registration_status(CellularNetwork::C_GREG, stat)); - CHECK(stat == CellularNetwork::NotRegistered); - CHECK(NSAPI_ERROR_OK == nw.get_registration_status(CellularNetwork::C_EREG, stat)); - CHECK(stat == CellularNetwork::RegistrationDenied); - - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - stat = CellularNetwork::NotRegistered; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_status(CellularNetwork::C_EREG, stat)); - CHECK(stat == -1); - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_registration_status(CellularNetwork::C_GREG, stat)); - CHECK(stat == -1); - - stat = CellularNetwork::NotRegistered; - CHECK(NSAPI_ERROR_UNSUPPORTED == nw.get_registration_status(CellularNetwork::C_GREG, stat)); - CHECK(stat == CellularNetwork::NotRegistered); - CHECK(NSAPI_ERROR_DEVICE_ERROR == nw.get_registration_status(CellularNetwork::C_EREG, stat)); - CHECK(stat == -1); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_network_registering_mode() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - - ATHandler_stub::int_value = 0; - CellularNetwork::NWRegisteringMode mode = CellularNetwork::NWModeManual; - CHECK(NSAPI_ERROR_OK == cn.get_network_registering_mode(mode)); - CHECK(mode == CellularNetwork::NWModeAutomatic); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - mode = CellularNetwork::NWModeManual; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_network_registering_mode(mode)); - CHECK(mode == -1); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_registration_urc() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - - CellularNetwork::RegistrationType type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_OK == cn.set_registration_urc(type, true)); - - my_AT_CN nw(at); - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_OK == nw.set_registration_urc(type, true)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, true)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_OK == nw.set_registration_urc(type, true)); - - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_OK == cn.set_registration_urc(type, false)); - - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_OK == nw.set_registration_urc(type, false)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, false)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_OK == nw.set_registration_urc(type, false)); - - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, true)); - - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, true)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, true)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, true)); - - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_registration_urc(type, false)); - - type = CellularNetwork::C_EREG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, false)); - type = CellularNetwork::C_GREG; - CHECK(NSAPI_ERROR_UNSUPPORTED == nw.set_registration_urc(type, false)); - type = CellularNetwork::C_REG; - CHECK(NSAPI_ERROR_DEVICE_ERROR == nw.set_registration_urc(type, false)); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_attach() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::int_value = 0; - CHECK(NSAPI_ERROR_OK == cn.set_attach()); - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == cn.set_attach()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_attach()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_attach() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CellularNetwork::AttachStatus stat = CellularNetwork::Detached; - ATHandler_stub::int_value = 1; - ATHandler_stub::bool_value = true; - CHECK(NSAPI_ERROR_OK == cn.get_attach(stat)); - CHECK(stat == CellularNetwork::Attached); - - ATHandler_stub::int_value = 0; - CHECK(NSAPI_ERROR_OK == cn.get_attach(stat)); - CHECK(stat == CellularNetwork::Detached); - - stat = CellularNetwork::Attached; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_attach(stat)); - CHECK(stat == CellularNetwork::Detached); - - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_OK == cn.get_attach(stat)); - CHECK(stat == CellularNetwork::Detached); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_attach(stat)); - CHECK(stat == CellularNetwork::Detached); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_detach() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - my_AT_CN cn(at); - - CHECK(NSAPI_ERROR_OK == cn.detach()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.detach()); - - // connect so we can test callback in detach - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - cn.set_stack_type(IPV4_STACK); - CHECK(NSAPI_ERROR_OK == cn.connect()); - CHECK(NSAPI_STATUS_GLOBAL_UP == cn.get_connection_status()); - // attach callback - cn.attach(&network_cb); - network_cb_count = 0; - CHECK(NSAPI_ERROR_OK == cn.detach()); - CHECK(network_cb_count == 1); - CHECK(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_rate_control() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - int ur = -1; - CellularNetwork::RateControlExceptionReports reports = CellularNetwork::NotAllowedToBeSent; - CellularNetwork::RateControlUplinkTimeUnit timeUnit = CellularNetwork::Unrestricted; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); - CHECK(reports == CellularNetwork::NotAllowedToBeSent); - CHECK(timeUnit == CellularNetwork::Unrestricted); - CHECK(ur == -1); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::int_value = 1; - CHECK(NSAPI_ERROR_OK == cn.get_rate_control(reports, timeUnit, ur)); - CHECK(reports == CellularNetwork::AllowedToBeSent); - CHECK(timeUnit == CellularNetwork::Minute); - CHECK(ur == 1); - - // test second if in get_rate_control - reports = CellularNetwork::NotAllowedToBeSent; - timeUnit = CellularNetwork::Unrestricted; - ur = -1; - - ATHandler_stub::int_count = 1; - ATHandler_stub::int_valid_count_table[0] = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); - CHECK(reports == CellularNetwork::NotAllowedToBeSent); - CHECK(timeUnit == CellularNetwork::Unrestricted); - CHECK(ur == -1); - - // test second if in get_rate_control - ATHandler_stub::int_count = 2; - ATHandler_stub::int_valid_count_table[0] = 1; - ATHandler_stub::int_valid_count_table[1] = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); - CHECK(reports == CellularNetwork::AllowedToBeSent); - CHECK(timeUnit == CellularNetwork::Unrestricted); - CHECK(ur == -1); - - // test third if in get_rate_control - ATHandler_stub::int_count = 3; - ATHandler_stub::int_valid_count_table[0] = 3; - ATHandler_stub::int_valid_count_table[1] = 1; - ATHandler_stub::int_valid_count_table[2] = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_rate_control(reports, timeUnit, ur)); - CHECK(reports == CellularNetwork::AllowedToBeSent); - CHECK(timeUnit == CellularNetwork::Day); - CHECK(ur == -1); - - ATHandler_stub::int_count = 4; - ATHandler_stub::int_valid_count_table[0] = 5; - ATHandler_stub::int_valid_count_table[1] = 3; - ATHandler_stub::int_valid_count_table[2] = 1; - ATHandler_stub::int_valid_count_table[3] = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.get_rate_control(reports, timeUnit, ur)); - CHECK(reports == CellularNetwork::AllowedToBeSent); - CHECK(timeUnit == CellularNetwork::Day); - CHECK(ur == 5); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_apn_backoff_timer() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - int time = -1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_PARAMETER == cn.get_apn_backoff_timer(time)); - CHECK(time == -1); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_PARAMETER == cn.get_apn_backoff_timer(time)); - CHECK(time == -1); - - ATHandler_stub::resp_info_true_counter = 0; - ATHandler_stub::bool_value = false; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - cn.set_credentials("internet", NULL, NULL); - CHECK(NSAPI_ERROR_OK == cn.get_apn_backoff_timer(time)); - CHECK(time == -1); - - ATHandler_stub::resp_info_true_counter = 0; - ATHandler_stub::bool_value = true; - ATHandler_stub::int_value = 55; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - cn.set_credentials("internet", NULL, NULL); - CHECK(NSAPI_ERROR_OK == cn.get_apn_backoff_timer(time)); - CHECK(time == 55); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_ip_address() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CHECK(!cn.get_ip_address()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_access_technology() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_UNKNOWN)); - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_GSM_COMPACT)); - - my_AT_CN my_cn(at); - CHECK(NSAPI_ERROR_OK == my_cn.set_access_technology(CellularNetwork::RAT_GSM_COMPACT)); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_access_technology() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CellularNetwork::RadioAccessTechnology rat; - - CHECK(NSAPI_ERROR_OK == cn.get_access_technology(rat)); - CHECK(CellularNetwork::RAT_UNKNOWN == rat); -} - - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_scan_plmn() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - int c = -1; - CellularNetwork::operList_t ops; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.scan_plmn(ops, c)); - CHECK(c == 0); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); - CHECK(c == 0); - - - ATHandler_stub::read_string_index = 3; - ATHandler_stub::read_string_table[0] = "44444"; - ATHandler_stub::read_string_table[1] = "33333"; - ATHandler_stub::read_string_table[2] = "12345"; - ATHandler_stub::int_value = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::info_elem_true_counter = 1; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); - CHECK(c == 1); - CHECK(ops.get_head() != NULL); - CellularNetwork::operator_t *op = ops.get_head(); - CHECK(op->op_status == CellularNetwork::operator_t::Available); - CHECK(strcmp(op->op_long, "12345") == 0); - CHECK(strcmp(op->op_short, "33333") == 0); - CHECK(strcmp(op->op_num, "44444") == 0); - ops.delete_all(); - - ATHandler_stub::read_string_index = 3; - ATHandler_stub::int_value = 6; // RAT_HSDPA_HSUPA - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::info_elem_true_counter = 1; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.set_access_technology(CellularNetwork::RAT_UTRAN)); - CHECK(NSAPI_ERROR_OK == cn.scan_plmn(ops, c)); - CHECK(c == 0); - CHECK(ops.get_head() == NULL); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_ciot_optimization_config() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.set_ciot_optimization_config(CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT, CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE)); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_ciot_optimization_config() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CellularNetwork::Supported_UE_Opt sup = CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT; - CellularNetwork::Preferred_UE_Opt pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; - ATHandler_stub::int_value = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.get_ciot_optimization_config(sup, pref)); - CHECK(sup == CellularNetwork::SUPPORTED_UE_OPT_CONTROL_PLANE); - CHECK(pref == CellularNetwork::PREFERRED_UE_OPT_CONTROL_PLANE); - - sup = CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT; - pref = CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE; - ATHandler_stub::int_value = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_ciot_optimization_config(sup, pref)); - CHECK(sup == CellularNetwork::SUPPORTED_UE_OPT_NO_SUPPORT); - CHECK(pref == CellularNetwork::PREFERRED_UE_OPT_NO_PREFERENCE); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_set_stack_type() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CHECK(NSAPI_ERROR_PARAMETER == cn.set_stack_type(IPV4_STACK)); - - CHECK(NSAPI_ERROR_OK == cn.set_stack_type(DEFAULT_STACK)); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_stack_type() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CHECK(DEFAULT_STACK == cn.get_stack_type()); - - my_AT_CN my_cn(at); - CHECK(DEFAULT_STACK == my_cn.get_stack_type()); - CHECK(NSAPI_ERROR_OK == my_cn.set_stack_type(IPV4_STACK)); - CHECK(DEFAULT_STACK == my_cn.get_stack_type()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_pdpcontext_params() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CellularNetwork::pdpContextList_t list; - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_pdpcontext_params(list)); - - // don't got to while loop - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - ATHandler_stub::resp_info_true_counter = 0; - CHECK(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list)); - CHECK(NULL == list.get_head()); - - // go to while loop and check values - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::int_count = 9; - ATHandler_stub::int_valid_count_table[8] = 1; - ATHandler_stub::int_valid_count_table[7] = 2; - ATHandler_stub::int_valid_count_table[6] = 3; - ATHandler_stub::int_valid_count_table[5] = 4; - ATHandler_stub::int_valid_count_table[4] = 5; - ATHandler_stub::int_valid_count_table[3] = 6; - ATHandler_stub::int_valid_count_table[2] = 7; - ATHandler_stub::int_valid_count_table[1] = 8; - ATHandler_stub::int_valid_count_table[0] = 9; - - ATHandler_stub::read_string_index = 7; - ATHandler_stub::read_string_table[6] = "internet"; - ATHandler_stub::read_string_table[5] = "1.2.3.4.5.6.7.8.9.10.11.112.13.14.15.16.1.2.3.44.55.6.7.8.9.10.11.12.13.14.15.16"; - ATHandler_stub::read_string_table[4] = "23.33.44.1.2.3.55.123.225.34.11.1.0.0.123.234"; - ATHandler_stub::read_string_table[3] = "1.2.3.4"; - ATHandler_stub::read_string_table[2] = "0.255.0.255"; - ATHandler_stub::read_string_table[1] = "25.66.77.88"; - ATHandler_stub::read_string_table[0] = "004.003.002.001"; - - CHECK(NSAPI_ERROR_OK == cn.get_pdpcontext_params(list)); - CellularNetwork::pdpcontext_params_t *params = list.get_head(); - CHECK(params != NULL); - CHECK(params->next == NULL); - CHECK(params->cid == 1); - CHECK(params->bearer_id == 2); - CHECK(params->im_signalling_flag == 3); - CHECK(params->lipa_indication == 4); - CHECK(params->ipv4_mtu == 5); - CHECK(params->wlan_offload == 6); - CHECK(params->local_addr_ind == 7); - CHECK(params->non_ip_mtu == 8); - CHECK(params->serving_plmn_rate_control_value == 9); - CHECK(strcmp(params->apn, "internet") == 0); - CHECK(strcmp(params->local_addr, "102:304:506:708:90A:B70:D0E:F10") == 0); - CHECK(strcmp(params->local_subnet_mask, "102:32C:3706:708:90A:B0C:D0E:F10") == 0); - CHECK(strcmp(params->gateway_addr, "1721:2C01:203:377B:E122:B01:000:7BEA") == 0); - CHECK(strcmp(params->dns_primary_addr, "1.2.3.4") == 0); - CHECK(strcmp(params->dns_secondary_addr, "0.255.0.255") == 0); - CHECK(strcmp(params->p_cscf_prim_addr, "25.66.77.88") == 0); - CHECK(strcmp(params->p_cscf_sec_addr, "004.003.002.001") == 0); - -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_extended_signal_quality() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - int rx = -1, be = -1, rs = -1, ec = -1, rsrq = -1, rsrp = -1; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_extended_signal_quality(rx, be, rs, ec, rsrq, rsrp)); - CHECK(rx == -1 && be == -1 && rs == -1 && ec == -1 && rsrq == -1 && rsrp == -1); - - ATHandler_stub::int_value = 5; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.get_extended_signal_quality(rx, be, rs, ec, rsrq, rsrp)); - CHECK(rx == 5 && be == 5 && rs == 5 && ec == 5 && rsrq == 5 && rsrp == 5); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_signal_quality() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - int rs = -1, ber = -1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_signal_quality(rs, ber)); - CHECK(rs == -1 && ber == -1); - - ATHandler_stub::int_value = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.get_signal_quality(rs, ber)); - CHECK(rs == 1 && ber == 1); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_cell_id() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - int id = 0; - CHECK(NSAPI_ERROR_OK == cn.get_cell_id(id)); - CHECK(id == -1); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_OK == cn.get_cell_id(id)); - CHECK(id == -1); - - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[1] = "00C3"; - ATHandler_stub::read_string_table[0] = "1234FFC1"; //== cellid and in dec: 305463233 - ATHandler_stub::int_value = 1; - // Get registration status to modify cell_id - CellularNetwork::RegistrationType type; - CellularNetwork::RegistrationStatus status; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.get_registration_status(CellularNetwork::C_EREG, status)); - CHECK(NSAPI_ERROR_OK == cn.get_cell_id(id)); - CHECK(id == 305463233); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_3gpp_error() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::int_value = 8; - CHECK(8 == cn.get_3gpp_error()); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_operator_params() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - int format; - CellularNetwork::operator_t ops; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_operator_params(format, ops)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::int_value = 0; - ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "12345"; - CHECK(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); - CHECK(format == 0); - CHECK(strcmp(ops.op_long, "12345") == 0); - CHECK(strlen(ops.op_short) == 0); - CHECK(strlen(ops.op_num) == 0); - CHECK(ops.op_rat == CellularNetwork::RAT_GSM); - - ops.op_long[0] = 0; - ATHandler_stub::int_value = 1; - ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "12345"; - CHECK(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); - CHECK(format == 1); - CHECK(strlen(ops.op_long) == 0); - CHECK(strcmp(ops.op_short, "12345") == 0); - CHECK(strlen(ops.op_num) == 0); - CHECK(ops.op_rat == CellularNetwork::RAT_GSM_COMPACT); - - ops.op_short[0] = 0; - ATHandler_stub::int_value = 2; - ATHandler_stub::read_string_index = 1; - ATHandler_stub::read_string_table[0] = "12345"; - CHECK(NSAPI_ERROR_OK == cn.get_operator_params(format, ops)); - CHECK(format == 2); - CHECK(strlen(ops.op_long) == 0); - CHECK(strlen(ops.op_short) == 0); - CHECK(strcmp(ops.op_num, "12345") == 0); - CHECK(ops.op_rat == CellularNetwork::RAT_UTRAN); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_get_operator_names() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - CellularNetwork::operator_names_list name_list; - - ATHandler_stub::resp_info_true_counter = 0; - ATHandler_stub::bool_value = false; - CHECK(NSAPI_ERROR_OK == cn.get_operator_names(name_list)); - CHECK(name_list.get_head() == NULL); - - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == cn.get_operator_names(name_list)); - CHECK(name_list.get_head() != NULL); - CHECK(name_list.get_head()->next == NULL); - - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_index = 2; - ATHandler_stub::read_string_table[1] = "12345"; - ATHandler_stub::read_string_table[0] = "56789"; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - name_list.delete_all(); - CHECK(NSAPI_ERROR_OK == cn.get_operator_names(name_list)); - CellularNetwork::operator_names_t *op_names = name_list.get_head(); - CHECK(op_names != NULL); - CHECK(op_names->next == NULL); - CHECK(strcmp(op_names->numeric, "12345") == 0); - CHECK(strcmp(op_names->alpha, "56789") == 0); -} - -void Test_AT_CellularNetwork::test_AT_CellularNetwork_attach() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - network_cb_count = 0; - cn.attach(&network_cb); - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.connect()); - CHECK(network_cb_count == 2); // check that attached callback was called twice -} - -void Test_AT_CellularNetwork::test_get_connection_status() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - network_cb_count = 0; - cn.attach(&network_cb); - CHECK(NSAPI_ERROR_UNSUPPORTED == cn.connect()); - CHECK(network_cb_count == 2); // check that attached callback was called twice - CHECK(NSAPI_STATUS_DISCONNECTED == cn.get_connection_status()); - - my_AT_CN my_cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::bool_value = false; - cn.set_stack_type(IPV4_STACK); - CHECK(NSAPI_ERROR_OK == my_cn.connect()); - CHECK(network_cb_count == 2); - CHECK(NSAPI_STATUS_GLOBAL_UP == my_cn.get_connection_status()); -} - -void Test_AT_CellularNetwork::test_set_blocking() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularNetwork cn(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == cn.set_blocking(false)); - CHECK(NSAPI_ERROR_OK == cn.set_blocking(true)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_OK == cn.set_blocking(false)); - CHECK(NSAPI_ERROR_OK == cn.set_blocking(true)); -} - diff --git a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h b/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h deleted file mode 100644 index 2327a30979..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularnetwork/test_at_cellularnetwork.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARNETWORK_H -#define TEST_AT_CELLULARNETWORK_H - -class Test_AT_CellularNetwork { -public: - Test_AT_CellularNetwork(); - - virtual ~Test_AT_CellularNetwork(); - - void test_AT_CellularNetwork_constructor(); - - void test_AT_CellularNetwork_init(); - - void test_AT_CellularNetwork_set_credentials(); - - void test_AT_CellularNetwork_activate_context(); - - void test_AT_CellularNetwork_connect(); - - void test_AT_CellularNetwork_disconnect(); - - void test_AT_CellularNetwork_get_stack(); - - void test_AT_CellularNetwork_set_registration(); - - void test_AT_CellularNetwork_get_registration_status(); - - void test_AT_CellularNetwork_get_network_registering_mode(); - - void test_AT_CellularNetwork_set_registration_urc(); - - void test_AT_CellularNetwork_set_attach(); - - void test_AT_CellularNetwork_get_attach(); - - void test_AT_CellularNetwork_detach(); - - void test_AT_CellularNetwork_get_rate_control(); - - void test_AT_CellularNetwork_get_apn_backoff_timer(); - - void test_AT_CellularNetwork_get_ip_address(); - - void test_AT_CellularNetwork_set_access_technology(); - - void test_AT_CellularNetwork_get_access_technology(); - - void test_AT_CellularNetwork_scan_plmn(); - - void test_AT_CellularNetwork_set_ciot_optimization_config(); - - void test_AT_CellularNetwork_get_ciot_optimization_config(); - - void test_AT_CellularNetwork_set_stack_type(); - - void test_AT_CellularNetwork_get_stack_type(); - - void test_AT_CellularNetwork_get_pdpcontext_params(); - - void test_AT_CellularNetwork_get_extended_signal_quality(); - - void test_AT_CellularNetwork_get_signal_quality(); - - void test_AT_CellularNetwork_get_cell_id(); - - void test_AT_CellularNetwork_get_3gpp_error(); - - void test_AT_CellularNetwork_get_operator_params(); - - void test_AT_CellularNetwork_get_operator_names(); - - void test_AT_CellularNetwork_attach(); - - void test_get_connection_status(); - - void test_set_blocking(); -}; - -#endif // TEST_AT_CELLULARNETWORK_H - diff --git a/features/cellular/UNITTESTS/at/at_cellularpower/Makefile b/features/cellular/UNITTESTS/at/at_cellularpower/Makefile deleted file mode 100644 index 6ebcef37e4..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularpower/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularPower_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularPower.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularpowertest.cpp \ - test_at_cellularpower.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/CellularUtil_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularpower/at_cellularpowertest.cpp b/features/cellular/UNITTESTS/at/at_cellularpower/at_cellularpowertest.cpp deleted file mode 100644 index 2ce7b6dd02..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularpower/at_cellularpowertest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularpower.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularPower) -{ - Test_AT_CellularPower *unit; - - void setup() { - unit = new Test_AT_CellularPower(); - } - - void teardown() { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularPower, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularPower, test_AT_CellularPower_constructor) -{ - unit->test_AT_CellularPower_constructor(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_on) -{ - unit->test_AT_CellularPower_on(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_off) -{ - unit->test_AT_CellularPower_off(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_set_at_mode) -{ - unit->test_AT_CellularPower_set_at_mode(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_set_power_level) -{ - unit->test_AT_CellularPower_set_power_level(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_reset) -{ - unit->test_AT_CellularPower_reset(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_opt_power_save_mode) -{ - unit->test_AT_CellularPower_opt_power_save_mode(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_opt_receive_period) -{ - unit->test_AT_CellularPower_opt_receive_period(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_is_device_ready) -{ - unit->test_AT_CellularPower_is_device_ready(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb) -{ - unit->test_AT_CellularPower_set_device_ready_urc_cb(); -} - -TEST(AT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb) -{ - unit->test_AT_CellularPower_remove_device_ready_urc_cb(); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularpower/main.cpp b/features/cellular/UNITTESTS/at/at_cellularpower/main.cpp deleted file mode 100644 index 5580d26166..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularpower/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularPower); - diff --git a/features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.cpp b/features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.cpp deleted file mode 100644 index 593f4c447b..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularpower.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularPower.h" -#include "FileHandle_stub.h" -#include "ATHandler_stub.h" - -using namespace mbed; -using namespace events; - -Test_AT_CellularPower::Test_AT_CellularPower() -{ - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; -} - -Test_AT_CellularPower::~Test_AT_CellularPower() -{ -} - -void Test_AT_CellularPower::test_AT_CellularPower_constructor() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower *pow = new AT_CellularPower(at); - - delete pow; -} - -void Test_AT_CellularPower::test_AT_CellularPower_on() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - CHECK(NSAPI_ERROR_UNSUPPORTED == pow.on()); -} - -void Test_AT_CellularPower::test_AT_CellularPower_off() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - CHECK(NSAPI_ERROR_UNSUPPORTED == pow.off()); -} - -void Test_AT_CellularPower::test_AT_CellularPower_set_at_mode() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == pow.set_at_mode()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode()); -} - -void Test_AT_CellularPower::test_AT_CellularPower_set_power_level() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == pow.set_power_level(6)); - CHECK(NSAPI_ERROR_OK == pow.set_power_level(1, 1)); - CHECK(NSAPI_ERROR_OK == pow.set_power_level(1, 0)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6)); -} - -void Test_AT_CellularPower::test_AT_CellularPower_reset() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == pow.reset()); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.reset()); -} - -void Test_AT_CellularPower::test_AT_CellularPower_opt_power_save_mode() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345)); - - CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0)); -} - -void Test_AT_CellularPower::test_AT_CellularPower_opt_receive_period() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3)); -} - -void Test_AT_CellularPower::test_AT_CellularPower_is_device_ready() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready()); -} - -static void device_ready_cb() -{ -} - -void Test_AT_CellularPower::test_AT_CellularPower_set_device_ready_urc_cb() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb)); - CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL)); -} - -void Test_AT_CellularPower::test_AT_CellularPower_remove_device_ready_urc_cb() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularPower pow(at); - CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb)); - - pow.remove_device_ready_urc_cb(NULL); - pow.remove_device_ready_urc_cb(&device_ready_cb); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.h b/features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.h deleted file mode 100644 index c24f7809e6..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularpower/test_at_cellularpower.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARPOWER_H -#define TEST_AT_CELLULARPOWER_H - -class Test_AT_CellularPower { -public: - Test_AT_CellularPower(); - - virtual ~Test_AT_CellularPower(); - - void test_AT_CellularPower_constructor(); - - void test_AT_CellularPower_on(); - - void test_AT_CellularPower_off(); - - void test_AT_CellularPower_set_at_mode(); - - void test_AT_CellularPower_set_power_level(); - - void test_AT_CellularPower_reset(); - - void test_AT_CellularPower_opt_power_save_mode(); - - void test_AT_CellularPower_opt_receive_period(); - - void test_AT_CellularPower_is_device_ready(); - - void test_AT_CellularPower_set_device_ready_urc_cb(); - - void test_AT_CellularPower_remove_device_ready_urc_cb(); -}; - -#endif // TEST_AT_CELLULARPOWER_H - diff --git a/features/cellular/UNITTESTS/at/at_cellularsim/Makefile b/features/cellular/UNITTESTS/at/at_cellularsim/Makefile deleted file mode 100644 index 8c50af13cc..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsim/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularSIM_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularSIM.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularsimtest.cpp \ - test_at_cellularsim.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/CellularUtil_stub.cpp \ - ../../stubs/us_ticker_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularsim/at_cellularsimtest.cpp b/features/cellular/UNITTESTS/at/at_cellularsim/at_cellularsimtest.cpp deleted file mode 100644 index 2d4c2c70ec..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsim/at_cellularsimtest.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularsim.h" -#include "ATHandler_stub.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularSIM) -{ - Test_AT_CellularSIM *unit; - - void setup() - { - unit = new Test_AT_CellularSIM(); - ATHandler_stub::read_string_index = kRead_string_table_size; - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularSIM, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_constructor) -{ - unit->test_AT_CellularSIM_constructor(); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_set_pin) -{ - unit->test_AT_CellularSIM_set_pin(); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_change_pin) -{ - unit->test_AT_CellularSIM_change_pin(); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_set_pin_query) -{ - unit->test_AT_CellularSIM_set_pin_query(); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_get_sim_state) -{ - unit->test_AT_CellularSIM_get_sim_state(); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_get_imsi) -{ - unit->test_AT_CellularSIM_get_imsi(); -} - -TEST(AT_CellularSIM, test_AT_CellularSIM_get_iccid) -{ - unit->test_AT_CellularSIM_get_iccid(); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularsim/main.cpp b/features/cellular/UNITTESTS/at/at_cellularsim/main.cpp deleted file mode 100644 index 394a1f7d6d..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsim/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularSIM); - diff --git a/features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.cpp b/features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.cpp deleted file mode 100644 index 3ba07f791e..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularsim.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularSIM.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" -#include "ATHandler_stub.h" - -using namespace mbed; -using namespace events; - -Test_AT_CellularSIM::Test_AT_CellularSIM() -{ - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = 0; -} - -Test_AT_CellularSIM::~Test_AT_CellularSIM() -{ -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_constructor() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM *sim = new AT_CellularSIM(at); - - delete sim; -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == sim.set_pin("12")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "READY"; - ATHandler_stub::ssize_value = 5; - CHECK(NSAPI_ERROR_OK == sim.set_pin("12")); - - CHECK(NSAPI_ERROR_OK == sim.set_pin(NULL)); -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_change_pin() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == sim.change_pin("12", "34")); - CHECK(NSAPI_ERROR_OK == sim.change_pin(NULL, "34")); - CHECK(NSAPI_ERROR_OK == sim.change_pin("12", NULL)); - CHECK(NSAPI_ERROR_OK == sim.change_pin(NULL, NULL)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34")); -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin_query() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == sim.set_pin_query("12", true)); - CHECK(NSAPI_ERROR_OK == sim.set_pin_query(NULL, true)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == sim.set_pin_query("12", false)); - CHECK(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false)); - CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true)); -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_get_sim_state() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - CellularSIM::SimState state; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::read_string_value = NULL; - CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state)); - CHECK(CellularSIM::SimStateUnknown == state); - - ATHandler_stub::read_string_value = "READY"; - ATHandler_stub::ssize_value = 5; - CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state)); - CHECK(CellularSIM::SimStateReady == state); - - ATHandler_stub::read_string_value = "SIM PIN"; - ATHandler_stub::ssize_value = 7; - CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state)); - CHECK(CellularSIM::SimStatePinNeeded == state); - - ATHandler_stub::read_string_value = "SIM PUK"; - ATHandler_stub::ssize_value = 7; - CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state)); - CHECK(CellularSIM::SimStatePukNeeded == state); - - ATHandler_stub::read_string_value = "SOME CRAP"; - ATHandler_stub::ssize_value = 9; - CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state)); - CHECK(CellularSIM::SimStateUnknown == state); -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_get_imsi() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - char imsi[16]; - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "123456789012345"; - ATHandler_stub::ssize_value = 15; - CHECK(NSAPI_ERROR_OK == sim.get_imsi(imsi)); - CHECK(strcmp(ATHandler_stub::read_string_value, imsi) == 0); - - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::read_string_index = -1; - imsi[0] = 0; - CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi)); - CHECK(strlen(imsi) == 0); - - CHECK(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL)); - - // this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation. - // Now we have improved documentation that that the given imsi buffer size must be over 15. - //char imsi2[5]; - //CHECK(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2)); -} - -void Test_AT_CellularSIM::test_AT_CellularSIM_get_iccid() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - char buf[16]; - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = "123456789012345"; - ATHandler_stub::ssize_value = 15; - CHECK(NSAPI_ERROR_OK == sim.get_iccid(buf, 16)); - CHECK(strcmp(ATHandler_stub::read_string_value, buf) == 0); - - buf[0] = 0; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = -1; - CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16)); - CHECK(strlen(buf) == 0); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.h b/features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.h deleted file mode 100644 index 5c78cdbd40..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsim/test_at_cellularsim.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARSIM_H -#define TEST_AT_CELLULARSIM_H - -class Test_AT_CellularSIM { -public: - Test_AT_CellularSIM(); - - virtual ~Test_AT_CellularSIM(); - - void test_AT_CellularSIM_constructor(); - - void test_AT_CellularSIM_set_pin(); - - void test_AT_CellularSIM_change_pin(); - - void test_AT_CellularSIM_set_pin_query(); - - void test_AT_CellularSIM_get_sim_state(); - - void test_AT_CellularSIM_get_imsi(); - - void test_AT_CellularSIM_get_iccid(); -}; - -#endif // TEST_AT_CELLULARSIM_H - diff --git a/features/cellular/UNITTESTS/at/at_cellularsms/Makefile b/features/cellular/UNITTESTS/at/at_cellularsms/Makefile deleted file mode 100644 index dd7a07ce1b..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsms/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularSMS_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularSMS.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularsmstest.cpp \ - test_at_cellularsms.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/CellularUtil_stub.cpp \ - ../../stubs/us_ticker_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - ../../stubs/mbed_wait_api_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularsms/at_cellularsmstest.cpp b/features/cellular/UNITTESTS/at/at_cellularsms/at_cellularsmstest.cpp deleted file mode 100644 index d207cc8291..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsms/at_cellularsmstest.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularsms.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularSMS) -{ - Test_AT_CellularSMS *unit; - - void setup() - { - unit = new Test_AT_CellularSMS(); - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularSMS, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_constructor) -{ - unit->test_AT_CellularSMS_constructor(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_initialize) -{ - unit->test_AT_CellularSMS_initialize(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_send_sms) -{ - unit->test_AT_CellularSMS_send_sms(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_get_sms) -{ - unit->test_AT_CellularSMS_get_sms(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_set_sms_callback) -{ - unit->test_AT_CellularSMS_set_sms_callback(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_set_cpms) -{ - unit->test_AT_CellularSMS_set_cpms(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_set_csca) -{ - unit->test_AT_CellularSMS_set_csca(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_set_cscs) -{ - unit->test_AT_CellularSMS_set_cscs(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_delete_all_messages) -{ - unit->test_AT_CellularSMS_delete_all_messages(); -} - -TEST(AT_CellularSMS, test_AT_CellularSMS_set_extra_sim_wait_time) -{ - unit->test_AT_CellularSMS_set_extra_sim_wait_time(); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularsms/main.cpp b/features/cellular/UNITTESTS/at/at_cellularsms/main.cpp deleted file mode 100644 index 04d6d690b0..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsms/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularSMS); - diff --git a/features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.cpp b/features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.cpp deleted file mode 100644 index 94c5884a63..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularsms.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "ATHandler_stub.h" -#include "AT_CellularSMS.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" - -using namespace mbed; -using namespace events; - -Test_AT_CellularSMS::Test_AT_CellularSMS() -{ - ATHandler_stub::return_given_size = false; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; -} - -Test_AT_CellularSMS::~Test_AT_CellularSMS() -{ -} - -void Test_AT_CellularSMS::test_AT_CellularSMS_constructor() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS *sms = new AT_CellularSMS(at); - - delete sms; -} - -void Test_AT_CellularSMS::test_AT_CellularSMS_initialize() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText)); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - LONGS_EQUAL(NSAPI_ERROR_PARAMETER, sms.send_sms(NULL, "2", 1)); - - sms.initialize(CellularSMS::CellularSMSMmodeText); - ATHandler_stub::size_value = 1; - LONGS_EQUAL(1, sms.send_sms("1", "22", 2)); - - ATHandler_stub::size_value = 2; - LONGS_EQUAL(2, sms.send_sms("1", "22", 2)); - - ATHandler_stub::return_given_size = true; // PDU mode write is much longer than than msg len - sms.initialize(CellularSMS::CellularSMSMmodePDU); - LONGS_EQUAL(2, sms.send_sms("1", "23", 2));; - - ATHandler_stub::nsapi_error_ok_counter = 1; - ATHandler_stub::size_value = 32; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8)); - - ATHandler_stub::nsapi_error_ok_counter = 2; - ATHandler_stub::size_value = 32; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - char table[] = "232323232323232323232323232323232323232323232323232323\ - 232323232323232323232323232323232323232323232323232323\ - 232323232323232323232323232323232323232323232323232323\ - 23232323232323232323232323232323232323\0"; - - LONGS_EQUAL(strlen(table), sms.send_sms("1", table, strlen(table))); - LONGS_EQUAL(strlen(table), sms.send_sms("12", table, strlen(table))); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - char buf[16]; - char phone[21]; - char stamp[21]; - int size; - CHECK(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size)); - - ATHandler_stub::resp_info_true_counter = 1; - ATHandler_stub::int_value = 0; - CHECK(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); - - ATHandler_stub::resp_info_true_counter = 2; - ATHandler_stub::int_value = 11; - CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); - //TODO: Should make add_info to happen, before calling get_sms! - - ATHandler_stub::resp_info_true_counter = 2; - ATHandler_stub::int_value = 11; - sms.initialize(CellularSMS::CellularSMSMmodePDU); - CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size)); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - sms.set_sms_callback(NULL); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4")); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1)); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2")); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; - CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages()); -} - - -void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSMS sms(at); - sms.set_extra_sim_wait_time(56); - -} - diff --git a/features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.h b/features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.h deleted file mode 100644 index c83d312fa1..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularsms/test_at_cellularsms.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARSMS_H -#define TEST_AT_CELLULARSMS_H - -class Test_AT_CellularSMS { -public: - Test_AT_CellularSMS(); - - virtual ~Test_AT_CellularSMS(); - - void test_AT_CellularSMS_constructor(); - - void test_AT_CellularSMS_initialize(); - - void test_AT_CellularSMS_send_sms(); - - void test_AT_CellularSMS_get_sms(); - - void test_AT_CellularSMS_set_sms_callback(); - - void test_AT_CellularSMS_set_cpms(); - - void test_AT_CellularSMS_set_csca(); - - void test_AT_CellularSMS_set_cscs(); - - void test_AT_CellularSMS_delete_all_messages(); - - void test_AT_CellularSMS_set_extra_sim_wait_time(); -}; - -#endif // TEST_AT_CELLULARSMS_H - diff --git a/features/cellular/UNITTESTS/at/at_cellularstack/Makefile b/features/cellular/UNITTESTS/at/at_cellularstack/Makefile deleted file mode 100644 index 5371687a3e..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularstack/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = AT_CellularStack_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/AT_CellularStack.cpp - -TEST_SRC_FILES = \ - main.cpp \ - at_cellularstacktest.cpp \ - test_at_cellularstack.cpp \ - ../../stubs/ATHandler_stub.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/CellularUtil_stub.cpp \ - ../../stubs/us_ticker_stub.cpp \ - ../../stubs/NetworkStack_stub.cpp \ - ../../stubs/SocketAddress_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/at/at_cellularstack/at_cellularstacktest.cpp b/features/cellular/UNITTESTS/at/at_cellularstack/at_cellularstacktest.cpp deleted file mode 100644 index 60a5ab6664..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularstack/at_cellularstacktest.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_at_cellularstack.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(AT_CellularStack) -{ - Test_AT_CellularStack *unit; - - void setup() - { - unit = new Test_AT_CellularStack(); - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(AT_CellularStack, Create) -{ - CHECK(unit != NULL); -} - -TEST(AT_CellularStack, test_AT_CellularStack_constructor) -{ - unit->test_AT_CellularStack_constructor(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_get_ip_address) -{ - unit->test_AT_CellularStack_get_ip_address(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_open) -{ - unit->test_AT_CellularStack_socket_open(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_close) -{ - unit->test_AT_CellularStack_socket_close(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_bind) -{ - unit->test_AT_CellularStack_socket_bind(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_listen) -{ - unit->test_AT_CellularStack_socket_listen(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_connect) -{ - unit->test_AT_CellularStack_socket_connect(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_accept) -{ - unit->test_AT_CellularStack_socket_accept(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_send) -{ - unit->test_AT_CellularStack_socket_send(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_recv) -{ - unit->test_AT_CellularStack_socket_recv(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_sendto) -{ - unit->test_AT_CellularStack_socket_sendto(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_recvfrom) -{ - unit->test_AT_CellularStack_socket_recvfrom(); -} - -TEST(AT_CellularStack, test_AT_CellularStack_socket_attach) -{ - unit->test_AT_CellularStack_socket_attach(); -} - diff --git a/features/cellular/UNITTESTS/at/at_cellularstack/main.cpp b/features/cellular/UNITTESTS/at/at_cellularstack/main.cpp deleted file mode 100644 index ee45007dde..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularstack/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(AT_CellularStack); - diff --git a/features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.cpp b/features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.cpp deleted file mode 100644 index 0e4eefca2c..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_at_cellularstack.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularStack.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" -#include "ATHandler_stub.h" -#include "SocketAddress.h" - -using namespace mbed; -using namespace events; - -class MyStack : public AT_CellularStack { -public: - bool bool_value; - bool max_sock_value; - nsapi_error_t create_error; - CellularSocket socket; - - MyStack(ATHandler &atr, int cid, nsapi_ip_stack_t typ) : AT_CellularStack(atr, cid, typ) - { - bool_value = false; - max_sock_value = 0; - create_error = NSAPI_ERROR_OK; - } - - virtual int get_max_socket_count() - { - return max_sock_value; - } - - virtual bool is_protocol_supported(nsapi_protocol_t protocol) - { - return bool_value; - } - - virtual nsapi_error_t socket_close_impl(int sock_id) - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t create_socket_impl(CellularSocket *socket) - { - return create_error; - } - - virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, - const void *data, nsapi_size_t size) - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, - void *buffer, nsapi_size_t size) - { - return NSAPI_ERROR_OK; - } - - virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) - { - return AT_CellularStack::socket_open(handle, proto); - } - - virtual nsapi_error_t socket_close(nsapi_socket_t handle) - { - return AT_CellularStack::socket_close(handle); - } - - virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) - { - return AT_CellularStack::socket_bind(handle, address); - } - - virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) - { - return AT_CellularStack::socket_listen(handle, backlog); - } - - virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) - { - return AT_CellularStack::socket_connect(handle, address); - } - - virtual nsapi_error_t socket_accept(nsapi_socket_t server, - nsapi_socket_t *handle, SocketAddress *address = 0) - { - return AT_CellularStack::socket_accept(server, handle, address); - } - - virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, - const void *data, nsapi_size_t size) - { - return AT_CellularStack::socket_send(handle, data, size); - } - - virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, - void *data, nsapi_size_t size) - { - return AT_CellularStack::socket_recv(handle, data, size); - } - - virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, - const void *data, nsapi_size_t size) - { - return AT_CellularStack::socket_sendto(handle, address, data, size); - } - - virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, - void *buffer, nsapi_size_t size) - { - return AT_CellularStack::socket_recvfrom(handle, address, buffer, size); - } - - virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) - { - return AT_CellularStack::socket_attach(handle, callback, data); - } -}; - -Test_AT_CellularStack::Test_AT_CellularStack() -{ - ATHandler_stub::ssize_value = 0; - ATHandler_stub::bool_value = false; - ATHandler_stub::read_string_value = NULL; -} - -Test_AT_CellularStack::~Test_AT_CellularStack() -{ -} - -void Test_AT_CellularStack::test_AT_CellularStack_constructor() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack *st = new MyStack(at, 0, IPV4_STACK); - - delete st; -} - -void Test_AT_CellularStack::test_AT_CellularStack_get_ip_address() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - CHECK(0 == strlen(st.get_ip_address())); - - char table[] = "1.2.3.4.5.65.7.8.9.10.11\0"; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::bool_value = true; - ATHandler_stub::read_string_value = table; - CHECK(NULL == st.get_ip_address()); - - ATHandler_stub::ssize_value = strlen(table); - ATHandler_stub::bool_value = true; - ATHandler_stub::read_string_value = table; - CHECK(st.get_ip_address()); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_open() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - st.bool_value = false; - CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP)); - - st.bool_value = true; - st.max_sock_value = 0; - nsapi_socket_t sock = &st.socket; - CHECK(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP)); - - MyStack st2(at, 0, IPV6_STACK); - st2.bool_value = true; - st2.max_sock_value = 1; - sock = &st2.socket; - CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_close() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(&st.socket)); - - nsapi_socket_t sock = &st.socket; - st.bool_value = true; - st.max_sock_value = 1; - CHECK(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP)); - st.max_sock_value = 0; - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock)); - - MyStack st2(at, 0, IPV6_STACK); - st2.max_sock_value = 1; - st2.bool_value = true; - sock = &st2.socket; - CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP)); - CHECK(NSAPI_ERROR_OK == st2.socket_close(sock)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_bind() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - SocketAddress addr; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_ALREADY; - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr)); - - CHECK(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_listen() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_connect() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - SocketAddress addr; - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr)); - - CHECK(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_accept() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - nsapi_socket_t sock = &st.socket; - CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_send() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4)); - - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4)); - - SocketAddress addr; - st.max_sock_value = 1; - st.bool_value = true; - nsapi_socket_t sock = &st.socket; - st.socket_open(&sock, NSAPI_TCP); - st.socket_connect(sock, addr); - CHECK(NSAPI_ERROR_OK == st.socket_send(sock, "addr", 4)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - - SocketAddress addr; - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4)); - - st.max_sock_value = 1; - st.bool_value = true; - nsapi_socket_t sock = &st.socket; - st.socket_open(&sock, NSAPI_TCP); - st.socket_connect(sock, addr); - st.create_error = NSAPI_ERROR_CONNECTION_LOST; - CHECK(NSAPI_ERROR_CONNECTION_LOST == st.socket_sendto(sock, addr, "addr", 4)); - - st.create_error = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_recv() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - char table[4]; - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - char table[4]; - CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4)); - - SocketAddress addr; - st.max_sock_value = 1; - st.bool_value = true; - nsapi_socket_t sock = &st.socket; - st.socket_open(&sock, NSAPI_TCP); - st.socket_connect(sock, addr); - st.create_error = NSAPI_ERROR_CONNECTION_LOST; - CHECK(NSAPI_ERROR_CONNECTION_LOST == st.socket_recvfrom(sock, &addr, table, 4)); - - st.create_error = NSAPI_ERROR_OK; - CHECK(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4)); -} - -void Test_AT_CellularStack::test_AT_CellularStack_socket_attach() -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - MyStack st(at, 0, IPV6_STACK); - - st.socket_attach(NULL, NULL, NULL); - st.max_sock_value = 1; - st.bool_value = true; - nsapi_socket_t sock = &st.socket; - st.socket_open(&sock, NSAPI_TCP); - st.socket_attach(sock, NULL, NULL); -} diff --git a/features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.h b/features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.h deleted file mode 100644 index b86a6d761c..0000000000 --- a/features/cellular/UNITTESTS/at/at_cellularstack/test_at_cellularstack.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_AT_CELLULARSTACK_H -#define TEST_AT_CELLULARSTACK_H - -class Test_AT_CellularStack { -public: - Test_AT_CellularStack(); - - virtual ~Test_AT_CellularStack(); - - void test_AT_CellularStack_constructor(); - - void test_AT_CellularStack_get_ip_address(); - - void test_AT_CellularStack_socket_open(); - - void test_AT_CellularStack_socket_close(); - - void test_AT_CellularStack_socket_bind(); - - void test_AT_CellularStack_socket_listen(); - - void test_AT_CellularStack_socket_connect(); - - void test_AT_CellularStack_socket_accept(); - - void test_AT_CellularStack_socket_send(); - - void test_AT_CellularStack_socket_recv(); - - void test_AT_CellularStack_socket_sendto(); - - void test_AT_CellularStack_socket_recvfrom(); - - void test_AT_CellularStack_socket_attach(); -}; - -#endif // TEST_AT_CELLULARSTACK_H - diff --git a/features/cellular/UNITTESTS/at/athandler/Makefile b/features/cellular/UNITTESTS/at/athandler/Makefile deleted file mode 100644 index 6e2b33c35c..0000000000 --- a/features/cellular/UNITTESTS/at/athandler/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = ATHandler_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/AT/ATHandler.cpp \ - ../../../framework/common/CellularUtil.cpp - -TEST_SRC_FILES = \ - main.cpp \ - athandlertest.cpp \ - test_athandler.cpp \ - ../../stubs/AT_CellularBase_stub.cpp \ - ../../stubs/EventQueue_stub.cpp \ - ../../stubs/FileHandle_stub.cpp \ - ../../stubs/us_ticker_stub.cpp \ - ../../stubs/mbed_wait_api_stub.cpp \ - ../../stubs/mbed_assert_stub.cpp \ - ../../stubs/mbed_poll_stub.cpp \ - ../../stubs/Timer_stub.cpp \ - ../../stubs/equeue_stub.cpp \ - ../../stubs/Kernel.cpp \ - ../../stubs/Thread_stub.cpp \ - ../../stubs/randLIB_stub.cpp - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT -DMBED_CONF_CELLULAR_DEBUG_AT=1 - diff --git a/features/cellular/UNITTESTS/at/athandler/athandlertest.cpp b/features/cellular/UNITTESTS/at/athandler/athandlertest.cpp deleted file mode 100644 index b8b46b2ca8..0000000000 --- a/features/cellular/UNITTESTS/at/athandler/athandlertest.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_athandler.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(ATHandler) -{ - Test_ATHandler *unit; - - void setup() - { - unit = new Test_ATHandler(); - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(ATHandler, Create) -{ - CHECK(unit != NULL); -} - -TEST(ATHandler, test_ATHandler_constructor) -{ - unit->test_ATHandler_constructor(); -} - -TEST(ATHandler, test_ATHandler_get_file_handle) -{ - unit->test_ATHandler_get_file_handle(); -} - -TEST(ATHandler, test_ATHandler_set_file_handle) -{ - unit->test_ATHandler_set_file_handle(); -} - -TEST(ATHandler, test_ATHandler_lock) -{ - unit->test_ATHandler_lock(); -} - -TEST(ATHandler, test_ATHandler_unlock) -{ - unit->test_ATHandler_unlock(); -} - -TEST(ATHandler, test_ATHandler_unlock_return_error) -{ - unit->test_ATHandler_unlock_return_error(); -} - -TEST(ATHandler, test_ATHandler_set_urc_handler) -{ - unit->test_ATHandler_set_urc_handler(); -} - -TEST(ATHandler, test_ATHandler_get_last_error) -{ - unit->test_ATHandler_get_last_error(); -} - -TEST(ATHandler, test_ATHandler_get_last_device_error) -{ - unit->test_ATHandler_get_last_device_error(); -} - -TEST(ATHandler, test_ATHandler_inc_ref_count) -{ - unit->test_ATHandler_inc_ref_count(); -} - -TEST(ATHandler, test_ATHandler_dec_ref_count) -{ - unit->test_ATHandler_dec_ref_count(); -} - -TEST(ATHandler, test_ATHandler_get_ref_count) -{ - unit->test_ATHandler_get_ref_count(); -} - -TEST(ATHandler, test_ATHandler_set_at_timeout) -{ - unit->test_ATHandler_set_at_timeout(); -} - -TEST(ATHandler, test_ATHandler_restore_at_timeout) -{ - unit->test_ATHandler_restore_at_timeout(); -} - -TEST(ATHandler, test_ATHandler_clear_error) -{ - unit->test_ATHandler_clear_error(); -} - -TEST(ATHandler, test_ATHandler_process_oob) -{ - unit->test_ATHandler_process_oob(); -} - -TEST(ATHandler, test_ATHandler_set_filehandle_sigio) -{ - unit->test_ATHandler_set_filehandle_sigio(); -} - -TEST(ATHandler, test_ATHandler_flush) -{ - unit->test_ATHandler_flush(); -} - -TEST(ATHandler, test_ATHandler_cmd_start) -{ - unit->test_ATHandler_cmd_start(); -} - -TEST(ATHandler, test_ATHandler_write_int) -{ - unit->test_ATHandler_write_int(); -} - -TEST(ATHandler, test_ATHandler_write_string) -{ - unit->test_ATHandler_write_string(); -} - -TEST(ATHandler, test_ATHandler_cmd_stop) -{ - unit->test_ATHandler_cmd_stop(); -} - -TEST(ATHandler, test_ATHandler_write_bytes) -{ - unit->test_ATHandler_write_bytes(); -} - -TEST(ATHandler, test_ATHandler_set_stop_tag) -{ - unit->test_ATHandler_set_stop_tag(); -} - -TEST(ATHandler, test_ATHandler_set_delimiter) -{ - unit->test_ATHandler_set_delimiter(); -} - -TEST(ATHandler, test_ATHandler_skip_param) -{ - unit->test_ATHandler_skip_param(); -} - -TEST(ATHandler, test_ATHandler_read_bytes) -{ - unit->test_ATHandler_read_bytes(); -} - -TEST(ATHandler, test_ATHandler_read_string) -{ - unit->test_ATHandler_read_string(); -} - -TEST(ATHandler, test_ATHandler_read_hex_string) -{ - unit->test_ATHandler_read_hex_string(); -} - -TEST(ATHandler, test_ATHandler_read_int) -{ - unit->test_ATHandler_read_int(); -} - -TEST(ATHandler, test_ATHandler_resp_start) -{ - unit->test_ATHandler_resp_start(); -} - -TEST(ATHandler, test_ATHandler_resp_stop) -{ - unit->test_ATHandler_resp_stop(); -} - -TEST(ATHandler, test_ATHandler_info_resp) -{ - unit->test_ATHandler_info_resp(); -} - -TEST(ATHandler, test_ATHandler_info_elem) -{ - unit->test_ATHandler_info_elem(); -} - -TEST(ATHandler, test_ATHandler_consume_to_stop_tag) -{ - unit->test_ATHandler_consume_to_stop_tag(); -} - -TEST(ATHandler, test_ATHandler_set_debug) -{ - unit->test_ATHandler_set_debug(); -} - -TEST(ATHandler, test_ATHandler_get_3gpp_error) -{ - unit->test_ATHandler_get_3gpp_error(); -} diff --git a/features/cellular/UNITTESTS/at/athandler/main.cpp b/features/cellular/UNITTESTS/at/athandler/main.cpp deleted file mode 100644 index 3f7505ccbb..0000000000 --- a/features/cellular/UNITTESTS/at/athandler/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(ATHandler); - diff --git a/features/cellular/UNITTESTS/at/athandler/test_athandler.cpp b/features/cellular/UNITTESTS/at/athandler/test_athandler.cpp deleted file mode 100644 index 3d01ad0cad..0000000000 --- a/features/cellular/UNITTESTS/at/athandler/test_athandler.cpp +++ /dev/null @@ -1,1016 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_athandler.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularStack.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" -#include "mbed_poll_stub.h" - -#include "Timer_stub.h" - -using namespace mbed; -using namespace events; - -void urc_callback() -{ -} - -Test_ATHandler::Test_ATHandler() -{ - -} - -Test_ATHandler::~Test_ATHandler() -{ -} - -void Test_ATHandler::test_ATHandler_constructor() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler *at = new ATHandler(&fh1, que, 0, ","); - - delete at; - - at = new ATHandler(&fh1, que, 0, NULL); - - delete at; -} - -void Test_ATHandler::test_ATHandler_get_file_handle() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - CHECK_EQUAL(&fh1, at.get_file_handle()); -} - -void Test_ATHandler::test_ATHandler_set_file_handle() -{ - EventQueue que; - FileHandle_stub fh1, fh2; - - ATHandler at(&fh1, que, 0, ","); - - at.set_file_handle(&fh2); -} - -void Test_ATHandler::test_ATHandler_lock() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - - at.lock(); -} - -void Test_ATHandler::test_ATHandler_unlock() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - filehandle_stub_short_value_counter = 1; - fh1.short_value = POLLIN; - at.unlock(); -} - -void Test_ATHandler::test_ATHandler_unlock_return_error() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - CHECK(NSAPI_ERROR_OK == at.unlock_return_error()); -} - -void Test_ATHandler::test_ATHandler_set_urc_handler() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - const char ch[] = "testtesttesttest"; - at.set_urc_handler(ch, &urc_callback); -} - -void Test_ATHandler::test_ATHandler_get_last_error() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - CHECK(NSAPI_ERROR_OK == at.get_last_error()); -} - -void Test_ATHandler::test_ATHandler_get_last_device_error() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - CHECK(0 == at.get_last_device_error().errCode); -} - -void Test_ATHandler::test_ATHandler_inc_ref_count() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.inc_ref_count(); -} - -void Test_ATHandler::test_ATHandler_dec_ref_count() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.dec_ref_count(); -} - -void Test_ATHandler::test_ATHandler_get_ref_count() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - CHECK(1 == at.get_ref_count()); - - at.inc_ref_count(); - CHECK(2 == at.get_ref_count()); - - at.inc_ref_count(); - CHECK(3 == at.get_ref_count()); - - at.dec_ref_count(); - at.dec_ref_count(); - CHECK(1 == at.get_ref_count()); -} - -void Test_ATHandler::test_ATHandler_set_at_timeout() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.set_at_timeout(8); - - at.set_at_timeout(80, true); -} - -void Test_ATHandler::test_ATHandler_restore_at_timeout() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.set_at_timeout(80, true); - at.set_at_timeout(800); - at.restore_at_timeout(); -} - -void Test_ATHandler::test_ATHandler_clear_error() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.clear_error(); -} - -void Test_ATHandler::test_ATHandler_process_oob() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - filehandle_stub_short_value_counter = 1; - fh1.short_value = POLLIN; - at.set_urc_handler("s", &urc_callback); - at.process_oob(); - - filehandle_stub_short_value_counter = 2; - at.process_oob(); - - //at.fill_buffer(); - uint8_t buf[5]; - at.clear_error(); - char table[] = "ssssssssssssssssssssssssssssssss\0"; - filehandle_stub_table = table; - filehandle_stub_table_pos = 0; - at.read_bytes(buf, 5); - - filehandle_stub_short_value_counter = 2; - at.process_oob(); - - at.clear_error(); - timer_stub_value = 0; - filehandle_stub_table_pos = 0; - at.read_bytes(buf, 5); - - filehandle_stub_short_value_counter = 1; - at.process_oob(); - - char table2[4]; - table2[0] = '\r'; - table2[1] = '\r'; - table2[2] = '\n'; - table2[3] = 0; - filehandle_stub_table = table2; - - at.clear_error(); - timer_stub_value = 0; - filehandle_stub_table_pos = 0; - at.read_bytes(buf, 1); - - filehandle_stub_short_value_counter = 1; - at.process_oob(); - - - filehandle_stub_table = table; - - - filehandle_stub_short_value_counter = 0; - filehandle_stub_table_pos = 0; - filehandle_stub_table = NULL; -} - -void Test_ATHandler::test_ATHandler_set_filehandle_sigio() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.set_filehandle_sigio(); -} - -void Test_ATHandler::test_ATHandler_flush() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - filehandle_stub_short_value_counter = 1; - fh1.short_value = POLLIN; - at.flush(); -} - -void Test_ATHandler::test_ATHandler_cmd_start() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - mbed_poll_stub::revents_value = POLLOUT; - mbed_poll_stub::int_value = 1; - fh1.size_value = 3; - at.cmd_start("s"); - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 0; - - at.cmd_start("s"); - - at.cmd_start("s"); -} - -void Test_ATHandler::test_ATHandler_write_int() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - fh1.size_value = -1; - at.write_int(4); - - at.clear_error(); - mbed_poll_stub::revents_value = POLLOUT; - mbed_poll_stub::int_value = 1; - fh1.size_value = 6; - at.write_int(4); - - at.write_int(2147483647); - - at.write_int(2147483647 + 1); - -// at.at_error(0, DeviceErrorType(0)); -// at.write_int(4); -} - -void Test_ATHandler::test_ATHandler_write_string() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.write_string("help"); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - - at.clear_error(); - mbed_poll_stub::revents_value = POLLOUT; - mbed_poll_stub::int_value = 1; - fh1.size_value = -1; - at.cmd_start("s"); - at.write_string("help", true); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - - at.clear_error(); - mbed_poll_stub::revents_value = POLLOUT; - mbed_poll_stub::int_value = 1; - fh1.size_value = -1; - at.write_string("help", true); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - - at.clear_error(); - mbed_poll_stub::revents_value = POLLOUT; - mbed_poll_stub::int_value = 1; - fh1.size_value = 7; - at.write_string("help", true); - CHECK(NSAPI_ERROR_OK == at.get_last_error()); -} - -void Test_ATHandler::test_ATHandler_cmd_stop() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - fh1.size_value = -1; - at.cmd_stop(); - - at.write_string("help", true); - - at.cmd_stop(); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); -} - -void Test_ATHandler::test_ATHandler_write_bytes() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - fh1.size_value = -1; - uint8_t data[] = "data"; - at.write_bytes(data, 4); - - at.write_bytes(data, 4); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); -} - -void Test_ATHandler::test_ATHandler_set_stop_tag() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.set_stop_tag("s"); -} - -void Test_ATHandler::test_ATHandler_set_delimiter() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.set_delimiter('+'); -} - -void Test_ATHandler::test_ATHandler_skip_param() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.skip_param(); - - char table[] = "ssssssssssssssssssssssssssssOK\r\n\0"; - filehandle_stub_table = table; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - at.skip_param(); - CHECK(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR); - - char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0"; - filehandle_stub_table = table1; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - at.skip_param(); - - char table2[] = "sssOK\r\n\0"; - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - at.skip_param(); - - char table3[] = "sssssssOK\nssss\0"; - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - - //Need to create a new instance because stop tag already found - ATHandler at2(&fh1, que, 0, ","); - at2.flush(); - at2.clear_error(); - at2.resp_start(); - at2.skip_param(); - - at2.skip_param(4, 3); - - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - - at2.flush(); - at2.clear_error(); - at2.resp_start(); - at2.skip_param(4, 3); - - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - - at2.flush(); - at2.clear_error(); - at2.resp_start(); - at2.skip_param(24, 17); -} - -void Test_ATHandler::test_ATHandler_read_bytes() -{ - EventQueue que; - FileHandle_stub fh1; - filehandle_stub_table = NULL; - filehandle_stub_table_pos = 0; - - ATHandler at(&fh1, que, 0, ","); - uint8_t buf[5]; - - // TEST EMPTY BUFFER - // Shouldn't read any byte since buffer is empty - CHECK(-1 == at.read_bytes(buf, 1)); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - // Return error due to error set to at handler by the above call on empty buffer - CHECK(-1 == at.read_bytes(buf, 1)); - - // TEST DATA IN BUFFER - at.clear_error(); - char table1[] = "1234512345678OK\r\n\0"; - filehandle_stub_table = table1; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1;; - - // Read 5 bytes - CHECK(5 == at.read_bytes(buf, 5)); - CHECK(!memcmp(buf, table1, 5)); - // get_char triggered above should have filled in the whole reading buffer(fill_buffer()) - CHECK(filehandle_stub_table_pos == (strlen(table1) - 1)); - // Read another 8 bytes - CHECK(8 == at.read_bytes(buf, 8) && !memcmp(buf, table1 + 5, 8)); - // Reading more than the 4 bytes left -> ERROR - CHECK(-1 == at.read_bytes(buf, 5)); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); -} - -void Test_ATHandler::test_ATHandler_read_string() -{ - EventQueue que; - FileHandle_stub fh1; - filehandle_stub_table = NULL; - filehandle_stub_table_pos = 0; - - ATHandler at(&fh1, que, 0, ","); - - // *** EMPTY *** - at.clear_error(); - char table1[] = ""; - at.flush(); - filehandle_stub_table = table1; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf1[1]; - // No _stop_tag set without resp_start - CHECK(-1 == at.read_string(buf1, 1)); - at.clear_error(); - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - // Device error because buffer is empty - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - at.clear_error(); - // Device error because empty buffer and attempt to fill_buffer by consume_char('\"') - CHECK(-1 == at.read_string(buf1, 1)); - - // *** 1 BYTE *** - at.clear_error(); - char table2[] = "s\0"; - at.flush(); - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf2[1]; - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - // Device error because no CRLF and no more data to read - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - at.clear_error(); - CHECK(0 == at.read_string(buf2, 1)); - - // *** CRLF *** - at.clear_error(); - char table3[] = "\r\ns\r\n\0"; - at.flush(); - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf3[1]; - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - // OK because after CRLF matched there is more data to read ending in CRLF - CHECK(NSAPI_ERROR_OK == at.get_last_error()); - // To read 0 bytes from: s\r\n - CHECK(0 == at.read_string(buf3, 0 + 1/*for NULL*/)); - // To read 1 byte from: s\r\n -> read s - CHECK(1 == at.read_string(buf3, 1 + 1/*for NULL*/)); - - // *** Reading more than available in buffer *** - at.clear_error(); - char table4[] = "\"s,\"OK\r\n\0"; - at.flush(); - filehandle_stub_table = table4; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf4[7]; - uint8_t buf5[5]; - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read 5 bytes from: "s,"OK\r\n -> read "s,"O - at.read_bytes(buf5, 5); - // K\r\n left to be read -> reading more than 3 + 1(for NULL) -> ERROR - CHECK(-1 == at.read_string(buf4, 4 + 1/*for NULL*/)); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - - // *** Encountering delimiter after reading 1 byte *** - at.clear_error(); - at.flush(); - filehandle_stub_table = table4; - filehandle_stub_table_pos = 0; - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read 1 byte from: "s,"OK\r\n -> read " - at.read_bytes(buf5, 1); - // TO read max 4 from: s,"OK\r\n -> read s and stop on , - CHECK(1 == at.read_string(buf4, 4 + 1/*for NULL*/)); - - // *** Encountering delimiter as first char in buffer *** - at.clear_error(); - at.flush(); - filehandle_stub_table = table4; - filehandle_stub_table_pos = 0; - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read 2 bytes from: "s,"OK\r\n -> read "s - at.read_bytes(buf5, 2); - // TO read max 4 bytes from: ,"OK\r\n -> stop on , - CHECK(0 == at.read_string(buf4, 4 + 1/*for NULL*/)); - - // *** Read as much as buffer size is without encountering any delimiter " or OKCRLF *** - at.clear_error(); - char table5[] = "\"s\"OK\r\nabcd\0"; - at.flush(); - filehandle_stub_table = table5; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read 1 byte from: "s"OK\r\n -> read " - at.read_bytes(buf5, 1); - // TO read max 1 byte from: s"OK\r\n -> read s - CHECK(1 == at.read_string(buf4, 1 + 1/*for NULL*/)); - - // *** Consume " and run into OKCRLF *** - // TO read max 1 byte from: "OK\r\n -> consume " and find stop tag OKCRLF - CHECK(0 == at.read_string(buf4, 1 + 1/*for NULL*/)); - - // *** Try to read after stop tag was found *** - // stop tag found do not read further - CHECK(-1 == at.read_string(buf4, 1 + 1/*for NULL*/)); - - // *** Try to read after stop tag was found when parameter allows it *** - // stop tag found but flag indicates to read despite stop_tag found - CHECK(4 == at.read_string(buf4, 4 + 1/*for NULL*/, true)); - - // *** Read as much as buffer size is without encountering any delimiter " or OKCRLF *** - at.clear_error(); - char table6[] = "sss\rsss\0"; - at.flush(); - filehandle_stub_table = table6; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - at.resp_start("s"); - // TO read from: ss\rsss -> read all 6 chars ss\rsss - CHECK(6 == at.read_string(buf4, 6 + 1/*for NULL*/)); - - // *** Reading when buffer only has " *** - at.clear_error(); - char table7[] = "s\"\0"; - at.flush(); - filehandle_stub_table = table7; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - at.resp_start("s"); - // TO read from buffer having only " -> consume " -> trying to read when nothing in buffer - CHECK(-1 == at.read_string(buf4, 5)); - CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error()); - - // *** Reading through partially matching stop tag *** - at.clear_error(); - char table8[] = "\"s\"OK\rabcd\r\n\0"; - at.flush(); - filehandle_stub_table = table8; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf8[9]; - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read from - CHECK(8 == at.read_string(buf8, 8 + 1/*for NULL*/)); - - // *** Reading through partially matching stop tag *** - at.clear_error(); - char table9[] = "\"s\"Oabcd\r\n\0"; - at.flush(); - filehandle_stub_table = table9; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf9[5]; - - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read from - CHECK(6 == at.read_string(buf9, 6 + 1/*for NULL*/)); - - // *** CRLF part of the string *** - at.clear_error(); - char table10[] = "\"s\"\r\nOK\r\n\0"; - at.flush(); - filehandle_stub_table = table10; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf10[10]; - - // NO prefix, NO OK, NO ERROR and NO URC match, CRLF found -> return so buffer could be read - at.resp_start(); - // TO read from - CHECK(3 == at.read_string(buf10, 9 + 1/*for NULL*/)); -} - -void Test_ATHandler::test_ATHandler_read_hex_string() -{ - EventQueue que; - FileHandle_stub fh1; - filehandle_stub_table = NULL; - filehandle_stub_table_pos = 0; - - ATHandler at(&fh1, que, 0, ","); - - // *** Read up to delimiter, even length *** - at.clear_error(); - char table1[] = "68656C6C6F,"; - at.flush(); - filehandle_stub_table = table1; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf1[10]; - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - CHECK(5 == at.read_hex_string(buf1, 5)); - CHECK(!strncmp(buf1, "hello", 5)); - - // *** Read up to delimiter, odd length *** - at.clear_error(); - char table2[] = "68656C6C6F7,"; - at.flush(); - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf2[10]; - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - CHECK(5 == at.read_hex_string(buf2, 6)); - CHECK(!strncmp(buf2, "hello", 5)); - - // *** Read with stop tag, even length *** - at.clear_error(); - char table3[] = "6865OK\r\n"; - at.flush(); - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf3[6]; - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - CHECK(2 == at.read_hex_string(buf3, 2 + 1/*get to stop tag match*/)); - CHECK(!strncmp(buf3, "he", 2)); - at.resp_stop(); - - // *** Read with stop tag, odd length *** - at.clear_error(); - char table4[] = "686OK\r\n"; - at.flush(); - filehandle_stub_table = table4; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = 1; - char buf4[6]; - // Set _stop_tag to resp_stop(OKCRLF) - at.resp_start(); - CHECK(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/)); - CHECK(!strncmp(buf4, "h", 1)); -} - -void Test_ATHandler::test_ATHandler_read_int() -{ - EventQueue que; - FileHandle_stub fh1; - filehandle_stub_table = NULL; - filehandle_stub_table_pos = 0; - - ATHandler at(&fh1, que, 0, ","); - - int32_t ret = at.read_int(); - CHECK(-1 == ret); - at.clear_error(); - - char table[] = "\",\"OK\r\n\0"; - filehandle_stub_table = table; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = strlen(table); - - at.resp_start(); - - ret = at.read_int(); - CHECK(-1 == ret); - at.flush(); - at.clear_error(); - - char table2[] = "\"2,\"OK\r\n\0"; - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = strlen(table2); - - at.resp_start(); - - ret = at.read_int(); - CHECK(2 == ret); - -} - -void Test_ATHandler::test_ATHandler_resp_start() -{ - EventQueue que; - FileHandle_stub fh1; - - filehandle_stub_table = NULL; - filehandle_stub_table_pos = 0; - - ATHandler at(&fh1, que, 0, ","); - at.resp_start(); - at.resp_start(); - - char table2[] = "\"2,\"OK\r\n\0"; - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start("ssssaaaassssaaaassss"); //too long prefix - - char table3[] = "+CME ERROR: 108\0"; - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - - char table4[] = "+CMS ERROR: 6\0"; - filehandle_stub_table = table4; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - - char table5[] = "ERROR\r\n\0"; - filehandle_stub_table = table5; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - - char table6[] = "OK\r\n\0"; - filehandle_stub_table = table6; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - - char table7[] = "ssssss\0"; - filehandle_stub_table = table7; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.set_urc_handler("ss", NULL); - at.resp_start(); -} - -void Test_ATHandler::test_ATHandler_resp_stop() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - - char table[] = "21 OK\r\n\0"; - filehandle_stub_table = table; - filehandle_stub_table_pos = 0; - - at.info_elem('2'); - at.set_stop_tag("OK\r\n"); - at.resp_stop(); - - char table3[] = "+CME ERROR: 108\0"; - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start(); - - at.resp_stop(); - - char table7[] = "ssssss\0"; - filehandle_stub_table = table7; - filehandle_stub_table_pos = 0; - - at.flush(); - at.clear_error(); - at.resp_start("ss", false); - at.resp_stop(); -} - -void Test_ATHandler::test_ATHandler_info_resp() -{ - EventQueue que; - FileHandle_stub fh1; - - filehandle_stub_table = NULL; - - ATHandler at(&fh1, que, 0, ","); - CHECK(at.info_resp()); - - at.resp_start(); - CHECK(!at.info_resp()); - - at.flush(); - at.clear_error(); - - char table2[] = "21 OK\r\n\0"; - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = strlen(table2); - - at.resp_start("21"); - CHECK(at.info_resp()); - - CHECK(!at.info_resp()); - - at.flush(); - at.clear_error(); - - char table3[] = "21 OK\r\n\0"; - filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = strlen(table3); - - CHECK(at.info_resp()); -} - -void Test_ATHandler::test_ATHandler_info_elem() -{ - EventQueue que; - FileHandle_stub fh1; - - char table[] = "21 OK\r\n\0"; - filehandle_stub_table = table; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = strlen(table); - - ATHandler at(&fh1, que, 0, ","); - CHECK(!at.info_elem('O')); - at.flush(); - - char table2[] = "21 OK\r\n\0"; - filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; - mbed_poll_stub::revents_value = POLLIN; - mbed_poll_stub::int_value = strlen(table2); - - at.clear_error(); - at.resp_start("21"); - CHECK(at.info_elem('O')); - at.flush(); - - filehandle_stub_table = NULL; - filehandle_stub_table_pos = 0; - - at.clear_error(); - at.resp_start("21"); - CHECK(!at.info_elem('2')); -} - -void Test_ATHandler::test_ATHandler_consume_to_stop_tag() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - CHECK(at.consume_to_stop_tag()); -} - -void Test_ATHandler::test_ATHandler_set_debug() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - at.set_debug(true); - - at.set_debug(false); -} - -void Test_ATHandler::test_ATHandler_get_3gpp_error() -{ - EventQueue que; - FileHandle_stub fh1; - - ATHandler at(&fh1, que, 0, ","); - int ret = at.get_3gpp_error(); -} diff --git a/features/cellular/UNITTESTS/at/athandler/test_athandler.h b/features/cellular/UNITTESTS/at/athandler/test_athandler.h deleted file mode 100644 index 3d74fb0afd..0000000000 --- a/features/cellular/UNITTESTS/at/athandler/test_athandler.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_ATHANDLER_H -#define TEST_ATHANDLER_H - -class Test_ATHandler { -public: - Test_ATHandler(); - - virtual ~Test_ATHandler(); - - void test_ATHandler_constructor(); - - void test_ATHandler_get_file_handle(); - - void test_ATHandler_set_file_handle(); - - void test_ATHandler_lock(); - - void test_ATHandler_unlock(); - - void test_ATHandler_unlock_return_error(); - - void test_ATHandler_set_urc_handler(); - - void test_ATHandler_get_last_error(); - - void test_ATHandler_get_last_device_error(); - - void test_ATHandler_inc_ref_count(); - - void test_ATHandler_dec_ref_count(); - - void test_ATHandler_get_ref_count(); - - void test_ATHandler_set_at_timeout(); - - void test_ATHandler_restore_at_timeout(); - - void test_ATHandler_clear_error(); - - void test_ATHandler_process_oob(); - - void test_ATHandler_set_filehandle_sigio(); - - void test_ATHandler_flush(); - - void test_ATHandler_cmd_start(); - - void test_ATHandler_write_int(); - - void test_ATHandler_write_string(); - - void test_ATHandler_cmd_stop(); - - void test_ATHandler_write_bytes(); - - void test_ATHandler_set_stop_tag(); - - void test_ATHandler_set_delimiter(); - - void test_ATHandler_skip_param(); - - void test_ATHandler_read_bytes(); - - void test_ATHandler_read_string(); - - void test_ATHandler_read_hex_string(); - - void test_ATHandler_read_int(); - - void test_ATHandler_resp_start(); - - void test_ATHandler_resp_stop(); - - void test_ATHandler_info_resp(); - - void test_ATHandler_info_elem(); - - void test_ATHandler_consume_to_stop_tag(); - - void test_ATHandler_set_debug(); - - void test_ATHandler_get_3gpp_error(); -}; - -#endif // TEST_ATHANDLER_H - diff --git a/features/cellular/UNITTESTS/common/util/Makefile b/features/cellular/UNITTESTS/common/util/Makefile deleted file mode 100644 index bcfa9092b2..0000000000 --- a/features/cellular/UNITTESTS/common/util/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -include ../../makefile_defines.txt - -COMPONENT_NAME = util_unit - -#This must be changed manually -SRC_FILES = \ - ../../../framework/common/CellularUtil.cpp - -TEST_SRC_FILES = \ - main.cpp \ - utiltest.cpp \ - test_util.cpp \ - ../../stubs/randLIB_stub.cpp \ - -include ../../MakefileWorker.mk - -CPPUTESTFLAGS += -DFEA_TRACE_SUPPORT - diff --git a/features/cellular/UNITTESTS/common/util/main.cpp b/features/cellular/UNITTESTS/common/util/main.cpp deleted file mode 100644 index 6ebe329133..0000000000 --- a/features/cellular/UNITTESTS/common/util/main.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 "CppUTest/CommandLineTestRunner.h" -#include "CppUTest/TestPlugin.h" -#include "CppUTest/TestRegistry.h" -#include "CppUTestExt/MockSupportPlugin.h" -int main(int ac, char **av) -{ - return CommandLineTestRunner::RunAllTests(ac, av); -} - -IMPORT_TEST_GROUP(util); - diff --git a/features/cellular/UNITTESTS/common/util/test_util.cpp b/features/cellular/UNITTESTS/common/util/test_util.cpp deleted file mode 100644 index a8078dcf5b..0000000000 --- a/features/cellular/UNITTESTS/common/util/test_util.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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 "CppUTest/TestHarness.h" -#include "test_util.h" -#include -#include "CellularUtil.h" - -using namespace mbed_cellular_util; - -Test_util::Test_util() -{ - -} - -Test_util::~Test_util() -{ -} - -void Test_util::test_util_uint_to_binary_string() -{ - char str[33]; - uint_to_binary_str(15, str, 33, 32); - str[32] = '\0'; - // 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111" - STRCMP_EQUAL("00000000000000000000000000001111", str); - - // test NULL pointer - uint_to_binary_str(15, NULL, 0, 32); - - // test give too small buffer - char too_small[5]; - uint_to_binary_str(15, too_small, 5, 6); -} - -void Test_util::test_util_char_str_to_hex() -{ - // basic conversion test, happy days - char hex_buf[50]; - uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf); - hex_buf[number_of_hex_chars] = '\0'; - STRCMP_EQUAL("31323334", hex_buf); - LONGS_EQUAL(8, number_of_hex_chars); - - number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf); - hex_buf[number_of_hex_chars] = '\0'; - STRCMP_EQUAL("7775687575", hex_buf); - LONGS_EQUAL(10, number_of_hex_chars); - - // First don't omit the leading zero and then omit and check that leading zero is missing - number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf); - hex_buf[number_of_hex_chars] = '\0'; - STRCMP_EQUAL("0A7775687575", hex_buf); - LONGS_EQUAL(12, number_of_hex_chars); - - number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true); - hex_buf[number_of_hex_chars] = '\0'; - STRCMP_EQUAL("A7775687575", hex_buf); - LONGS_EQUAL(11, number_of_hex_chars); - - // test giving a null pointer - number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf); - LONGS_EQUAL(0, number_of_hex_chars); - number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL); - LONGS_EQUAL(0, number_of_hex_chars); -} - -void Test_util::test_util_convert_ipv6() -{ - // leading zeros omitted - char ipv6[64]; - strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64); - convert_ipv6(ipv6); - STRCMP_EQUAL("101:101:101:101:101:101:101:101", ipv6); - LONGS_EQUAL(31, strlen(ipv6)); - - // some omitted and some not so much - strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64); - convert_ipv6(ipv6); - STRCMP_EQUAL("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6); - LONGS_EQUAL(38, strlen(ipv6)); - - // test giving a null pointer - convert_ipv6(NULL); -} - -void Test_util::test_util_prefer_ipv6() -{ - char tt[20] = "62.241.198.246"; - char temp[64] = "2001:14B8:1000:000:000:000:000:002"; - - // not enough space to swap, arrays should stay the same - prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp)); - STRCMP_EQUAL("62.241.198.246", tt); - STRCMP_EQUAL("2001:14B8:1000:000:000:000:000:002", temp); - - // should swap as first one was ip4 and later was ipv6 and enough space - char tt2[64] = "62.241.198.246"; - prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp)); - STRCMP_EQUAL("62.241.198.246", temp); - STRCMP_EQUAL("2001:14B8:1000:000:000:000:000:002", tt2); -} - -void Test_util::test_util_separate_ip_addresses() -{ - char *s = (char *)malloc(128); - - char ip[64] = {0}; - char subnet[64] = {0}; - - strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip); - STRCMP_EQUAL("001:203:405:607:809:A0B:C0D:E0F", subnet); - - strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip); - STRCMP_EQUAL("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4\0", 8); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("1.2.3.4", ip); - STRCMP_EQUAL("", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4.5.6.7.8\0", 16); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("1.2.3.4", ip); - STRCMP_EQUAL("5.6.7.8", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("102:304:506:708:90A:B0C:D0E:F10", ip); - STRCMP_EQUAL("", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip); - STRCMP_EQUAL("", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("1.2.3.4", ip); - STRCMP_EQUAL("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet); - - ip[0] = '\0'; - subnet[0] = '\0'; - strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51); - separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); - STRCMP_EQUAL("1.2.3.4", ip); - STRCMP_EQUAL("506:708:90A:B0C:D0E:F10:1112:1314", subnet); - STRCMP_EQUAL("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s); - -} diff --git a/features/cellular/UNITTESTS/common/util/test_util.h b/features/cellular/UNITTESTS/common/util/test_util.h deleted file mode 100644 index 7f6b28ee5f..0000000000 --- a/features/cellular/UNITTESTS/common/util/test_util.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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. - */ -#ifndef TEST_UTIL_H -#define TEST_UTIL_H - -class Test_util { -public: - Test_util(); - - virtual ~Test_util(); - - void test_util_uint_to_binary_string(); - - void test_util_char_str_to_hex(); - - void test_util_convert_ipv6(); - - void test_util_prefer_ipv6(); - - void test_util_separate_ip_addresses(); -}; - -#endif // TEST_UTIL_H - diff --git a/features/cellular/UNITTESTS/common/util/utiltest.cpp b/features/cellular/UNITTESTS/common/util/utiltest.cpp deleted file mode 100644 index 52a6db6c07..0000000000 --- a/features/cellular/UNITTESTS/common/util/utiltest.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2015, 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 "CppUTest/TestHarness.h" -#include "test_util.h" - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -TEST_GROUP(util) -{ - Test_util *unit; - - void setup() - { - unit = new Test_util(); - } - - void teardown() - { - delete unit; - } -}; -// *INDENT-ON* - -TEST(util, Create) -{ - CHECK(unit != NULL); -} - -TEST(util, test_util_uint_to_binary_string) -{ - unit->test_util_uint_to_binary_string(); -} - -TEST(util, char_str_to_hex) -{ - unit->test_util_char_str_to_hex(); -} - -TEST(util, convert_ipv6) -{ - unit->test_util_convert_ipv6(); -} - -TEST(util, prefer_ipv6) -{ - unit->test_util_prefer_ipv6(); -} - -TEST(util, separate_ip_addresses) -{ - unit->test_util_separate_ip_addresses(); -} diff --git a/features/cellular/UNITTESTS/makefile_defines.txt b/features/cellular/UNITTESTS/makefile_defines.txt deleted file mode 100755 index d11de61cfd..0000000000 --- a/features/cellular/UNITTESTS/makefile_defines.txt +++ /dev/null @@ -1,32 +0,0 @@ -#--- Inputs ----# -CPPUTEST_HOME = /usr -CPPUTEST_USE_EXTENSIONS = Y -CPPUTEST_USE_VPATH = Y -CPPUTEST_USE_GCOV = Y -CPPUTEST_USE_MEM_LEAK_DETECTION = N -CPP_PLATFORM = gcc -INCLUDE_DIRS =\ - .\ - ../../stubs\ - ../../target_h\ - ../../..\ - ../../../../../features \ - ../../../../../features/netsocket \ - ../../../../.. \ - ../../../../../rtos \ - ../../../../../rtos/TARGET_CORTEX \ - ../../../../../platform \ - ../../../../../hal \ - ../../../../../events \ - ../../../../../events/equeue \ - ../../../../../drivers \ - ../../../framework\ - ../../../framework/common\ - ../../../framework/AT\ - ../../../framework/API\ - /usr/include\ - $(CPPUTEST_HOME)/include\ - -CPPUTESTFLAGS = -D__thumb2__ -w -D__INLINE=__inline -CPPUTEST_CFLAGS += -std=gnu99 - diff --git a/features/cellular/UNITTESTS/run_tests b/features/cellular/UNITTESTS/run_tests deleted file mode 100755 index f4f7a48298..0000000000 --- a/features/cellular/UNITTESTS/run_tests +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash -echo -echo Build Cellular unit tests -echo - -#replace by empty string if no branch coverage is needed -#branch_cov="--rc lcov_branch_coverage=1" -branch_cov="" -#branch_data="--rc branch-coverage=1" -branch_data="--no-branch-coverage" - -# Remember to add new test folder to Makefile -make clean >/dev/null 2>&1 -make all - -echo -echo Create results -echo -mkdir results - -find ./ -name '*.xml' | xargs cp -t ./results/ - -echo -echo Create coverage document -echo -mkdir coverages -cd coverages - -lcov -q -d ../. -c -o app.info $branch_cov -lcov -q -r app.info "/test*" -o app.info $branch_cov -lcov -q -r app.info "/usr*" -o app.info $branch_cov -lcov -q -r app.info "/UNITTESTS/common*" -o app.info $branch_cov -lcov -q -r app.info "/UNITTESTS/*" -o app.info $branch_cov -lcov -q -r app.info "/UNITTESTS/stubs*" -o app.info $branch_cov -lcov -q -r app.info "/UNITTESTS/target_h*" -o app.info $branch_cov -lcov -q -r app.info "/mbed-client*" -o app.info $branch_cov -lcov -q -r app.info "/events*" -o app.info $branch_cov -lcov -q -r app.info "/features/netsocket*" -o app.info $branch_cov -lcov -q -r app.info "/platform*" -o app.info $branch_cov -genhtml $branch_data app.info -cd .. -echo -echo -echo -echo Have a nice bug hunt! -echo -echo -echo diff --git a/features/cellular/UNITTESTS/stubs/ATCmdParser.cpp b/features/cellular/UNITTESTS/stubs/ATCmdParser.cpp deleted file mode 100644 index d9157ec848..0000000000 --- a/features/cellular/UNITTESTS/stubs/ATCmdParser.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright (c) 2017, 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 "ATCmdParser.h" -#include "mbed_poll.h" -#include "mbed_debug.h" - -#ifdef LF -#undef LF -#define LF 10 -#else -#define LF 10 -#endif - -#ifdef CR -#undef CR -#define CR 13 -#else -#define CR 13 -#endif - -// getc/putc handling with timeouts -int ATCmdParser::putc(char c) -{ - pollfh fhs; - fhs.fh = _fh; - fhs.events = POLLOUT; - - int count = poll(&fhs, 1, _timeout); - if (count > 0 && (fhs.revents & POLLOUT)) { - return _fh->write(&c, 1) == 1 ? 0 : -1; - } else { - return -1; - } -} - -int ATCmdParser::getc() -{ - pollfh fhs; - fhs.fh = _fh; - fhs.events = POLLIN; - - int count = poll(&fhs, 1, _timeout); - if (count > 0 && (fhs.revents & POLLIN)) { - unsigned char ch; - return _fh->read(&ch, 1) == 1 ? ch : -1; - } else { - return -1; - } -} - -void ATCmdParser::flush() -{ - while (_fh->readable()) { - unsigned char ch; - _fh->read(&ch, 1); - } -} - - -// read/write handling with timeouts -int ATCmdParser::write(const char *data, int size) -{ - int i = 0; - for (; i < size; i++) { - if (putc(data[i]) < 0) { - return -1; - } - } - return i; -} - -int ATCmdParser::read(char *data, int size) -{ - int i = 0; - for (; i < size; i++) { - int c = getc(); - if (c < 0) { - return -1; - } - data[i] = c; - } - return i; -} - - -// printf/scanf handling -int ATCmdParser::vprintf(const char *format, va_list args) -{ - - if (vsprintf(_buffer, format, args) < 0) { - return false; - } - - int i = 0; - for (; _buffer[i]; i++) { - if (putc(_buffer[i]) < 0) { - return -1; - } - } - return i; -} - -int ATCmdParser::vscanf(const char *format, va_list args) -{ - // Since format is const, we need to copy it into our buffer to - // add the line's null terminator and clobber value-matches with asterisks. - // - // We just use the beginning of the buffer to avoid unnecessary allocations. - int i = 0; - int offset = 0; - - while (format[i]) { - if (format[i] == '%' && format[i + 1] != '%' && format[i + 1] != '*') { - _buffer[offset++] = '%'; - _buffer[offset++] = '*'; - i++; - } else { - _buffer[offset++] = format[i++]; - } - } - - // Scanf has very poor support for catching errors - // fortunately, we can abuse the %n specifier to determine - // if the entire string was matched. - _buffer[offset++] = '%'; - _buffer[offset++] = 'n'; - _buffer[offset++] = 0; - - // To workaround scanf's lack of error reporting, we actually - // make two passes. One checks the validity with the modified - // format string that only stores the matched characters (%n). - // The other reads in the actual matched values. - // - // We keep trying the match until we succeed or some other error - // derails us. - int j = 0; - - while (true) { - // Ran out of space - if (j + 1 >= _buffer_size - offset) { - return false; - } - // Recieve next character - int c = getc(); - if (c < 0) { - return -1; - } - _buffer[offset + j++] = c; - _buffer[offset + j] = 0; - - // Check for match - int count = -1; - sscanf(_buffer + offset, _buffer, &count); - - // We only succeed if all characters in the response are matched - if (count == j) { - // Store the found results - vsscanf(_buffer + offset, format, args); - return j; - } - } -} - - -// Command parsing with line handling -bool ATCmdParser::vsend(const char *command, va_list args) -{ - // Create and send command - if (vsprintf(_buffer, command, args) < 0) { - return false; - } - - for (int i = 0; _buffer[i]; i++) { - if (putc(_buffer[i]) < 0) { - return false; - } - } - - // Finish with newline - for (size_t i = 0; _output_delimiter[i]; i++) { - if (putc(_output_delimiter[i]) < 0) { - return false; - } - } - - debug_if(_dbg_on, "AT> %s\n", _buffer); - return true; -} - -bool ATCmdParser::vrecv(const char *response, va_list args) -{ -restart: - _aborted = false; - // Iterate through each line in the expected response - while (response[0]) { - // Since response is const, we need to copy it into our buffer to - // add the line's null terminator and clobber value-matches with asterisks. - // - // We just use the beginning of the buffer to avoid unnecessary allocations. - int i = 0; - int offset = 0; - bool whole_line_wanted = false; - - while (response[i]) { - if (response[i] == '%' && response[i + 1] != '%' && response[i + 1] != '*') { - _buffer[offset++] = '%'; - _buffer[offset++] = '*'; - i++; - } else { - _buffer[offset++] = response[i++]; - // Find linebreaks, taking care not to be fooled if they're in a %[^\n] conversion specification - if (response[i - 1] == '\n' && !(i >= 3 && response[i - 3] == '[' && response[i - 2] == '^')) { - whole_line_wanted = true; - break; - } - } - } - - // Scanf has very poor support for catching errors - // fortunately, we can abuse the %n specifier to determine - // if the entire string was matched. - _buffer[offset++] = '%'; - _buffer[offset++] = 'n'; - _buffer[offset++] = 0; - - debug_if(_dbg_on, "AT? %s\n", _buffer); - // To workaround scanf's lack of error reporting, we actually - // make two passes. One checks the validity with the modified - // format string that only stores the matched characters (%n). - // The other reads in the actual matched values. - // - // We keep trying the match until we succeed or some other error - // derails us. - int j = 0; - - while (true) { - // Receive next character - int c = getc(); - if (c < 0) { - debug_if(_dbg_on, "AT(Timeout)\n"); - return false; - } - // Simplify newlines (borrowed from retarget.cpp) - if ((c == CR && _in_prev != LF) || - (c == LF && _in_prev != CR)) { - _in_prev = c; - c = '\n'; - } else if ((c == CR && _in_prev == LF) || - (c == LF && _in_prev == CR)) { - _in_prev = c; - // onto next character - continue; - } else { - _in_prev = c; - } - _buffer[offset + j++] = c; - _buffer[offset + j] = 0; - - // Check for oob data - for (struct oob *oob = _oobs; oob; oob = oob->next) { - if ((unsigned)j == oob->len && memcmp( - oob->prefix, _buffer + offset, oob->len) == 0) { - debug_if(_dbg_on, "AT! %s\n", oob->prefix); - oob->cb(); - - if (_aborted) { - debug_if(_dbg_on, "AT(Aborted)\n"); - return false; - } - // oob may have corrupted non-reentrant buffer, - // so we need to set it up again - goto restart; - } - } - - // Check for match - int count = -1; - if (whole_line_wanted && c != '\n') { - // Don't attempt scanning until we get delimiter if they included it in format - // This allows recv("Foo: %s\n") to work, and not match with just the first character of a string - // (scanf does not itself match whitespace in its format string, so \n is not significant to it) - } else { - sscanf(_buffer + offset, _buffer, &count); - } - - // We only succeed if all characters in the response are matched - if (count == j) { - debug_if(_dbg_on, "AT= %s\n", _buffer + offset); - // Reuse the front end of the buffer - memcpy(_buffer, response, i); - _buffer[i] = 0; - - // Store the found results - vsscanf(_buffer + offset, _buffer, args); - - // Jump to next line and continue parsing - response += i; - break; - } - - // Clear the buffer when we hit a newline or ran out of space - // running out of space usually means we ran into binary data - if (c == '\n' || j + 1 >= _buffer_size - offset) { - debug_if(_dbg_on, "AT< %s", _buffer + offset); - j = 0; - } - } - } - - return true; -} - -// Mapping to vararg functions -int ATCmdParser::printf(const char *format, ...) -{ - va_list args; - va_start(args, format); - int res = vprintf(format, args); - va_end(args); - return res; -} - -int ATCmdParser::scanf(const char *format, ...) -{ - va_list args; - va_start(args, format); - int res = vscanf(format, args); - va_end(args); - return res; -} - -bool ATCmdParser::send(const char *command, ...) -{ - va_list args; - va_start(args, command); - bool res = vsend(command, args); - va_end(args); - return res; -} - -bool ATCmdParser::recv(const char *response, ...) -{ - va_list args; - va_start(args, response); - bool res = vrecv(response, args); - va_end(args); - return res; -} - -// oob registration -void ATCmdParser::oob(const char *prefix, Callback cb) -{ - struct oob *oob = new struct oob; - oob->len = strlen(prefix); - oob->prefix = prefix; - oob->cb = cb; - oob->next = _oobs; - _oobs = oob; -} - -void ATCmdParser::abort() -{ - _aborted = true; -} - -bool ATCmdParser::process_oob() -{ - if (!_fh->readable()) { - return false; - } - - int i = 0; - while (true) { - // Receive next character - int c = getc(); - if (c < 0) { - return false; - } - _buffer[i++] = c; - _buffer[i] = 0; - - // Check for oob data - struct oob *oob = _oobs; - while (oob) { - if (i == (int)oob->len && memcmp( - oob->prefix, _buffer, oob->len) == 0) { - debug_if(_dbg_on, "AT! %s\r\n", oob->prefix); - oob->cb(); - return true; - } - oob = oob->next; - } - - // Clear the buffer when we hit a newline or ran out of space - // running out of space usually means we ran into binary data - if (i + 1 >= _buffer_size || - strcmp(&_buffer[i - _output_delim_size], _output_delimiter) == 0) { - - debug_if(_dbg_on, "AT< %s", _buffer); - i = 0; - } - } -} - - diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.cpp deleted file mode 100644 index e1f8526f5f..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2017, 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 "nsapi_types.h" -#include "AT_CellularBase.h" -#include "AT_CellularBase_stub.h" - - -using namespace mbed; - -ATHandler *AT_CellularBase_stub::handler_value = NULL; -ATHandler *AT_CellularBase_stub::handler_at_constructor_value = NULL; -device_err_t AT_CellularBase_stub::device_err_value; -bool AT_CellularBase_stub::supported_bool = true; - -AT_CellularBase::AT_CellularBase(ATHandler &at) : _at(at) -{ - AT_CellularBase_stub::handler_at_constructor_value = &_at; -} - -ATHandler &AT_CellularBase::get_at_handler() -{ - return *AT_CellularBase_stub::handler_value; -} - -device_err_t AT_CellularBase::get_device_error() const -{ - return AT_CellularBase_stub::device_err_value; -} - -bool AT_CellularBase::is_supported(SupportedFeature feature) -{ - return AT_CellularBase_stub::supported_bool; -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.h b/features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.h deleted file mode 100644 index f7d117d192..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularBase_stub.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2017, 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 "ATHandler.h" - -namespace AT_CellularBase_stub { -extern mbed::ATHandler *handler_value; -extern mbed::ATHandler *handler_at_constructor_value; -extern mbed::device_err_t device_err_value; -extern bool supported_bool; -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularDevice_stub.cpp deleted file mode 100644 index 2010018ced..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularDevice.h" - -AT_CellularDevice::AT_CellularDevice(EventQueue &queue) : - _atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _multiplexer(0), _information(0), _queue(queue) -{ -} - -AT_CellularDevice::~AT_CellularDevice() -{ -} - -ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle) -{ - return NULL; -} - -void AT_CellularDevice::release_at_handler(ATHandler *at_handler) -{ - -} - -CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) -{ - return NULL; -} - -CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) -{ - return NULL; -} - -CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) -{ - return NULL; -} - -CellularPower *AT_CellularDevice::open_power(FileHandle *fh) -{ - return NULL; -} - -CellularMultiplexer *AT_CellularDevice::open_multiplexer(FileHandle *fh) -{ - return NULL; -} - -CellularInformation *AT_CellularDevice::open_information(FileHandle *fh) -{ - return NULL; -} - -void AT_CellularDevice::close_network() -{ -} - -void AT_CellularDevice::close_sms() -{ -} - -void AT_CellularDevice::close_power() -{ -} - -void AT_CellularDevice::close_sim() -{ -} - -void AT_CellularDevice::close_multiplexer() -{ -} - -void AT_CellularDevice::close_information() -{ -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularInformation_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularInformation_stub.cpp deleted file mode 100644 index a41b3080d5..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularInformation_stub.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 "AT_CellularInformation.h" -#include "nsapi_types.h" - -using namespace mbed; - -AT_CellularInformation::AT_CellularInformation(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularInformation::~AT_CellularInformation() -{ -} - -nsapi_error_t AT_CellularInformation::get_manufacturer(char *buf, size_t buf_size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularInformation::get_model(char *buf, size_t buf_size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type) -{ - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp deleted file mode 100644 index c397d5fb38..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularMultiplexer_stub.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularMultiplexer.h" -#include "CellularLog.h" -#include "nsapi_types.h" - -using namespace mbed; - -AT_CellularMultiplexer::AT_CellularMultiplexer(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularMultiplexer::~AT_CellularMultiplexer() -{ -} - -nsapi_error_t AT_CellularMultiplexer::multiplexer_mode_start() -{ - return 0; -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp deleted file mode 100644 index c4ba878439..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularNetwork_stub.cpp +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularNetwork.h" -#include "CellularNetwork.h" -#include "CellularUtil.h" -#include "CellularLog.h" -#include "FileHandle.h" -#include "nsapi_types.h" - -using namespace mbed; -using namespace mbed_cellular_util; - -AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler) -{ -} - -AT_CellularNetwork::~AT_CellularNetwork() -{ -} - -nsapi_error_t AT_CellularNetwork::init() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn, - const char *username, const char *password) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn, - AuthenticationType type, const char *username, const char *password) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::connect(const char *apn, - const char *username, const char *password) -{ - return connect(); -} - -nsapi_error_t AT_CellularNetwork::connect() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::activate_context() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::open_data_channel() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::disconnect() -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularNetwork::attach(Callback status_cb) -{ -} - -nsapi_connection_status_t AT_CellularNetwork::get_connection_status() const -{ - return NSAPI_STATUS_LOCAL_UP; -} - -nsapi_error_t AT_CellularNetwork::set_blocking(bool blocking) -{ - return NSAPI_ERROR_OK;; -} - -nsapi_ip_stack_t AT_CellularNetwork::string_to_stack_type(const char *pdp_type) -{ - return IPV4_STACK; -} - -nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bool urc_on) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_network_registering_mode(NWRegisteringMode &mode) -{ - mode = NWModeAutomatic; - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type, RegistrationStatus &status) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_cell_id(int &cell_id) -{ - return NSAPI_ERROR_OK; -} - -AT_CellularNetwork::RegistrationMode AT_CellularNetwork::has_registration(RegistrationType reg_type) -{ - return RegistrationModeDisable; -} - -nsapi_error_t AT_CellularNetwork::set_attach(int timeout) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::detach() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoffTime) -{ - return NSAPI_ERROR_OK; -} - -NetworkStack *AT_CellularNetwork::get_stack() -{ - return NULL; -} - -const char *AT_CellularNetwork::get_ip_address() -{ - return NULL; -} - -nsapi_error_t AT_CellularNetwork::set_stack_type(nsapi_ip_stack_t stack_type) -{ - return NSAPI_ERROR_OK; -} - -nsapi_ip_stack_t AT_CellularNetwork::get_stack_type() -{ - return IPV4_STACK; -} - -bool AT_CellularNetwork::get_modem_stack_type(nsapi_ip_stack_t requested_stack) -{ - return false; -} - -void AT_CellularNetwork::urc_no_carrier() -{ - -} - -nsapi_error_t AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::set_access_technology(RadioAccessTechnology opAct) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_access_technology(RadioAccessTechnology &rat) -{ - rat = RAT_CATM1; - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt supported_opt, - Preferred_UE_Opt preferred_opt) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt &supported_opt, - Preferred_UE_Opt &preferred_opt) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_rate_control( - CellularNetwork::RateControlExceptionReports &reports, - CellularNetwork::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate) -{ - return NSAPI_ERROR_OK; -} - - -nsapi_error_t AT_CellularNetwork::get_pdpcontext_params(pdpContextList_t ¶ms_list) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::get_operator_params(int &format, operator_t &operator_params) -{ - return NSAPI_ERROR_OK; -} - -int AT_CellularNetwork::get_3gpp_error() -{ - return 0; -} - -nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_names) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularNetwork::do_user_authentication() -{ - return NSAPI_ERROR_OK; -} - - - diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularPower_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularPower_stub.cpp deleted file mode 100644 index 3459088ce5..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularPower_stub.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularPower.h" -#include "CellularUtil.h" -#include "CellularLog.h" - -using namespace mbed_cellular_util; -using namespace mbed; - -AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularPower::~AT_CellularPower() -{ -} - -nsapi_error_t AT_CellularPower::on() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::off() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::set_at_mode() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::reset() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int active_time) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback callback) -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback callback) -{ - -} - -nsapi_error_t AT_CellularPower::is_device_ready() -{ - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularSIM_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularSIM_stub.cpp deleted file mode 100644 index fc4be35b94..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularSIM_stub.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularSIM::~AT_CellularSIM() -{ -} - -nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::get_imsi(char *imsi) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - return NSAPI_ERROR_OK; -} diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularSMS_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularSMS_stub.cpp deleted file mode 100644 index 66456d7295..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularSMS_stub.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (c) 2017, 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 -#include "AT_CellularSMS.h" -#include "CellularLog.h" - -using namespace mbed; - -#define CTRL_Z "\x1a" -#define ESC "\x1b" - -const int SMS_STATUS_SIZE = 12 + 1; -const int FIRST_OCTET_DELIVER_SUBMIT = 17; -const int TP_VALIDITY_PERIOD_24_HOURS = 167; -const int TP_PROTOCOL_IDENTIFIER = 0; -const int SMS_DATA_CODING_SCHEME = 0; - -const uint16_t SMS_MAX_8BIT_CONCATENATED_SINGLE_SMS_SIZE = 134; -const uint16_t SMS_MAX_GSM7_CONCATENATED_SINGLE_SMS_SIZE = 153; - - -AT_CellularSMS::AT_CellularSMS(ATHandler &at) : AT_CellularBase(at), _cb(0), _mode(CellularSMSMmodeText), - _use_8bit_encoding(false), _sim_wait_time(0), _sms_message_ref_number(1), _sms_info(NULL) -{ -} - -AT_CellularSMS::~AT_CellularSMS() -{ -} - -void AT_CellularSMS::cmt_urc() -{ -} - -void AT_CellularSMS::cmti_urc() -{ -} - -nsapi_error_t AT_CellularSMS::set_cnmi() -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSMS::set_csdh(int show_header) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode) -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularSMS::set_extra_sim_wait_time(int sim_wait_time) -{ -} - -char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message, uint8_t message_length, uint8_t msg_parts, - uint8_t msg_part_number, uint8_t &header_size) -{ - return NULL; -} - -nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const char *message, int msg_len) -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularSMS::set_sms_callback(Callback func) -{ -} - -nsapi_error_t AT_CellularSMS::set_cpms(const char *memr, const char *memw, const char *mems) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSMS::set_csca(const char *sca, int type) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularSMS::set_cscs(const char *chr_set) -{ - return NSAPI_ERROR_OK; -} - -//nsapi_error_t AT_CellularSMS::set_csms(int msg_service) -//{ -// return NSAPI_ERROR_OK; -//} - -nsapi_error_t AT_CellularSMS::delete_sms(sms_info_t *sms) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSMS::delete_all_messages() -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char *buf, uint16_t len, char *phone_num, char *time_stamp) -{ - return NSAPI_ERROR_OK; -} - -// read msg in PDU mode -nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char *phone_num, char *time_stamp) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *phone_num, uint16_t phone_len, - char *time_stamp, uint16_t time_len, int *buf_size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularSMS::get_data_from_pdu(const char *pdu, sms_info_t *info, int *part_number, char *phone_number, char *msg) -{ - return NSAPI_ERROR_OK; -} - -// read params from User DEfined Header -int AT_CellularSMS::read_udh_from_pdu(const char *pdu, sms_info_t *info, int &part_number, int &padding_bits) -{ - return 0; -} - -nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload(const char *pdu, int msg_len, int scheme, char *msg, int padding_bits) -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularSMS::free_linked_list() -{ -} - -void AT_CellularSMS::add_info(sms_info_t *info, int index, int part_number) -{ -} - -// reads all the messages to the linked list AT_CellularSMS::_sms_info -nsapi_error_t AT_CellularSMS::list_messages() -{ - return NSAPI_ERROR_OK; -} - -AT_CellularSMS::sms_info_t *AT_CellularSMS::get_oldest_sms_index() -{ - return NULL; -} - -// if time_string_1 is greater (more fresh date) then return 1, same 0, smaller -1. Error -2 -int AT_CellularSMS::compare_time_strings(const char *time_string_1, const char *time_string_2) -{ - return 0; -} - -bool AT_CellularSMS::create_time(const char *time_string, time_t *time) -{ - return 0; -} - diff --git a/features/cellular/UNITTESTS/stubs/AT_CellularStack_stub.cpp b/features/cellular/UNITTESTS/stubs/AT_CellularStack_stub.cpp deleted file mode 100644 index 640d8c1b68..0000000000 --- a/features/cellular/UNITTESTS/stubs/AT_CellularStack_stub.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularStack.h" -#include "CellularUtil.h" -#include "CellularLog.h" - -using namespace mbed_cellular_util; - -AT_CellularStack::AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : _at(atHandler), _socket(NULL), _cid(cid), _stack_type(stack_type) -{ -} - -AT_CellularStack::~AT_CellularStack() -{ -} - -const char *AT_CellularStack::get_ip_address() -{ - return NULL; -} - -nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularStack::socket_close(nsapi_socket_t handle) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularStack::socket_bind(nsapi_socket_t handle, const SocketAddress &addr) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularStack::socket_listen(nsapi_socket_t handle, int backlog) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularStack::socket_send(nsapi_socket_t handle, const void *data, unsigned size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &addr, const void *data, unsigned size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularStack::socket_recv(nsapi_socket_t handle, void *data, unsigned size) -{ - return NSAPI_ERROR_OK; -} - -nsapi_size_or_error_t AT_CellularStack::socket_recvfrom(nsapi_socket_t handle, SocketAddress *addr, void *buffer, unsigned size) -{ - return NSAPI_ERROR_OK; -} - -void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) -{ -} - diff --git a/features/cellular/UNITTESTS/stubs/CellularUtil_stub.cpp b/features/cellular/UNITTESTS/stubs/CellularUtil_stub.cpp deleted file mode 100644 index d4bcaf4916..0000000000 --- a/features/cellular/UNITTESTS/stubs/CellularUtil_stub.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) , 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 "CellularUtil.h" -#include -#include -#include - -namespace mbed_cellular_util { - -#define MAX_STRING_LEN 200 - -void str_copy_skip_char(char *dest, uint16_t dest_size, const char *src, char c) -{ -} - -void str_remove_char(char *src, char c) -{ -} - -void uint_to_binary_str(uint32_t num, char *str, uint8_t str_size, uint8_t bit_cnt) -{ -} - -// converts the given str to hex string to buf -uint16_t char_str_to_hex(const char *str, uint16_t len, char *buf, bool omit_leading_zero) -{ - return 0; -} - -void convert_ipv6(char *ip) -{ - -} - -char *find_dot_number(char *str, int dot_number) -{ - return NULL; -} - -void separate_ip4like_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size) -{ -} - -void separate_ip_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size) -{ -} - -void prefer_ipv6(char *ip, size_t ip_size, char *ip2, size_t ip2_size) -{ -} - -void int_to_hex_str(uint8_t num, char *buf) -{ - buf[0] = '0'; - buf[1] = '2'; -} - -int hex_str_to_int(const char *hex_string, int hex_string_length) -{ - return 0; -} - -int hex_str_to_char_str(const char *str, uint16_t len, char *buf) -{ - return 0; -} - -void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt) -{ - -} - -int char_str_to_hex_str(const char *str, uint16_t len, char *buf, bool omit_leading_zero) -{ - //The code is dependent on this, so this is easiest just to put here - if (!str || !buf) { - return 0; - } - - char *ptr = buf; - int i = 0; - while (i < len) { - if (omit_leading_zero == true && i == 0 && !(str[i] >> 4 & 0x0F)) { - *ptr++ = hex_values[(str[i]) & 0x0F]; - } else { - *ptr++ = hex_values[((str[i]) >> 4) & 0x0F]; - *ptr++ = hex_values[(str[i]) & 0x0F]; - } - i++; - } - return ptr - buf; -} - -uint16_t get_dynamic_ip_port() -{ - return 0; -} - -} // namespace mbed_cellular_util diff --git a/features/cellular/UNITTESTS/stubs/EventQueue_stub.cpp b/features/cellular/UNITTESTS/stubs/EventQueue_stub.cpp deleted file mode 100644 index 2df6028977..0000000000 --- a/features/cellular/UNITTESTS/stubs/EventQueue_stub.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) , 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 "EventQueue.h" -#include "Callback.h" - -using namespace mbed; - -namespace events { - -EventQueue::EventQueue(unsigned event_size, unsigned char *event_pointer) -{ -} - -EventQueue::~EventQueue() -{ -} - -void EventQueue::dispatch(int ms) -{ -} - -void EventQueue::break_dispatch() -{ -} - -unsigned EventQueue::tick() -{ - return 0; -} - -void EventQueue::cancel(int id) -{ -} - -void EventQueue::background(Callback update) -{ -} - -void EventQueue::chain(EventQueue *target) -{ -} - -} diff --git a/features/cellular/UNITTESTS/stubs/FileHandle_stub.cpp b/features/cellular/UNITTESTS/stubs/FileHandle_stub.cpp deleted file mode 100644 index d14d52b6fb..0000000000 --- a/features/cellular/UNITTESTS/stubs/FileHandle_stub.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) , 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 "FileHandle_stub.h" - -namespace mbed { - -off_t FileHandle::size() -{ - return 0; -} - -std::FILE *fdopen(FileHandle *fh, const char *mode) -{ - return NULL; -} - -} diff --git a/features/cellular/UNITTESTS/stubs/FileHandle_stub.h b/features/cellular/UNITTESTS/stubs/FileHandle_stub.h deleted file mode 100644 index e1548f2322..0000000000 --- a/features/cellular/UNITTESTS/stubs/FileHandle_stub.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#ifndef __FILE_HANDLE_STUB_H__ -#define __FILE_HANDLE_STUB_H__ - -#include "FileHandle.h" - - -namespace mbed { - -static uint8_t filehandle_stub_short_value_counter = 0; -static char *filehandle_stub_table = NULL; -static uint8_t filehandle_stub_table_pos = 0; - -class FileHandle_stub : public FileHandle { -public: - ssize_t size_value; - - FileHandle_stub() - { - size_value = 0; - } - - virtual ssize_t read(void *buffer, size_t size) - { - if (filehandle_stub_table) { - ssize_t ret = strlen(filehandle_stub_table) - filehandle_stub_table_pos; - if (ret >= 0 && size < ret) { - ret = size; - } - if (ret >= 0) { - memcpy(buffer, filehandle_stub_table, ret); - } - - filehandle_stub_table_pos += ret; - return ret; - } - return 0; - } - - virtual ssize_t write(const void *buffer, size_t size) - { - if (size_value > 0) { - size_value--; - return size; - } else if (size_value < 0) { - return -1; - } - return 0; - } - - virtual off_t seek(off_t offset, int whence = SEEK_SET) - { - return 0; - } - - virtual int close() {} - - virtual short poll(short events) const - { - if (filehandle_stub_short_value_counter) { - filehandle_stub_short_value_counter--; - return short_value; - } - return 0; - } - - virtual void sigio(Callback func) - { - func(); - } - - short short_value; -}; - -} - -#endif - - diff --git a/features/cellular/UNITTESTS/stubs/Kernel.cpp b/features/cellular/UNITTESTS/stubs/Kernel.cpp deleted file mode 100644 index ecfa1d80af..0000000000 --- a/features/cellular/UNITTESTS/stubs/Kernel.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) , 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 "Kernel.h" - -namespace rtos { - -uint64_t Kernel::get_ms_count() -{ - return 20; -} -} diff --git a/features/cellular/UNITTESTS/stubs/NetworkInterface_stub.cpp b/features/cellular/UNITTESTS/stubs/NetworkInterface_stub.cpp deleted file mode 100644 index 0e8eaa15a9..0000000000 --- a/features/cellular/UNITTESTS/stubs/NetworkInterface_stub.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2015, 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 "netsocket/NetworkInterface.h" -#include "netsocket/NetworkStack.h" -#include - - -// Default network-interface state -const char *NetworkInterface::get_mac_address() -{ - return 0; -} - -const char *NetworkInterface::get_ip_address() -{ - return 0; -} - -const char *NetworkInterface::get_netmask() -{ - return 0; -} - -const char *NetworkInterface::get_gateway() -{ - return 0; -} - -nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::set_dhcp(bool dhcp) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -// DNS operations go through the underlying stack by default -nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -void NetworkInterface::attach(mbed::Callback status_cb) -{ - -} - -nsapi_connection_status_t NetworkInterface::get_connection_status() const -{ - return NSAPI_STATUS_LOCAL_UP; -} - -nsapi_error_t NetworkInterface::set_blocking(bool blocking) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_value_or_error_t NetworkInterface::gethostbyname_async(char const *, mbed::Callback, nsapi_version) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - diff --git a/features/cellular/UNITTESTS/stubs/NetworkStack_stub.cpp b/features/cellular/UNITTESTS/stubs/NetworkStack_stub.cpp deleted file mode 100644 index 372812effb..0000000000 --- a/features/cellular/UNITTESTS/stubs/NetworkStack_stub.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2015, 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 "NetworkStack.h" -#include "nsapi_dns.h" -#include "mbed.h" -#include "stddef.h" -#include - -// Default NetworkStack operations -nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t NetworkStack::get_dns_server(int index, SocketAddress *address) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -// Conversion function for network stacks -NetworkStack *nsapi_create_stack(nsapi_stack_t *stack) -{ - return NULL; -} - -NetworkStack *nsapi_create_stack(NetworkStack *stack) -{ - return NULL; -} - -nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *host, hostbyname_cb_t callback, - nsapi_version_t version) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -call_in_callback_cb_t NetworkStack::get_call_in_callback() -{ - return NULL; -} - -nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback func) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -const char *NetworkStack::get_ip_address() -{ - return NULL; -} diff --git a/features/cellular/UNITTESTS/stubs/Semaphore_stub.cpp b/features/cellular/UNITTESTS/stubs/Semaphore_stub.cpp deleted file mode 100644 index ada09df114..0000000000 --- a/features/cellular/UNITTESTS/stubs/Semaphore_stub.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) , 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 "Semaphore.h" - -namespace rtos { - -Semaphore::Semaphore(int32_t count) -{ - -} - -Semaphore::Semaphore(int32_t count, uint16_t max_count) -{ - -} - -void Semaphore::constructor(int32_t count, uint16_t max_count) -{ - -} - -int32_t Semaphore::wait(uint32_t millisec) -{ - return 0; -} - -int32_t Semaphore::wait_until(uint64_t millisec) -{ - return 0; -} - -osStatus Semaphore::release(void) -{ - return 0; -} - -Semaphore::~Semaphore() -{ - -} - -} diff --git a/features/cellular/UNITTESTS/stubs/SocketAddress_stub.cpp b/features/cellular/UNITTESTS/stubs/SocketAddress_stub.cpp deleted file mode 100644 index 9ed53f03cf..0000000000 --- a/features/cellular/UNITTESTS/stubs/SocketAddress_stub.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2015, 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 "SocketAddress.h" -#include "NetworkInterface.h" -#include "NetworkStack.h" -#include -#include "mbed.h" - - -static bool ipv6_is_valid(const char *addr) -{ - return false; -} - -static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk) -{ - return 0; -} - - -SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port) -{ -} - -SocketAddress::SocketAddress(const char *addr, uint16_t port) -{ -} - -SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port) -{ -} - -SocketAddress::SocketAddress(const SocketAddress &addr) -{ -} - -SocketAddress::~SocketAddress() -{ -} - -bool SocketAddress::set_ip_address(const char *addr) -{ - return false; -} - -void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version) -{ -} - -void SocketAddress::set_addr(nsapi_addr_t addr) -{ -} - -void SocketAddress::set_port(uint16_t port) -{ -} - -const char *SocketAddress::get_ip_address() const -{ - return NULL; -} - -const void *SocketAddress::get_ip_bytes() const -{ - return NULL; -} - -nsapi_version_t SocketAddress::get_ip_version() const -{ - nsapi_version_t ver = NSAPI_IPv6; - return ver; -} - -nsapi_addr_t SocketAddress::get_addr() const -{ - nsapi_addr_t addr; - addr.version = NSAPI_IPv6; - return _addr; -} - -uint16_t SocketAddress::get_port() const -{ - return 0; -} - -SocketAddress::operator bool() const -{ - return false; -} - -SocketAddress &SocketAddress::operator=(const SocketAddress &addr) -{ - set_addr(addr.get_addr()); - set_port(addr.get_port()); - return *this; -} - -bool operator==(const SocketAddress &a, const SocketAddress &b) -{ - return false; -} - -bool operator!=(const SocketAddress &a, const SocketAddress &b) -{ - return false; -} diff --git a/features/cellular/UNITTESTS/stubs/Thread_stub.cpp b/features/cellular/UNITTESTS/stubs/Thread_stub.cpp deleted file mode 100644 index 8eed1e7f2a..0000000000 --- a/features/cellular/UNITTESTS/stubs/Thread_stub.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) , 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 "Thread.h" - -namespace rtos { - -osStatus Thread::wait_until(uint64_t millisec) -{ - return 0; -} - -} diff --git a/features/cellular/UNITTESTS/stubs/Timer_stub.cpp b/features/cellular/UNITTESTS/stubs/Timer_stub.cpp deleted file mode 100644 index 2e20c161ae..0000000000 --- a/features/cellular/UNITTESTS/stubs/Timer_stub.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) , 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 "Timer.h" -#include "Timer_stub.h" - -namespace mbed { - -Timer::Timer() -{ -} - -Timer::Timer(const ticker_data_t *data) -{ -} - -Timer::~Timer() -{ -} - -void Timer::start() -{ -} - -void Timer::stop() -{ - ; -} - -int Timer::read_us() -{ - return 0; -} - -float Timer::read() -{ - return 0; -} - -int Timer::read_ms() -{ - timer_stub_value += timer_stub_step; - return timer_stub_value; -} - -us_timestamp_t Timer::read_high_resolution_us() -{ - return 0; -} - -void Timer::reset() -{ -} - -Timer::operator float() -{ - return 0; -} - -} // namespace mbed diff --git a/features/cellular/UNITTESTS/stubs/Timer_stub.h b/features/cellular/UNITTESTS/stubs/Timer_stub.h deleted file mode 100644 index 699fdd0c53..0000000000 --- a/features/cellular/UNITTESTS/stubs/Timer_stub.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#ifndef TIMER_STUB_H -#define TIMER_STUB_H - - -static uint16_t timer_stub_value = 0; -static uint16_t timer_stub_step = 20; - -#endif diff --git a/features/cellular/UNITTESTS/stubs/equeue_stub.c b/features/cellular/UNITTESTS/stubs/equeue_stub.c deleted file mode 100644 index 55a52174e7..0000000000 --- a/features/cellular/UNITTESTS/stubs/equeue_stub.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) , 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 "equeue.h" - -int equeue_create(equeue_t *queue, size_t size) -{ - return 0; -} - -int equeue_create_inplace(equeue_t *queue, size_t size, void *buffer) -{ - return 0; -} - -void equeue_destroy(equeue_t *queue) -{ - -} - -void equeue_dispatch(equeue_t *queue, int ms) -{ - -} - -void equeue_break(equeue_t *queue) -{ - -} - -int equeue_call(equeue_t *queue, void (*cb)(void *), void *data) -{ - return 0; -} - -int equeue_call_in(equeue_t *queue, int ms, void (*cb)(void *), void *data) -{ - return 0; -} - -int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data) -{ - return 0; -} - -void *equeue_alloc(equeue_t *queue, size_t size) -{ - return NULL; -} - -void equeue_dealloc(equeue_t *queue, void *event) -{ - -} - -void equeue_event_delay(void *event, int ms) -{ - -} - -void equeue_event_period(void *event, int ms) -{ - -} - -void equeue_event_dtor(void *event, void (*dtor)(void *)) -{ - -} - -int equeue_post(equeue_t *queue, void (*cb)(void *), void *event) -{ - return 0; -} - -void equeue_cancel(equeue_t *queue, int id) -{ - -} - -void equeue_background(equeue_t *queue, - void (*update)(void *timer, int ms), void *timer) -{ - -} - -void equeue_chain(equeue_t *queue, equeue_t *target) -{ - -} diff --git a/features/cellular/UNITTESTS/stubs/mbed_assert_stub.cpp b/features/cellular/UNITTESTS/stubs/mbed_assert_stub.cpp deleted file mode 100644 index 341881a7f5..0000000000 --- a/features/cellular/UNITTESTS/stubs/mbed_assert_stub.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) , 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 "mbed_assert.h" - -void mbed_assert_internal(const char *expr, const char *file, int line) -{ - -} - diff --git a/features/cellular/UNITTESTS/stubs/mbed_poll_stub.cpp b/features/cellular/UNITTESTS/stubs/mbed_poll_stub.cpp deleted file mode 100644 index 1914399d2a..0000000000 --- a/features/cellular/UNITTESTS/stubs/mbed_poll_stub.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) , 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 "mbed_poll.h" -#include "mbed_poll_stub.h" - -int mbed_poll_stub::revents_value = POLLOUT; -int mbed_poll_stub::int_value = 0; - -namespace mbed { - -int poll(pollfh fhs[], unsigned nfhs, int timeout) -{ - fhs->revents = mbed_poll_stub::revents_value; - return mbed_poll_stub::int_value; -} - -} diff --git a/features/cellular/UNITTESTS/stubs/mbed_poll_stub.h b/features/cellular/UNITTESTS/stubs/mbed_poll_stub.h deleted file mode 100644 index 6c0a4327a9..0000000000 --- a/features/cellular/UNITTESTS/stubs/mbed_poll_stub.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#ifndef __MBED_POLL_STUB_H__ -#define __MBED_POLL_STUB_H__ - -#include - -namespace mbed_poll_stub { -extern int revents_value; -extern int int_value; -} - -#endif diff --git a/features/cellular/UNITTESTS/stubs/mbed_wait_api_stub.cpp b/features/cellular/UNITTESTS/stubs/mbed_wait_api_stub.cpp deleted file mode 100644 index f8b240544d..0000000000 --- a/features/cellular/UNITTESTS/stubs/mbed_wait_api_stub.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) , 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 "mbed_wait_api.h" - -void wait(float s) -{ -} - -void wait_ms(int ms) -{ -} - -void wait_us(int us) -{ -} diff --git a/features/cellular/UNITTESTS/stubs/randLIB_stub.cpp b/features/cellular/UNITTESTS/stubs/randLIB_stub.cpp deleted file mode 100644 index 61cd893d0e..0000000000 --- a/features/cellular/UNITTESTS/stubs/randLIB_stub.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017, 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 "randLIB.h" - -void randLIB_seed_random(void) -{ -} - -uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max) -{ - return min; -} - diff --git a/features/cellular/UNITTESTS/stubs/us_ticker_stub.cpp b/features/cellular/UNITTESTS/stubs/us_ticker_stub.cpp deleted file mode 100644 index 69c96accee..0000000000 --- a/features/cellular/UNITTESTS/stubs/us_ticker_stub.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) , 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 "stdlib.h" -#include "us_ticker_api.h" - -const ticker_data_t *get_us_ticker_data(void) -{ - return NULL; -} - -void us_ticker_irq_handler(void) -{ -} - -void us_ticker_init(void) -{ -} - -uint32_t us_ticker_read(void) -{ - return 0; -} - -void us_ticker_set_interrupt(timestamp_t timestamp) -{ -} - -void us_ticker_disable_interrupt(void) -{ -} - -void us_ticker_clear_interrupt(void) -{ -} - -void us_ticker_fire_interrupt(void) -{ -} diff --git a/features/cellular/UNITTESTS/target_h/ATCmdParser.h b/features/cellular/UNITTESTS/target_h/ATCmdParser.h deleted file mode 100644 index c1994cc2af..0000000000 --- a/features/cellular/UNITTESTS/target_h/ATCmdParser.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#ifndef __AT_CMD_PARSER_H__ -#define __AT_CMD_PARSER_H__ - -#include "mbed.h" -#include -#include "FileHandle.h" - -class ATCmdParser { -public: - ATCmdParser(mbed::FileHandle *fh, const char *output_delimiter = "\r", - int buffer_size = 256, int timeout = 8000, bool debug = false) {} - - ~ATCmdParser() {} -}; - -#endif //__AT_CMD_PARSER_H__ - diff --git a/features/cellular/UNITTESTS/target_h/PeripheralNames.h b/features/cellular/UNITTESTS/target_h/PeripheralNames.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/PeripheralNames.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/PinNames.h b/features/cellular/UNITTESTS/target_h/PinNames.h deleted file mode 100644 index 9f92be6f1d..0000000000 --- a/features/cellular/UNITTESTS/target_h/PinNames.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#ifndef __PINNAMES_H__ -#define __PINNAMES_H__ - - - -typedef enum { - -} PinName; - -#endif - diff --git a/features/cellular/UNITTESTS/target_h/arm_math.h b/features/cellular/UNITTESTS/target_h/arm_math.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/arm_math.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/cmsis.h b/features/cellular/UNITTESTS/target_h/cmsis.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/cmsis.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/cmsis_compiler.h b/features/cellular/UNITTESTS/target_h/cmsis_compiler.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/cmsis_compiler.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/cmsis_os.h b/features/cellular/UNITTESTS/target_h/cmsis_os.h deleted file mode 100644 index a40ab9e73b..0000000000 --- a/features/cellular/UNITTESTS/target_h/cmsis_os.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) , 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. - */ - -#ifndef CMSIS_OS_H_ -#define CMSIS_OS_H_ - -#include "cmsis_os2.h" - -#define osPriority osPriority_t - -#define osThreadId osThreadId_t - -typedef struct { -} osEvent; - -#endif diff --git a/features/cellular/UNITTESTS/target_h/cmsis_os2.h b/features/cellular/UNITTESTS/target_h/cmsis_os2.h deleted file mode 100644 index dcd0c20c61..0000000000 --- a/features/cellular/UNITTESTS/target_h/cmsis_os2.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) , 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. - */ - -#ifndef __CMSIS_OS2_H__ -#define __CMSIS_OS2_H__ - -//If conflicts, then remove these, copied from cmsis_os.h -typedef int32_t osStatus; - -#define osOK 0 - - - -//These are from cmsis_os2.h -typedef void *osSemaphoreId_t; - -typedef struct { - const char *name; ///< name of the semaphore - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osSemaphoreAttr_t; - -//Thread -typedef enum { - osPriorityNormal = 24 ///< Priority: normal -} osPriority_t; - -typedef void *osThreadId_t; - -/// Attributes structure for thread. -typedef struct { -} osThreadAttr_t; - -#define osWaitForever 0xFFFFFFFFU - - -#endif diff --git a/features/cellular/UNITTESTS/target_h/device.h b/features/cellular/UNITTESTS/target_h/device.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/device.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/mbed-trace/mbed_trace.h b/features/cellular/UNITTESTS/target_h/mbed-trace/mbed_trace.h deleted file mode 100644 index 7d6e56bdd9..0000000000 --- a/features/cellular/UNITTESTS/target_h/mbed-trace/mbed_trace.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ -#ifndef CELLULAR_UNITTESTS_MBED_TRACE_H_ -#define CELLULAR_UNITTESTS_MBED_TRACE_H_ - -#define tr_debug(...) -#define tr_info(...) -#define tr_warning(...) -#define tr_warn(...) -#define tr_error(...) -#define tr_err(...) - -#endif /* CELLULAR_UNITTESTS_MBED_TRACE_H_ */ diff --git a/features/cellular/UNITTESTS/target_h/mbed.h b/features/cellular/UNITTESTS/target_h/mbed.h deleted file mode 100644 index e401087fec..0000000000 --- a/features/cellular/UNITTESTS/target_h/mbed.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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. - */ -#ifndef MBED_H -#define MBED_H - -#include -#include - -#endif // MBED_H - diff --git a/features/cellular/UNITTESTS/target_h/mbed_rtos1_types.h b/features/cellular/UNITTESTS/target_h/mbed_rtos1_types.h deleted file mode 100644 index 2b9bd19f67..0000000000 --- a/features/cellular/UNITTESTS/target_h/mbed_rtos1_types.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) , 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 "cmsis_os.h" diff --git a/features/cellular/UNITTESTS/target_h/mbed_rtos_storage.h b/features/cellular/UNITTESTS/target_h/mbed_rtos_storage.h deleted file mode 100644 index f2282eed38..0000000000 --- a/features/cellular/UNITTESTS/target_h/mbed_rtos_storage.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) , 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 "cmsis_os2.h" -#include "rtx_os.h" -#include "rtx_lib.h" -#include "mbed_rtx_conf.h" - -typedef os_semaphore_t mbed_rtos_storage_semaphore_t; -typedef os_thread_t mbed_rtos_storage_thread_t; diff --git a/features/cellular/UNITTESTS/target_h/mbed_rtx.h b/features/cellular/UNITTESTS/target_h/mbed_rtx.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/mbed_rtx.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/mbed_rtx_conf.h b/features/cellular/UNITTESTS/target_h/mbed_rtx_conf.h deleted file mode 100644 index 18d985fa49..0000000000 --- a/features/cellular/UNITTESTS/target_h/mbed_rtx_conf.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) , 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. - */ - -#define OS_STACK_SIZE 0 diff --git a/features/cellular/UNITTESTS/target_h/nsapi_ppp.h b/features/cellular/UNITTESTS/target_h/nsapi_ppp.h deleted file mode 100644 index a431b392e7..0000000000 --- a/features/cellular/UNITTESTS/target_h/nsapi_ppp.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) , 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. - */ diff --git a/features/cellular/UNITTESTS/target_h/platform/mbed_power_mgmt.h b/features/cellular/UNITTESTS/target_h/platform/mbed_power_mgmt.h deleted file mode 100644 index 2810b22dae..0000000000 --- a/features/cellular/UNITTESTS/target_h/platform/mbed_power_mgmt.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) , 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. - */ - diff --git a/features/cellular/UNITTESTS/target_h/platform/mbed_retarget.h b/features/cellular/UNITTESTS/target_h/platform/mbed_retarget.h deleted file mode 100644 index 796e687292..0000000000 --- a/features/cellular/UNITTESTS/target_h/platform/mbed_retarget.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) , 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 -#define EAGAIN 11 -#define ENOTTY 25 diff --git a/features/cellular/UNITTESTS/target_h/randLIB.h b/features/cellular/UNITTESTS/target_h/randLIB.h deleted file mode 100644 index a621be3688..0000000000 --- a/features/cellular/UNITTESTS/target_h/randLIB.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017, 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. - */ -#ifndef FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ -#define FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ - -#include - -extern void randLIB_seed_random(void); - -uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max); - - -#endif /* FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ */ diff --git a/features/cellular/UNITTESTS/target_h/rtos/Mutex.h b/features/cellular/UNITTESTS/target_h/rtos/Mutex.h deleted file mode 100644 index 68d797d3eb..0000000000 --- a/features/cellular/UNITTESTS/target_h/rtos/Mutex.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) , 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. - */ - -typedef void *Mutex; diff --git a/features/cellular/UNITTESTS/target_h/rtos/Semaphore.h b/features/cellular/UNITTESTS/target_h/rtos/Semaphore.h deleted file mode 100644 index 34e472dea6..0000000000 --- a/features/cellular/UNITTESTS/target_h/rtos/Semaphore.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright (c) , 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. - */ - -typedef void *Semaphore; diff --git a/features/cellular/UNITTESTS/target_h/rtx_lib.h b/features/cellular/UNITTESTS/target_h/rtx_lib.h deleted file mode 100644 index 2b2368f0a6..0000000000 --- a/features/cellular/UNITTESTS/target_h/rtx_lib.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#ifndef __RTX_LIB_H__ -#define __RTX_LIB_H__ - -#include "rtx_os.h" - -#define os_semaphore_t osRtxSemaphore_t -#define os_thread_t osRtxThread_t - -#endif diff --git a/features/cellular/UNITTESTS/target_h/rtx_os.h b/features/cellular/UNITTESTS/target_h/rtx_os.h deleted file mode 100644 index bb29a2164c..0000000000 --- a/features/cellular/UNITTESTS/target_h/rtx_os.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) , 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. - */ - -#ifndef __RTX_OS__ -#define __RTX_OS__ - -#include "inttypes.h" - -typedef struct osRtxSemaphore_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t reserved; - const char *name; ///< Object Name - uint16_t tokens; ///< Current number of tokens - uint16_t max_tokens; ///< Maximum number of tokens -} osRtxSemaphore_t; - -typedef struct osRtxThread_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t attr; ///< Object Attributes - const char *name; ///< Object Name - struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list - struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list - struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list - struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list - struct osRtxThread_s *thread_join; ///< Thread waiting to Join - uint32_t delay; ///< Delay Time - int8_t priority; ///< Thread Priority - int8_t priority_base; ///< Base Priority - uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0]) - uint8_t flags_options; ///< Thread/Event Flags Options - uint32_t wait_flags; ///< Waiting Thread/Event Flags - uint32_t thread_flags; ///< Thread Flags - struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes - void *stack_mem; ///< Stack Memory - uint32_t stack_size; ///< Stack Size - uint32_t sp; ///< Current Stack Pointer - uint32_t thread_addr; ///< Thread entry address - uint32_t tz_memory; ///< TrustZone Memory Identifier - void *context; ///< Context for OsEventObserver objects -} osRtxThread_t; - -#endif diff --git a/features/cellular/UNITTESTS/target_h/sys/syslimits.h b/features/cellular/UNITTESTS/target_h/sys/syslimits.h deleted file mode 100644 index 5c90b373f1..0000000000 --- a/features/cellular/UNITTESTS/target_h/sys/syslimits.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) , 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. - */ -#define NAME_MAX 255 From a6b4938844a07ea2c3328fb1ffd85264d5e0cd89 Mon Sep 17 00:00:00 2001 From: Antti Kauppila Date: Wed, 5 Sep 2018 16:07:00 +0300 Subject: [PATCH 3/4] Small improvements for test cases --- .../at_cellulardevicetest.cpp | 7 ++ .../AT/at_cellularsms/at_cellularsmstest.cpp | 16 ++++ .../framework/AT/athandler/athandlertest.cpp | 78 +++++++++++++++---- .../framework/common/util/utiltest.cpp | 20 +++++ UNITTESTS/stubs/ATHandler_stub.cpp | 4 + UNITTESTS/stubs/ATHandler_stub.h | 1 + UNITTESTS/stubs/Mutex_stub.cpp | 5 -- UNITTESTS/unit_test/test.py | 3 + features/cellular/framework/AT/ATHandler.cpp | 6 +- features/cellular/framework/AT/ATHandler.h | 2 +- .../cellular/framework/AT/AT_CellularSMS.cpp | 4 +- .../framework/common/CellularUtil.cpp | 4 +- 12 files changed, 123 insertions(+), 27 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 33f47399af..c394854c1e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -265,3 +265,10 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) AT_CellularDevice dev(que); EXPECT_TRUE(0 == dev.get_send_delay()); } + +TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module) +{ + EventQueue que; + AT_CellularDevice dev(que); + EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL)); +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp index a586c2e652..a21b7098de 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp @@ -56,15 +56,31 @@ TEST_F(TestAT_CellularSMS, Create) delete sms; } +void my_callback() +{ + +} + TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize) { EventQueue que; FileHandle_stub fh1; ATHandler at(&fh1, que, 0, ","); + ATHandler_stub::call_immediately = true; + AT_CellularSMS sms(at); ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE; EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText)); + + sms.set_sms_callback(&my_callback); + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + EXPECT_TRUE(NSAPI_ERROR_OK == sms.initialize(CellularSMS::CellularSMSMmodeText)); + + ATHandler_stub::call_immediately = false; } TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_send_sms) diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp index df0780cfc5..52a32a367b 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp @@ -33,6 +33,10 @@ void urc_callback() { } +void urc2_callback() +{ +} + // AStyle ignored as the definition is not clear due to preprocessor usage // *INDENT-OFF* class TestATHandler : public testing::Test { @@ -119,7 +123,27 @@ TEST_F(TestATHandler, test_ATHandler_set_urc_handler) ATHandler at(&fh1, que, 0, ","); const char ch[] = "testtesttesttest"; - at.set_urc_handler(ch, &urc_callback); + + mbed::Callback cb(&urc_callback); + at.set_urc_handler(ch, cb); + + //THIS IS NOT same callback in find_urc_handler??? + EXPECT_TRUE(NSAPI_ERROR_OK == at.set_urc_handler(ch, cb)); +} + +TEST_F(TestATHandler, test_ATHandler_remove_urc_handler) +{ + EventQueue que; + FileHandle_stub fh1; + + ATHandler at(&fh1, que, 0, ","); + const char ch[] = "testtesttesttest"; + + mbed::Callback cb(&urc_callback); + at.set_urc_handler(ch, cb); + + //This does nothing!!! + at.remove_urc_handler(ch, cb); } TEST_F(TestATHandler, test_ATHandler_get_last_error) @@ -214,6 +238,12 @@ TEST_F(TestATHandler, test_ATHandler_process_oob) FileHandle_stub fh1; ATHandler at(&fh1, que, 0, ","); + at.set_at_timeout(10); + + at.set_is_filehandle_usable(false); + at.process_oob(); + at.set_is_filehandle_usable(true); + filehandle_stub_short_value_counter = 1; fh1.short_value = POLLIN; at.set_urc_handler("s", &urc_callback); @@ -228,6 +258,8 @@ TEST_F(TestATHandler, test_ATHandler_process_oob) char table[] = "ssssssssssssssssssssssssssssssss\0"; filehandle_stub_table = table; filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; at.read_bytes(buf, 5); filehandle_stub_short_value_counter = 2; @@ -241,25 +273,26 @@ TEST_F(TestATHandler, test_ATHandler_process_oob) filehandle_stub_short_value_counter = 1; at.process_oob(); - char table2[4]; + char table2[5]; table2[0] = '\r'; table2[1] = '\r'; table2[2] = '\n'; - table2[3] = 0; + table2[3] = '\n'; + table2[4] = 0; filehandle_stub_table = table2; at.clear_error(); timer_stub_value = 0; filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; at.read_bytes(buf, 1); filehandle_stub_short_value_counter = 1; at.process_oob(); - filehandle_stub_table = table; - filehandle_stub_short_value_counter = 0; filehandle_stub_table_pos = 0; filehandle_stub_table = NULL; @@ -412,62 +445,72 @@ TEST_F(TestATHandler, test_ATHandler_skip_param) FileHandle_stub fh1; ATHandler at(&fh1, que, 0, ","); + at.set_stop_tag("OK\r\n"); at.skip_param(); char table[] = "ssssssssssssssssssssssssssssOK\r\n\0"; filehandle_stub_table = table; - filehandle_stub_table_pos = 0; at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; + mbed_poll_stub::revents_value = POLLIN; + mbed_poll_stub::int_value = 1; + filehandle_stub_short_value_counter = 1; + fh1.short_value = POLLIN; at.resp_start(); at.skip_param(); EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR); char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0"; filehandle_stub_table = table1; - filehandle_stub_table_pos = 0; at.flush(); at.clear_error(); + filehandle_stub_short_value_counter = 1; + filehandle_stub_table_pos = 0; at.resp_start(); at.skip_param(); char table2[] = "sssOK\r\n\0"; filehandle_stub_table = table2; - filehandle_stub_table_pos = 0; at.flush(); at.clear_error(); + filehandle_stub_short_value_counter = 1; + filehandle_stub_table_pos = 0; at.resp_start(); at.skip_param(); char table3[] = "sssssssOK\nssss\0"; filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; //Need to create a new instance because stop tag already found ATHandler at2(&fh1, que, 0, ","); at2.flush(); at2.clear_error(); + filehandle_stub_short_value_counter = 1; + filehandle_stub_table_pos = 0; at2.resp_start(); at2.skip_param(); at2.skip_param(4, 3); filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; at2.flush(); at2.clear_error(); + filehandle_stub_short_value_counter = 1; + filehandle_stub_table_pos = 0; at2.resp_start(); at2.skip_param(4, 3); filehandle_stub_table = table3; - filehandle_stub_table_pos = 0; at2.flush(); at2.clear_error(); + filehandle_stub_short_value_counter = 1; + filehandle_stub_table_pos = 0; at2.resp_start(); at2.skip_param(24, 17); } @@ -834,6 +877,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start) at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start("ssssaaaassssaaaassss"); //too long prefix char table3[] = "+CME ERROR: 108\0"; @@ -842,20 +886,22 @@ TEST_F(TestATHandler, test_ATHandler_resp_start) at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start(); - filehandle_stub_table_pos = 0; at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start(); char table4[] = "+CMS ERROR: 6\0"; filehandle_stub_table = table4; - filehandle_stub_table_pos = 0; + filehandle_stub_table_pos = 0; at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start(); char table5[] = "ERROR\r\n\0"; @@ -864,6 +910,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start) at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start(); char table6[] = "OK\r\n\0"; @@ -872,6 +919,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start) at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start(); char table7[] = "ssssss\0"; @@ -881,6 +929,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_start) at.flush(); at.clear_error(); at.set_urc_handler("ss", NULL); + filehandle_stub_table_pos = 0; at.resp_start(); } @@ -905,6 +954,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop) at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start(); at.resp_stop(); @@ -915,6 +965,7 @@ TEST_F(TestATHandler, test_ATHandler_resp_stop) at.flush(); at.clear_error(); + filehandle_stub_table_pos = 0; at.resp_start("ss", false); at.resp_stop(); } @@ -1020,3 +1071,4 @@ TEST_F(TestATHandler, test_ATHandler_get_3gpp_error) ATHandler at(&fh1, que, 0, ","); at.get_3gpp_error(); } + diff --git a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp index 237316608b..18cb36cb5f 100644 --- a/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp +++ b/UNITTESTS/features/cellular/framework/common/util/utiltest.cpp @@ -127,6 +127,8 @@ TEST_F(Testutil, separate_ip_addresses) char subnet[64] = {0}; strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94); + separate_ip_addresses(NULL, ip, sizeof(ip), subnet, sizeof(subnet)); + separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet)); EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip); EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet); @@ -179,3 +181,21 @@ TEST_F(Testutil, separate_ip_addresses) EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet); EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s); } + +TEST_F(Testutil, get_dynamic_ip_port) +{ + uint16_t port = get_dynamic_ip_port(); + uint16_t port2 = get_dynamic_ip_port(); + + EXPECT_TRUE(port != port2); +} + +TEST_F(Testutil, int_to_hex_str) +{ + char buf[2]; + int_to_hex_str(100, (char*)buf); + + EXPECT_TRUE(buf[0] == '6'); + EXPECT_TRUE(buf[1] == '4'); +} + diff --git a/UNITTESTS/stubs/ATHandler_stub.cpp b/UNITTESTS/stubs/ATHandler_stub.cpp index 81267d0b44..7c65253af3 100644 --- a/UNITTESTS/stubs/ATHandler_stub.cpp +++ b/UNITTESTS/stubs/ATHandler_stub.cpp @@ -44,6 +44,7 @@ uint8_t ATHandler_stub::uint8_value = 0; FileHandle_stub *ATHandler_stub::fh_value = NULL; device_err_t ATHandler_stub::device_err_value; Callback ATHandler_stub::callback = NULL; +bool ATHandler_stub::call_immediately = false; uint8_t ATHandler_stub::resp_info_true_counter = false; uint8_t ATHandler_stub::info_elem_true_counter = false; int ATHandler_stub::int_valid_count_table[kRead_int_table_size]; @@ -98,6 +99,9 @@ void ATHandler::set_file_handle(FileHandle *fh) nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback cb) { ATHandler_stub::callback = cb; + if (ATHandler_stub::call_immediately) { + cb(); + } return ATHandler_stub::nsapi_error_value; } diff --git a/UNITTESTS/stubs/ATHandler_stub.h b/UNITTESTS/stubs/ATHandler_stub.h index 856ed9cb7d..3341aa4ced 100644 --- a/UNITTESTS/stubs/ATHandler_stub.h +++ b/UNITTESTS/stubs/ATHandler_stub.h @@ -51,6 +51,7 @@ extern uint8_t uint8_value; extern mbed::FileHandle_stub *fh_value; extern mbed::device_err_t device_err_value; extern mbed::Callback callback; +extern bool call_immediately; extern char *read_string_table[kRead_string_table_size]; extern int read_string_index; extern int int_valid_count_table[kRead_int_table_size]; diff --git a/UNITTESTS/stubs/Mutex_stub.cpp b/UNITTESTS/stubs/Mutex_stub.cpp index cd226064f8..153e8e5e19 100644 --- a/UNITTESTS/stubs/Mutex_stub.cpp +++ b/UNITTESTS/stubs/Mutex_stub.cpp @@ -27,11 +27,6 @@ rtos::Mutex::~Mutex() return; } -osStatus rtos::Mutex::lock(void) -{ - return osOK; -} - osStatus rtos::Mutex::lock(uint32_t millisec) { return osOK; diff --git a/UNITTESTS/unit_test/test.py b/UNITTESTS/unit_test/test.py index 889b0a35b3..6be991bb79 100644 --- a/UNITTESTS/unit_test/test.py +++ b/UNITTESTS/unit_test/test.py @@ -136,6 +136,9 @@ class UnitTestTool(object): for path in excludes: args.extend(["-e", path.replace("\\", "/")]) + #Exclude header files from report + args.extend(["-e", ".*\.h"]) + if logging.getLogger().getEffectiveLevel() == logging.DEBUG: args.append("-v") diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index b52cece0bb..e3c6cdd39d 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -159,7 +159,7 @@ void ATHandler::set_is_filehandle_usable(bool usable) nsapi_error_t ATHandler::set_urc_handler(const char *prefix, mbed::Callback callback) { - if (find_urc_handler(prefix, callback)) { + if (find_urc_handler(prefix, &callback)) { tr_warn("URC already added with prefix: %s", prefix); return NSAPI_ERROR_OK; } @@ -205,11 +205,11 @@ void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback ca } } -bool ATHandler::find_urc_handler(const char *prefix, mbed::Callback callback) +bool ATHandler::find_urc_handler(const char *prefix, mbed::Callback *callback) { struct oob_t *oob = _oobs; while (oob) { - if (strcmp(prefix, oob->prefix) == 0 && oob->cb == callback) { + if (strcmp(prefix, oob->prefix) == 0 && oob->cb == *callback) { return true; } oob = oob->next; diff --git a/features/cellular/framework/AT/ATHandler.h b/features/cellular/framework/AT/ATHandler.h index 17bb4d33a6..4962c14223 100644 --- a/features/cellular/framework/AT/ATHandler.h +++ b/features/cellular/framework/AT/ATHandler.h @@ -510,7 +510,7 @@ private: const char *mem_str(const char *dest, size_t dest_len, const char *src, size_t src_len); // check is urc is already added - bool find_urc_handler(const char *prefix, mbed::Callback callback); + bool find_urc_handler(const char *prefix, mbed::Callback *callback); // print contents of a buffer to trace log void debug_print(char *p, int len); diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index 7605566cbb..3dab1509f9 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -256,8 +256,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header) nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode) { - if (_at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)) || - _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) { + if (NSAPI_ERROR_OK != _at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc)) || + NSAPI_ERROR_OK != _at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc))) { return NSAPI_ERROR_NO_MEMORY; } diff --git a/features/cellular/framework/common/CellularUtil.cpp b/features/cellular/framework/common/CellularUtil.cpp index b6262996d7..c68dec2925 100644 --- a/features/cellular/framework/common/CellularUtil.cpp +++ b/features/cellular/framework/common/CellularUtil.cpp @@ -330,9 +330,7 @@ uint16_t get_dynamic_ip_port() } port_counter += randLIB_get_random_in_range(1, RANDOM_PORT_NUMBER_MAX_STEP); - if (port_counter >= RANDOM_PORT_NUMBER_COUNT) { - port_counter -= RANDOM_PORT_NUMBER_COUNT; - } + port_counter %= RANDOM_PORT_NUMBER_COUNT; return (RANDOM_PORT_NUMBER_START + port_counter); } From 2b7a087849d459a4f15cd22b2c5216d14fc462a2 Mon Sep 17 00:00:00 2001 From: Antti Kauppila Date: Sun, 9 Sep 2018 13:21:54 +0300 Subject: [PATCH 4/4] Rebased & fixed --- .../at_cellulardevicetest.cpp | 13 +++++--- .../InternetSocket/test_InternetSocket.cpp | 2 +- .../netsocket/InternetSocket/unittest.cmake | 4 ++- .../netsocket/TCPSocket/unittest.cmake | 4 ++- .../netsocket/UDPSocket/unittest.cmake | 4 ++- UNITTESTS/stubs/ip4tos_stub.c | 30 +++++++++++++++++ UNITTESTS/stubs/stoip4_stub.c | 32 +++++++++++++++++++ 7 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 UNITTESTS/stubs/ip4tos_stub.c create mode 100644 UNITTESTS/stubs/stoip4_stub.c diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index c394854c1e..7ab8f742f3 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -124,7 +124,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network) EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.close_network(); - EXPECT_TRUE(ATHandler_stub::ref_count == 0); + EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) @@ -139,7 +139,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms) EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.close_sms(); - EXPECT_TRUE(ATHandler_stub::ref_count == 0); + EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) @@ -154,7 +154,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.close_power(); - EXPECT_TRUE(ATHandler_stub::ref_count == 0); + EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) @@ -163,16 +163,19 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) AT_CellularDevice dev(que); FileHandle_stub fh1; ATHandler_stub::ref_count = 0; - + int ana = 0; EXPECT_TRUE(dev.open_sim(&fh1)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; + ana = ATHandler_stub::ref_count; + dev.close_sms(); // this should not affect to refcount as it's not opened EXPECT_TRUE(ATHandler_stub::ref_count == 1); + ana = ATHandler_stub::ref_count; dev.close_sim(); - EXPECT_TRUE(ATHandler_stub::ref_count == 0); + EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) diff --git a/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp b/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp index fae48b7ede..115c93f60a 100644 --- a/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp +++ b/UNITTESTS/features/netsocket/InternetSocket/test_InternetSocket.cpp @@ -153,7 +153,7 @@ TEST_F(TestInternetSocket, sigio) callback_is_called = false; // I'm calling sigio() through the DEPRECATED method, just to get coverage for both. // Not sure if this is wise at all, we should not aim for 100% - socket->attach(mbed::callback(my_callback)); + socket->sigio(mbed::callback(my_callback)); socket->event(); EXPECT_EQ(callback_is_called, true); } diff --git a/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake b/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake index ee22788fa4..a8a79bf90e 100644 --- a/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake @@ -15,6 +15,7 @@ set(unittest-sources ) set(unittest-test-sources + features/netsocket/InternetSocket/test_InternetSocket.cpp stubs/Mutex_stub.cpp stubs/mbed_assert_stub.c stubs/equeue_stub.c @@ -22,5 +23,6 @@ set(unittest-test-sources stubs/mbed_shared_queues_stub.cpp stubs/nsapi_dns_stub.cpp stubs/EventFlags_stub.cpp - features/netsocket/InternetSocket/test_InternetSocket.cpp + stubs/stoip4_stub.c + stubs/ip4tos_stub.c ) diff --git a/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake b/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake index 437463ee31..4128378d8c 100644 --- a/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake @@ -15,8 +15,10 @@ set(unittest-sources ) set(unittest-test-sources + features/netsocket/TCPSocket/test_TCPSocket.cpp stubs/Mutex_stub.cpp stubs/mbed_assert_stub.c stubs/EventFlags_stub.cpp - features/netsocket/TCPSocket/test_TCPSocket.cpp + stubs/stoip4_stub.c + stubs/ip4tos_stub.c ) diff --git a/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake b/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake index ee0f7f54b2..e8a8c828ed 100644 --- a/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake @@ -16,6 +16,7 @@ set(unittest-sources ) set(unittest-test-sources + features/netsocket/UDPSocket/test_UDPSocket.cpp stubs/Mutex_stub.cpp stubs/mbed_assert_stub.c stubs/equeue_stub.c @@ -23,5 +24,6 @@ set(unittest-test-sources stubs/mbed_shared_queues_stub.cpp stubs/EventFlags_stub.cpp stubs/nsapi_dns_stub.cpp - features/netsocket/UDPSocket/test_UDPSocket.cpp + stubs/stoip4_stub.c + stubs/ip4tos_stub.c ) diff --git a/UNITTESTS/stubs/ip4tos_stub.c b/UNITTESTS/stubs/ip4tos_stub.c new file mode 100644 index 0000000000..35957fe232 --- /dev/null +++ b/UNITTESTS/stubs/ip4tos_stub.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2014-2018 ARM Limited. All rights reserved. + * 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 +#include +#include "common_functions.h" +#include "ip4string.h" + +static void ipv4_itoa(char *string, uint8_t byte); + +uint_fast8_t ip4tos(const void *ip4addr, char *p) +{ + return 0; +} + +static void ipv4_itoa(char *string, uint8_t byte) +{ +} diff --git a/UNITTESTS/stubs/stoip4_stub.c b/UNITTESTS/stubs/stoip4_stub.c new file mode 100644 index 0000000000..d22c20e23e --- /dev/null +++ b/UNITTESTS/stubs/stoip4_stub.c @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014-2018 ARM Limited. All rights reserved. + * 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 +#include +#include +#include "common_functions.h" +#include "ip4string.h" + +/** + * Convert numeric IPv4 address string to a binary. + * \param ip4addr IPv4 address in string format. + * \param len Length of IPv4 string, maximum of 16.. + * \param dest buffer for address. MUST be 4 bytes. + * \return boolean set to true if conversion succeded, false if it didn't + */ +bool stoip4(const char *ip4addr, size_t len, void *dest) +{ + return true; +}