check against the correct class. cast the value to bool before setting.
[AROS.git] / test / clib / fseek_test.c
blob3d0a0d3753ccdfb3da3417a998d9effc90acbf55
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <errno.h>
10 #define SHOW_PROGRESS 0
12 // Global variables
13 int global_test_counter = 0;
14 int global_test_step_counter = 0;
15 int global_failure_indicator = 0;
17 FILE * testfilepointer = NULL;
18 size_t buffersize = 1024;
19 char writedata[1024] = {0};
20 char * testfilename = "fseek_test_file";
22 void reset_global_test_counter()
24 global_test_counter = 0;
25 global_test_step_counter = 0;
28 void next_test()
30 global_test_counter++;
31 global_test_step_counter = 0;
34 void next_test_step()
36 global_test_step_counter++;
39 // Reporting functions
40 void report(const char * status, const char * message)
42 printf("REPORT : %s : %s \n", status, message);
45 void report_progress(const char * message)
47 report("PROGRESS", message);
50 void report_failure(const char * message)
52 report("FAILED", message);
55 void report_failure_strerror()
57 report_failure((const char*)strerror(errno));
60 void test_report(const char * status, const char * message)
62 printf("TEST %d-%d : %s : %s \n", global_test_counter , global_test_step_counter, status, message);
65 void test_report_progress(const char * message)
67 #if SHOW_PROGRESS == 1
68 test_report("PROGRESS", message);
69 #endif
72 void test_report_failure(const char * message)
74 test_report("FAILED", message);
77 void test_report_success(const char * message)
79 test_report("OK", message);
82 void test_report_description(const char * message)
84 test_report("TEST DESCRIPTION", message);
87 void test_report_failure_strerror()
89 test_report_failure((const char*)strerror(errno));
92 void erase_buffer(char * buffer, size_t size)
94 memset(buffer, 0, size);
97 int compare_buffers(const char * buffer1, const char * buffer2, size_t bufferssize)
99 return memcmp(buffer1, buffer2, bufferssize);
102 void close_test_file()
104 if (testfilepointer != NULL)
106 if (fclose(testfilepointer) != 0)
108 report_failure_strerror();
109 report_failure("Failed to close the file.");
110 return;
112 testfilepointer = NULL;
116 // Tests
117 int test_fseek_ftell_preparation(const char * fopenflags)
119 size_t operationsize = 0;
121 report_progress("Starting test_fseek_ftell_preparation");
122 report_progress(fopenflags);
124 if (testfilepointer != NULL)
126 report_failure("Pointer for test file not closed.");
127 return -1;
130 // zero buffer
131 erase_buffer(writedata, buffersize);
133 // open file, write data
134 testfilepointer = fopen(testfilename, fopenflags);
135 if (testfilepointer == NULL)
137 report_failure_strerror();
138 report_failure("Failed to open file for writting.");
139 return -1;
141 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
142 if (operationsize != buffersize)
144 report_failure_strerror();
145 report_failure("Failed to write data.");
146 return -1;
149 // Seek to beginning
150 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
152 report_failure_strerror();
153 report_failure("Failed to seek to file beginning.");
154 return -1;
157 return 0;
161 int test_fseek_ftell()
164 /* Expects that testfilepointer is opened in correct mode */
165 int ftellposition = 0;
166 char conv[16] = {0};
168 report_progress("Start test_fseek_ftell");
171 * TEST
174 next_test_step();
176 test_report_description("seek to begin, tell location");
178 // seek to begin, tell location
179 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
181 test_report_failure_strerror();
182 test_report_failure("Failed to seek to beginning of file");
183 return -1;
185 test_report_progress("Seek to beginning of file.");
186 ftellposition = ftell(testfilepointer);
187 if (ftellposition == -1)
189 test_report_failure_strerror();
190 test_report_failure("Failed to tell position");
191 return -1;
193 else
194 if (ftellposition != 0)
196 test_report_failure("Wrong position in stream reported");
197 sprintf(conv, "%d", ftellposition);
198 test_report_failure(conv);
199 return -1;
201 test_report_success("Correct position in stream reported");
202 test_report_success("SUCCESS");
205 * TEST END
209 * TEST
212 next_test_step();
214 test_report_description("seek foreward, tell location");
216 // seek to begin, tell location
217 if (fseek(testfilepointer, 153, SEEK_CUR) != 0)
219 test_report_failure_strerror();
220 test_report_failure("Failed to seek foreward");
221 return -1;
223 test_report_progress("Seek foreward made.");
224 ftellposition = ftell(testfilepointer);
225 if (ftellposition == -1)
227 test_report_failure_strerror();
228 test_report_failure("Failed to tell position");
229 return -1;
231 else
232 if (ftellposition != 153)
234 test_report_failure("Wrong position in stream reported");
235 sprintf(conv, "%d", ftellposition);
236 test_report_failure(conv);
237 return -1;
239 test_report_success("Correct position in stream reported");
240 test_report_success("SUCCESS");
243 * TEST END
247 * TEST
250 next_test_step();
252 test_report_description("seek backwards, tell location");
254 // seek backwards, tell location
255 if (fseek(testfilepointer, -80, SEEK_CUR) != 0)
257 test_report_failure_strerror();
258 test_report_failure("Failed to seek backwards");
259 return -1;
261 test_report_progress("Seek backwards made.");
262 ftellposition = ftell(testfilepointer);
263 if (ftellposition == -1)
265 test_report_failure_strerror();
266 test_report_failure("Failed to tell position");
267 return -1;
269 else
270 if (ftellposition != (153-80))
272 test_report_failure("Wrong position in stream reported");
273 sprintf(conv, "%d", ftellposition);
274 test_report_failure(conv);
275 return -1;
277 test_report_success("Correct position in stream reported");
278 test_report_success("SUCCESS");
281 * TEST END
285 * TEST
288 next_test_step();
290 test_report_description("seek to the end, tell location");
292 // seek to begin, tell location
293 if (fseek(testfilepointer, 0, SEEK_END) != 0)
295 test_report_failure_strerror();
296 test_report_failure("Failed to seek to end of file");
297 return -1;
299 test_report_progress("Seek to end of file made.");
300 ftellposition = ftell(testfilepointer);
301 if (ftellposition == -1)
303 test_report_failure_strerror();
304 test_report_failure("Failed to tell position");
305 return -1;
307 else
308 if (ftellposition != buffersize)
310 test_report_failure("Wrong position in stream reported");
311 sprintf(conv, "%d", ftellposition);
312 test_report_failure(conv);
313 return -1;
315 test_report_success("Correct position in stream reported");
316 test_report_success("SUCCESS");
319 * TEST END
323 * TEST
326 next_test_step();
328 test_report_description("seek foreward(beyond file), tell location");
330 // seek foreward(beyond file), tell location
331 if (fseek(testfilepointer, 120, SEEK_CUR) != 0)
333 test_report_failure_strerror();
334 test_report_failure("Failed to seek beyond file end");
335 return -1;
337 test_report_progress("Seek beyond file end made.");
338 ftellposition = ftell(testfilepointer);
339 if (ftellposition == -1)
341 test_report_failure_strerror();
342 test_report_failure("Failed to tell position");
343 return -1;
345 else
346 if (ftellposition != buffersize + 120)
348 test_report_failure("Wrong position in stream reported");
349 sprintf(conv, "%d", ftellposition);
350 test_report_failure(conv);
351 return -1;
353 test_report_success("Correct position in stream reported");
354 test_report_success("SUCCESS");
357 * TEST END
361 * TEST
364 next_test_step();
366 test_report_description("seek backwards, tell location");
368 // seek backwards, tell location
369 if (fseek(testfilepointer, -240, SEEK_CUR) != 0)
371 test_report_failure_strerror();
372 test_report_failure("Failed to seek backwards");
373 return -1;
375 test_report_progress("Seek backwards made.");
376 ftellposition = ftell(testfilepointer);
377 if (ftellposition == -1)
379 test_report_failure_strerror();
380 test_report_failure("Failed to tell position");
381 return -1;
383 else
384 if (ftellposition != buffersize - 120)
386 test_report_failure("Wrong position in stream reported");
387 sprintf(conv, "%d", ftellposition);
388 test_report_failure(conv);
389 return -1;
391 test_report_success("Correct position in stream reported");
392 test_report_success("SUCCESS");
395 * TEST END
399 * TEST
402 next_test_step();
404 test_report_description("seek to end with positive offset, tell location");
406 // seek to end with positive offset, tell location
407 if (fseek(testfilepointer, 120, SEEK_END) != 0)
409 test_report_failure_strerror();
410 test_report_failure("Failed to seek to end with positive offset");
411 return -1;
413 test_report_progress("Seek to end with positive offset made.");
414 ftellposition = ftell(testfilepointer);
415 if (ftellposition == -1)
417 test_report_failure_strerror();
418 test_report_failure("Failed to tell position");
419 return -1;
421 else
422 if (ftellposition != buffersize + 120)
424 test_report_failure("Wrong position in stream reported");
425 sprintf(conv, "%d", ftellposition);
426 test_report_failure(conv);
427 return -1;
429 test_report_success("Correct position in stream reported");
430 test_report_success("SUCCESS");
433 * TEST END
436 return 0;
439 int test_fseek_ftell_wrapper(const char * fopenflags)
441 next_test();
443 int result = test_fseek_ftell_preparation(fopenflags);
444 if (result != 0)
446 report_failure("Preparation failed");
448 else
449 result = test_fseek_ftell();
451 close_test_file();
453 return result;
474 int test_fseek_and_fread_preparation(const char * fopenflags)
476 char readdatabuffer1[1024] = {0};
477 int i = 0;
478 size_t operationsize = 0;
480 report_progress("Starting test_fseek_and_fread_preparation");
481 report_progress(fopenflags);
483 if (testfilepointer != NULL)
485 report_failure("Pointer for test file not closed.");
486 return -1;
489 // initialize with random data (always the same because of const seed)
490 srand(1);
491 for(i = 0; i < buffersize; i++)
492 writedata[i] = (char)rand();
494 // open file, write data, close file
495 testfilepointer = fopen(testfilename, "wb+");
496 if (testfilepointer == NULL)
498 report_failure_strerror();
499 report_failure("Failed to open file for writting.");
500 return -1;
502 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
503 if (operationsize != buffersize)
505 report_failure_strerror();
506 report_failure("Failed to write data.");
507 return -1;
510 if ((strcmp(fopenflags, "w+b") == 0) ||
511 (strcmp(fopenflags, "wb+") == 0))
513 // Seek to beginning
514 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
516 report_failure_strerror();
517 report_failure("Failed to seek to file beginning (w+b).");
518 return -1;
521 else
524 if (fclose(testfilepointer) != 0)
526 report_failure_strerror();
527 report_failure("Failed to close file.");
528 return -1;
531 // open file
532 testfilepointer = fopen(testfilename, "rb");
533 if (testfilepointer == NULL)
535 report_failure_strerror();
536 report_failure("Failed to open file for reading.");
537 return -1;
541 //read data, compare data, close file
542 erase_buffer(readdatabuffer1, buffersize);
543 operationsize = fread(readdatabuffer1, 1, buffersize, testfilepointer);
544 if (operationsize != buffersize)
546 report_failure_strerror();
547 report_failure("Failed to read data.");
548 return -1;
550 if (compare_buffers(readdatabuffer1, writedata, buffersize) != 0)
552 report_failure("Read data differs from written data");
553 return -1;
556 if ((strcmp(fopenflags, "w+b") == 0) ||
557 (strcmp(fopenflags, "wb+") == 0))
559 // Seek to beginning
560 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
562 report_failure_strerror();
563 report_failure("Failed to seek to file beginning (w+b).");
564 return -1;
567 else
569 // Close file and open it with new flags
570 if (fclose(testfilepointer) != 0)
572 report_failure_strerror();
573 report_failure("Failed to close file.");
574 return -1;
577 testfilepointer = fopen(testfilename, fopenflags);
578 if (testfilepointer == NULL)
580 report_failure_strerror();
581 report_failure("Failed to open file for seek testing.");
582 return -1;
586 return 0;
590 int test_fseek_and_fread()
593 /* Expects that testfilepointer is opened in correct mode */
594 size_t chunksize = 128;
595 char readdatabuffer1[1024] = {0};
596 int i = 0;
597 size_t operationsize = 0;
600 * TEST
603 report_progress("Start test_fseek_and_fread");
605 next_test_step();
607 test_report_description("seek to begin, read some data , check data");
609 // seek to begin, read some data, check data
610 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
612 test_report_failure_strerror();
613 test_report_failure("Failed to seek to beginning of file");
614 return -1;
616 test_report_progress("Seek to beginning of file.");
617 erase_buffer(readdatabuffer1, buffersize);
618 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
619 if (operationsize != chunksize)
621 test_report_failure_strerror();
622 test_report_failure("Failed to read chunk of data.");
623 return -1;
625 test_report_progress("Chunk read.");
626 if (compare_buffers(readdatabuffer1, writedata, chunksize) != 0)
628 test_report_failure("Read data does not match written data");
629 return -1;
631 test_report_success("Read data match written data.");
632 test_report_success("SUCCESS");
635 * TEST END
640 * TEST
643 next_test_step();
645 test_report_description("make absolute seek, read some data , check data");
647 // make absolute seek, read some data, check data
648 if (fseek(testfilepointer, 350, SEEK_SET) != 0)
650 test_report_failure_strerror();
651 test_report_failure("Failed to make absolute seek");
652 return -1;
654 test_report_progress("Absolute seek made.");
655 erase_buffer(readdatabuffer1, buffersize);
656 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
657 if (operationsize != chunksize)
659 test_report_failure_strerror();
660 test_report_failure("Failed to read chunk of data.");
661 return -1;
663 test_report_progress("Chunk read.");
664 if (compare_buffers(readdatabuffer1, writedata + 350, chunksize) != 0)
666 test_report_failure("Read data does not match written data");
667 return -1;
669 test_report_success("Read data match written data.");
670 test_report_success("SUCCESS");
673 * TEST END
678 * TEST
681 next_test_step();
683 test_report_description("make relative seek backwards, read some data , check data");
684 // make relative seek backwards, read some data, check data
685 if (fseek(testfilepointer, - (120 + chunksize), SEEK_CUR) != 0)
687 test_report_failure_strerror();
688 test_report_failure("Failed to make relative seek");
689 return -1;
691 test_report_progress("Relative seek made.");
692 erase_buffer(readdatabuffer1, buffersize);
693 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
694 if (operationsize != chunksize)
696 test_report_failure_strerror();
697 test_report_failure("Failed to read chunk of data.");
698 return -1;
700 test_report_progress("Chunk read.");
701 if (compare_buffers(readdatabuffer1, writedata + (350 - 120), chunksize) != 0)
703 test_report_failure("Read data does not match written data");
704 return -1;
706 test_report_success("Read data match written data.");
707 test_report_success("SUCCESS");
710 * TEST END
715 * TEST
718 next_test_step();
720 test_report_description("make relative seek forewards, read some data , check data");
721 // make relative seek forewards, read some data, check data
722 if (fseek(testfilepointer, 138, SEEK_CUR) != 0)
724 test_report_failure_strerror();
725 test_report_failure("Failed to make relative seek");
726 return -1;
728 test_report_progress("Relative seek made.");
729 erase_buffer(readdatabuffer1, buffersize);
730 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
731 if (operationsize != chunksize)
733 test_report_failure_strerror();
734 test_report_failure("Failed to read chunk of data.");
735 return -1;
737 test_report_progress("Chunk read.");
738 if (compare_buffers(readdatabuffer1, writedata + (350 - 120 + chunksize + 138), chunksize) != 0)
740 test_report_failure("Read data does not match written data");
741 return -1;
743 test_report_success("Read data match written data.");
744 test_report_success("SUCCESS");
748 * TEST END
753 * TEST
756 next_test_step();
758 test_report_description("seek to end, make relative seek backwards, read some data , check data");
759 // seek to end, make relative seek backwards, read some data, check data
760 if (fseek(testfilepointer, 0, SEEK_END) != 0)
762 test_report_failure_strerror();
763 test_report_failure("Failed to seek to end");
764 return -1;
766 test_report_progress("Seek to end made");
767 if (fseek(testfilepointer, -210, SEEK_CUR) != 0)
769 test_report_failure_strerror();
770 test_report_failure("Failed to make relative seek");
771 return -1;
773 test_report_progress("Relative seek made.");
774 erase_buffer(readdatabuffer1, buffersize);
775 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
776 if (operationsize != chunksize)
778 test_report_failure_strerror();
779 test_report_failure("Failed to read chunk of data.");
780 return -1;
782 test_report_progress("Chunk read.");
783 if (compare_buffers(readdatabuffer1, writedata + buffersize - 210, chunksize) != 0)
785 test_report_failure("Read data does not match written data");
786 return -1;
788 test_report_success("Read data match written data.");
789 test_report_success("SUCCESS");
792 * TEST END
797 * TEST
800 next_test_step();
802 test_report_description("read some data (more than is in file) , check error code data");
803 // read some data (more than is in file) , check error code data
804 erase_buffer(readdatabuffer1, buffersize);
805 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
806 if (operationsize != chunksize)
808 if (errno != 0/*rb*/ && errno != EINVAL/*a+b, w+b, r+b*/)
810 test_report_failure_strerror();
811 test_report_failure("Error different than expected reported");
812 return -1;
815 else
817 test_report_failure("Number of read data should be different than requested data");
818 return -1;
820 test_report_success("Error reported");
821 test_report_success("SUCCESS");
824 * TEST END
829 * TEST
832 next_test_step();
834 test_report_description("seek to beginning, seek forewards, seek backwards beyond file start, check error code");
835 // seek to beginning, seek forewards, seek backwards beyond file start, check error code
836 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
838 test_report_failure_strerror();
839 test_report_failure("Failed to seek to beginning");
840 return -1;
842 test_report_progress("Seek to beginning made.");
843 if (fseek(testfilepointer, 99, SEEK_CUR) != 0)
845 test_report_failure_strerror();
846 test_report_failure("Failed to make relative seek forewards");
847 return -1;
849 test_report_progress("Relative seek forewards made.");
850 if (fseek(testfilepointer, -150, SEEK_CUR) != 0)
852 if (errno != EINVAL)
854 test_report_failure_strerror();
855 test_report_failure("Error different than expected reported");
856 return -1;
859 else
861 test_report_progress("Should not made relative seek backwards beyond file start.");
862 return -1;
864 test_report_success("Error reported");
865 test_report_success("SUCCESS");
868 * TEST END
873 * TEST
876 next_test_step();
878 test_report_description("seek to end, seek forewards, read some data, check error code");
879 // seek to end, seek forewards, read some data, check error code
880 if (fseek(testfilepointer, 0, SEEK_END) != 0)
882 test_report_failure_strerror();
883 test_report_failure("Failed to seek to end");
884 return -1;
886 test_report_progress("Seek to end made.");
887 if (fseek(testfilepointer, 99, SEEK_CUR) != 0)
889 test_report_failure_strerror();
890 test_report_failure("Failed to make relative seek forewards");
891 return -1;
893 test_report_progress("Relative seek forewards made.");
894 erase_buffer(readdatabuffer1, buffersize);
895 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
896 if (operationsize != chunksize)
898 if (errno != EINVAL)
900 test_report_failure_strerror();
901 test_report_failure("Error different than expected reported");
902 return -1;
905 else
907 test_report_failure("Number of read data should be different than requested data");
908 return -1;
910 test_report_success("Error reported");
911 test_report_success("SUCCESS");
914 * TEST END
919 * TEST
922 next_test_step();
924 test_report_description("seek to end with offset, read some data, check error code");
925 // seek to end with offset, read some data, check error code
926 if (fseek(testfilepointer, 100, SEEK_END) != 0)
928 test_report_failure_strerror();
929 test_report_failure("Failed to seek to end with offset");
930 return -1;
932 test_report_progress("Seek to end with offset made.");
933 erase_buffer(readdatabuffer1, buffersize);
934 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
935 if (operationsize != chunksize)
937 if (errno != EINVAL)
939 test_report_failure_strerror();
940 test_report_failure("Error different than expected reported");
941 return -1;
944 else
946 test_report_failure("Number of read data should be different than requested data");
947 return -1;
949 test_report_success("Error reported");
950 test_report_success("SUCCESS");
951 return 0;
954 int test_fseek_and_fread_wrapper(const char * fopenflags)
956 next_test();
958 int result = test_fseek_and_fread_preparation(fopenflags);
959 if (result != 0)
961 report_failure("Preparation failed");
963 else
964 result = test_fseek_and_fread();
966 close_test_file();
968 return result;
971 int test_fseek_fwrite_fread_preparation()
973 char readdatabuffer1[1024] = {0};
974 int i = 0;
975 size_t operationsize = 0;
977 report_progress("Starting test_fseek_fwrite_fread_preparation");
979 if (testfilepointer != NULL)
981 report_failure("Pointer for test file not closed.");
982 return -1;
985 // Initilize random write buffer
986 srand(1);
987 for (i = 0; i < buffersize; i++)
988 writedata[i] = (char)rand();
990 // open file, write data
991 testfilepointer = fopen(testfilename, "wb+");
992 if (testfilepointer == NULL)
994 report_failure_strerror();
995 report_failure("Failed to open file for writting.");
996 return -1;
998 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
999 if (operationsize != buffersize)
1001 report_failure_strerror();
1002 report_failure("Failed to write data.");
1003 return -1;
1006 // Seek to beginning
1007 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1009 report_failure_strerror();
1010 report_failure("Failed to seek to file beginning (w+b).");
1011 return -1;
1014 //read data, compare data
1015 erase_buffer(readdatabuffer1, buffersize);
1016 operationsize = fread(readdatabuffer1, 1, buffersize, testfilepointer);
1017 if (operationsize != buffersize)
1019 report_failure_strerror();
1020 report_failure("Failed to read data.");
1021 return -1;
1023 if (compare_buffers(readdatabuffer1, writedata, buffersize) != 0)
1025 report_failure("Read data differs from written data");
1026 return -1;
1029 // Seek to beginning
1030 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1032 report_failure_strerror();
1033 report_failure("Failed to seek to file beginning (w+b).");
1034 return -1;
1037 return 0;
1041 int test_fseek_fwrite_fread()
1043 /* Expects that testfilepointer is opened in correct mode */
1044 char randomwritebuffer[1024] = {0};
1045 size_t chunksize = 128;
1046 char readdatabuffer1[1024] = {0};
1047 char zerobuffer[1024] = {0};
1048 int i = 0;
1049 size_t operationsize = 0;
1051 // Initilize random write buffer
1052 // Don't initialize srand or randomwritebuffer == writedata
1053 for (i = 0; i < buffersize; i++)
1054 randomwritebuffer[i] = (char)rand();
1057 * TEST
1060 report_progress("Start test_fseek_fwrite_fread");
1062 next_test_step();
1064 test_report_description("seek to begin, write some data , seek to begin, read 2x some data, check data");
1066 // seek to begin, write some data , seek to begin, read 2x some data, check data
1067 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1069 test_report_failure_strerror();
1070 test_report_failure("Failed to seek to beginning of file");
1071 return -1;
1073 test_report_progress("Seek to beginning of file.");
1074 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1075 if (operationsize != chunksize)
1077 test_report_failure_strerror();
1078 test_report_failure("Failed to write chunk of data.");
1079 return -1;
1081 test_report_progress("Chunk written.");
1082 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1084 test_report_failure_strerror();
1085 test_report_failure("Failed to seek to beginning of file");
1086 return -1;
1088 test_report_progress("Seek to beginning of file.");
1089 erase_buffer(readdatabuffer1, buffersize);
1090 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1091 if (operationsize != 2 * chunksize)
1093 test_report_failure_strerror();
1094 test_report_failure("Failed to read chunk of data.");
1095 return -1;
1097 test_report_progress("Chunk read.");
1098 if (compare_buffers(readdatabuffer1, randomwritebuffer, chunksize) != 0)
1100 test_report_failure("Read data does not match written data for first chunk");
1101 return -1;
1103 test_report_success("Read data match written data for first chunk.");
1104 if (compare_buffers(readdatabuffer1 + chunksize, writedata + chunksize, chunksize) != 0)
1106 test_report_failure("Read data does not match written data for second chunk");
1107 return -1;
1109 test_report_success("Read data match written data for second chunk.");
1110 test_report_success("SUCCESS");
1113 * TEST END
1117 * TEST
1120 next_test_step();
1122 test_report_description("seek foreward, write some data , seek backward, read data, check data");
1124 // seek foreward, write some data , seek backward, read data, check data
1125 if (fseek(testfilepointer, 3 * chunksize, SEEK_CUR) != 0)
1127 test_report_failure_strerror();
1128 test_report_failure("Failed to seek foreward");
1129 return -1;
1131 test_report_progress("Seek foreward made.");
1132 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1133 if (operationsize != chunksize)
1135 test_report_failure_strerror();
1136 test_report_failure("Failed to write chunk of data.");
1137 return -1;
1139 test_report_progress("Chunk written.");
1140 if (fseek(testfilepointer, - chunksize, SEEK_CUR) != 0)
1142 test_report_failure_strerror();
1143 test_report_failure("Failed to seek backwards");
1144 return -1;
1146 test_report_progress("Seek backwards made.");
1147 erase_buffer(readdatabuffer1, buffersize);
1148 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1149 if (operationsize != chunksize)
1151 test_report_failure_strerror();
1152 test_report_failure("Failed to read chunk of data.");
1153 return -1;
1155 test_report_progress("Chunk read.");
1156 if (compare_buffers(readdatabuffer1, randomwritebuffer, chunksize) != 0)
1158 test_report_failure("Read data does not match written");
1159 return -1;
1161 test_report_success("Read data match written data.");
1162 test_report_success("SUCCESS");
1165 * TEST END
1169 * TEST
1172 next_test_step();
1174 test_report_description("seek backward, write some data , seek backward, read 2 x data, check data");
1176 // seek backward, write some data , seek backward, read 2 x data, check data
1177 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1179 test_report_failure_strerror();
1180 test_report_failure("Failed to seek backwards");
1181 return -1;
1183 test_report_progress("Seek backwards made.");
1184 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1185 if (operationsize != chunksize)
1187 test_report_failure_strerror();
1188 test_report_failure("Failed to write chunk of data.");
1189 return -1;
1191 test_report_progress("Chunk written.");
1192 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1194 test_report_failure_strerror();
1195 test_report_failure("Failed to seek backwards");
1196 return -1;
1198 test_report_progress("Seek backwards made.");
1199 erase_buffer(readdatabuffer1, buffersize);
1200 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1201 if (operationsize != 2 * chunksize)
1203 test_report_failure_strerror();
1204 test_report_failure("Failed to read chunk of data.");
1205 return -1;
1207 test_report_progress("Chunk read.");
1208 if (compare_buffers(readdatabuffer1, randomwritebuffer + chunksize, chunksize) != 0)
1210 test_report_failure("Read data does not match written for first chunk");
1211 return -1;
1213 test_report_success("Read data match written data for first chunk.");
1214 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer, chunksize) != 0)
1216 test_report_failure("Read data does not match written for second chunk");
1217 return -1;
1219 test_report_success("Read data match written data for second chunk.");
1220 test_report_success("SUCCESS");
1223 * TEST END
1227 * TEST
1230 next_test_step();
1232 test_report_description("seek to end, write some data , seek backward, read data, check data");
1234 // seek to end, write some data , seek backward, read data, check data
1235 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1237 test_report_failure_strerror();
1238 test_report_failure("Failed to seek to end");
1239 return -1;
1241 test_report_progress("Seek to end of file made.");
1242 operationsize = fwrite(randomwritebuffer + 2 * chunksize, 1, chunksize, testfilepointer);
1243 if (operationsize != chunksize)
1245 test_report_failure_strerror();
1246 test_report_failure("Failed to write chunk of data.");
1247 return -1;
1249 test_report_progress("Chunk written.");
1250 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1252 test_report_failure_strerror();
1253 test_report_failure("Failed to seek backwards");
1254 return -1;
1256 test_report_progress("Seek backwards made.");
1257 erase_buffer(readdatabuffer1, buffersize);
1258 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1259 if (operationsize != chunksize)
1261 test_report_failure_strerror();
1262 test_report_failure("Failed to read chunk of data.");
1263 return -1;
1265 test_report_progress("Chunk read.");
1266 if (compare_buffers(readdatabuffer1, randomwritebuffer + 2 * chunksize, chunksize) != 0)
1268 test_report_failure("Read data does not match written data");
1269 return -1;
1271 test_report_success("Read data match written data.");
1272 test_report_success("SUCCESS");
1275 * TEST END
1279 * TEST
1282 next_test_step();
1284 test_report_description("seek to end, seek foreward, write some data , seek backward, read 2 x data, check data");
1286 // seek to end, seek foreward, write some data , seek backward, read 2 x data, check data
1287 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1289 test_report_failure_strerror();
1290 test_report_failure("Failed to seek to end");
1291 return -1;
1293 test_report_progress("Seek to end of file made.");
1294 if (fseek(testfilepointer, chunksize, SEEK_CUR) != 0)
1296 test_report_failure_strerror();
1297 test_report_failure("Failed to seek foreward");
1298 return -1;
1300 test_report_progress("Seek foreward made.");
1301 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1302 if (operationsize != chunksize)
1304 test_report_failure_strerror();
1305 test_report_failure("Failed to write chunk of data.");
1306 return -1;
1308 test_report_progress("Chunk written.");
1309 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1311 test_report_failure_strerror();
1312 test_report_failure("Failed to seek backwards");
1313 return -1;
1315 test_report_progress("Seek backwards made.");
1316 erase_buffer(readdatabuffer1, buffersize);
1317 erase_buffer(zerobuffer, buffersize);
1318 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1319 if (operationsize != 2 * chunksize)
1321 test_report_failure_strerror();
1322 test_report_failure("Failed to read chunk of data.");
1323 return -1;
1325 test_report_progress("Chunk read.");
1326 if (compare_buffers(readdatabuffer1, zerobuffer, chunksize) != 0)
1328 test_report_failure("Read data does not match written data for first chunk");
1329 return -1;
1331 test_report_success("Read data match written data for first chunk.");
1332 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer, chunksize) != 0)
1334 test_report_failure("Read data does not match written data for second chunk");
1335 return -1;
1337 test_report_success("Read data match written data for second chunk.");
1338 test_report_success("SUCCESS");
1341 * TEST END
1345 * TEST
1348 next_test_step();
1350 test_report_description("seek beoynd end, write some data , seek backward, read 2 x data, check data");
1352 // seek beoynd end, write some data , seek backward, read 2 x data, check data
1353 if (fseek(testfilepointer, chunksize, SEEK_END) != 0)
1355 test_report_failure_strerror();
1356 test_report_failure("Failed to seek beyond end of file");
1357 return -1;
1359 test_report_progress("Seek beyond end of file made.");
1360 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1361 if (operationsize != chunksize)
1363 test_report_failure_strerror();
1364 test_report_failure("Failed to write chunk of data.");
1365 return -1;
1367 test_report_progress("Chunk written.");
1368 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1370 test_report_failure_strerror();
1371 test_report_failure("Failed to seek backwards");
1372 return -1;
1374 test_report_progress("Seek backwards made.");
1375 erase_buffer(readdatabuffer1, buffersize);
1376 erase_buffer(zerobuffer, buffersize);
1377 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1378 if (operationsize != 2 * chunksize)
1380 test_report_failure_strerror();
1381 test_report_failure("Failed to read chunk of data.");
1382 return -1;
1384 test_report_progress("Chunk read.");
1385 if (compare_buffers(readdatabuffer1, zerobuffer, chunksize) != 0)
1387 test_report_failure("Read data does not match written data for first chunk");
1388 return -1;
1390 test_report_success("Read data match written data for first chunk.");
1391 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer + chunksize, chunksize) != 0)
1393 test_report_failure("Read data does not match written data for second chunk");
1394 return -1;
1396 test_report_success("Read data match written data for second chunk.");
1397 test_report_success("SUCCESS");
1400 * TEST END
1403 return 0;
1406 int test_fseek_fwrite_fread_wrapper()
1408 next_test();
1410 int result = test_fseek_fwrite_fread_preparation();
1411 if (result != 0)
1413 report_failure("Preparation failed");
1415 else
1416 result = test_fseek_fwrite_fread();
1418 close_test_file();
1420 return result;
1423 int test_fseek_fwrite_fread_append_preparation()
1425 char readdatabuffer1[1024] = {0};
1426 int i = 0;
1427 size_t operationsize = 0;
1429 report_progress("Starting test_fseek_fwrite_fread_append_preparation");
1431 if (testfilepointer != NULL)
1433 report_failure("Pointer for test file not closed.");
1434 return -1;
1437 // Initilize random write buffer
1438 srand(1);
1439 for (i = 0; i < buffersize; i++)
1440 writedata[i] = (char)rand();
1442 // open file, write data
1443 testfilepointer = fopen(testfilename, "wb+");
1444 if (testfilepointer == NULL)
1446 report_failure_strerror();
1447 report_failure("Failed to open file for writting.");
1448 return -1;
1450 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
1451 if (operationsize != buffersize)
1453 report_failure_strerror();
1454 report_failure("Failed to write data.");
1455 return -1;
1458 // Seek to beginning
1459 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1461 report_failure_strerror();
1462 report_failure("Failed to seek to file beginning (w+b).");
1463 return -1;
1466 //read data, compare data
1467 erase_buffer(readdatabuffer1, buffersize);
1468 operationsize = fread(readdatabuffer1, 1, buffersize, testfilepointer);
1469 if (operationsize != buffersize)
1471 report_failure_strerror();
1472 report_failure("Failed to read data.");
1473 return -1;
1475 if (compare_buffers(readdatabuffer1, writedata, buffersize) != 0)
1477 report_failure("Read data differs from written data");
1478 return -1;
1481 // close
1482 if (fclose(testfilepointer) != 0)
1484 report_failure_strerror();
1485 report_failure("Failed to close the file.");
1486 return;
1489 // open
1490 testfilepointer = fopen(testfilename, "ab+");
1491 if (testfilepointer == NULL)
1493 report_failure_strerror();
1494 report_failure("Failed to open file for appending.");
1495 return -1;
1498 return 0;
1502 int test_fseek_fwrite_fread_append()
1504 /* Expects that testfilepointer is opened in correct mode */
1505 char randomwritebuffer[1024] = {0};
1506 size_t chunksize = 128;
1507 char readdatabuffer1[1024] = {0};
1508 char zerobuffer[1024] = {0};
1509 int i = 0;
1510 size_t operationsize = 0;
1512 // Initilize random write buffer
1513 // Don't initialize srand or randomwritebuffer == writedata
1514 for (i = 0; i < buffersize; i++)
1515 randomwritebuffer[i] = (char)rand();
1518 * TEST
1521 report_progress("Start test_fseek_fwrite_fread_append");
1523 next_test_step();
1525 test_report_description("seek to begin, write some data , seek to begin, read 2x some data, check data");
1527 // seek to begin, write some data , seek to begin, read 2x some data, check data
1528 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1530 test_report_failure_strerror();
1531 test_report_failure("Failed to seek to beginning of file");
1532 return -1;
1534 test_report_progress("Seek to beginning of file.");
1535 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1536 if (operationsize != chunksize)
1538 test_report_failure_strerror();
1539 test_report_failure("Failed to write chunk of data.");
1540 return -1;
1542 test_report_progress("Chunk written.");
1543 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1545 test_report_failure_strerror();
1546 test_report_failure("Failed to seek to beginning of file");
1547 return -1;
1549 test_report_progress("Seek to beginning of file.");
1550 erase_buffer(readdatabuffer1, buffersize);
1551 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1552 if (operationsize != 2 * chunksize)
1554 test_report_failure_strerror();
1555 test_report_failure("Failed to read chunk of data.");
1556 return -1;
1558 test_report_progress("Chunk read.");
1559 if (compare_buffers(readdatabuffer1, writedata, chunksize) != 0)
1561 test_report_failure("Read data does not match written data for first chunk");
1562 return -1;
1564 test_report_success("Read data match written data for first chunk.");
1565 if (compare_buffers(readdatabuffer1 + chunksize, writedata + chunksize, chunksize) != 0)
1567 test_report_failure("Read data does not match written data for second chunk");
1568 return -1;
1570 test_report_success("Read data match written data for second chunk.");
1571 test_report_success("SUCCESS");
1574 * TEST END
1578 * TEST
1581 next_test_step();
1583 test_report_description("seek foreward, write some data , seek backward, read data, check data");
1585 // seek foreward, write some data , seek backward, read data, check data
1586 if (fseek(testfilepointer, 3 * chunksize, SEEK_CUR) != 0)
1588 test_report_failure_strerror();
1589 test_report_failure("Failed to seek foreward");
1590 return -1;
1592 test_report_progress("Seek foreward made.");
1593 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1594 if (operationsize != chunksize)
1596 test_report_failure_strerror();
1597 test_report_failure("Failed to write chunk of data.");
1598 return -1;
1600 test_report_progress("Chunk written.");
1601 if (fseek(testfilepointer, - chunksize, SEEK_CUR) != 0)
1603 test_report_failure_strerror();
1604 test_report_failure("Failed to seek backwards");
1605 return -1;
1607 test_report_progress("Seek backwards made.");
1608 erase_buffer(readdatabuffer1, buffersize);
1609 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1610 if (operationsize != chunksize)
1612 test_report_failure_strerror();
1613 test_report_failure("Failed to read chunk of data.");
1614 return -1;
1616 test_report_progress("Chunk read.");
1617 if (compare_buffers(readdatabuffer1, randomwritebuffer, chunksize) != 0)
1619 test_report_failure("Read data does not match written");
1620 return -1;
1622 test_report_success("Read data match written data.");
1623 test_report_success("SUCCESS");
1626 * TEST END
1630 * TEST
1633 next_test_step();
1635 test_report_description("seek backward, write some data , seek backward, read 2 x data, check error");
1637 // seek backward, write some data , seek backward, read 2 x data, check error
1638 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1640 test_report_failure_strerror();
1641 test_report_failure("Failed to seek backwards");
1642 return -1;
1644 test_report_progress("Seek backwards made.");
1645 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1646 if (operationsize != chunksize)
1648 test_report_failure_strerror();
1649 test_report_failure("Failed to write chunk of data.");
1650 return -1;
1652 test_report_progress("Chunk written.");
1653 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1655 test_report_failure_strerror();
1656 test_report_failure("Failed to seek backwards");
1657 return -1;
1659 test_report_progress("Seek backwards made.");
1660 erase_buffer(readdatabuffer1, buffersize);
1661 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1662 if (operationsize != 2 * chunksize)
1664 if (errno != EINVAL)
1666 test_report_failure_strerror();
1667 test_report_failure("Different than expected error reported.");
1668 return -1;
1671 else
1673 test_report_failure("Expected error");
1674 return -1;
1676 test_report_success("Error reported.");
1677 test_report_success("SUCCESS");
1680 * TEST END
1684 * TEST
1687 next_test_step();
1689 test_report_description("seek to end, write some data , seek backward, read data, check data");
1691 // seek to end, write some data , seek backward, read data, check data
1692 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1694 test_report_failure_strerror();
1695 test_report_failure("Failed to seek to end");
1696 return -1;
1698 test_report_progress("Seek to end of file made.");
1699 operationsize = fwrite(randomwritebuffer + 2 * chunksize, 1, chunksize, testfilepointer);
1700 if (operationsize != chunksize)
1702 test_report_failure_strerror();
1703 test_report_failure("Failed to write chunk of data.");
1704 return -1;
1706 test_report_progress("Chunk written.");
1707 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1709 test_report_failure_strerror();
1710 test_report_failure("Failed to seek backwards");
1711 return -1;
1713 test_report_progress("Seek backwards made.");
1714 erase_buffer(readdatabuffer1, buffersize);
1715 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1716 if (operationsize != chunksize)
1718 test_report_failure_strerror();
1719 test_report_failure("Failed to read chunk of data.");
1720 return -1;
1722 test_report_progress("Chunk read.");
1723 if (compare_buffers(readdatabuffer1, randomwritebuffer + 2 * chunksize, chunksize) != 0)
1725 test_report_failure("Read data does not match written data");
1726 return -1;
1728 test_report_success("Read data match written data.");
1729 test_report_success("SUCCESS");
1732 * TEST END
1736 * TEST
1739 next_test_step();
1741 test_report_description("seek to end, seek foreward, write some data , seek backward, read 2 x data, check data");
1743 // seek to end, seek foreward, write some data , seek backward, read 2 x data, check data
1744 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1746 test_report_failure_strerror();
1747 test_report_failure("Failed to seek to end");
1748 return -1;
1750 test_report_progress("Seek to end of file made.");
1751 if (fseek(testfilepointer, chunksize, SEEK_CUR) != 0)
1753 test_report_failure_strerror();
1754 test_report_failure("Failed to seek foreward");
1755 return -1;
1757 test_report_progress("Seek foreward made.");
1758 operationsize = fwrite(randomwritebuffer + 3 * chunksize, 1, chunksize, testfilepointer);
1759 if (operationsize != chunksize)
1761 test_report_failure_strerror();
1762 test_report_failure("Failed to write chunk of data.");
1763 return -1;
1765 test_report_progress("Chunk written.");
1766 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1768 test_report_failure_strerror();
1769 test_report_failure("Failed to seek backwards");
1770 return -1;
1772 test_report_progress("Seek backwards made.");
1773 erase_buffer(readdatabuffer1, buffersize);
1774 erase_buffer(zerobuffer, buffersize);
1775 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1776 if (operationsize != 2 * chunksize)
1778 test_report_failure_strerror();
1779 test_report_failure("Failed to read chunk of data.");
1780 return -1;
1782 test_report_progress("Chunk read.");
1783 if (compare_buffers(readdatabuffer1, randomwritebuffer + 2 * chunksize, chunksize) != 0)
1785 test_report_failure("Read data does not match written data for first chunk");
1786 return -1;
1788 test_report_success("Read data match written data for first chunk.");
1789 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer + 3 * chunksize, chunksize) != 0)
1791 test_report_failure("Read data does not match written data for second chunk");
1792 return -1;
1794 test_report_success("Read data match written data for second chunk.");
1795 test_report_success("SUCCESS");
1798 * TEST END
1802 * TEST
1805 next_test_step();
1807 test_report_description("seek beyond end, write some data , seek backward, read 2 x data, check data");
1809 // seek beoynd end, write some data , seek backward, read 2 x data, check data
1810 if (fseek(testfilepointer, chunksize, SEEK_END) != 0)
1812 test_report_failure_strerror();
1813 test_report_failure("Failed to seek beyond end of file");
1814 return -1;
1816 test_report_progress("Seek beyond end of file made.");
1817 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1818 if (operationsize != chunksize)
1820 test_report_failure_strerror();
1821 test_report_failure("Failed to write chunk of data.");
1822 return -1;
1824 test_report_progress("Chunk written.");
1825 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1827 test_report_failure_strerror();
1828 test_report_failure("Failed to seek backwards");
1829 return -1;
1831 test_report_progress("Seek backwards made.");
1832 erase_buffer(readdatabuffer1, buffersize);
1833 erase_buffer(zerobuffer, buffersize);
1834 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1835 if (operationsize != 2 * chunksize)
1837 test_report_failure_strerror();
1838 test_report_failure("Failed to read chunk of data.");
1839 return -1;
1841 test_report_progress("Chunk read.");
1842 if (compare_buffers(readdatabuffer1, randomwritebuffer + 3 * chunksize, chunksize) != 0)
1844 test_report_failure("Read data does not match written data for first chunk");
1845 return -1;
1847 test_report_success("Read data match written data for first chunk.");
1848 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer + chunksize, chunksize) != 0)
1850 test_report_failure("Read data does not match written data for second chunk");
1851 return -1;
1853 test_report_success("Read data match written data for second chunk.");
1854 test_report_success("SUCCESS");
1857 * TEST END
1860 return 0;
1863 int test_fseek_fwrite_fread_append_wrapper()
1865 next_test();
1867 int result = test_fseek_fwrite_fread_append_preparation();
1868 if (result != 0)
1870 report_failure("Preparation failed");
1872 else
1873 result = test_fseek_fwrite_fread_append();
1875 close_test_file();
1877 return result;
1880 int main()
1882 report_progress("Starting tests");
1884 reset_global_test_counter();
1886 // seek/tell
1887 if (test_fseek_ftell_wrapper("wb") != 0)
1888 global_failure_indicator = 1;
1889 if (test_fseek_ftell_wrapper("w+b") != 0)
1890 global_failure_indicator = 1;
1892 // seek/read test
1893 // no tested:
1894 // wb - can only write
1895 // ab - can only append
1896 if (test_fseek_and_fread_wrapper("rb") != 0)
1897 global_failure_indicator = 1;
1899 if (test_fseek_and_fread_wrapper("r+b") != 0)
1900 global_failure_indicator = 1;
1902 if (test_fseek_and_fread_wrapper("a+b") != 0)
1903 global_failure_indicator = 1;
1905 if (test_fseek_and_fread_wrapper("w+b") != 0)
1906 global_failure_indicator = 1;
1908 // seek/write/read
1909 if (test_fseek_fwrite_fread_wrapper() != 0)
1910 global_failure_indicator = 1;
1912 // seek/write/read (append)
1913 if (test_fseek_fwrite_fread_append_wrapper() != 0)
1914 global_failure_indicator = 1;
1916 if (global_failure_indicator == 1)
1917 report_failure("One of the tests FAILED");
1918 else
1919 report_progress("All tests SUCCEEDED");
1921 report_progress("Tests finished");