Skip to content

Commit 43e08a0

Browse files
author
Teppo Järvelin
committed
Cellular: fixing unit test after refactor.
1 parent ad2abbe commit 43e08a0

File tree

15 files changed

+719
-690
lines changed

15 files changed

+719
-690
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ set(unittest-includes-base
117117
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs"
118118
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/API"
119119
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
120+
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/device"
120121
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
121122
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
122123
"${PROJECT_SOURCE_DIR}/../features/lorawan"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2018, Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include "gtest/gtest.h"
18+
#include <string.h>
19+
#include "AT_CellularContext.h"
20+
#include "EventQueue.h"
21+
#include "ATHandler.h"
22+
#include "AT_CellularDevice.h"
23+
#include "FileHandle_stub.h"
24+
#include "CellularLog.h"
25+
#include "ATHandler_stub.h"
26+
#include "AT_CellularStack.h"
27+
28+
using namespace mbed;
29+
using namespace events;
30+
31+
// AStyle ignored as the definition is not clear due to preprocessor usage
32+
// *INDENT-OFF*
33+
class TestAT_CellularContext : public testing::Test {
34+
protected:
35+
36+
void SetUp()
37+
{
38+
ATHandler_stub::int_count = kRead_int_table_size;
39+
ATHandler_stub::read_string_index = kRead_string_table_size;
40+
ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
41+
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
42+
ATHandler_stub::int_value = -1;
43+
}
44+
45+
void TearDown()
46+
{
47+
}
48+
};
49+
// *INDENT-ON*
50+
class my_stack : public AT_CellularStack {
51+
public:
52+
my_stack(ATHandler &atHandler) : AT_CellularStack(atHandler, 1, IPV4_STACK) {}
53+
virtual int get_max_socket_count()
54+
{
55+
return 1;
56+
}
57+
virtual int get_max_packet_size()
58+
{
59+
return 200;
60+
}
61+
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
62+
{
63+
return true;
64+
}
65+
virtual nsapi_error_t socket_close_impl(int sock_id)
66+
{
67+
return NSAPI_ERROR_OK;
68+
}
69+
virtual nsapi_error_t create_socket_impl(CellularSocket *socket)
70+
{
71+
return NSAPI_ERROR_OK;
72+
}
73+
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
74+
const void *data, nsapi_size_t size)
75+
{
76+
return 100;
77+
}
78+
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
79+
void *buffer, nsapi_size_t size)
80+
{
81+
return 100;
82+
}
83+
};
84+
85+
class my_AT_CTX : public AT_CellularContext {
86+
public:
87+
my_AT_CTX(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN,
88+
nsapi_ip_stack_t stack = DEFAULT_STACK) : AT_CellularContext(at, device, apn, stack) {}
89+
virtual ~my_AT_CTX() {}
90+
};
91+
92+
class my_AT_CTXIPV6 : public AT_CellularContext {
93+
public:
94+
my_AT_CTXIPV6(ATHandler &at, CellularDevice *device, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN,
95+
nsapi_ip_stack_t stack = DEFAULT_STACK) : AT_CellularContext(at, device, apn, stack) {}
96+
virtual ~my_AT_CTXIPV6() {}
97+
};
98+
99+
static int network_cb_count;
100+
static void network_cb(nsapi_event_t ev, intptr_t intptr)
101+
{
102+
network_cb_count++;
103+
}
104+
105+
TEST_F(TestAT_CellularContext, Create)
106+
{
107+
EventQueue que;
108+
FileHandle_stub fh1;
109+
ATHandler at(&fh1, que, 0, ",");
110+
111+
AT_CellularContext *ctx = new AT_CellularContext(at, NULL);
112+
EXPECT_TRUE(ctx != NULL);
113+
delete ctx;
114+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
####################
3+
# UNIT TESTS
4+
####################
5+
6+
# Add test specific include paths
7+
set(unittest-includes ${unittest-includes}
8+
features/cellular/framework/common/util
9+
../features/cellular/framework/common
10+
../features/cellular/framework/AT
11+
../features/cellular/framework/device
12+
)
13+
14+
# Source files
15+
set(unittest-sources
16+
../features/cellular/framework/AT/AT_CellularContext.cpp
17+
)
18+
19+
# Test files
20+
set(unittest-test-sources
21+
features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp
22+
stubs/ATHandler_stub.cpp
23+
stubs/AT_CellularBase_stub.cpp
24+
stubs/EventQueue_stub.cpp
25+
stubs/FileHandle_stub.cpp
26+
stubs/NetworkInterface_stub.cpp
27+
stubs/NetworkStack_stub.cpp
28+
stubs/us_ticker_stub.cpp
29+
stubs/mbed_assert_stub.c
30+
stubs/CellularDevice_stub.cpp
31+
stubs/CellularStateMachine_stub.cpp
32+
stubs/Semaphore_stub.cpp
33+
stubs/CellularUtil_stub.cpp
34+
stubs/equeue_stub.c
35+
)

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
7070
AT_CellularDevice dev(que);
7171
FileHandle_stub fh1;
7272

73-
EXPECT_TRUE(!dev.open_network(NULL));
74-
EXPECT_TRUE(dev.open_network(&fh1));
73+
CellularNetwork *nw = dev.open_network(NULL);
74+
CellularNetwork *nw1 = dev.open_network(&fh1);
75+
76+
EXPECT_TRUE(nw);
77+
EXPECT_TRUE(nw1);
78+
EXPECT_TRUE(nw1 == nw);
7579
}
7680

