@@ -384,17 +384,15 @@ void test_fprintf_fscanf()
384
384
385
385
/* * Test fseek and ftell
386
386
*
387
- * Given already opened file is empty
388
- *
389
- * When set the file position indicator via fseek
390
- * Then underneath retargeting layer seek function is called
391
- * fseek return with succeed and ftell return already set position
387
+ * ARM library is quite good at optimising out unnecessary calls to underlying
388
+ * seek, so only test real non empty files.
392
389
*
393
390
* Given already opened file is not empty
394
391
*
395
392
* When set the file position indicator via fseek
396
393
* Then underneath retargeting layer seek function is called
397
394
* fseek return with succeed and ftell return already set position
395
+ * Check actual character read or written.
398
396
*
399
397
*/
400
398
void test_fseek_ftell ()
@@ -413,19 +411,6 @@ void test_fseek_ftell()
413
411
ftell_ret = std::ftell (file);
414
412
TEST_ASSERT_EQUAL (0 , ftell_ret);
415
413
416
- TestFile<FS>::resetFunctionCallHistory ();
417
- fssek_ret = std::fseek (file, 0 , SEEK_CUR);
418
- TEST_ASSERT_EQUAL (0 , fssek_ret);
419
-
420
- TestFile<FS>::resetFunctionCallHistory ();
421
- fssek_ret = std::fseek (file, 0 , SEEK_SET);
422
- TEST_ASSERT_EQUAL (0 , fssek_ret);
423
-
424
- TestFile<FS>::resetFunctionCallHistory ();
425
- fssek_ret = std::fseek (file, 0 , SEEK_END);
426
- TEST_ASSERT_TRUE (TestFile<FS>::functionCalled (TestFile<FS>::fnSeek));
427
- TEST_ASSERT_EQUAL (0 , fssek_ret);
428
-
429
414
const char *str = " Hello world" ;
430
415
const std::size_t size = std::strlen (str);
431
416
@@ -440,19 +425,28 @@ void test_fseek_ftell()
440
425
TEST_ASSERT_EQUAL (0 , fssek_ret);
441
426
ftell_ret = std::ftell (file);
442
427
TEST_ASSERT_EQUAL (5 , ftell_ret);
428
+ int c = std::fgetc (file);
429
+ TEST_ASSERT_TRUE (TestFile<FS>::functionCalled (TestFile<FS>::fnRead));
430
+ TEST_ASSERT_EQUAL (c, str[5 ]);
443
431
444
432
TestFile<FS>::resetFunctionCallHistory ();
445
- fssek_ret = std::fseek (file, -5 , SEEK_CUR);
433
+ fssek_ret = std::fseek (file, -6 , SEEK_CUR);
446
434
TEST_ASSERT_EQUAL (0 , fssek_ret);
447
435
ftell_ret = std::ftell (file);
448
436
TEST_ASSERT_EQUAL (0 , ftell_ret);
437
+ c = std::fgetc (file);
438
+ TEST_ASSERT_TRUE (TestFile<FS>::functionCalled (TestFile<FS>::fnRead));
439
+ TEST_ASSERT_EQUAL (c, str[0 ]);
449
440
450
441
TestFile<FS>::resetFunctionCallHistory ();
451
442
fssek_ret = std::fseek (file, 0 , SEEK_END);
452
- TEST_ASSERT_TRUE (TestFile<FS>::functionCalled (TestFile<FS>::fnSeek));
453
443
TEST_ASSERT_EQUAL (0 , fssek_ret);
454
444
ftell_ret = std::ftell (file);
455
445
TEST_ASSERT_EQUAL (size, ftell_ret);
446
+ c = std::fputc (' !' , file);
447
+ TEST_ASSERT_TRUE (TestFile<FS>::functionCalled (TestFile<FS>::fnWrite));
448
+ TEST_ASSERT_EQUAL (c, ' !' );
449
+ TEST_ASSERT_EQUAL (fh.size (), size + 1 );
456
450
457
451
std::fclose (file);
458
452
}
0 commit comments