Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UNITTESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ set(unittest-includes-base
"${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/device"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
"${PROJECT_SOURCE_DIR}/../features/lorawan"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <string.h>
#include "AT_CellularContext.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularDevice.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "ATHandler_stub.h"
#include "AT_CellularStack.h"

using namespace mbed;
using namespace events;

// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularContext : public testing::Test {
protected:

void SetUp()
{
ATHandler_stub::int_count = kRead_int_table_size;
ATHandler_stub::read_string_index = kRead_string_table_size;
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::int_value = -1;
}

void TearDown()
{
}
};
// *INDENT-ON*
class my_stack : public AT_CellularStack {
public:
my_stack(ATHandler &atHandler) : AT_CellularStack(atHandler, 1, IPV4_STACK) {}
virtual int get_max_socket_count()
{
return 1;
}
virtual int get_max_packet_size()
{
return 200;
}
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
{
return true;
}
virtual nsapi_error_t socket_close_impl(int sock_id)
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t create_socket_impl(CellularSocket *socket)
{
return NSAPI_ERROR_OK;
}
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size)
{
return 100;
}
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size)
{
return 100;
}
};

class my_AT_CTX : public AT_CellularContext {
public:
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn) {}
virtual ~my_AT_CTX() {}
};

class my_AT_CTXIPV6 : public AT_CellularContext {
public:
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) :
AT_CellularContext(at, device, apn) {}
virtual ~my_AT_CTXIPV6() {}
};

static int network_cb_count;
static void network_cb(nsapi_event_t ev, intptr_t intptr)
{
network_cb_count++;
}

TEST_F(TestAT_CellularContext, Create)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");

AT_CellularContext *ctx = new AT_CellularContext(at, NULL);
EXPECT_TRUE(ctx != NULL);
delete ctx;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

####################
# UNIT TESTS
####################

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/cellular/framework/device
)

# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularContext.cpp
)

# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.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.c
stubs/CellularDevice_stub.cpp
stubs/CellularStateMachine_stub.cpp
stubs/Semaphore_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/equeue_stub.c
)
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,21 @@ class TestAT_CellularDevice : public testing::Test {

TEST_F(TestAT_CellularDevice, Create)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

CellularDevice *dev2 = new AT_CellularDevice(que);
CellularDevice *dev2 = new AT_CellularDevice(&fh1);

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;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(dev.open_network(&fh1));
EXPECT_TRUE(dev.open_sms(&fh2));
Expand All @@ -66,59 +65,73 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(!dev.open_network(NULL));
EXPECT_TRUE(dev.open_network(&fh1));
CellularNetwork *nw = dev.open_network(NULL);
CellularNetwork *nw1 = dev.open_network(&fh1);

EXPECT_TRUE(nw);
EXPECT_TRUE(nw1);
EXPECT_TRUE(nw1 == nw);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(!dev.open_sms(NULL));
EXPECT_TRUE(dev.open_sms(&fh1));
CellularSMS *sms = dev.open_sms(NULL);
CellularSMS *sms1 = dev.open_sms(&fh1);

EXPECT_TRUE(sms);
EXPECT_TRUE(sms1);
EXPECT_TRUE(sms1 == sms);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(!dev.open_power(NULL));
EXPECT_TRUE(dev.open_power(&fh1));
CellularPower *pwr = dev.open_power(NULL);
CellularPower *pwr1 = dev.open_power(&fh1);

EXPECT_TRUE(pwr);
EXPECT_TRUE(pwr1);
EXPECT_TRUE(pwr1 == pwr);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(! dev.open_sim(NULL));
EXPECT_TRUE(dev.open_sim(&fh1));
CellularSIM *sim = dev.open_sim(NULL);
CellularSIM *sim1 = dev.open_sim(&fh1);

EXPECT_TRUE(sim);
EXPECT_TRUE(sim1);
EXPECT_TRUE(sim1 == sim);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);

EXPECT_TRUE(!dev.open_information(NULL));
EXPECT_TRUE(dev.open_information(&fh1));
CellularInformation *info = dev.open_information(NULL);
CellularInformation *info1 = dev.open_information(&fh1);

EXPECT_TRUE(info);
EXPECT_TRUE(info1);
EXPECT_TRUE(info1 == info);
}

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::ref_count = 0;

EXPECT_TRUE(dev.open_network(&fh1));
Expand All @@ -131,9 +144,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::ref_count = 0;

EXPECT_TRUE(dev.open_sms(&fh1));
Expand All @@ -146,9 +158,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::ref_count = 0;

EXPECT_TRUE(dev.open_power(&fh1));
Expand All @@ -161,9 +172,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::ref_count = 0;
int ana = 0;

Expand All @@ -182,9 +192,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::int_value = 0;

EXPECT_TRUE(dev.open_information(&fh1));
Expand All @@ -193,6 +202,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
AT_CellularBase_stub::handler_value = NULL;
dev.close_information();

EventQueue que;
ATHandler_stub::fh_value = &fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularBase_stub::handler_value = &at;
Expand All @@ -208,9 +218,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::timeout = 0;
ATHandler_stub::default_timeout = false;

Expand All @@ -231,9 +240,8 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)

TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
ATHandler_stub::debug_on = false;

// no interfaces open so debug toggling should not affect
Expand All @@ -249,31 +257,16 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
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);
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
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));
FileHandle_stub fh1;
AT_CellularDevice dev(&fh1);
EXPECT_TRUE(NSAPI_ERROR_OK == dev.init_module());
}
Loading