Merge pull request #7944 from AnttiKauppila/unittests

Cellular Unittests refactored to GoogleTest framework
pull/7696/head
Cruz Monrreal 2018-09-18 11:30:23 -05:00 committed by GitHub
commit f00c5643e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
156 changed files with 3098 additions and 4640 deletions

View File

@ -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)

View File

@ -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();
}

View File

@ -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 <string.h>
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;
}

View File

@ -1,31 +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();
};
#endif // TEST_AT_CELLULARBASE_H

View File

@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularbase.h"
#include "gtest/gtest.h"
#include "AT_CellularBase.h"
#include "EventQueue.h"
#include "AT_CellularBase.h"
#include "ATHandler_stub.h"
@ -57,26 +58,44 @@ public:
}
};
Test_AT_CellularBase::Test_AT_CellularBase()
{
// 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_AT_CellularBase::~Test_AT_CellularBase()
{
}
void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler()
TEST_F(TestAT_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());
EXPECT_TRUE(&ah == &at.get_at_handler());
}
void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
{
EventQueue eq;
FileHandle_stub fh;
@ -85,12 +104,12 @@ void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
ATHandler_stub::device_err_value.errCode = 8;
CHECK_EQUAL(8, at.get_device_error().errCode);
EXPECT_EQ(8, at.get_device_error().errCode);
ATHandler_stub::device_err_value.errCode = 0;
}
void Test_AT_CellularBase::test_AT_CellularBase_set_unsupported_features()
TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features)
{
EventQueue eq;
FileHandle_stub fh;
@ -105,15 +124,14 @@ void Test_AT_CellularBase::test_AT_CellularBase_set_unsupported_features()
at.set_unsupported_features(unsupported_features);
}
void Test_AT_CellularBase::test_AT_CellularBase_is_supported()
TEST_F(TestAT_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());
EXPECT_TRUE(true == my_at.check_supported());
EXPECT_TRUE(true == my_at.check_supported_not_found());
EXPECT_TRUE(false == my_at.check_not_supported());
}

View File

@ -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
)

View File

