Added basic implementation of destroying a GPT table: just delete the
[AROS.git] / test / clib / fseek_test.c
blob8c73b9fc61b0940515f5019fd001149787c23f9a
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
5 #define SHOW_PROGRESS 0
7 // Global variables
8 int global_test_counter = 0;
9 int global_test_step_counter = 0;
10 int global_failure_indicator = 0;
12 FILE * testfilepointer = NULL;
13 size_t buffersize = 1024;
14 char writedata[1024] = {0};
15 char * testfilename = "fseek_test_file";
17 void reset_global_test_counter()
19 global_test_counter = 0;
20 global_test_step_counter = 0;
23 void next_test()
25 global_test_counter++;
26 global_test_step_counter = 0;
29 void next_test_step()
31 global_test_step_counter++;
34 // Reporting functions
35 void report(const char * status, const char * message)
37 printf("REPORT : %s : %s \n", status, message);
40 void report_progress(const char * message)
42 report("PROGRESS", message);
45 void report_failure(const char * message)
47 report("FAILED", message);
50 void report_failure_strerror()
52 report_failure((const char*)strerror(errno));
55 void test_report(const char * status, const char * message)
57 printf("TEST %d-%d : %s : %s \n", global_test_counter , global_test_step_counter, status, message);
60 void test_report_progress(const char * message)
62 #if SHOW_PROGRESS == 1
63 test_report("PROGRESS", message);
64 #endif
67 void test_report_failure(const char * message)
69 test_report("FAILED", message);
72 void test_report_success(const char * message)
74 test_report("OK", message);
77 void test_report_description(const char * message)
79 test_report("TEST DESCRIPTION", message);
82 void test_report_failure_strerror()
84 test_report_failure((const char*)strerror(errno));
87 void erase_buffer(char * buffer, size_t size)
89 memset(buffer, 0, size);
92 int compare_buffers(const char * buffer1, const char * buffer2, size_t bufferssize)
94 return memcmp(buffer1, buffer2, bufferssize);
97 void close_test_file()
99 if (testfilepointer != NULL)
101 if (fclose(testfilepointer) != 0)
103 report_failure_strerror();
104 report_failure("Failed to close the file.");
105 return;
107 testfilepointer = NULL;
111 // Tests
112 int test_fseek_ftell_preparation(const char * fopenflags)
114 size_t operationsize = 0;
116 report_progress("Starting test_fseek_ftell_preparation");
117 report_progress(fopenflags);
119 if (testfilepointer != NULL)
121 report_failure("Pointer for test file not closed.");
122 return -1;
125 // zero buffer
126 erase_buffer(writedata, buffersize);
128 // open file, write data
129 testfilepointer = fopen(testfilename, fopenflags);
130 if (testfilepointer == NULL)
132 report_failure_strerror();
133 report_failure("Failed to open file for writting.");
134 return -1;
136 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
137 if (operationsize != buffersize)
139 report_failure_strerror();
140 report_failure("Failed to write data.");
141 return -1;
144 // Seek to beginning
145 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
147 report_failure_strerror();
148 report_failure("Failed to seek to file beginning.");
149 return -1;
152 return 0;
156 int test_fseek_ftell()
159 /* Expects that testfilepointer is opened in correct mode */
160 int ftellposition = 0;
161 char conv[16] = {0};
163 report_progress("Start test_fseek_ftell");
166 * TEST
169 next_test_step();
171 test_report_description("seek to begin, tell location");
173 // seek to begin, tell location
174 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
176 test_report_failure_strerror();
177 test_report_failure("Failed to seek to beginning of file");
178 return -1;
180 test_report_progress("Seek to beginning of file.");
181 ftellposition = ftell(testfilepointer);
182 if (ftellposition == -1)
184 test_report_failure_strerror();
185 test_report_failure("Failed to tell position");
186 return -1;
188 else
189 if (ftellposition != 0)
191 test_report_failure("Wrong position in stream reported");
192 sprintf(conv, "%d", ftellposition);
193 test_report_failure(conv);
194 return -1;
196 test_report_success("Correct position in stream reported");
197 test_report_success("SUCCESS");
200 * TEST END
204 * TEST
207 next_test_step();
209 test_report_description("seek foreward, tell location");
211 // seek to begin, tell location
212 if (fseek(testfilepointer, 153, SEEK_CUR) != 0)
214 test_report_failure_strerror();
215 test_report_failure("Failed to seek foreward");
216 return -1;
218 test_report_progress("Seek foreward made.");
219 ftellposition = ftell(testfilepointer);
220 if (ftellposition == -1)
222 test_report_failure_strerror();
223 test_report_failure("Failed to tell position");
224 return -1;
226 else
227 if (ftellposition != 153)
229 test_report_failure("Wrong position in stream reported");
230 sprintf(conv, "%d", ftellposition);
231 test_report_failure(conv);
232 return -1;
234 test_report_success("Correct position in stream reported");
235 test_report_success("SUCCESS");
238 * TEST END
242 * TEST
245 next_test_step();
247 test_report_description("seek backwards, tell location");
249 // seek backwards, tell location
250 if (fseek(testfilepointer, -80, SEEK_CUR) != 0)
252 test_report_failure_strerror();
253 test_report_failure("Failed to seek backwards");
254 return -1;
256 test_report_progress("Seek backwards made.");
257 ftellposition = ftell(testfilepointer);
258 if (ftellposition == -1)
260 test_report_failure_strerror();
261 test_report_failure("Failed to tell position");
262 return -1;
264 else
265 if (ftellposition != (153-80))
267 test_report_failure("Wrong position in stream reported");
268 sprintf(conv, "%d", ftellposition);
269 test_report_failure(conv);
270 return -1;
272 test_report_success("Correct position in stream reported");
273 test_report_success("SUCCESS");
276 * TEST END
280 * TEST
283 next_test_step();
285 test_report_description("seek to the end, tell location");
287 // seek to begin, tell location
288 if (fseek(testfilepointer, 0, SEEK_END) != 0)
290 test_report_failure_strerror();
291 test_report_failure("Failed to seek to end of file");
292 return -1;
294 test_report_progress("Seek to end of file made.");
295 ftellposition = ftell(testfilepointer);
296 if (ftellposition == -1)
298 test_report_failure_strerror();
299 test_report_failure("Failed to tell position");
300 return -1;
302 else
303 if (ftellposition != buffersize)
305 test_report_failure("Wrong position in stream reported");
306 sprintf(conv, "%d", ftellposition);
307 test_report_failure(conv);
308 return -1;
310 test_report_success("Correct position in stream reported");
311 test_report_success("SUCCESS");
314 * TEST END
318 * TEST
321 next_test_step();
323 test_report_description("seek foreward(beyond file), tell location");
325 // seek foreward(beyond file), tell location
326 if (fseek(testfilepointer, 120, SEEK_CUR) != 0)
328 test_report_failure_strerror();
329 test_report_failure("Failed to seek beyond file end");
330 return -1;
332 test_report_progress("Seek beyond file end made.");
333 ftellposition = ftell(testfilepointer);
334 if (ftellposition == -1)
336 test_report_failure_strerror();
337 test_report_failure("Failed to tell position");
338 return -1;
340 else
341 if (ftellposition != buffersize + 120)
343 test_report_failure("Wrong position in stream reported");
344 sprintf(conv, "%d", ftellposition);
345 test_report_failure(conv);
346 return -1;
348 test_report_success("Correct position in stream reported");
349 test_report_success("SUCCESS");
352 * TEST END
356 * TEST
359 next_test_step();
361 test_report_description("seek backwards, tell location");
363 // seek backwards, tell location
364 if (fseek(testfilepointer, -240, SEEK_CUR) != 0)
366 test_report_failure_strerror();
367 test_report_failure("Failed to seek backwards");
368 return -1;
370 test_report_progress("Seek backwards made.");
371 ftellposition = ftell(testfilepointer);
372 if (ftellposition == -1)
374 test_report_failure_strerror();
375 test_report_failure("Failed to tell position");
376 return -1;
378 else
379 if (ftellposition != buffersize - 120)
381 test_report_failure("Wrong position in stream reported");
382 sprintf(conv, "%d", ftellposition);
383 test_report_failure(conv);
384 return -1;
386 test_report_success("Correct position in stream reported");
387 test_report_success("SUCCESS");
390 * TEST END
394 * TEST
397 next_test_step();
399 test_report_description("seek to end with positive offset, tell location");
401 // seek to end with positive offset, tell location
402 if (fseek(testfilepointer, 120, SEEK_END) != 0)
404 test_report_failure_strerror();
405 test_report_failure("Failed to seek to end with positive offset");
406 return -1;
408 test_report_progress("Seek to end with positive offset made.");
409 ftellposition = ftell(testfilepointer);
410 if (ftellposition == -1)
412 test_report_failure_strerror();
413 test_report_failure("Failed to tell position");
414 return -1;
416 else
417 if (ftellposition != buffersize + 120)
419 test_report_failure("Wrong position in stream reported");
420 sprintf(conv, "%d", ftellposition);
421 test_report_failure(conv);
422 return -1;
424 test_report_success("Correct position in stream reported");
425 test_report_success("SUCCESS");
428 * TEST END
431 return 0;
434 int test_fseek_ftell_wrapper(const char * fopenflags)
436 next_test();
438 int result = test_fseek_ftell_preparation(fopenflags);
439 if (result != 0)
441 report_failure("Preparation failed");
443 else
444 result = test_fseek_ftell();
446 close_test_file();
448 return result;
469 int test_fseek_and_fread_preparation(const char * fopenflags)
471 char readdatabuffer1[1024] = {0};
472 int i = 0;
473 size_t operationsize = 0;
475 report_progress("Starting test_fseek_and_fread_preparation");
476 report_progress(fopenflags);
478 if (testfilepointer != NULL)
480 report_failure("Pointer for test file not closed.");
481 return -1;
484 // initialize with random data (always the same because of const seed)
485 srand(1);
486 for(i = 0; i < buffersize; i++)
487 writedata[i] = (char)rand();
489 // open file, write data, close file
490 testfilepointer = fopen(testfilename, "wb+");
491 if (testfilepointer == NULL)
493 report_failure_strerror();
494 report_failure("Failed to open file for writting.");
495 return -1;
497 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
498 if (operationsize != buffersize)
500 report_failure_strerror();
501 report_failure("Failed to write data.");
502 return -1;
505 if ((strcmp(fopenflags, "w+b") == 0) ||
506 (strcmp(fopenflags, "wb+") == 0))
508 // Seek to beginning
509 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
511 report_failure_strerror();
512 report_failure("Failed to seek to file beginning (w+b).");
513 return -1;
516 else
519 if (fclose(testfilepointer) != 0)
521 report_failure_strerror();
522 report_failure("Failed to close file.");
523 return -1;
526 // open file
527 testfilepointer = fopen(testfilename, "rb");
528 if (testfilepointer == NULL)
530 report_failure_strerror();
531 report_failure("Failed to open file for reading.");
532 return -1;
536 //read data, compare data, close file
537 erase_buffer(readdatabuffer1, buffersize);
538 operationsize = fread(readdatabuffer1, 1, buffersize, testfilepointer);
539 if (operationsize != buffersize)
541 report_failure_strerror();
542 report_failure("Failed to read data.");
543 return -1;
545 if (compare_buffers(readdatabuffer1, writedata, buffersize) != 0)
547 report_failure("Read data differs from written data");
548 return -1;
551 if ((strcmp(fopenflags, "w+b") == 0) ||
552 (strcmp(fopenflags, "wb+") == 0))
554 // Seek to beginning
555 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
557 report_failure_strerror();
558 report_failure("Failed to seek to file beginning (w+b).");
559 return -1;
562 else
564 // Close file and open it with new flags
565 if (fclose(testfilepointer) != 0)
567 report_failure_strerror();
568 report_failure("Failed to close file.");
569 return -1;
572 testfilepointer = fopen(testfilename, fopenflags);
573 if (testfilepointer == NULL)
575 report_failure_strerror();
576 report_failure("Failed to open file for seek testing.");
577 return -1;
581 return 0;
585 int test_fseek_and_fread()
588 /* Expects that testfilepointer is opened in correct mode */
589 size_t chunksize = 128;
590 char readdatabuffer1[1024] = {0};
591 int i = 0;
592 size_t operationsize = 0;
595 * TEST
598 report_progress("Start test_fseek_and_fread");
600 next_test_step();
602 test_report_description("seek to begin, read some data , check data");
604 // seek to begin, read some data, check data
605 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
607 test_report_failure_strerror();
608 test_report_failure("Failed to seek to beginning of file");
609 return -1;
611 test_report_progress("Seek to beginning of file.");
612 erase_buffer(readdatabuffer1, buffersize);
613 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
614 if (operationsize != chunksize)
616 test_report_failure_strerror();
617 test_report_failure("Failed to read chunk of data.");
618 return -1;
620 test_report_progress("Chunk read.");
621 if (compare_buffers(readdatabuffer1, writedata, chunksize) != 0)
623 test_report_failure("Read data does not match written data");
624 return -1;
626 test_report_success("Read data match written data.");
627 test_report_success("SUCCESS");
630 * TEST END
635 * TEST
638 next_test_step();
640 test_report_description("make absolute seek, read some data , check data");
642 // make absolute seek, read some data, check data
643 if (fseek(testfilepointer, 350, SEEK_SET) != 0)
645 test_report_failure_strerror();
646 test_report_failure("Failed to make absolute seek");
647 return -1;
649 test_report_progress("Absolute seek made.");
650 erase_buffer(readdatabuffer1, buffersize);
651 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
652 if (operationsize != chunksize)
654 test_report_failure_strerror();
655 test_report_failure("Failed to read chunk of data.");
656 return -1;
658 test_report_progress("Chunk read.");
659 if (compare_buffers(readdatabuffer1, writedata + 350, chunksize) != 0)
661 test_report_failure("Read data does not match written data");
662 return -1;
664 test_report_success("Read data match written data.");
665 test_report_success("SUCCESS");
668 * TEST END
673 * TEST
676 next_test_step();
678 test_report_description("make relative seek backwards, read some data , check data");
679 // make relative seek backwards, read some data, check data
680 if (fseek(testfilepointer, - (120 + chunksize), SEEK_CUR) != 0)
682 test_report_failure_strerror();
683 test_report_failure("Failed to make relative seek");
684 return -1;
686 test_report_progress("Relative seek made.");
687 erase_buffer(readdatabuffer1, buffersize);
688 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
689 if (operationsize != chunksize)
691 test_report_failure_strerror();
692 test_report_failure("Failed to read chunk of data.");
693 return -1;
695 test_report_progress("Chunk read.");
696 if (compare_buffers(readdatabuffer1, writedata + (350 - 120), chunksize) != 0)
698 test_report_failure("Read data does not match written data");
699 return -1;
701 test_report_success("Read data match written data.");
702 test_report_success("SUCCESS");
705 * TEST END
710 * TEST
713 next_test_step();
715 test_report_description("make relative seek forewards, read some data , check data");
716 // make relative seek forewards, read some data, check data
717 if (fseek(testfilepointer, 138, SEEK_CUR) != 0)
719 test_report_failure_strerror();
720 test_report_failure("Failed to make relative seek");
721 return -1;
723 test_report_progress("Relative seek made.");
724 erase_buffer(readdatabuffer1, buffersize);
725 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
726 if (operationsize != chunksize)
728 test_report_failure_strerror();
729 test_report_failure("Failed to read chunk of data.");
730 return -1;
732 test_report_progress("Chunk read.");
733 if (compare_buffers(readdatabuffer1, writedata + (350 - 120 + chunksize + 138), chunksize) != 0)
735 test_report_failure("Read data does not match written data");
736 return -1;
738 test_report_success("Read data match written data.");
739 test_report_success("SUCCESS");
743 * TEST END
748 * TEST
751 next_test_step();
753 test_report_description("seek to end, make relative seek backwards, read some data , check data");
754 // seek to end, make relative seek backwards, read some data, check data
755 if (fseek(testfilepointer, 0, SEEK_END) != 0)
757 test_report_failure_strerror();
758 test_report_failure("Failed to seek to end");
759 return -1;
761 test_report_progress("Seek to end made");
762 if (fseek(testfilepointer, -210, SEEK_CUR) != 0)
764 test_report_failure_strerror();
765 test_report_failure("Failed to make relative seek");
766 return -1;
768 test_report_progress("Relative seek made.");
769 erase_buffer(readdatabuffer1, buffersize);
770 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
771 if (operationsize != chunksize)
773 test_report_failure_strerror();
774 test_report_failure("Failed to read chunk of data.");
775 return -1;
777 test_report_progress("Chunk read.");
778 if (compare_buffers(readdatabuffer1, writedata + buffersize - 210, chunksize) != 0)
780 test_report_failure("Read data does not match written data");
781 return -1;
783 test_report_success("Read data match written data.");
784 test_report_success("SUCCESS");
787 * TEST END
792 * TEST
795 next_test_step();
797 test_report_description("read some data (more than is in file) , check error code data");
798 // read some data (more than is in file) , check error code data
799 erase_buffer(readdatabuffer1, buffersize);
800 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
801 if (operationsize != chunksize)
803 if (errno != 0/*rb*/ && errno != EINVAL/*a+b, w+b, r+b*/)
805 test_report_failure_strerror();
806 test_report_failure("Error different than expected reported");
807 return -1;
810 else
812 test_report_failure("Number of read data should be different than requested data");
813 return -1;
815 test_report_success("Error reported");
816 test_report_success("SUCCESS");
819 * TEST END
824 * TEST
827 next_test_step();
829 test_report_description("seek to beginning, seek forewards, seek backwards beyond file start, check error code");
830 // seek to beginning, seek forewards, seek backwards beyond file start, check error code
831 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
833 test_report_failure_strerror();
834 test_report_failure("Failed to seek to beginning");
835 return -1;
837 test_report_progress("Seek to beginning made.");
838 if (fseek(testfilepointer, 99, SEEK_CUR) != 0)
840 test_report_failure_strerror();
841 test_report_failure("Failed to make relative seek forewards");
842 return -1;
844 test_report_progress("Relative seek forewards made.");
845 if (fseek(testfilepointer, -150, SEEK_CUR) != 0)
847 if (errno != EINVAL)
849 test_report_failure_strerror();
850 test_report_failure("Error different than expected reported");
851 return -1;
854 else
856 test_report_progress("Should not made relative seek backwards beyond file start.");
857 return -1;
859 test_report_success("Error reported");
860 test_report_success("SUCCESS");
863 * TEST END
868 * TEST
871 next_test_step();
873 test_report_description("seek to end, seek forewards, read some data, check error code");
874 // seek to end, seek forewards, read some data, check error code
875 if (fseek(testfilepointer, 0, SEEK_END) != 0)
877 test_report_failure_strerror();
878 test_report_failure("Failed to seek to end");
879 return -1;
881 test_report_progress("Seek to end made.");
882 if (fseek(testfilepointer, 99, SEEK_CUR) != 0)
884 test_report_failure_strerror();
885 test_report_failure("Failed to make relative seek forewards");
886 return -1;
888 test_report_progress("Relative seek forewards made.");
889 erase_buffer(readdatabuffer1, buffersize);
890 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
891 if (operationsize != chunksize)
893 if (errno != EINVAL)
895 test_report_failure_strerror();
896 test_report_failure("Error different than expected reported");
897 return -1;
900 else
902 test_report_failure("Number of read data should be different than requested data");
903 return -1;
905 test_report_success("Error reported");
906 test_report_success("SUCCESS");
909 * TEST END
914 * TEST
917 next_test_step();
919 test_report_description("seek to end with offset, read some data, check error code");
920 // seek to end with offset, read some data, check error code
921 if (fseek(testfilepointer, 100, SEEK_END) != 0)
923 test_report_failure_strerror();
924 test_report_failure("Failed to seek to end with offset");
925 return -1;
927 test_report_progress("Seek to end with offset made.");
928 erase_buffer(readdatabuffer1, buffersize);
929 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
930 if (operationsize != chunksize)
932 if (errno != EINVAL)
934 test_report_failure_strerror();
935 test_report_failure("Error different than expected reported");
936 return -1;
939 else
941 test_report_failure("Number of read data should be different than requested data");
942 return -1;
944 test_report_success("Error reported");
945 test_report_success("SUCCESS");
946 return 0;
949 int test_fseek_and_fread_wrapper(const char * fopenflags)
951 next_test();
953 int result = test_fseek_and_fread_preparation(fopenflags);
954 if (result != 0)
956 report_failure("Preparation failed");
958 else
959 result = test_fseek_and_fread();
961 close_test_file();
963 return result;
966 int test_fseek_fwrite_fread_preparation()
968 char readdatabuffer1[1024] = {0};
969 int i = 0;
970 size_t operationsize = 0;
972 report_progress("Starting test_fseek_fwrite_fread_preparation");
974 if (testfilepointer != NULL)
976 report_failure("Pointer for test file not closed.");
977 return -1;
980 // Initilize random write buffer
981 srand(1);
982 for (i = 0; i < buffersize; i++)
983 writedata[i] = (char)rand();
985 // open file, write data
986 testfilepointer = fopen(testfilename, "wb+");
987 if (testfilepointer == NULL)
989 report_failure_strerror();
990 report_failure("Failed to open file for writting.");
991 return -1;
993 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
994 if (operationsize != buffersize)
996 report_failure_strerror();
997 report_failure("Failed to write data.");
998 return -1;
1001 // Seek to beginning
1002 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1004 report_failure_strerror();
1005 report_failure("Failed to seek to file beginning (w+b).");
1006 return -1;
1009 //read data, compare data
1010 erase_buffer(readdatabuffer1, buffersize);
1011 operationsize = fread(readdatabuffer1, 1, buffersize, testfilepointer);
1012 if (operationsize != buffersize)
1014 report_failure_strerror();
1015 report_failure("Failed to read data.");
1016 return -1;
1018 if (compare_buffers(readdatabuffer1, writedata, buffersize) != 0)
1020 report_failure("Read data differs from written data");
1021 return -1;
1024 // Seek to beginning
1025 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1027 report_failure_strerror();
1028 report_failure("Failed to seek to file beginning (w+b).");
1029 return -1;
1032 return 0;
1036 int test_fseek_fwrite_fread()
1038 /* Expects that testfilepointer is opened in correct mode */
1039 char randomwritebuffer[1024] = {0};
1040 size_t chunksize = 128;
1041 char readdatabuffer1[1024] = {0};
1042 char zerobuffer[1024] = {0};
1043 int i = 0;
1044 size_t operationsize = 0;
1046 // Initilize random write buffer
1047 // Don't initialize srand or randomwritebuffer == writedata
1048 for (i = 0; i < buffersize; i++)
1049 randomwritebuffer[i] = (char)rand();
1052 * TEST
1055 report_progress("Start test_fseek_fwrite_fread");
1057 next_test_step();
1059 test_report_description("seek to begin, write some data , seek to begin, read 2x some data, check data");
1061 // seek to begin, write some data , seek to begin, read 2x some data, check data
1062 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1064 test_report_failure_strerror();
1065 test_report_failure("Failed to seek to beginning of file");
1066 return -1;
1068 test_report_progress("Seek to beginning of file.");
1069 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1070 if (operationsize != chunksize)
1072 test_report_failure_strerror();
1073 test_report_failure("Failed to write chunk of data.");
1074 return -1;
1076 test_report_progress("Chunk written.");
1077 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1079 test_report_failure_strerror();
1080 test_report_failure("Failed to seek to beginning of file");
1081 return -1;
1083 test_report_progress("Seek to beginning of file.");
1084 erase_buffer(readdatabuffer1, buffersize);
1085 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1086 if (operationsize != 2 * chunksize)
1088 test_report_failure_strerror();
1089 test_report_failure("Failed to read chunk of data.");
1090 return -1;
1092 test_report_progress("Chunk read.");
1093 if (compare_buffers(readdatabuffer1, randomwritebuffer, chunksize) != 0)
1095 test_report_failure("Read data does not match written data for first chunk");
1096 return -1;
1098 test_report_success("Read data match written data for first chunk.");
1099 if (compare_buffers(readdatabuffer1 + chunksize, writedata + chunksize, chunksize) != 0)
1101 test_report_failure("Read data does not match written data for second chunk");
1102 return -1;
1104 test_report_success("Read data match written data for second chunk.");
1105 test_report_success("SUCCESS");
1108 * TEST END
1112 * TEST
1115 next_test_step();
1117 test_report_description("seek foreward, write some data , seek backward, read data, check data");
1119 // seek foreward, write some data , seek backward, read data, check data
1120 if (fseek(testfilepointer, 3 * chunksize, SEEK_CUR) != 0)
1122 test_report_failure_strerror();
1123 test_report_failure("Failed to seek foreward");
1124 return -1;
1126 test_report_progress("Seek foreward made.");
1127 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1128 if (operationsize != chunksize)
1130 test_report_failure_strerror();
1131 test_report_failure("Failed to write chunk of data.");
1132 return -1;
1134 test_report_progress("Chunk written.");
1135 if (fseek(testfilepointer, - chunksize, SEEK_CUR) != 0)
1137 test_report_failure_strerror();
1138 test_report_failure("Failed to seek backwards");
1139 return -1;
1141 test_report_progress("Seek backwards made.");
1142 erase_buffer(readdatabuffer1, buffersize);
1143 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1144 if (operationsize != chunksize)
1146 test_report_failure_strerror();
1147 test_report_failure("Failed to read chunk of data.");
1148 return -1;
1150 test_report_progress("Chunk read.");
1151 if (compare_buffers(readdatabuffer1, randomwritebuffer, chunksize) != 0)
1153 test_report_failure("Read data does not match written");
1154 return -1;
1156 test_report_success("Read data match written data.");
1157 test_report_success("SUCCESS");
1160 * TEST END
1164 * TEST
1167 next_test_step();
1169 test_report_description("seek backward, write some data , seek backward, read 2 x data, check data");
1171 // seek backward, write some data , seek backward, read 2 x data, check data
1172 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1174 test_report_failure_strerror();
1175 test_report_failure("Failed to seek backwards");
1176 return -1;
1178 test_report_progress("Seek backwards made.");
1179 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1180 if (operationsize != chunksize)
1182 test_report_failure_strerror();
1183 test_report_failure("Failed to write chunk of data.");
1184 return -1;
1186 test_report_progress("Chunk written.");
1187 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1189 test_report_failure_strerror();
1190 test_report_failure("Failed to seek backwards");
1191 return -1;
1193 test_report_progress("Seek backwards made.");
1194 erase_buffer(readdatabuffer1, buffersize);
1195 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1196 if (operationsize != 2 * chunksize)
1198 test_report_failure_strerror();
1199 test_report_failure("Failed to read chunk of data.");
1200 return -1;
1202 test_report_progress("Chunk read.");
1203 if (compare_buffers(readdatabuffer1, randomwritebuffer + chunksize, chunksize) != 0)
1205 test_report_failure("Read data does not match written for first chunk");
1206 return -1;
1208 test_report_success("Read data match written data for first chunk.");
1209 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer, chunksize) != 0)
1211 test_report_failure("Read data does not match written for second chunk");
1212 return -1;
1214 test_report_success("Read data match written data for second chunk.");
1215 test_report_success("SUCCESS");
1218 * TEST END
1222 * TEST
1225 next_test_step();
1227 test_report_description("seek to end, write some data , seek backward, read data, check data");
1229 // seek to end, write some data , seek backward, read data, check data
1230 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1232 test_report_failure_strerror();
1233 test_report_failure("Failed to seek to end");
1234 return -1;
1236 test_report_progress("Seek to end of file made.");
1237 operationsize = fwrite(randomwritebuffer + 2 * chunksize, 1, chunksize, testfilepointer);
1238 if (operationsize != chunksize)
1240 test_report_failure_strerror();
1241 test_report_failure("Failed to write chunk of data.");
1242 return -1;
1244 test_report_progress("Chunk written.");
1245 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1247 test_report_failure_strerror();
1248 test_report_failure("Failed to seek backwards");
1249 return -1;
1251 test_report_progress("Seek backwards made.");
1252 erase_buffer(readdatabuffer1, buffersize);
1253 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1254 if (operationsize != chunksize)
1256 test_report_failure_strerror();
1257 test_report_failure("Failed to read chunk of data.");
1258 return -1;
1260 test_report_progress("Chunk read.");
1261 if (compare_buffers(readdatabuffer1, randomwritebuffer + 2 * chunksize, chunksize) != 0)
1263 test_report_failure("Read data does not match written data");
1264 return -1;
1266 test_report_success("Read data match written data.");
1267 test_report_success("SUCCESS");
1270 * TEST END
1274 * TEST
1277 next_test_step();
1279 test_report_description("seek to end, seek foreward, write some data , seek backward, read 2 x data, check data");
1281 // seek to end, seek foreward, write some data , seek backward, read 2 x data, check data
1282 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1284 test_report_failure_strerror();
1285 test_report_failure("Failed to seek to end");
1286 return -1;
1288 test_report_progress("Seek to end of file made.");
1289 if (fseek(testfilepointer, chunksize, SEEK_CUR) != 0)
1291 test_report_failure_strerror();
1292 test_report_failure("Failed to seek foreward");
1293 return -1;
1295 test_report_progress("Seek foreward made.");
1296 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1297 if (operationsize != chunksize)
1299 test_report_failure_strerror();
1300 test_report_failure("Failed to write chunk of data.");
1301 return -1;
1303 test_report_progress("Chunk written.");
1304 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1306 test_report_failure_strerror();
1307 test_report_failure("Failed to seek backwards");
1308 return -1;
1310 test_report_progress("Seek backwards made.");
1311 erase_buffer(readdatabuffer1, buffersize);
1312 erase_buffer(zerobuffer, buffersize);
1313 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1314 if (operationsize != 2 * chunksize)
1316 test_report_failure_strerror();
1317 test_report_failure("Failed to read chunk of data.");
1318 return -1;
1320 test_report_progress("Chunk read.");
1321 if (compare_buffers(readdatabuffer1, zerobuffer, chunksize) != 0)
1323 test_report_failure("Read data does not match written data for first chunk");
1324 return -1;
1326 test_report_success("Read data match written data for first chunk.");
1327 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer, chunksize) != 0)
1329 test_report_failure("Read data does not match written data for second chunk");
1330 return -1;
1332 test_report_success("Read data match written data for second chunk.");
1333 test_report_success("SUCCESS");
1336 * TEST END
1340 * TEST
1343 next_test_step();
1345 test_report_description("seek beoynd end, write some data , seek backward, read 2 x data, check data");
1347 // seek beoynd end, write some data , seek backward, read 2 x data, check data
1348 if (fseek(testfilepointer, chunksize, SEEK_END) != 0)
1350 test_report_failure_strerror();
1351 test_report_failure("Failed to seek beyond end of file");
1352 return -1;
1354 test_report_progress("Seek beyond end of file made.");
1355 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1356 if (operationsize != chunksize)
1358 test_report_failure_strerror();
1359 test_report_failure("Failed to write chunk of data.");
1360 return -1;
1362 test_report_progress("Chunk written.");
1363 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1365 test_report_failure_strerror();
1366 test_report_failure("Failed to seek backwards");
1367 return -1;
1369 test_report_progress("Seek backwards made.");
1370 erase_buffer(readdatabuffer1, buffersize);
1371 erase_buffer(zerobuffer, buffersize);
1372 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1373 if (operationsize != 2 * chunksize)
1375 test_report_failure_strerror();
1376 test_report_failure("Failed to read chunk of data.");
1377 return -1;
1379 test_report_progress("Chunk read.");
1380 if (compare_buffers(readdatabuffer1, zerobuffer, chunksize) != 0)
1382 test_report_failure("Read data does not match written data for first chunk");
1383 return -1;
1385 test_report_success("Read data match written data for first chunk.");
1386 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer + chunksize, chunksize) != 0)
1388 test_report_failure("Read data does not match written data for second chunk");
1389 return -1;
1391 test_report_success("Read data match written data for second chunk.");
1392 test_report_success("SUCCESS");
1395 * TEST END
1398 return 0;
1401 int test_fseek_fwrite_fread_wrapper()
1403 next_test();
1405 int result = test_fseek_fwrite_fread_preparation();
1406 if (result != 0)
1408 report_failure("Preparation failed");
1410 else
1411 result = test_fseek_fwrite_fread();
1413 close_test_file();
1415 return result;
1418 int test_fseek_fwrite_fread_append_preparation()
1420 char readdatabuffer1[1024] = {0};
1421 int i = 0;
1422 size_t operationsize = 0;
1424 report_progress("Starting test_fseek_fwrite_fread_append_preparation");
1426 if (testfilepointer != NULL)
1428 report_failure("Pointer for test file not closed.");
1429 return -1;
1432 // Initilize random write buffer
1433 srand(1);
1434 for (i = 0; i < buffersize; i++)
1435 writedata[i] = (char)rand();
1437 // open file, write data
1438 testfilepointer = fopen(testfilename, "wb+");
1439 if (testfilepointer == NULL)
1441 report_failure_strerror();
1442 report_failure("Failed to open file for writting.");
1443 return -1;
1445 operationsize = fwrite(writedata, 1, buffersize, testfilepointer);
1446 if (operationsize != buffersize)
1448 report_failure_strerror();
1449 report_failure("Failed to write data.");
1450 return -1;
1453 // Seek to beginning
1454 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1456 report_failure_strerror();
1457 report_failure("Failed to seek to file beginning (w+b).");
1458 return -1;
1461 //read data, compare data
1462 erase_buffer(readdatabuffer1, buffersize);
1463 operationsize = fread(readdatabuffer1, 1, buffersize, testfilepointer);
1464 if (operationsize != buffersize)
1466 report_failure_strerror();
1467 report_failure("Failed to read data.");
1468 return -1;
1470 if (compare_buffers(readdatabuffer1, writedata, buffersize) != 0)
1472 report_failure("Read data differs from written data");
1473 return -1;
1476 // close
1477 if (fclose(testfilepointer) != 0)
1479 report_failure_strerror();
1480 report_failure("Failed to close the file.");
1481 return;
1484 // open
1485 testfilepointer = fopen(testfilename, "ab+");
1486 if (testfilepointer == NULL)
1488 report_failure_strerror();
1489 report_failure("Failed to open file for appending.");
1490 return -1;
1493 return 0;
1497 int test_fseek_fwrite_fread_append()
1499 /* Expects that testfilepointer is opened in correct mode */
1500 char randomwritebuffer[1024] = {0};
1501 size_t chunksize = 128;
1502 char readdatabuffer1[1024] = {0};
1503 char zerobuffer[1024] = {0};
1504 int i = 0;
1505 size_t operationsize = 0;
1507 // Initilize random write buffer
1508 // Don't initialize srand or randomwritebuffer == writedata
1509 for (i = 0; i < buffersize; i++)
1510 randomwritebuffer[i] = (char)rand();
1513 * TEST
1516 report_progress("Start test_fseek_fwrite_fread_append");
1518 next_test_step();
1520 test_report_description("seek to begin, write some data , seek to begin, read 2x some data, check data");
1522 // seek to begin, write some data , seek to begin, read 2x some data, check data
1523 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1525 test_report_failure_strerror();
1526 test_report_failure("Failed to seek to beginning of file");
1527 return -1;
1529 test_report_progress("Seek to beginning of file.");
1530 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1531 if (operationsize != chunksize)
1533 test_report_failure_strerror();
1534 test_report_failure("Failed to write chunk of data.");
1535 return -1;
1537 test_report_progress("Chunk written.");
1538 if (fseek(testfilepointer, 0, SEEK_SET) != 0)
1540 test_report_failure_strerror();
1541 test_report_failure("Failed to seek to beginning of file");
1542 return -1;
1544 test_report_progress("Seek to beginning of file.");
1545 erase_buffer(readdatabuffer1, buffersize);
1546 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1547 if (operationsize != 2 * chunksize)
1549 test_report_failure_strerror();
1550 test_report_failure("Failed to read chunk of data.");
1551 return -1;
1553 test_report_progress("Chunk read.");
1554 if (compare_buffers(readdatabuffer1, writedata, chunksize) != 0)
1556 test_report_failure("Read data does not match written data for first chunk");
1557 return -1;
1559 test_report_success("Read data match written data for first chunk.");
1560 if (compare_buffers(readdatabuffer1 + chunksize, writedata + chunksize, chunksize) != 0)
1562 test_report_failure("Read data does not match written data for second chunk");
1563 return -1;
1565 test_report_success("Read data match written data for second chunk.");
1566 test_report_success("SUCCESS");
1569 * TEST END
1573 * TEST
1576 next_test_step();
1578 test_report_description("seek foreward, write some data , seek backward, read data, check data");
1580 // seek foreward, write some data , seek backward, read data, check data
1581 if (fseek(testfilepointer, 3 * chunksize, SEEK_CUR) != 0)
1583 test_report_failure_strerror();
1584 test_report_failure("Failed to seek foreward");
1585 return -1;
1587 test_report_progress("Seek foreward made.");
1588 operationsize = fwrite(randomwritebuffer, 1, chunksize, testfilepointer);
1589 if (operationsize != chunksize)
1591 test_report_failure_strerror();
1592 test_report_failure("Failed to write chunk of data.");
1593 return -1;
1595 test_report_progress("Chunk written.");
1596 if (fseek(testfilepointer, - chunksize, SEEK_CUR) != 0)
1598 test_report_failure_strerror();
1599 test_report_failure("Failed to seek backwards");
1600 return -1;
1602 test_report_progress("Seek backwards made.");
1603 erase_buffer(readdatabuffer1, buffersize);
1604 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1605 if (operationsize != chunksize)
1607 test_report_failure_strerror();
1608 test_report_failure("Failed to read chunk of data.");
1609 return -1;
1611 test_report_progress("Chunk read.");
1612 if (compare_buffers(readdatabuffer1, randomwritebuffer, chunksize) != 0)
1614 test_report_failure("Read data does not match written");
1615 return -1;
1617 test_report_success("Read data match written data.");
1618 test_report_success("SUCCESS");
1621 * TEST END
1625 * TEST
1628 next_test_step();
1630 test_report_description("seek backward, write some data , seek backward, read 2 x data, check error");
1632 // seek backward, write some data , seek backward, read 2 x data, check error
1633 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1635 test_report_failure_strerror();
1636 test_report_failure("Failed to seek backwards");
1637 return -1;
1639 test_report_progress("Seek backwards made.");
1640 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1641 if (operationsize != chunksize)
1643 test_report_failure_strerror();
1644 test_report_failure("Failed to write chunk of data.");
1645 return -1;
1647 test_report_progress("Chunk written.");
1648 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1650 test_report_failure_strerror();
1651 test_report_failure("Failed to seek backwards");
1652 return -1;
1654 test_report_progress("Seek backwards made.");
1655 erase_buffer(readdatabuffer1, buffersize);
1656 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1657 if (operationsize != 2 * chunksize)
1659 if (errno != EINVAL)
1661 test_report_failure_strerror();
1662 test_report_failure("Different than expected error reported.");
1663 return -1;
1666 else
1668 test_report_failure("Expected error");
1669 return -1;
1671 test_report_success("Error reported.");
1672 test_report_success("SUCCESS");
1675 * TEST END
1679 * TEST
1682 next_test_step();
1684 test_report_description("seek to end, write some data , seek backward, read data, check data");
1686 // seek to end, write some data , seek backward, read data, check data
1687 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1689 test_report_failure_strerror();
1690 test_report_failure("Failed to seek to end");
1691 return -1;
1693 test_report_progress("Seek to end of file made.");
1694 operationsize = fwrite(randomwritebuffer + 2 * chunksize, 1, chunksize, testfilepointer);
1695 if (operationsize != chunksize)
1697 test_report_failure_strerror();
1698 test_report_failure("Failed to write chunk of data.");
1699 return -1;
1701 test_report_progress("Chunk written.");
1702 if (fseek(testfilepointer, -chunksize, SEEK_CUR) != 0)
1704 test_report_failure_strerror();
1705 test_report_failure("Failed to seek backwards");
1706 return -1;
1708 test_report_progress("Seek backwards made.");
1709 erase_buffer(readdatabuffer1, buffersize);
1710 operationsize = fread(readdatabuffer1, 1, chunksize, testfilepointer);
1711 if (operationsize != chunksize)
1713 test_report_failure_strerror();
1714 test_report_failure("Failed to read chunk of data.");
1715 return -1;
1717 test_report_progress("Chunk read.");
1718 if (compare_buffers(readdatabuffer1, randomwritebuffer + 2 * chunksize, chunksize) != 0)
1720 test_report_failure("Read data does not match written data");
1721 return -1;
1723 test_report_success("Read data match written data.");
1724 test_report_success("SUCCESS");
1727 * TEST END
1731 * TEST
1734 next_test_step();
1736 test_report_description("seek to end, seek foreward, write some data , seek backward, read 2 x data, check data");
1738 // seek to end, seek foreward, write some data , seek backward, read 2 x data, check data
1739 if (fseek(testfilepointer, 0, SEEK_END) != 0)
1741 test_report_failure_strerror();
1742 test_report_failure("Failed to seek to end");
1743 return -1;
1745 test_report_progress("Seek to end of file made.");
1746 if (fseek(testfilepointer, chunksize, SEEK_CUR) != 0)
1748 test_report_failure_strerror();
1749 test_report_failure("Failed to seek foreward");
1750 return -1;
1752 test_report_progress("Seek foreward made.");
1753 operationsize = fwrite(randomwritebuffer + 3 * chunksize, 1, chunksize, testfilepointer);
1754 if (operationsize != chunksize)
1756 test_report_failure_strerror();
1757 test_report_failure("Failed to write chunk of data.");
1758 return -1;
1760 test_report_progress("Chunk written.");
1761 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1763 test_report_failure_strerror();
1764 test_report_failure("Failed to seek backwards");
1765 return -1;
1767 test_report_progress("Seek backwards made.");
1768 erase_buffer(readdatabuffer1, buffersize);
1769 erase_buffer(zerobuffer, buffersize);
1770 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1771 if (operationsize != 2 * chunksize)
1773 test_report_failure_strerror();
1774 test_report_failure("Failed to read chunk of data.");
1775 return -1;
1777 test_report_progress("Chunk read.");
1778 if (compare_buffers(readdatabuffer1, randomwritebuffer + 2 * chunksize, chunksize) != 0)
1780 test_report_failure("Read data does not match written data for first chunk");
1781 return -1;
1783 test_report_success("Read data match written data for first chunk.");
1784 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer + 3 * chunksize, chunksize) != 0)
1786 test_report_failure("Read data does not match written data for second chunk");
1787 return -1;
1789 test_report_success("Read data match written data for second chunk.");
1790 test_report_success("SUCCESS");
1793 * TEST END
1797 * TEST
1800 next_test_step();
1802 test_report_description("seek beyond end, write some data , seek backward, read 2 x data, check data");
1804 // seek beoynd end, write some data , seek backward, read 2 x data, check data
1805 if (fseek(testfilepointer, chunksize, SEEK_END) != 0)
1807 test_report_failure_strerror();
1808 test_report_failure("Failed to seek beyond end of file");
1809 return -1;
1811 test_report_progress("Seek beyond end of file made.");
1812 operationsize = fwrite(randomwritebuffer + chunksize, 1, chunksize, testfilepointer);
1813 if (operationsize != chunksize)
1815 test_report_failure_strerror();
1816 test_report_failure("Failed to write chunk of data.");
1817 return -1;
1819 test_report_progress("Chunk written.");
1820 if (fseek(testfilepointer, -2 * chunksize, SEEK_CUR) != 0)
1822 test_report_failure_strerror();
1823 test_report_failure("Failed to seek backwards");
1824 return -1;
1826 test_report_progress("Seek backwards made.");
1827 erase_buffer(readdatabuffer1, buffersize);
1828 erase_buffer(zerobuffer, buffersize);
1829 operationsize = fread(readdatabuffer1, 1, 2 * chunksize, testfilepointer);
1830 if (operationsize != 2 * chunksize)
1832 test_report_failure_strerror();
1833 test_report_failure("Failed to read chunk of data.");
1834 return -1;
1836 test_report_progress("Chunk read.");
1837 if (compare_buffers(readdatabuffer1, randomwritebuffer + 3 * chunksize, chunksize) != 0)
1839 test_report_failure("Read data does not match written data for first chunk");
1840 return -1;
1842 test_report_success("Read data match written data for first chunk.");
1843 if (compare_buffers(readdatabuffer1 + chunksize, randomwritebuffer + chunksize, chunksize) != 0)
1845 test_report_failure("Read data does not match written data for second chunk");
1846 return -1;
1848 test_report_success("Read data match written data for second chunk.");
1849 test_report_success("SUCCESS");
1852 * TEST END
1855 return 0;
1858 int test_fseek_fwrite_fread_append_wrapper()
1860 next_test();
1862 int result = test_fseek_fwrite_fread_append_preparation();
1863 if (result != 0)
1865 report_failure("Preparation failed");
1867 else
1868 result = test_fseek_fwrite_fread_append();
1870 close_test_file();
1872 return result;
1875 int main()
1877 report_progress("Starting tests");
1879 reset_global_test_counter();
1881 // seek/tell
1882 if (test_fseek_ftell_wrapper("wb") != 0)
1883 global_failure_indicator = 1;
1884 if (test_fseek_ftell_wrapper("w+b") != 0)
1885 global_failure_indicator = 1;
1887 // seek/read test
1888 // no tested:
1889 // wb - can only write
1890 // ab - can only append
1891 if (test_fseek_and_fread_wrapper("rb") != 0)
1892 global_failure_indicator = 1;
1894 if (test_fseek_and_fread_wrapper("r+b") != 0)
1895 global_failure_indicator = 1;
1897 if (test_fseek_and_fread_wrapper("a+b") != 0)
1898 global_failure_indicator = 1;
1900 if (test_fseek_and_fread_wrapper("w+b") != 0)
1901 global_failure_indicator = 1;
1903 // seek/write/read
1904 if (test_fseek_fwrite_fread_wrapper() != 0)
1905 global_failure_indicator = 1;
1907 // seek/write/read (append)
1908 if (test_fseek_fwrite_fread_append_wrapper() != 0)
1909 global_failure_indicator = 1;
1911 if (global_failure_indicator == 1)
1912 report_failure("One of the tests FAILED");
1913 else
1914 report_progress("All tests SUCCEEDED");
1916 report_progress("Tests finished");