2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
11 #define SHOW_PROGRESS 0
14 int global_test_counter
= 0;
15 int global_test_step_counter
= 0;
16 int global_failure_indicator
= 0;
18 /* 2008-03-22 - All test pass (if manual configuration is done correclty) */
20 /* COMPILE WITH '-nix' for unix2amiga path conversion */
22 /* These values are arbitrary and influence test results! */
23 /* Existing objects should have RWED permitions (even the volume!) */
26 const char * existing_volume
= "/Work/";
27 const char * existing_directory
= "/SYS/Classes";
28 const char * existing_file
= "/SYS/Classes/Datatypes/bmp.datatype";
29 const char * non_existing_volume
= "/sw243";
30 const char * non_existing_directory
= "/SYS/sdgfer";
31 const char * non_existing_file
= "/SYS/Classes/ggg.txt";
33 const char * existing_volume
= "/usr";
34 const char * existing_directory
= "/usr/bin";
35 const char * existing_file
= "/usr/bin/gcc";
36 const char * non_existing_volume
= "/sw243";
37 const char * non_existing_directory
= "/usr/sdgfer";
38 const char * non_existing_file
= "/usr/lib/ggg.txt";
41 /* These files need to be prepared in application directory with appriopriate access rights! */
42 const char * read_only_file
= "read_only_file";
43 const char * write_only_file
= "write_only_file";
44 const char * execute_only_file
= "execute_only_file";
45 const char * all_access_file
= "all_access_file";
47 void reset_global_test_counter()
49 global_test_counter
= 0;
50 global_test_step_counter
= 0;
55 global_test_counter
++;
56 global_test_step_counter
= 0;
61 global_test_step_counter
++;
64 // Reporting functions
65 void report(const char * status
, const char * message
)
67 printf("REPORT : %s : %s \n", status
, message
);
70 void report_progress(const char * message
)
72 report("PROGRESS", message
);
75 void report_failure(const char * message
)
77 report("FAILED", message
);
80 void report_failure_strerror()
82 report_failure((const char*)strerror(errno
));
85 void test_report(const char * status
, const char * message
)
87 printf("TEST %d-%d : %s : %s \n", global_test_counter
, global_test_step_counter
, status
, message
);
90 void test_report_progress(const char * message
)
92 #if SHOW_PROGRESS == 1
93 test_report("PROGRESS", message
);
97 void test_report_failure(const char * message
)
99 test_report("FAILED", message
);
102 void test_report_success(const char * message
)
104 test_report("OK", message
);
107 void test_report_description(const char * message
)
109 test_report("TEST DESCRIPTION", message
);
112 void test_report_failure_strerror()
114 test_report_failure((const char*)strerror(errno
));
118 int test_access_preparation()
122 int test_access(int mode
)
124 report_progress("Start test_access");
126 report_progress("R_OK");
128 report_progress("W_OK");
130 report_progress("X_OK");
132 report_progress("F_OK");
141 test_report_description("access existing volume");
143 // access existing volume
144 if (access(existing_volume
, mode
) != 0)
146 test_report_failure_strerror();
147 test_report_failure("Failed accessing existing volume");
150 test_report_success("Accessed existing volume");
151 test_report_success("SUCCESS");
163 test_report_description("access existing directory");
165 // access existing directory
166 if (access(existing_directory
, mode
) != 0)
168 test_report_failure_strerror();
169 test_report_failure("Failed accessing existing directory");
172 test_report_success("Accessed existing directory");
173 test_report_success("SUCCESS");
185 test_report_description("access existing file");
187 // access existing file
188 if (access(existing_file
, mode
) != 0)
190 test_report_failure_strerror();
191 test_report_failure("Failed accessing existing file");
194 test_report_success("Accessed existing file");
195 test_report_success("SUCCESS");
207 test_report_description("access non existing volume");
209 // access non existing volume
210 if (access(non_existing_volume
, mode
) == 0)
212 test_report_failure("This call should fail");
219 test_report_failure_strerror();
220 test_report_failure("Different error expected");
224 test_report_success("Correct error reported");
225 test_report_success("SUCCESS");
237 test_report_description("access non existing directory");
239 // access non existing directory
240 if (access(non_existing_directory
, mode
) == 0)
242 test_report_failure("This call should fail");
249 test_report_failure_strerror();
250 test_report_failure("Different error expected");
254 test_report_success("Correct error reported");
255 test_report_success("SUCCESS");
267 test_report_description("access non existing file");
269 // access non existing file
270 if (access(non_existing_file
, mode
) == 0)
272 test_report_failure("This call should fail");
279 test_report_failure_strerror();
280 test_report_failure("Different error expected");
284 test_report_success("Correct error reported");
285 test_report_success("SUCCESS");
294 int test_access_wrapper(int mode
)
297 return test_access(mode
);
300 int test_single_file_access_modes()
304 /* Manual action required for test. See top of file */
306 report_progress("Start test_file_access_modes");
314 test_report_description("access F_OK for read_only_file");
316 // access F_OK for read_only_file
317 if (access(read_only_file
, F_OK
) != 0)
319 test_report_failure_strerror();
320 test_report_failure("Failed accessing file");
323 test_report_success("File accessed");
324 test_report_success("SUCCESS");
336 test_report_description("access F_OK for write_only_file");
338 // access F_OK for write_only_file
339 if (access(write_only_file
, F_OK
) != 0)
341 test_report_failure_strerror();
342 test_report_failure("Failed accessing file");
345 test_report_success("File accessed");
346 test_report_success("SUCCESS");
358 test_report_description("access F_OK for execute_only_file");
360 // access F_OK for execute_only_file
361 if (access(execute_only_file
, F_OK
) != 0)
363 test_report_failure_strerror();
364 test_report_failure("Failed accessing file");
367 test_report_success("File accessed");
368 test_report_success("SUCCESS");
380 test_report_description("access R_OK for read_only_file");
382 // access R_OK for read_only_file
383 if (access(read_only_file
, R_OK
) != 0)
385 test_report_failure_strerror();
386 test_report_failure("Failed accessing file");
389 test_report_success("File accessed");
390 test_report_success("SUCCESS");
402 test_report_description("access R_OK | W_OK for read_only_file");
404 // access R_OK | W_OK for read_only_file
405 if (access(read_only_file
, R_OK
| W_OK
) != 0)
409 test_report_failure_strerror();
410 test_report_failure("Different error expected");
416 test_report_failure("This operation should fail");
419 test_report_success("Correct error reported");
420 test_report_success("SUCCESS");
432 test_report_description("access R_OK | X_OK for read_only_file");
434 // access R_OK | X_OK for read_only_file
435 if (access(read_only_file
, R_OK
| X_OK
) != 0)
439 test_report_failure_strerror();
440 test_report_failure("Different error expected");
446 test_report_failure("This operation should fail");
449 test_report_success("Correct error reported");
450 test_report_success("SUCCESS");
462 test_report_description("access W_OK for write_only_file");
464 // access W_OK for write_only_file
465 if (access(write_only_file
, W_OK
) != 0)
467 test_report_failure_strerror();
468 test_report_failure("Failed accessing file");
471 test_report_success("File accessed");
472 test_report_success("SUCCESS");
484 test_report_description("access W_OK | R_OK for write_only_file");
486 // access W_OK | R_OK for write_only_file
487 if (access(write_only_file
, W_OK
| R_OK
) != 0)
491 test_report_failure_strerror();
492 test_report_failure("Different error expected");
498 test_report_failure("This operation should fail");
501 test_report_success("Correct error reported");
502 test_report_success("SUCCESS");
514 test_report_description("access W_OK | X_OK for write_only_file");
516 // access W_OK | X_OK for write_only_file
517 if (access(write_only_file
, W_OK
| X_OK
) != 0)
521 test_report_failure_strerror();
522 test_report_failure("Different error expected");
528 test_report_failure("This operation should fail");
531 test_report_success("Correct error reported");
532 test_report_success("SUCCESS");
545 test_report_description("access X_OK for execute_only_file");
547 // access X_OK for execute_only_file
548 if (access(execute_only_file
, X_OK
) != 0)
550 test_report_failure_strerror();
551 test_report_failure("Failed accessing file");
554 test_report_success("File accessed");
555 test_report_success("SUCCESS");
567 test_report_description("access X_OK | R_OK for execute_only_file");
569 // access X_OK | R_OK for execute_only_file
570 if (access(execute_only_file
, X_OK
| R_OK
) != 0)
574 test_report_failure_strerror();
575 test_report_failure("Different error expected");
581 test_report_failure("This operation should fail");
584 test_report_success("Correct error reported");
585 test_report_success("SUCCESS");
597 test_report_description("access X_OK | W_OK for execute_only_file");
599 // access X_OK | W_OK for execute_only_file
600 if (access(execute_only_file
, X_OK
| W_OK
) != 0)
604 test_report_failure_strerror();
605 test_report_failure("Different error expected");
611 test_report_failure("This operation should fail");
614 test_report_success("Correct error reported");
615 test_report_success("SUCCESS");
624 int test_combined_file_access_modes()
628 /* Manual action required for test. See top of file */
630 report_progress("Start test_combined_file_access_modes");
639 test_report_description("access R_OK | W_OK for all_access_file");
641 // access R_OK | W_OK for all_access_file
642 if (access(all_access_file
, R_OK
| W_OK
) != 0)
644 test_report_failure_strerror();
645 test_report_failure("Failed accessing file");
648 test_report_success("File accessed");
649 test_report_success("SUCCESS");
661 test_report_description("access R_OK | X_OK for all_access_file");
663 // access R_OK | X_OK for all_access_file
664 if (access(all_access_file
, R_OK
| X_OK
) != 0)
666 test_report_failure_strerror();
667 test_report_failure("Failed accessing file");
670 test_report_success("File accessed");
671 test_report_success("SUCCESS");
683 test_report_description("access W_OK | X_OK for all_access_file");
685 // access W_OK | X_OK for all_access_file
686 if (access(all_access_file
, W_OK
| X_OK
) != 0)
688 test_report_failure_strerror();
689 test_report_failure("Failed accessing file");
692 test_report_success("File accessed");
693 test_report_success("SUCCESS");
705 test_report_description("access R_OK | W_OK | X_OK for all_access_file");
707 // access R_OK | W_OK | X_OK for all_access_file
708 if (access(all_access_file
, R_OK
| W_OK
| X_OK
) != 0)
710 test_report_failure_strerror();
711 test_report_failure("Failed accessing file");
714 test_report_success("File accessed");
715 test_report_success("SUCCESS");
727 test_report_description("access R_OK | W_OK | X_OK | F_OK for all_access_file");
729 // access R_OK | W_OK | X_OK | F_OK for all_access_file
730 if (access(all_access_file
, R_OK
| W_OK
| X_OK
| F_OK
) != 0)
732 test_report_failure_strerror();
733 test_report_failure("Failed accessing file");
736 test_report_success("File accessed");
737 test_report_success("SUCCESS");
747 report_progress("Starting tests");
749 reset_global_test_counter();
752 if (test_access_wrapper(F_OK
) != 0)
753 global_failure_indicator
= 1;
755 if (test_access_wrapper(R_OK
) != 0)
756 global_failure_indicator
= 1;
758 if (test_access_wrapper(W_OK
) != 0)
759 global_failure_indicator
= 1;
761 if (test_access_wrapper(X_OK
) != 0)
762 global_failure_indicator
= 1;
764 if (test_access_wrapper(R_OK
| W_OK
| X_OK
) != 0)
765 global_failure_indicator
= 1;
767 if (test_single_file_access_modes() != 0)
768 global_failure_indicator
= 1;
770 if (test_combined_file_access_modes() != 0)
771 global_failure_indicator
= 1;
773 if (global_failure_indicator
== 1)
774 report_failure("One of the tests FAILED");
776 report_progress("All tests SUCCEEDED");
778 report_progress("Tests finished");