@ -0,0 +1,277 @@
/*
* 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 <string.h>
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));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_network();
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
}
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));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_sms();
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
}
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));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_power();
EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
{
EventQueue que;
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 == kATHandler_destructor_ref_ount);
}
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();
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
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());
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_init_module)
{
EventQueue que;
AT_CellularDevice dev(que);
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module(NULL));
}

View File

@ -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
)

View File

@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularinformation.h"
#include "gtest/gtest.h"
#include <string.h>
#include "ATHandler_stub.h"
#include "EventQueue.h"
@ -28,16 +27,32 @@
using namespace mbed;
using namespace events;
Test_AT_CellularInformation::Test_AT_CellularInformation()
{
// 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_AT_CellularInformation::~Test_AT_CellularInformation()
{
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_manufacturer()
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_manufacturer)
{
EventQueue eq;
FileHandle_stub fh;
@ -49,17 +64,17 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_manufacturer()
ATHandler_stub::ssize_value = 4;
char buf[8];
CHECK(NSAPI_ERROR_OK == aci.get_manufacturer(buf, 8));
CHECK(strcmp("some", buf) == 0);
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8));
CHECK(strlen(buf) == 0);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8));
EXPECT_TRUE(strlen(buf) == 0);
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_model()
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_model)
{
EventQueue eq;
FileHandle_stub fh;
@ -70,17 +85,17 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_model()
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);
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8));
CHECK(strlen(buf) == 0);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8));
EXPECT_TRUE(strlen(buf) == 0);
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_revision()
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision)
{
EventQueue eq;
FileHandle_stub fh;
@ -94,19 +109,19 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_revision()
ATHandler_stub::ssize_value = 8;
char buf[9];
CHECK(NSAPI_ERROR_OK == aci->get_revision(buf, 9));
CHECK(strcmp("revision", buf) == 0);
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8));
CHECK(strlen(buf) == 0);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8));
EXPECT_TRUE(strlen(buf) == 0);
delete aci;
}
void Test_AT_CellularInformation::test_AT_CellularInformation_get_serial_number()
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number)
{
EventQueue eq;
FileHandle_stub fh;
@ -118,24 +133,23 @@ void Test_AT_CellularInformation::test_AT_CellularInformation_get_serial_number(
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);
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == aci.get_serial_number(buf, 8, CellularInformation::SN));
CHECK(strlen(buf) == 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;
CHECK(NSAPI_ERROR_UNSUPPORTED == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
CHECK(strlen(buf) == 0);
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;
CHECK(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
CHECK(strcmp("1234567", buf) == 0);
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
EXPECT_TRUE(strcmp("1234567", buf) == 0);
}

View File

@ -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
)

View File

@ -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
)

View File

@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularpower.h"
#include "gtest/gtest.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
@ -27,47 +26,60 @@
using namespace mbed;
using namespace events;
Test_AT_CellularPower::Test_AT_CellularPower()
{
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularPower : public testing::Test {
protected:
Test_AT_CellularPower::~Test_AT_CellularPower()
void SetUp() {
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
void TearDown() {
}
};
// *INDENT-ON*
static void device_ready_cb()
{
}
void Test_AT_CellularPower::test_AT_CellularPower_constructor()
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;
}
void Test_AT_CellularPower::test_AT_CellularPower_on()
TEST_F(TestAT_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());
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.on());
}
void Test_AT_CellularPower::test_AT_CellularPower_off()
TEST_F(TestAT_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());
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off());
}
void Test_AT_CellularPower::test_AT_CellularPower_set_at_mode()
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_at_mode)
{
EventQueue que;
FileHandle_stub fh1;
@ -75,13 +87,13 @@ void Test_AT_CellularPower::test_AT_CellularPower_set_at_mode()
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
CHECK(NSAPI_ERROR_OK == pow.set_at_mode());
EXPECT_TRUE(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());
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode());
}
void Test_AT_CellularPower::test_AT_CellularPower_set_power_level()
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level)
{
EventQueue que;
FileHandle_stub fh1;
@ -89,15 +101,15 @@ void Test_AT_CellularPower::test_AT_CellularPower_set_power_level()
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));
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6));
}
void Test_AT_CellularPower::test_AT_CellularPower_reset()
TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
{
EventQueue que;
FileHandle_stub fh1;
@ -105,13 +117,13 @@ void Test_AT_CellularPower::test_AT_CellularPower_reset()
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
CHECK(NSAPI_ERROR_OK == pow.reset());
EXPECT_TRUE(NSAPI_ERROR_OK == pow.reset());
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
CHECK(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
}
void Test_AT_CellularPower::test_AT_CellularPower_opt_power_save_mode()
TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_power_save_mode)
{
EventQueue que;
FileHandle_stub fh1;
@ -119,27 +131,27 @@ void Test_AT_CellularPower::test_AT_CellularPower_opt_power_save_mode()
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345));
CHECK(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345));
EXPECT_TRUE(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));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0));
}
void Test_AT_CellularPower::test_AT_CellularPower_opt_receive_period()
TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_receive_period)
{
EventQueue que;
FileHandle_stub fh1;
@ -147,13 +159,13 @@ void Test_AT_CellularPower::test_AT_CellularPower_opt_receive_period()
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));
EXPECT_TRUE(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));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
}
void Test_AT_CellularPower::test_AT_CellularPower_is_device_ready()
TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready)
{
EventQueue que;
FileHandle_stub fh1;
@ -161,32 +173,28 @@ void Test_AT_CellularPower::test_AT_CellularPower_is_device_ready()
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready());
EXPECT_TRUE(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()
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);
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL));
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));
}
void Test_AT_CellularPower::test_AT_CellularPower_remove_device_ready_urc_cb()
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);
CHECK(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
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);

View File

@ -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
)

View File

@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularsim.h"
#include "gtest/gtest.h"
#include "ATHandler_stub.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
@ -28,18 +28,26 @@
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;
}
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularSIM : public testing::Test {
protected:
Test_AT_CellularSIM::~Test_AT_CellularSIM()
{
}
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 Test_AT_CellularSIM::test_AT_CellularSIM_constructor()
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularSIM, Create)
{
EventQueue que;
FileHandle_stub fh1;
@ -47,10 +55,11 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_constructor()
AT_CellularSIM *sim = new AT_CellularSIM(at);
EXPECT_TRUE(sim != NULL);
delete sim;
}
void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin()
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin)
{
EventQueue que;
FileHandle_stub fh1;
@ -58,20 +67,20 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin()
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
CHECK(NSAPI_ERROR_OK == sim.set_pin("12"));
EXPECT_TRUE(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"));
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;
CHECK(NSAPI_ERROR_OK == sim.set_pin("12"));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12"));
CHECK(NSAPI_ERROR_OK == sim.set_pin(NULL));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin(NULL));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_change_pin()
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_change_pin)
{
EventQueue que;
FileHandle_stub fh1;
@ -79,16 +88,16 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_change_pin()
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));
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34"));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34"));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin_query()
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin_query)
{
EventQueue que;
FileHandle_stub fh1;
@ -96,19 +105,19 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_set_pin_query()
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));
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;
CHECK(NSAPI_ERROR_OK == sim.set_pin_query("12", false));
CHECK(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false));
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false));
CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_get_sim_state()
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state)
{
EventQueue que;
FileHandle_stub fh1;
@ -119,31 +128,31 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_get_sim_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);
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;
CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state));
CHECK(CellularSIM::SimStateReady == state);
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;
CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state));
CHECK(CellularSIM::SimStatePinNeeded == state);
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;
CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state));
CHECK(CellularSIM::SimStatePukNeeded == state);
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;
CHECK(NSAPI_ERROR_OK == sim.get_sim_state(state));
CHECK(CellularSIM::SimStateUnknown == state);
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
EXPECT_TRUE(CellularSIM::SimStateUnknown == state);
}
void Test_AT_CellularSIM::test_AT_CellularSIM_get_imsi()
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi)
{
EventQueue que;
FileHandle_stub fh1;
@ -154,25 +163,25 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_get_imsi()
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);
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi));
CHECK(strlen(imsi) == 0);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi));
EXPECT_TRUE(strlen(imsi) == 0);
CHECK(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL));
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];
//CHECK(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2));
//EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2));
}
void Test_AT_CellularSIM::test_AT_CellularSIM_get_iccid()
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid)
{
EventQueue que;
FileHandle_stub fh1;
@ -183,13 +192,13 @@ void Test_AT_CellularSIM::test_AT_CellularSIM_get_iccid()
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);
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;
CHECK(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16));
CHECK(strlen(buf) == 0);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16));
EXPECT_TRUE(strlen(buf) == 0);
}

View File

@ -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
)

View File

@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularsms.h"
#include "gtest/gtest.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
@ -28,17 +27,24 @@
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;
}
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularSMS : public testing::Test {
protected:
Test_AT_CellularSMS::~Test_AT_CellularSMS()
{
}
void SetUp()
{
ATHandler_stub::return_given_size = false;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
void Test_AT_CellularSMS::test_AT_CellularSMS_constructor()
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularSMS, Create)
{
EventQueue que;
FileHandle_stub fh1;
@ -46,50 +52,66 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_constructor()
AT_CellularSMS *sms = new AT_CellularSMS(at);
EXPECT_TRUE(sms != NULL);
delete sms;
}
void Test_AT_CellularSMS::test_AT_CellularSMS_initialize()
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;
CHECK(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText));
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;
}
void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms()
TEST_F(TestAT_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));
EXPECT_EQ(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));
EXPECT_EQ(1, sms.send_sms("1", "22", 2));
ATHandler_stub::size_value = 2;
LONGS_EQUAL(2, sms.send_sms("1", "22", 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);
LONGS_EQUAL(2, sms.send_sms("1", "23", 2));;
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;
LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
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;
LONGS_EQUAL(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
char table[] = "232323232323232323232323232323232323232323232323232323\
@ -97,12 +119,11 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_send_sms()
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)));
EXPECT_EQ(strlen(table), sms.send_sms("1", table, strlen(table)));
EXPECT_EQ(strlen(table), sms.send_sms("12", table, strlen(table)));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_get_sms)
{
EventQueue que;
FileHandle_stub fh1;
@ -113,28 +134,27 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_get_sms()
char phone[21];
char stamp[21];
int size;
CHECK(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &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;
CHECK(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
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;
CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
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);
CHECK(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
EXPECT_TRUE(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));
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_sms_callback)
{
EventQueue que;
FileHandle_stub fh1;
@ -144,8 +164,7 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_sms_callback()
sms.set_sms_callback(NULL);
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cpms)
{
EventQueue que;
FileHandle_stub fh1;
@ -153,11 +172,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_cpms()
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4"));
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4"));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_csca)
{
EventQueue que;
FileHandle_stub fh1;
@ -165,11 +183,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_csca()
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1));
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cscs)
{
EventQueue que;
FileHandle_stub fh1;
@ -177,11 +194,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_cscs()
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2"));
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2"));
}
void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_delete_all_messages)
{
EventQueue que;
FileHandle_stub fh1;
@ -189,11 +205,10 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_delete_all_messages()
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
CHECK(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages());
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages());
}
void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time()
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_extra_sim_wait_time)
{
EventQueue que;
FileHandle_stub fh1;
@ -201,6 +216,4 @@ void Test_AT_CellularSMS::test_AT_CellularSMS_set_extra_sim_wait_time()
AT_CellularSMS sms(at);
sms.set_extra_sim_wait_time(56);
}

View File

@ -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
)

View File

@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_at_cellularstack.h"
#include "gtest/gtest.h"
#include "AT_CellularStack.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
@ -136,18 +136,27 @@ public:
}
};
Test_AT_CellularStack::Test_AT_CellularStack()
{
ATHandler_stub::ssize_value = 0;
ATHandler_stub::bool_value = false;
ATHandler_stub::read_string_value = NULL;
}
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularStack : public testing::Test {
protected:
Test_AT_CellularStack::~Test_AT_CellularStack()
{
}
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 Test_AT_CellularStack::test_AT_CellularStack_constructor()
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularStack, Create)
{
EventQueue que;
FileHandle_stub fh1;
@ -155,31 +164,32 @@ void Test_AT_CellularStack::test_AT_CellularStack_constructor()
MyStack *st = new MyStack(at, 0, IPV4_STACK);
EXPECT_TRUE(st != NULL);
delete st;
}
void Test_AT_CellularStack::test_AT_CellularStack_get_ip_address()
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);
CHECK(0 == strlen(st.get_ip_address()));
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;
CHECK(NULL == st.get_ip_address());
EXPECT_TRUE(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());
EXPECT_TRUE(st.get_ip_address());
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_open()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
{
EventQueue que;
FileHandle_stub fh1;
@ -187,45 +197,45 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_open()
MyStack st(at, 0, IPV6_STACK);
st.bool_value = false;
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP));
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;
CHECK(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP));
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;
CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_close()
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);
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(&st.socket));
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;
CHECK(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP));
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP));
st.max_sock_value = 0;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock));
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;
CHECK(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
CHECK(NSAPI_ERROR_OK == st2.socket_close(sock));
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_close(sock));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_bind()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_bind)
{
EventQueue que;
FileHandle_stub fh1;
@ -234,22 +244,22 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_bind()
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));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr));
CHECK(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr));
EXPECT_TRUE(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_listen()
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);
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4));
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_connect()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_connect)
{
EventQueue que;
FileHandle_stub fh1;
@ -257,12 +267,12 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_connect()
MyStack st(at, 0, IPV6_STACK);
SocketAddress addr;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr));
CHECK(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr));
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_accept()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_accept)
{
EventQueue que;
FileHandle_stub fh1;
@ -270,19 +280,19 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_accept()
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t sock = &st.socket;
CHECK(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock));
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_send()
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);
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4));
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4));
SocketAddress addr;
st.max_sock_value = 1;
@ -290,10 +300,10 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_send()
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));
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_send(sock, "addr", 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
{
EventQueue que;
FileHandle_stub fh1;
@ -302,7 +312,7 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
MyStack st(at, 0, IPV6_STACK);
SocketAddress addr;
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4));
st.max_sock_value = 1;
st.bool_value = true;
@ -310,13 +320,13 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_sendto()
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));
EXPECT_TRUE(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));
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_recv()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recv)
{
EventQueue que;
FileHandle_stub fh1;
@ -324,10 +334,10 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_recv()
MyStack st(at, 0, IPV6_STACK);
char table[4];
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
{
EventQueue que;
FileHandle_stub fh1;
@ -335,7 +345,7 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
MyStack st(at, 0, IPV6_STACK);
char table[4];
CHECK(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4));
SocketAddress addr;
st.max_sock_value = 1;
@ -344,13 +354,13 @@ void Test_AT_CellularStack::test_AT_CellularStack_socket_recvfrom()
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));
EXPECT_TRUE(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));
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4));
}
void Test_AT_CellularStack::test_AT_CellularStack_socket_attach()
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
{
EventQueue que;
FileHandle_stub fh1;

View File

@ -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
)

View File

@ -14,8 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CppUTest/TestHarness.h"
#include "test_athandler.h"
#include "gtest/gtest.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
@ -34,16 +33,26 @@ void urc_callback()
{
}
Test_ATHandler::Test_ATHandler()
{
}
Test_ATHandler::~Test_ATHandler()
void urc2_callback()
{
}
void Test_ATHandler::test_ATHandler_constructor()
// 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;
@ -54,19 +63,20 @@ void Test_ATHandler::test_ATHandler_constructor()
at = new ATHandler(&fh1, que, 0, NULL);
EXPECT_TRUE(at != NULL);
delete at;
}
void Test_ATHandler::test_ATHandler_get_file_handle()
TEST_F(TestATHandler, test_ATHandler_get_file_handle)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK_EQUAL(&fh1, at.get_file_handle());
EXPECT_EQ(&fh1, at.get_file_handle());
}
void Test_ATHandler::test_ATHandler_set_file_handle()
TEST_F(TestATHandler, test_ATHandler_set_file_handle)
{
EventQueue que;
FileHandle_stub fh1, fh2;
@ -76,7 +86,7 @@ void Test_ATHandler::test_ATHandler_set_file_handle()
at.set_file_handle(&fh2);
}
void Test_ATHandler::test_ATHandler_lock()
TEST_F(TestATHandler, test_ATHandler_lock)
{
EventQueue que;
FileHandle_stub fh1;
@ -86,7 +96,7 @@ void Test_ATHandler::test_ATHandler_lock()
at.lock();
}
void Test_ATHandler::test_ATHandler_unlock()
TEST_F(TestATHandler, test_ATHandler_unlock)
{
EventQueue que;
FileHandle_stub fh1;
@ -97,44 +107,64 @@ void Test_ATHandler::test_ATHandler_unlock()
at.unlock();
}
void Test_ATHandler::test_ATHandler_unlock_return_error()
TEST_F(TestATHandler, test_ATHandler_unlock_return_error)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(NSAPI_ERROR_OK == at.unlock_return_error());
EXPECT_TRUE(NSAPI_ERROR_OK == at.unlock_return_error());
}
void Test_ATHandler::test_ATHandler_set_urc_handler()
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);
mbed::Callback<void()> 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));
}
void Test_ATHandler::test_ATHandler_get_last_error()
TEST_F(TestATHandler, test_ATHandler_remove_urc_handler)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(NSAPI_ERROR_OK == at.get_last_error());
const char ch[] = "testtesttesttest";
mbed::Callback<void()> cb(&urc_callback);
at.set_urc_handler(ch, cb);
//This does nothing!!!
at.remove_urc_handler(ch, cb);
}
void Test_ATHandler::test_ATHandler_get_last_device_error()
TEST_F(TestATHandler, test_ATHandler_get_last_error)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(0 == at.get_last_device_error().errCode);
EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_inc_ref_count()
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;
@ -143,7 +173,7 @@ void Test_ATHandler::test_ATHandler_inc_ref_count()
at.inc_ref_count();
}
void Test_ATHandler::test_ATHandler_dec_ref_count()
TEST_F(TestATHandler, test_ATHandler_dec_ref_count)
{
EventQueue que;
FileHandle_stub fh1;
@ -152,26 +182,26 @@ void Test_ATHandler::test_ATHandler_dec_ref_count()
at.dec_ref_count();
}
void Test_ATHandler::test_ATHandler_get_ref_count()
TEST_F(TestATHandler, test_ATHandler_get_ref_count)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(1 == at.get_ref_count());
EXPECT_TRUE(1 == at.get_ref_count());
at.inc_ref_count();
CHECK(2 == at.get_ref_count());
EXPECT_TRUE(2 == at.get_ref_count());
at.inc_ref_count();
CHECK(3 == at.get_ref_count());
EXPECT_TRUE(3 == at.get_ref_count());
at.dec_ref_count();
at.dec_ref_count();
CHECK(1 == at.get_ref_count());
EXPECT_TRUE(1 == at.get_ref_count());
}
void Test_ATHandler::test_ATHandler_set_at_timeout()
TEST_F(TestATHandler, test_ATHandler_set_at_timeout)
{
EventQueue que;
FileHandle_stub fh1;
@ -182,7 +212,7 @@ void Test_ATHandler::test_ATHandler_set_at_timeout()
at.set_at_timeout(80, true);
}
void Test_ATHandler::test_ATHandler_restore_at_timeout()
TEST_F(TestATHandler, test_ATHandler_restore_at_timeout)
{
EventQueue que;
FileHandle_stub fh1;
@ -193,7 +223,7 @@ void Test_ATHandler::test_ATHandler_restore_at_timeout()
at.restore_at_timeout();
}
void Test_ATHandler::test_ATHandler_clear_error()
TEST_F(TestATHandler, test_ATHandler_clear_error)
{
EventQueue que;
FileHandle_stub fh1;
@ -202,12 +232,18 @@ void Test_ATHandler::test_ATHandler_clear_error()
at.clear_error();
}
void Test_ATHandler::test_ATHandler_process_oob()
TEST_F(TestATHandler, test_ATHandler_process_oob)
{
EventQueue que;
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);
@ -222,6 +258,8 @@ void Test_ATHandler::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;
@ -235,31 +273,32 @@ void Test_ATHandler::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;
}
void Test_ATHandler::test_ATHandler_set_filehandle_sigio()
TEST_F(TestATHandler, test_ATHandler_set_filehandle_sigio)
{
EventQueue que;
FileHandle_stub fh1;
@ -268,7 +307,7 @@ void Test_ATHandler::test_ATHandler_set_filehandle_sigio()
at.set_filehandle_sigio();
}
void Test_ATHandler::test_ATHandler_flush()
TEST_F(TestATHandler, test_ATHandler_flush)
{
EventQueue que;
FileHandle_stub fh1;
@ -279,7 +318,7 @@ void Test_ATHandler::test_ATHandler_flush()
at.flush();
}
void Test_ATHandler::test_ATHandler_cmd_start()
TEST_F(TestATHandler, test_ATHandler_cmd_start)
{
EventQueue que;
FileHandle_stub fh1;
@ -297,7 +336,7 @@ void Test_ATHandler::test_ATHandler_cmd_start()
at.cmd_start("s");
}
void Test_ATHandler::test_ATHandler_write_int()
TEST_F(TestATHandler, test_ATHandler_write_int)
{
EventQueue que;
FileHandle_stub fh1;
@ -320,14 +359,15 @@ void Test_ATHandler::test_ATHandler_write_int()
// at.write_int(4);
}
void Test_ATHandler::test_ATHandler_write_string()
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");
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
at.clear_error();
mbed_poll_stub::revents_value = POLLOUT;
@ -335,24 +375,24 @@ void Test_ATHandler::test_ATHandler_write_string()
fh1.size_value = -1;
at.cmd_start("s");
at.write_string("help", true);
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
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);
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
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);
CHECK(NSAPI_ERROR_OK == at.get_last_error());
EXPECT_TRUE(NSAPI_ERROR_OK == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_cmd_stop()
TEST_F(TestATHandler, test_ATHandler_cmd_stop)
{
EventQueue que;
FileHandle_stub fh1;
@ -364,10 +404,10 @@ void Test_ATHandler::test_ATHandler_cmd_stop()
at.write_string("help", true);
at.cmd_stop();
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_write_bytes()
TEST_F(TestATHandler, test_ATHandler_write_bytes)
{
EventQueue que;
FileHandle_stub fh1;
@ -378,10 +418,10 @@ void Test_ATHandler::test_ATHandler_write_bytes()
at.write_bytes(data, 4);
at.write_bytes(data, 4);
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_set_stop_tag()
TEST_F(TestATHandler, test_ATHandler_set_stop_tag)
{
EventQueue que;
FileHandle_stub fh1;
@ -390,7 +430,7 @@ void Test_ATHandler::test_ATHandler_set_stop_tag()
at.set_stop_tag("s");
}
void Test_ATHandler::test_ATHandler_set_delimiter()
TEST_F(TestATHandler, test_ATHandler_set_delimiter)
{
EventQueue que;
FileHandle_stub fh1;
@ -399,73 +439,83 @@ void Test_ATHandler::test_ATHandler_set_delimiter()
at.set_delimiter('+');
}
void Test_ATHandler::test_ATHandler_skip_param()
TEST_F(TestATHandler, test_ATHandler_skip_param)
{
EventQueue que;
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();
CHECK(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
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);
}
void Test_ATHandler::test_ATHandler_read_bytes()
TEST_F(TestATHandler, test_ATHandler_read_bytes)
{
EventQueue que;
FileHandle_stub fh1;
@ -477,10 +527,10 @@ void Test_ATHandler::test_ATHandler_read_bytes()
// 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());
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
CHECK(-1 == at.read_bytes(buf, 1));
EXPECT_TRUE(-1 == at.read_bytes(buf, 1));
// TEST DATA IN BUFFER
at.clear_error();
@ -491,18 +541,18 @@ void Test_ATHandler::test_ATHandler_read_bytes()
mbed_poll_stub::int_value = 1;;
// Read 5 bytes
CHECK(5 == at.read_bytes(buf, 5));
CHECK(!memcmp(buf, table1, 5));
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())
CHECK(filehandle_stub_table_pos == (strlen(table1) - 1));
EXPECT_TRUE(filehandle_stub_table_pos == (strlen(table1) - 1));
// Read another 8 bytes
CHECK(8 == at.read_bytes(buf, 8) && !memcmp(buf, table1 + 5, 8));
EXPECT_TRUE(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());
EXPECT_TRUE(-1 == at.read_bytes(buf, 5));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
}
void Test_ATHandler::test_ATHandler_read_string()
TEST_F(TestATHandler, test_ATHandler_read_string)
{
EventQueue que;
FileHandle_stub fh1;
@ -521,15 +571,15 @@ void Test_ATHandler::test_ATHandler_read_string()
mbed_poll_stub::int_value = 1;
char buf1[1];
// No _stop_tag set without resp_start
CHECK(-1 == at.read_string(buf1, 1));
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
CHECK(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
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('\"')
CHECK(-1 == at.read_string(buf1, 1));
EXPECT_TRUE(-1 == at.read_string(buf1, 1));
// *** 1 BYTE ***
at.clear_error();
@ -543,9 +593,9 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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());
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == at.get_last_error());
at.clear_error();
CHECK(0 == at.read_string(buf2, 1));
EXPECT_TRUE(0 == at.read_string(buf2, 1));
// *** CRLF ***
at.clear_error();
@ -559,11 +609,11 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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());
EXPECT_TRUE(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*/));
EXPECT_TRUE(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*/));
EXPECT_TRUE(1 == at.read_string(buf3, 1 + 1/*for NULL*/));
// *** Reading more than available in buffer ***
at.clear_error();
@ -580,8 +630,8 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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());
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();
@ -593,7 +643,7 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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*/));
EXPECT_TRUE(1 == at.read_string(buf4, 4 + 1/*for NULL*/));
// *** Encountering delimiter as first char in buffer ***
at.clear_error();
@ -605,7 +655,7 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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*/));
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();
@ -620,19 +670,19 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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*/));
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
CHECK(0 == at.read_string(buf4, 1 + 1/*for NULL*/));
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
CHECK(-1 == at.read_string(buf4, 1 + 1/*for NULL*/));
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
CHECK(4 == at.read_string(buf4, 4 + 1/*for NULL*/, true));
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();
@ -644,7 +694,7 @@ void Test_ATHandler::test_ATHandler_read_string()
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*/));
EXPECT_TRUE(6 == at.read_string(buf4, 6 + 1/*for NULL*/));
// *** Reading when buffer only has " ***
at.clear_error();
@ -656,8 +706,8 @@ void Test_ATHandler::test_ATHandler_read_string()
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());
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();
@ -671,7 +721,7 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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*/));
EXPECT_TRUE(8 == at.read_string(buf8, 8 + 1/*for NULL*/));
// *** Reading through partially matching stop tag ***
at.clear_error();
@ -686,7 +736,7 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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*/));
EXPECT_TRUE(6 == at.read_string(buf9, 6 + 1/*for NULL*/));
// *** CRLF part of the string ***
at.clear_error();
@ -701,10 +751,10 @@ void Test_ATHandler::test_ATHandler_read_string()
// 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*/));
EXPECT_TRUE(3 == at.read_string(buf10, 9 + 1/*for NULL*/));
}
void Test_ATHandler::test_ATHandler_read_hex_string()
TEST_F(TestATHandler, test_ATHandler_read_hex_string)
{
EventQueue que;
FileHandle_stub fh1;
@ -724,8 +774,8 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
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));
EXPECT_TRUE(5 == at.read_hex_string(buf1, 5));
EXPECT_TRUE(!strncmp(buf1, "hello", 5));
// *** Read up to delimiter, odd length ***
at.clear_error();
@ -738,8 +788,8 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
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));
EXPECT_TRUE(5 == at.read_hex_string(buf2, 6));
EXPECT_TRUE(!strncmp(buf2, "hello", 5));
// *** Read with stop tag, even length ***
at.clear_error();
@ -752,8 +802,8 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
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));
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 ***
@ -767,11 +817,11 @@ void Test_ATHandler::test_ATHandler_read_hex_string()
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));
EXPECT_TRUE(1 == at.read_hex_string(buf4, 2 + 1/*get to stop tag match*/));
EXPECT_TRUE(!strncmp(buf4, "h", 1));
}
void Test_ATHandler::test_ATHandler_read_int()
TEST_F(TestATHandler, test_ATHandler_read_int)
{
EventQueue que;
FileHandle_stub fh1;
@ -781,7 +831,7 @@ void Test_ATHandler::test_ATHandler_read_int()
ATHandler at(&fh1, que, 0, ",");
int32_t ret = at.read_int();
CHECK(-1 == ret);
EXPECT_TRUE(-1 == ret);
at.clear_error();
char table[] = "\",\"OK\r\n\0";
@ -793,7 +843,7 @@ void Test_ATHandler::test_ATHandler_read_int()
at.resp_start();
ret = at.read_int();
CHECK(-1 == ret);
EXPECT_TRUE(-1 == ret);
at.flush();
at.clear_error();
@ -806,11 +856,10 @@ void Test_ATHandler::test_ATHandler_read_int()
at.resp_start();
ret = at.read_int();
CHECK(2 == ret);
EXPECT_TRUE(2 == ret);
}
void Test_ATHandler::test_ATHandler_resp_start()
TEST_F(TestATHandler, test_ATHandler_resp_start)
{
EventQueue que;
FileHandle_stub fh1;
@ -828,6 +877,7 @@ void Test_ATHandler::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";
@ -836,20 +886,22 @@ void Test_ATHandler::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";
@ -858,6 +910,7 @@ void Test_ATHandler::test_ATHandler_resp_start()
at.flush();
at.clear_error();
filehandle_stub_table_pos = 0;
at.resp_start();
char table6[] = "OK\r\n\0";
@ -866,6 +919,7 @@ void Test_ATHandler::test_ATHandler_resp_start()
at.flush();
at.clear_error();
filehandle_stub_table_pos = 0;
at.resp_start();
char table7[] = "ssssss\0";
@ -875,10 +929,11 @@ void Test_ATHandler::test_ATHandler_resp_start()
at.flush();
at.clear_error();
at.set_urc_handler("ss", NULL);
filehandle_stub_table_pos = 0;
at.resp_start();
}
void Test_ATHandler::test_ATHandler_resp_stop()
TEST_F(TestATHandler, test_ATHandler_resp_stop)
{
EventQueue que;
FileHandle_stub fh1;
@ -899,6 +954,7 @@ void Test_ATHandler::test_ATHandler_resp_stop()
at.flush();
at.clear_error();
filehandle_stub_table_pos = 0;
at.resp_start();
at.resp_stop();
@ -909,11 +965,12 @@ void Test_ATHandler::test_ATHandler_resp_stop()
at.flush();
at.clear_error();
filehandle_stub_table_pos = 0;
at.resp_start("ss", false);
at.resp_stop();
}
void Test_ATHandler::test_ATHandler_info_resp()
TEST_F(TestATHandler, test_ATHandler_info_resp)
{
EventQueue que;
FileHandle_stub fh1;
@ -921,10 +978,10 @@ void Test_ATHandler::test_ATHandler_info_resp()
filehandle_stub_table = NULL;
ATHandler at(&fh1, que, 0, ",");
CHECK(at.info_resp());
EXPECT_TRUE(at.info_resp());
at.resp_start();
CHECK(!at.info_resp());
EXPECT_TRUE(!at.info_resp());
at.flush();
at.clear_error();
@ -936,9 +993,9 @@ void Test_ATHandler::test_ATHandler_info_resp()
mbed_poll_stub::int_value = strlen(table2);
at.resp_start("21");
CHECK(at.info_resp());
EXPECT_TRUE(at.info_resp());
CHECK(!at.info_resp());
EXPECT_TRUE(!at.info_resp());
at.flush();
at.clear_error();
@ -949,10 +1006,10 @@ void Test_ATHandler::test_ATHandler_info_resp()
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table3);
CHECK(at.info_resp());
EXPECT_TRUE(at.info_resp());
}
void Test_ATHandler::test_ATHandler_info_elem()
TEST_F(TestATHandler, test_ATHandler_info_elem)
{
EventQueue que;
FileHandle_stub fh1;
@ -964,7 +1021,7 @@ void Test_ATHandler::test_ATHandler_info_elem()
mbed_poll_stub::int_value = strlen(table);
ATHandler at(&fh1, que, 0, ",");
CHECK(!at.info_elem('O'));
EXPECT_TRUE(!at.info_elem('O'));
at.flush();
char table2[] = "21 OK\r\n\0";
@ -975,7 +1032,7 @@ void Test_ATHandler::test_ATHandler_info_elem()
at.clear_error();
at.resp_start("21");
CHECK(at.info_elem('O'));
EXPECT_TRUE(at.info_elem('O'));
at.flush();
filehandle_stub_table = NULL;
@ -983,19 +1040,19 @@ void Test_ATHandler::test_ATHandler_info_elem()
at.clear_error();
at.resp_start("21");
CHECK(!at.info_elem('2'));
EXPECT_TRUE(!at.info_elem('2'));
}
void Test_ATHandler::test_ATHandler_consume_to_stop_tag()
TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
CHECK(at.consume_to_stop_tag());
EXPECT_TRUE(at.consume_to_stop_tag());
}
void Test_ATHandler::test_ATHandler_set_debug()
TEST_F(TestATHandler, test_ATHandler_set_debug)
{
EventQueue que;
FileHandle_stub fh1;
@ -1006,11 +1063,12 @@ void Test_ATHandler::test_ATHandler_set_debug()
at.set_debug(false);
}
void Test_ATHandler::test_ATHandler_get_3gpp_error()
TEST_F(TestATHandler, test_ATHandler_get_3gpp_error)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
int ret = at.get_3gpp_error();
at.get_3gpp_error();
}

