Skip to content

Commit 9f9aa4a

Browse files
author
Antti Kauppila
committed
cellular unittests ported to googletest framework
1 parent 0cd4315 commit 9f9aa4a

File tree

85 files changed

+8137
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+8137
-371
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,35 @@ endif(COVERAGE)
9090
set(unittest-includes-base
9191
"${PROJECT_SOURCE_DIR}/target_h"
9292
"${PROJECT_SOURCE_DIR}/target_h/events"
93+
"${PROJECT_SOURCE_DIR}/target_h/events/equeue"
94+
"${PROJECT_SOURCE_DIR}/target_h/platform"
9395
"${PROJECT_SOURCE_DIR}/stubs"
9496
"${PROJECT_SOURCE_DIR}/.."
9597
"${PROJECT_SOURCE_DIR}/../features"
98+
"${PROJECT_SOURCE_DIR}/../features/netsocket"
9699
"${PROJECT_SOURCE_DIR}/../platform"
97100
"${PROJECT_SOURCE_DIR}/../drivers"
98101
"${PROJECT_SOURCE_DIR}/../hal"
99102
"${PROJECT_SOURCE_DIR}/../events"
103+
"${PROJECT_SOURCE_DIR}/../events/equeue"
104+
"${PROJECT_SOURCE_DIR}/../rtos"
100105
"${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX"
101106
"${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX/rtx5/Include"
102107
"${PROJECT_SOURCE_DIR}/../cmsis"
103-
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice/"
108+
"${PROJECT_SOURCE_DIR}/../features/frameworks"
109+
"${PROJECT_SOURCE_DIR}/../features/frameworks/mbed-trace"
110+
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice"
111+
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice"
112+
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat"
113+
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat/ChaN"
114+
"${PROJECT_SOURCE_DIR}/../features/filesystem/bd"
115+
"${PROJECT_SOURCE_DIR}/../features/filesystem/"
116+
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs"
117+
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs"
118+
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/API"
119+
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
120+
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
121+
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
104122
)
105123

106124
# Create a list for test suites.
@@ -168,3 +186,4 @@ foreach(testfile ${unittest-file-list})
168186
message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n")
169187
endif(unittest-test-sources)
170188
endforeach(testfile)
189+

UNITTESTS/features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

UNITTESTS/features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
18+
#include "gtest/gtest.h"
19+
#include "AT_CellularBase.h"
20+
#include "EventQueue.h"
21+
#include "AT_CellularBase.h"
22+
#include "ATHandler_stub.h"
23+
#include "FileHandle_stub.h"
24+
#include <string.h>
25+
26+
using namespace mbed;
27+
using namespace events;
28+
29+
class my_base : public AT_CellularBase {
30+
public:
31+
my_base(ATHandler &at) : AT_CellularBase(at)
32+
{
33+
}
34+
bool check_not_supported()
35+
{
36+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
37+
AT_CellularBase::AT_CGSN_WITH_TYPE,
38+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
39+
};
40+
set_unsupported_features(unsupported_features);
41+
return is_supported(AT_CGSN_WITH_TYPE);
42+
}
43+
44+
bool check_supported()
45+
{
46+
set_unsupported_features(NULL);
47+
return is_supported(AT_CGSN_WITH_TYPE);
48+
}
49+
50+
bool check_supported_not_found()
51+
{
52+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
53+
AT_CellularBase::AT_CGSN_WITH_TYPE,
54+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
55+
};
56+
set_unsupported_features(unsupported_features);
57+
return is_supported(SUPPORTED_FEATURE_END_MARK);
58+
}
59+
};
60+
61+
// AStyle ignored as the definition is not clear due to preprocessor usage
62+
// *INDENT-OFF*
63+
class TestAT_CellularBase : public testing::Test {
64+
protected:
65+
66+
void SetUp()
67+
{
68+
}
69+
70+
void TearDown()
71+
{
72+
}
73+
};
74+
// *INDENT-ON*
75+
76+
TEST_F(TestAT_CellularBase, Create)
77+
{
78+
EventQueue eq;
79+
FileHandle_stub fh;
80+
ATHandler ah(&fh, eq, 100, ",");
81+
AT_CellularBase *unit = new AT_CellularBase(ah);
82+
83+
EXPECT_TRUE(unit != NULL);
84+
85+
delete unit;
86+
}
87+
88+
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler)
89+
{
90+
EventQueue eq;
91+
FileHandle_stub fh;
92+
ATHandler ah(&fh, eq, 100, ",");
93+
AT_CellularBase at(ah);
94+
95+
EXPECT_TRUE(&ah == &at.get_at_handler());
96+
}
97+
98+
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
99+
{
100+
EventQueue eq;
101+
FileHandle_stub fh;
102+
ATHandler ah(&fh, eq, 0, ",");
103+
AT_CellularBase at(ah);
104+
105+
ATHandler_stub::device_err_value.errCode = 8;
106+
107+
EXPECT_EQ(8, at.get_device_error().errCode);
108+
109+
ATHandler_stub::device_err_value.errCode = 0;
110+
}
111+
112+
TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features)
113+
{
114+
EventQueue eq;
115+
FileHandle_stub fh;
116+
ATHandler ah(&fh, eq, 0, ",");
117+
AT_CellularBase at(ah);
118+
119+
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
120+
AT_CellularBase::AT_CGSN_WITH_TYPE,
121+
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
122+
};
123+
124+
at.set_unsupported_features(unsupported_features);
125+
}
126+
127+
TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported)
128+
{
129+
EventQueue eq;
130+
FileHandle_stub fh;
131+
ATHandler ah(&fh, eq, 0, ",");
132+
my_base my_at(ah);
133+
134+
EXPECT_TRUE(true == my_at.check_supported());
135+
EXPECT_TRUE(true == my_at.check_supported_not_found());
136+
EXPECT_TRUE(false == my_at.check_not_supported());
137+
}

UNITTESTS/features/cellular/framework/AT/AT_CellularBase/unittest.cmake renamed to UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ set(unittest-sources
2323

2424
# Test files
2525
set(unittest-test-sources
26+
features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp
2627
stubs/mbed_assert_stub.c
2728
stubs/ATHandler_stub.cpp
2829
stubs/EventQueue_stub.cpp
2930
stubs/FileHandle_stub.cpp
30-
features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp
31-
features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp
3231
)

0 commit comments

Comments
 (0)