-
Notifications
You must be signed in to change notification settings - Fork 94
/
u_cell_sim_test.c
148 lines (117 loc) · 4.56 KB
/
u_cell_sim_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
* Copyright 2019-2024 u-blox
*
* 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.
*/
/* Only #includes of u_* and the C standard library are allowed here,
* no platform stuff and no OS stuff. Anything required from the
* platform/OS must be brought in through u_port* to maintain
* portability.
*/
/** @file
* @brief Tests for the cellular SIM API: these should pass on all
* cellular modules. They are only compiled if U_CFG_TEST_CELL_MODULE_TYPE
* is defined.
*/
#ifdef U_CFG_TEST_CELL_MODULE_TYPE
# ifdef U_CFG_OVERRIDE
# include "u_cfg_override.h" // For a customer's configuration override
# endif
#include "stddef.h" // NULL, size_t etc.
#include "stdint.h" // int32_t etc.
#include "stdbool.h"
#include "u_cfg_sw.h"
#include "u_cfg_os_platform_specific.h"
#include "u_cfg_app_platform_specific.h"
#include "u_cfg_test_platform_specific.h"
#include "u_error_common.h"
#include "u_port.h"
#include "u_port_os.h"
#include "u_port_heap.h"
#include "u_port_debug.h"
#include "u_test_util_resource_check.h"
#include "u_at_client.h"
#include "u_cell_module_type.h"
#include "u_cell_net.h"
#include "u_cell_sim.h"
#include "u_cell_test_cfg.h"
#include "u_cell_test_private.h"
/* ----------------------------------------------------------------
* COMPILE-TIME MACROS
* -------------------------------------------------------------- */
/** The string to put at the start of all prints from this test.
*/
#define U_TEST_PREFIX "U_CELL_SIM_TEST: "
/** Print a whole line, with terminator, prefixed for this test file.
*/
#define U_TEST_PRINT_LINE(format, ...) uPortLog(U_TEST_PREFIX format "\n", ##__VA_ARGS__)
/* ----------------------------------------------------------------
* TYPES
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* VARIABLES
* -------------------------------------------------------------- */
/** Handle.
*/
static uCellTestPrivate_t gHandles = U_CELL_TEST_PRIVATE_DEFAULTS;
/* ----------------------------------------------------------------
* STATIC FUNCTIONS
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS
* -------------------------------------------------------------- */
/** Test deleting the FPLMN list from the SIM.
*
* IMPORTANT: see notes in u_cfg_test_platform_specific.h for the
* naming rules that must be followed when using the
* U_PORT_TEST_FUNCTION() macro.
*/
U_PORT_TEST_FUNCTION("[cellSim]", "cellSimFplmnDelete")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
int32_t x;
// In case a previous test failed
uCellTestPrivateCleanup(&gHandles);
// Obtain the initial resource count
resourceCount = uTestUtilGetDynamicResourceCount();
// Do the standard preamble
U_PORT_TEST_ASSERT(uCellTestPrivatePreamble(U_CFG_TEST_CELL_MODULE_TYPE,
&gHandles, true) == 0);
cellHandle = gHandles.cellHandle;
// Not a great deal to test here really
x = uCellSimFplmnListDelete(cellHandle);
U_TEST_PRINT_LINE("uCellSimFplmnListDelete() returned %d.\n", x);
U_PORT_TEST_ASSERT(x == 0);
// Do the standard postamble, leaving the module on for the next
// test to speed things up
uCellTestPrivatePostamble(&gHandles, false);
// Check for resource leaks
uTestUtilResourceCheck(U_TEST_PREFIX, NULL, true);
resourceCount = uTestUtilGetDynamicResourceCount() - resourceCount;
U_TEST_PRINT_LINE("we have leaked %d resources(s).", resourceCount);
U_PORT_TEST_ASSERT(resourceCount <= 0);
}
/** Clean-up to be run at the end of this round of tests, just
* in case there were test failures which would have resulted
* in the deinitialisation being skipped.
*/
U_PORT_TEST_FUNCTION("[cellSim]", "cellSimCleanUp")
{
uCellTestPrivateCleanup(&gHandles);
uPortDeinit();
// Printed for information: asserting happens in the postamble
uTestUtilResourceCheck(U_TEST_PREFIX, NULL, true);
}
#endif // #ifdef U_CFG_TEST_CELL_MODULE_TYPE
// End of file