View File

@ -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")

View File

@ -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 <string.h>
#include "CellularUtil.h"
#include <iostream>
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);
}

View File

@ -1,37 +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

View File

@ -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
)

View File

@ -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,187 @@
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "test_util.h"
#include <string.h>
#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);
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(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);
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);
}
TEST_F(TestUtil, separate_ip_addresses)
TEST_F(Testutil, get_dynamic_ip_port)
{
unit->test_util_separate_ip_addresses();
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');
}

View File

@ -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);
}

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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;
@ -40,29 +44,47 @@ uint8_t ATHandler_stub::uint8_value = 0;
FileHandle_stub *ATHandler_stub::fh_value = NULL;
device_err_t ATHandler_stub::device_err_value;
Callback<void()> 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];
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 = kATHandler_destructor_ref_ount;
}
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 +99,10 @@ void ATHandler::set_file_handle(FileHandle *fh)
nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
{
ATHandler_stub::callback = cb;
return NSAPI_ERROR_OK;
if (ATHandler_stub::call_immediately) {
cb();
}
return ATHandler_stub::nsapi_error_value;
}
void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
@ -108,6 +133,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 +147,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 +166,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 +238,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 +252,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 +290,5 @@ device_err_t ATHandler::get_last_device_error() const
void ATHandler::flush()
{
}