7781
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
@@ -80,8 +84,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
8084
AT_CellularDevice dev(que);
8185
FileHandle_stub fh1;
8286

83-
EXPECT_TRUE(!dev.open_sms(NULL));
84-
EXPECT_TRUE(dev.open_sms(&fh1));
87+
CellularSMS *sms = dev.open_sms(NULL);
88+
CellularSMS *sms1 = dev.open_sms(&fh1);
89+
90+
EXPECT_TRUE(sms);
91+
EXPECT_TRUE(sms1);
92+
EXPECT_TRUE(sms1 == sms);
8593
}
8694

8795
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
@@ -90,8 +98,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
9098
AT_CellularDevice dev(que);
9199
FileHandle_stub fh1;
92100

93-
EXPECT_TRUE(!dev.open_power(NULL));
94-
EXPECT_TRUE(dev.open_power(&fh1));
101+
CellularPower *pwr = dev.open_power(NULL);
102+
CellularPower *pwr1 = dev.open_power(&fh1);
103+
104+
EXPECT_TRUE(pwr);
105+
EXPECT_TRUE(pwr1);
106+
EXPECT_TRUE(pwr1 == pwr);
95107
}
96108

97109
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
@@ -100,8 +112,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
100112
AT_CellularDevice dev(que);
101113
FileHandle_stub fh1;
102114

103-
EXPECT_TRUE(! dev.open_sim(NULL));
104-
EXPECT_TRUE(dev.open_sim(&fh1));
115+
CellularSIM *sim = dev.open_sim(NULL);
116+
CellularSIM *sim1 = dev.open_sim(&fh1);
117+
118+
EXPECT_TRUE(sim);
119+
EXPECT_TRUE(sim1);
120+
EXPECT_TRUE(sim1 == sim);
105121
}
106122

107123
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
@@ -110,8 +126,12 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
110126
AT_CellularDevice dev(que);
111127
FileHandle_stub fh1;
112128

113-
EXPECT_TRUE(!dev.open_information(NULL));
114-
EXPECT_TRUE(dev.open_information(&fh1));
129+
CellularInformation *info = dev.open_information(NULL);
130+
CellularInformation *info1 = dev.open_information(&fh1);
131+
132+
EXPECT_TRUE(info);
133+
EXPECT_TRUE(info1);
134+
EXPECT_TRUE(info1 == info);
115135
}
116136

117137
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
@@ -249,21 +269,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
249269
dev.close_sim();
250270
}
251271

252-
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_stack)
253-
{
254-
EventQueue que;
255-
AT_CellularDevice dev(que);
256-
FileHandle_stub fh1;
257-
258-
NetworkStack *stack = dev.get_stack();
259-
EXPECT_TRUE(stack == NULL);
260-
261-
EXPECT_TRUE(dev.open_network(&fh1));
262-
263-
stack = dev.get_stack();
264-
EXPECT_TRUE(stack == NULL); // Not in PPP so also null but this is got from the network class
265-
}
266-
267272
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
268273
{
269274
EventQueue que;

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ set(unittest-includes ${unittest-includes}
88
features/cellular/framework/common/util
99
../features/cellular/framework/common
1010
../features/cellular/framework/AT
11+
../features/cellular/framework/device
1112
../features/frameworks/mbed-client-randlib/mbed-client-randlib
13+
../drivers
14+
../hal
1215
)
1316

1417
# Source files
@@ -33,4 +36,16 @@ set(unittest-test-sources
3336
stubs/FileHandle_stub.cpp
3437
stubs/mbed_assert_stub.c
3538
stubs/CellularDevice_stub.cpp
39+
stubs/NetworkStack_stub.cpp
40+
stubs/AT_CellularContext_stub.cpp
41+
stubs/Semaphore_stub.cpp
42+
stubs/UARTSerial_stub.cpp
43+
stubs/SerialBase_stub.cpp
3644
)
45+
46+
# defines
47+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDEVICE_SERIAL=1 -DDEVICE_INTERRUPTIN=1 -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN=NULL")
48+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMDMTXD=NC -DMDMRXD=NC -DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200")
49+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEVICE_SERIAL=1 -DDEVICE_INTERRUPTIN=1 -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN=NULL")
50+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMDMTXD=NC -DMDMRXD=NC -DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200")
51+

0 commit comments

Comments
 (0)