This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathu_cell_file_test.c
668 lines (553 loc) · 23.6 KB
/
u_cell_file_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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
/*
* 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 file cellular system API: these should pass on all
* platforms that have file system support. 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 "stdlib.h" // strtol()
#include "stddef.h" // NULL, size_t etc.
#include "stdint.h" // int32_t etc.
#include "stdbool.h"
#include "stdio.h" // snprintf()
#include "string.h" // memset(), strcmp()
#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_clib_platform_specific.h" /* Integer stdio, must be included
before the other port files if
any print or scan function is used. */
#include "u_port.h"
#include "u_port_os.h" // Required by u_cell_private.h
#include "u_port_heap.h"
#include "u_port_debug.h"
#include "u_test_util_resource_check.h"
#include "u_timeout.h"
#include "u_at_client.h"
#include "u_cell_module_type.h"
#include "u_cell.h"
#include "u_cell_file.h"
#include "u_cell_net.h" // Required by u_cell_private.h
#include "u_cell_private.h" // So that we can get at some innards
#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_FILE_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__)
/** The name of the file to use when testing.
*/
#define U_CELL_FILE_TEST_FILE_NAME "test"
/** strlen(U_CELL_FILE_TEST_FILE_NAME).
*/
#define U_CELL_FILE_TEST_FILE_NAME_LENGTH 4
/** The number of files to test for in the re-entrant listing
* version
*/
#define U_CELL_FILE_TEST_REENTRANT_NUM 3
/** The string to write to a file used in the re-entrant list testing.
*/
#define U_CELL_FILE_TEST_REENTRANT_STRING "delete me"
/** strlen(U_CELL_FILE_TEST_REENTRANT_STRING).
*/
#define U_CELL_FILE_TEST_REENTRANT_STRING_SIZE 9
/* ----------------------------------------------------------------
* TYPES
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* VARIABLES
* -------------------------------------------------------------- */
/** Handle.
*/
static uCellTestPrivate_t gHandles = U_CELL_TEST_PRIVATE_DEFAULTS;
/* ----------------------------------------------------------------
* STATIC FUNCTIONS
* -------------------------------------------------------------- */
// Update a tracking array, used by cellFileListAllReentrant().
static void updateTracker(const char *pFileName, bool *pTracker,
size_t size)
{
size_t x;
if (strlen(pFileName) == U_CELL_FILE_TEST_FILE_NAME_LENGTH + 1) {
x = strtol(pFileName + U_CELL_FILE_TEST_FILE_NAME_LENGTH, NULL, 10);
if (x < size) {
*(pTracker + x) = true;
}
}
}
// Check a tracking array, used by cellFileListAllReentrant();
// return true only if all elements are true.
static bool checkTracker(bool *pTracker, size_t size)
{
bool isGood = true;
for (size_t x = 0; (x < size) && isGood; x++, pTracker++) {
isGood = *pTracker;
}
return isGood;
}
/* ----------------------------------------------------------------
* PUBLIC FUNCTIONS
* -------------------------------------------------------------- */
/** Test writing data into file.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileWrite")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
const uCellPrivateModule_t *pModule;
int32_t result;
const char *pBuffer = "DEADBEEFDEADBEEF";
size_t length;
size_t y = 1;
length = strlen(pBuffer);
// 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;
// Make sure the test file name has been deleted in case a
// previous test was aborted half way
uCellFileDelete(cellHandle, U_CELL_FILE_TEST_FILE_NAME);
// Get the private module data as we need it for testing
pModule = pUCellPrivateGetModule(cellHandle);
U_PORT_TEST_ASSERT(pModule != NULL);
//lint -esym(613, pModule) Suppress possible use of NULL pointer
// for pModule from now on
// Do this twice if tags are supported
if (U_CELL_PRIVATE_HAS(pModule, U_CELL_PRIVATE_FEATURE_FILE_SYSTEM_TAG)) {
y = 2;
}
for (size_t x = 0; x < y; x++) {
if (x > 0) {
U_TEST_PRINT_LINE("repeating with tag...");
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, "USER") == 0);
} else {
U_PORT_TEST_ASSERT(pUCellFileGetTag(cellHandle) == NULL);
}
// Open file in write mode and write data into the file
U_TEST_PRINT_LINE("writing data into file...");
result = uCellFileWrite(cellHandle, // Cellular Handle
U_CELL_FILE_TEST_FILE_NAME, // File name
pBuffer, // Data to write into the file
length); // Data size
U_TEST_PRINT_LINE("number of bytes written into the file = %d.", result);
U_PORT_TEST_ASSERT(result == length);
if (x > 0) {
U_PORT_TEST_ASSERT(strcmp(pUCellFileGetTag(cellHandle), "USER") == 0);
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, NULL) == 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);
}
/** Test reading file size.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileSize")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
const uCellPrivateModule_t *pModule;
int32_t fileSize = 0;
size_t y = 1;
// 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;
// Get the private module data as we need it for testing
pModule = pUCellPrivateGetModule(cellHandle);
U_PORT_TEST_ASSERT(pModule != NULL);
//lint -esym(613, pModule) Suppress possible use of NULL pointer
// for pModule from now on
// Do this twice if tags are supported
if (U_CELL_PRIVATE_HAS(pModule, U_CELL_PRIVATE_FEATURE_FILE_SYSTEM_TAG)) {
y = 2;
}
for (size_t x = 0; x < y; x++) {
if (x > 0) {
U_TEST_PRINT_LINE("repeating with tag...");
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, "USER") == 0);
} else {
U_PORT_TEST_ASSERT(pUCellFileGetTag(cellHandle) == NULL);
}
// Read size of file
U_TEST_PRINT_LINE("reading file size...");
fileSize = uCellFileSize(cellHandle, // Cellular Handle
U_CELL_FILE_TEST_FILE_NAME); // File name
U_TEST_PRINT_LINE("file size = %d.", fileSize);
// This should pass if previous test has passed
U_PORT_TEST_ASSERT(fileSize > 0);
if (x > 0) {
U_PORT_TEST_ASSERT(strcmp(pUCellFileGetTag(cellHandle), "USER") == 0);
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, NULL) == 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);
}
/** Test block reading from file.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileBlockRead")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
const uCellPrivateModule_t *pModule;
int32_t result;
int32_t offset;
size_t length;
char buffer[9];
// 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;
// Get the private module data as we need it for testing
pModule = pUCellPrivateGetModule(cellHandle);
U_PORT_TEST_ASSERT(pModule != NULL);
//lint -esym(613, pModule) Suppress possible use of NULL pointer
// for pModule from now on
// Block read from file
length = 8;
offset = 7;
U_TEST_PRINT_LINE("reading data (block read) from file...");
U_TEST_PRINT_LINE("read %d bytes with the offset of %d bytes.",
length, offset);
memset(buffer, 0xaa, sizeof(buffer));
result = uCellFileBlockRead(cellHandle, // Cellular Handle
U_CELL_FILE_TEST_FILE_NAME, // File name
buffer, // Buffer to store file contents
offset, // offset from the beginning of file
length); // Number of bytes to read
U_TEST_PRINT_LINE("number of bytes read = %d.", result);
U_TEST_PRINT_LINE("data read \"%.*s\".", length, buffer);
U_PORT_TEST_ASSERT(result == length);
U_PORT_TEST_ASSERT(memcmp(buffer, "FDEADBEE", length) == 0);
U_PORT_TEST_ASSERT(*(buffer + length) == (char) 0xaa);
// Confirm that an error is returned if a tag is set
if (U_CELL_PRIVATE_HAS(pModule, U_CELL_PRIVATE_FEATURE_FILE_SYSTEM_TAG)) {
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, "USER") == 0);
U_PORT_TEST_ASSERT(uCellFileBlockRead(cellHandle,
U_CELL_FILE_TEST_FILE_NAME,
buffer, 0, 8) < 0);
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, NULL) == 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);
}
/** Test reading whole file.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileRead")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
const uCellPrivateModule_t *pModule;
int32_t length = 0;
char buffer[50];
size_t y = 1;
// 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;
// Get the private module data as we need it for testing
pModule = pUCellPrivateGetModule(cellHandle);
U_PORT_TEST_ASSERT(pModule != NULL);
//lint -esym(613, pModule) Suppress possible use of NULL pointer
// for pModule from now on
// Do this twice if tags are supported
if (U_CELL_PRIVATE_HAS(pModule, U_CELL_PRIVATE_FEATURE_FILE_SYSTEM_TAG)) {
y = 2;
}
for (size_t x = 0; x < y; x++) {
if (x > 0) {
U_TEST_PRINT_LINE("repeating with tag...");
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, "USER") == 0);
} else {
U_PORT_TEST_ASSERT(pUCellFileGetTag(cellHandle) == NULL);
}
// Read contents of file
U_TEST_PRINT_LINE("reading whole file...");
length = uCellFileRead(cellHandle, // Cellular Handle
U_CELL_FILE_TEST_FILE_NAME, // File name
buffer, sizeof(buffer)); // Buffer to store file contents
U_TEST_PRINT_LINE("number of bytes read = %d.", length);
U_TEST_PRINT_LINE("data read \"%.*s\".", length, buffer);
U_PORT_TEST_ASSERT(length > 0);
if (x > 0) {
U_PORT_TEST_ASSERT(strcmp(pUCellFileGetTag(cellHandle), "USER") == 0);
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, NULL) == 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);
}
/** Test list all files.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileListAll")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
const uCellPrivateModule_t *pModule;
bool found;
char *pFileName;
size_t y = 1;
pFileName = (char *) pUPortMalloc(U_CELL_FILE_NAME_MAX_LENGTH + 1);
U_PORT_TEST_ASSERT(pFileName != NULL);
// 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;
// Get the private module data as we need it for testing
pModule = pUCellPrivateGetModule(cellHandle);
U_PORT_TEST_ASSERT(pModule != NULL);
//lint -esym(613, pModule) Suppress possible use of NULL pointer
// for pModule from now on
// Do this twice if tags are supported
if (U_CELL_PRIVATE_HAS(pModule, U_CELL_PRIVATE_FEATURE_FILE_SYSTEM_TAG)) {
y = 2;
}
for (size_t x = 0; x < y; x++) {
if (x > 0) {
U_TEST_PRINT_LINE("repeating with tag...");
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, "USER") == 0);
} else {
U_PORT_TEST_ASSERT(pUCellFileGetTag(cellHandle) == NULL);
}
U_TEST_PRINT_LINE("listing all the files...");
found = false;
for (int32_t x = uCellFileListFirst(cellHandle, pFileName);
x >= 0;
x = uCellFileListNext(cellHandle, pFileName)) {
U_TEST_PRINT_LINE("\"%s\".", pFileName);
if (strcmp(pFileName, U_CELL_FILE_TEST_FILE_NAME) == 0) {
found = true;
}
}
if (x > 0) {
U_PORT_TEST_ASSERT(strcmp(pUCellFileGetTag(cellHandle), "USER") == 0);
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, NULL) == 0);
}
U_PORT_TEST_ASSERT(found);
}
uPortFree(pFileName);
// 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);
}
/** Test list all files, re-entrant version.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileListAllReentrant")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
int32_t result = U_CELL_FILE_TEST_REENTRANT_STRING_SIZE;
// Enough room for the test file name plus a single number
// plus a null terminator
size_t y = 0;
char buffer[U_CELL_FILE_TEST_FILE_NAME_LENGTH + 2];
char *pFileName;
void *pRentrantOuter;
bool trackerOuter[U_CELL_FILE_TEST_REENTRANT_NUM] = {0};
void *pRentrantInner;
bool trackerInner[U_CELL_FILE_TEST_REENTRANT_NUM];
pFileName = (char *) pUPortMalloc(U_CELL_FILE_NAME_MAX_LENGTH + 1);
U_PORT_TEST_ASSERT(pFileName != NULL);
// 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;
// Write the files we need to list
for (size_t x = 0; (x < U_CELL_FILE_TEST_REENTRANT_NUM) &&
(result == U_CELL_FILE_TEST_REENTRANT_STRING_SIZE); x++) {
snprintf(buffer, sizeof(buffer), "%s%1d", U_CELL_FILE_TEST_FILE_NAME, (int) x);
U_TEST_PRINT_LINE("writing file %s...", buffer);
result = uCellFileWrite(cellHandle, buffer,
U_CELL_FILE_TEST_REENTRANT_STRING,
U_CELL_FILE_TEST_REENTRANT_STRING_SIZE);
}
U_PORT_TEST_ASSERT(result == U_CELL_FILE_TEST_REENTRANT_STRING_SIZE);
// List the files in two loops, one within the other, making sure
// that all files are listed in both loops on each run
U_TEST_PRINT_LINE("listing the files...");
for (int32_t x = uCellFileListFirst_r(cellHandle, pFileName, &pRentrantOuter);
x >= 0;
x = uCellFileListNext_r(pFileName, &pRentrantOuter), y++) {
U_TEST_PRINT_LINE("outer loop: \"%s\".", pFileName);
updateTracker(pFileName, trackerOuter, sizeof(trackerOuter) / sizeof(trackerOuter[0]));
memset(trackerInner, 0, sizeof(trackerInner));
for (int32_t y = uCellFileListFirst_r(cellHandle, pFileName, &pRentrantInner);
y >= 0;
y = uCellFileListNext_r(pFileName, &pRentrantInner)) {
U_TEST_PRINT_LINE("inner loop: \"%s\".", pFileName);
updateTracker(pFileName, trackerInner, sizeof(trackerInner) / sizeof(trackerInner[0]));
}
U_PORT_TEST_ASSERT(checkTracker(trackerInner, sizeof(trackerInner) / sizeof(trackerInner[0])));
uCellFileListLast_r(&pRentrantInner);
U_TEST_PRINT_LINE("inner loop, all files listed on run %d.", y + 1);
}
U_PORT_TEST_ASSERT(checkTracker(trackerOuter, sizeof(trackerOuter) / sizeof(trackerOuter[0])));
uCellFileListLast_r(&pRentrantOuter);
U_TEST_PRINT_LINE("outer loop, all files listed.");
// Delete the files again, for tidiness
for (size_t x = 0; x < U_CELL_FILE_TEST_REENTRANT_NUM; x++) {
snprintf(buffer, sizeof(buffer), "%s%1d", U_CELL_FILE_TEST_FILE_NAME, (int) x);
U_TEST_PRINT_LINE("deleting file %s...", buffer);
U_PORT_TEST_ASSERT(uCellFileDelete(cellHandle, buffer) == 0);
}
uPortFree(pFileName);
// 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);
}
/** Test deleting file.
*/
U_PORT_TEST_FUNCTION("[cellFile]", "cellFileDelete")
{
int32_t resourceCount;
uDeviceHandle_t cellHandle;
const uCellPrivateModule_t *pModule;
size_t y = 1;
// 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;
// Get the private module data as we need it for testing
pModule = pUCellPrivateGetModule(cellHandle);
U_PORT_TEST_ASSERT(pModule != NULL);
//lint -esym(613, pModule) Suppress possible use of NULL pointer
// for pModule from now on
// Do this twice if tags are supported
if (U_CELL_PRIVATE_HAS(pModule, U_CELL_PRIVATE_FEATURE_FILE_SYSTEM_TAG)) {
y = 2;
}
for (size_t x = 0; x < y; x++) {
if (x > 0) {
U_TEST_PRINT_LINE("repeating with tag...");
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, "USER") == 0);
} else {
U_PORT_TEST_ASSERT(pUCellFileGetTag(cellHandle) == NULL);
}
U_TEST_PRINT_LINE("deleting file...");
U_PORT_TEST_ASSERT(uCellFileDelete(cellHandle, U_CELL_FILE_TEST_FILE_NAME) == 0);
if (x > 0) {
U_PORT_TEST_ASSERT(strcmp(pUCellFileGetTag(cellHandle), "USER") == 0);
U_PORT_TEST_ASSERT(uCellFileSetTag(cellHandle, NULL) == 0);
} else {
if (y > 1) {
// Re-create the file so that we can delete it again
U_TEST_PRINT_LINE("re-writing file...");
U_PORT_TEST_ASSERT(uCellFileWrite(cellHandle,
U_CELL_FILE_TEST_FILE_NAME,
"some text", 9) == 9);
}
}
}
// 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("[cellFile]", "cellFileCleanUp")
{
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