View File

@ -23,21 +23,40 @@
#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;
// 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;
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<void()> 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];
extern int int_count;
extern int resp_stop_success_count;
}
} // namespace ATHandler_stub
#endif

View File

@ -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 <algorithm>
#include <string.h>
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;
}

View File

@ -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;
}

View File

@ -15,6 +15,7 @@
* limitations under the License.
*/
#include <cstddef>
#include "rtos/EventFlags.h"
rtos::EventFlags::EventFlags() {}

View File

@ -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;
}

View File

@ -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 <algorithm>
#include <stdlib.h>
#include <string.h>
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;
}

View File

@ -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;
}

View File

@ -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 <algorithm>
// 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;
}

View File

@ -27,11 +27,6 @@ rtos::Mutex::~Mutex()
return;
}
osStatus rtos::Mutex::lock(void)
{
return osOK;
}
osStatus rtos::Mutex::lock(uint32_t millisec)
{
return osOK;

View File

@ -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<void(BlockDevice *)> 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)
{
}

View File

@ -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 <stdio.h>
#include <string.h>
#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)
{
}

View File

@ -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;
}

View File

@ -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 <string.h>
#include <stdlib.h>
#include <stdint.h>
#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;
}

View File

@ -18,6 +18,8 @@
#ifndef __CMSIS_OS2_H__
#define __CMSIS_OS2_H__
#include <inttypes.h>
//If conflicts, then remove these, copied from cmsis_os.h
typedef int32_t osStatus;
@ -42,11 +44,35 @@ typedef enum {
typedef void *osThreadId_t;
typedef void *osEventFlagsId_t;
/// Attributes structure for thread.
typedef struct {
} osThreadAttr_t;
#define osWaitForever 0xFFFFFFFFU
#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

View File

@ -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 <cstring>
#include "events/mbed_events.h"
#include "events/mbed_shared_queues.h"
namespace mbed {
#include "platform/Callback.h"

View File

@ -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

View File

@ -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
}

View File

@ -15,4 +15,6 @@
* limitations under the License.
*/
#ifndef OS_STACK_SIZE
#define OS_STACK_SIZE 0
#endif

View File

@ -18,7 +18,15 @@
#ifndef RETARGET_H
#define RETARGET_H
#include <inttypes.h>
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
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

View File

@ -14,11 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MUTEX_H__
#define __MUTEX_H__
#include <inttypes.h>
#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;
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

View File

@ -57,4 +57,14 @@ typedef struct osRtxThread_s {
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

View File

@ -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")

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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();
}

View File

@ -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);

Some files were not shown because too many files have changed in this diff Show More