Skip to content

Commit 0b9e80f

Browse files
author
Kimmo Vaisanen
committed
Unittests for CellularList
1 parent 3c47010 commit 0b9e80f

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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 "CellularList.h"
19+
20+
using namespace mbed;
21+
22+
// AStyle ignored as the definition is not clear due to preprocessor usage
23+
// *INDENT-OFF*
24+
class Testlist : public testing::Test {
25+
protected:
26+
27+
void SetUp()
28+
{
29+
}
30+
31+
void TearDown()
32+
{
33+
}
34+
};
35+
// *INDENT-ON*
36+
37+
struct entry_t {
38+
int i;
39+
entry_t *next;
40+
};
41+
42+
TEST_F(Testlist, test_list_int)
43+
{
44+
CellularList<entry_t> list;
45+
EXPECT_TRUE(NULL == list.get_head());
46+
47+
entry_t *first = list.add_new();
48+
first->i = 1;
49+
EXPECT_TRUE(NULL != first);
50+
51+
entry_t *second = list.add_new();
52+
first->i = 2;
53+
EXPECT_TRUE(NULL != second);
54+
55+
entry_t *third = list.add_new();
56+
first->i = 3;
57+
EXPECT_TRUE(NULL != third);
58+
59+
EXPECT_EQ(3, list.get_head()->i);
60+
61+
list.delete_last(); // Deletes first
62+
EXPECT_EQ(3, list.get_head()->i);
63+
64+
list.delete_all();
65+
EXPECT_TRUE(NULL == list.get_head());
66+
}
67+
68+
TEST_F(Testlist, delete_last_until_empty)
69+
{
70+
CellularList<entry_t> list;
71+
list.add_new();
72+
list.add_new();
73+
list.delete_last();
74+
list.delete_last();
75+
EXPECT_TRUE(NULL == list.get_head());
76+
}
77+
78+
TEST_F(Testlist, empty_list_delete_last)
79+
{
80+
CellularList<entry_t> list;
81+
list.delete_last();
82+
EXPECT_TRUE(NULL == list.get_head());
83+
}
84+
85+
TEST_F(Testlist, empty_list_delete_all)
86+
{
87+
CellularList<entry_t> list;
88+
list.delete_all();
89+
EXPECT_TRUE(NULL == list.get_head());
90+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
)
11+
12+
# Source files
13+
set(unittest-sources
14+
)
15+
16+
# Test files
17+
set(unittest-test-sources
18+
features/cellular/framework/common/list/listtest.cpp
19+
)

0 commit comments

Comments
 (0)