6 #define SHOW_PROGRESS 0
9 int global_test_counter
= 0;
10 int global_test_step_counter
= 0;
11 int global_failure_indicator
= 0;
13 /* 2008-03-22 - All test pass (if manual configuration is done correclty) */
15 /* COMPILE WITH '-nix' for unix2amiga path conversion */
17 /* These values are arbitrary and influence test results! */
18 /* Existing objects should have RWED permitions (even the volume!) */
21 const char * existing_volume
= "/Work/";
22 const char * existing_directory
= "/SYS/Classes";
23 const char * existing_file
= "/SYS/Classes/Datatypes/bmp.datatype";
24 const char * non_existing_volume
= "/sw243";
25 const char * non_existing_directory
= "/SYS/sdgfer";
26 const char * non_existing_file
= "/SYS/Classes/ggg.txt";
28 const char * existing_volume
= "/usr";
29 const char * existing_directory
= "/usr/bin";
30 const char * existing_file
= "/usr/bin/gcc";
31 const char * non_existing_volume
= "/sw243";
32 const char * non_existing_directory
= "/usr/sdgfer";
33 const char * non_existing_file
= "/usr/lib/ggg.txt";
36 /* These files need to be prepared in application directory with appriopriate access rights! */
37 const char * read_only_file
= "read_only_file";
38 const char * write_only_file
= "write_only_file";
39 const char * execute_only_file
= "execute_only_file";
40 const char * all_access_file
= "all_access_file";
42 void reset_global_test_counter()
44 global_test_counter
= 0;
45 global_test_step_counter
= 0;
50 global_test_counter
++;
51 global_test_step_counter
= 0;
56 global_test_step_counter
++;
59 // Reporting functions
60 void report(const char * status
, const char * message
)
62 printf("REPORT : %s : %s \n", status
, message
);
65 void report_progress(const char * message
)
67 report("PROGRESS", message
);
70 void report_failure(const char * message
)
72 report("FAILED", message
);
75 void report_failure_strerror()
77 report_failure((const char*)strerror(errno
));
80 void test_report(const char * status
, const char * message
)
82 printf("TEST %d-%d : %s : %s \n", global_test_counter
, global_test_step_counter
, status
, message
);
85 void test_report_progress(const char * message
)
87 #if SHOW_PROGRESS == 1
88 test_report("PROGRESS", message
);
92 void test_report_failure(const char * message
)
94 test_report("FAILED", message
);
97 void test_report_success(const char * message
)
99 test_report("OK", message
);
102 void test_report_description(const char * message
)
104 test_report("TEST DESCRIPTION", message
);
107 void test_report_failure_strerror()
109 test_report_failure((const char*)strerror(errno
));
113 int test_access_preparation()
117 int test_access(int mode
)
119 report_progress("Start test_access");
121 report_progress("R_OK");
123 report_progress("W_OK");
125 report_progress("X_OK");
127 report_progress("F_OK");
136 test_report_description("access existing volume");
138 // access existing volume
139 if (access(existing_volume
, mode
) != 0)
141 test_report_failure_strerror();
142 test_report_failure("Failed accessing existing volume");
145 test_report_success("Accessed existing volume");
146 test_report_success("SUCCESS");
158 test_report_description("access existing directory");
160 // access existing directory
161 if (access(existing_directory
, mode
) != 0)
163 test_report_failure_strerror();
164 test_report_failure("Failed accessing existing directory");
167 test_report_success("Accessed existing directory");
168 test_report_success("SUCCESS");
180 test_report_description("access existing file");
182 // access existing file
183 if (access(existing_file
, mode
) != 0)
185 test_report_failure_strerror();
186 test_report_failure("Failed accessing existing file");
189 test_report_success("Accessed existing file");
190 test_report_success("SUCCESS");
202 test_report_description("access non existing volume");
204 // access non existing volume
205 if (access(non_existing_volume
, mode
) == 0)
207 test_report_failure("This call should fail");
214 test_report_failure_strerror();
215 test_report_failure("Different error expected");
219 test_report_success("Correct error reported");
220 test_report_success("SUCCESS");
232 test_report_description("access non existing directory");
234 // access non existing directory
235 if (access(non_existing_directory
, mode
) == 0)
237 test_report_failure("This call should fail");
244 test_report_failure_strerror();
245 test_report_failure("Different error expected");
249 test_report_success("Correct error reported");
250 test_report_success("SUCCESS");
262 test_report_description("access non existing file");
264 // access non existing file
265 if (access(non_existing_file
, mode
) == 0)
267 test_report_failure("This call should fail");
274 test_report_failure_strerror();
275 test_report_failure("Different error expected");
279 test_report_success("Correct error reported");
280 test_report_success("SUCCESS");
289 int test_access_wrapper(int mode
)
292 return test_access(mode
);
295 int test_single_file_access_modes()
299 /* Manual action required for test. See top of file */
301 report_progress("Start test_file_access_modes");
309 test_report_description("access F_OK for read_only_file");
311 // access F_OK for read_only_file
312 if (access(read_only_file
, F_OK
) != 0)
314 test_report_failure_strerror();
315 test_report_failure("Failed accessing file");
318 test_report_success("File accessed");
319 test_report_success("SUCCESS");
331 test_report_description("access F_OK for write_only_file");
333 // access F_OK for write_only_file
334 if (access(write_only_file
, F_OK
) != 0)
336 test_report_failure_strerror();
337 test_report_failure("Failed accessing file");
340 test_report_success("File accessed");
341 test_report_success("SUCCESS");
353 test_report_description("access F_OK for execute_only_file");
355 // access F_OK for execute_only_file
356 if (access(execute_only_file
, F_OK
) != 0)
358 test_report_failure_strerror();
359 test_report_failure("Failed accessing file");
362 test_report_success("File accessed");
363 test_report_success("SUCCESS");
375 test_report_description("access R_OK for read_only_file");
377 // access R_OK for read_only_file
378 if (access(read_only_file
, R_OK
) != 0)
380 test_report_failure_strerror();
381 test_report_failure("Failed accessing file");
384 test_report_success("File accessed");
385 test_report_success("SUCCESS");
397 test_report_description("access R_OK | W_OK for read_only_file");
399 // access R_OK | W_OK for read_only_file
400 if (access(read_only_file
, R_OK
| W_OK
) != 0)
404 test_report_failure_strerror();
405 test_report_failure("Different error expected");
411 test_report_failure("This operation should fail");
414 test_report_success("Correct error reported");
415 test_report_success("SUCCESS");
427 test_report_description("access R_OK | X_OK for read_only_file");
429 // access R_OK | X_OK for read_only_file
430 if (access(read_only_file
, R_OK
| X_OK
) != 0)
434 test_report_failure_strerror();
435 test_report_failure("Different error expected");
441 test_report_failure("This operation should fail");
444 test_report_success("Correct error reported");
445 test_report_success("SUCCESS");
457 test_report_description("access W_OK for write_only_file");
459 // access W_OK for write_only_file
460 if (access(write_only_file
, W_OK
) != 0)
462 test_report_failure_strerror();
463 test_report_failure("Failed accessing file");
466 test_report_success("File accessed");
467 test_report_success("SUCCESS");
479 test_report_description("access W_OK | R_OK for write_only_file");
481 // access W_OK | R_OK for write_only_file
482 if (access(write_only_file
, W_OK
| R_OK
) != 0)
486 test_report_failure_strerror();
487 test_report_failure("Different error expected");
493 test_report_failure("This operation should fail");
496 test_report_success("Correct error reported");
497 test_report_success("SUCCESS");
509 test_report_description("access W_OK | X_OK for write_only_file");
511 // access W_OK | X_OK for write_only_file
512 if (access(write_only_file
, W_OK
| X_OK
) != 0)
516 test_report_failure_strerror();
517 test_report_failure("Different error expected");
523 test_report_failure("This operation should fail");
526 test_report_success("Correct error reported");
527 test_report_success("SUCCESS");
540 test_report_description("access X_OK for execute_only_file");
542 // access X_OK for execute_only_file
543 if (access(execute_only_file
, X_OK
) != 0)
545 test_report_failure_strerror();
546 test_report_failure("Failed accessing file");
549 test_report_success("File accessed");
550 test_report_success("SUCCESS");
562 test_report_description("access X_OK | R_OK for execute_only_file");
564 // access X_OK | R_OK for execute_only_file
565 if (access(execute_only_file
, X_OK
| R_OK
) != 0)
569 test_report_failure_strerror();
570 test_report_failure("Different error expected");
576 test_report_failure("This operation should fail");
579 test_report_success("Correct error reported");
580 test_report_success("SUCCESS");
592 test_report_description("access X_OK | W_OK for execute_only_file");
594 // access X_OK | W_OK for execute_only_file
595 if (access(execute_only_file
, X_OK
| W_OK
) != 0)
599 test_report_failure_strerror();
600 test_report_failure("Different error expected");
606 test_report_failure("This operation should fail");
609 test_report_success("Correct error reported");
610 test_report_success("SUCCESS");
619 int test_combined_file_access_modes()
623 /* Manual action required for test. See top of file */
625 report_progress("Start test_combined_file_access_modes");
634 test_report_description("access R_OK | W_OK for all_access_file");
636 // access R_OK | W_OK for all_access_file
637 if (access(all_access_file
, R_OK
| W_OK
) != 0)
639 test_report_failure_strerror();
640 test_report_failure("Failed accessing file");
643 test_report_success("File accessed");
644 test_report_success("SUCCESS");
656 test_report_description("access R_OK | X_OK for all_access_file");
658 // access R_OK | X_OK for all_access_file
659 if (access(all_access_file
, R_OK
| X_OK
) != 0)
661 test_report_failure_strerror();
662 test_report_failure("Failed accessing file");
665 test_report_success("File accessed");
666 test_report_success("SUCCESS");
678 test_report_description("access W_OK | X_OK for all_access_file");
680 // access W_OK | X_OK for all_access_file
681 if (access(all_access_file
, W_OK
| X_OK
) != 0)
683 test_report_failure_strerror();
684 test_report_failure("Failed accessing file");
687 test_report_success("File accessed");
688 test_report_success("SUCCESS");
700 test_report_description("access R_OK | W_OK | X_OK for all_access_file");
702 // access R_OK | W_OK | X_OK for all_access_file
703 if (access(all_access_file
, R_OK
| W_OK
| X_OK
) != 0)
705 test_report_failure_strerror();
706 test_report_failure("Failed accessing file");
709 test_report_success("File accessed");
710 test_report_success("SUCCESS");
722 test_report_description("access R_OK | W_OK | X_OK | F_OK for all_access_file");
724 // access R_OK | W_OK | X_OK | F_OK for all_access_file
725 if (access(all_access_file
, R_OK
| W_OK
| X_OK
| F_OK
) != 0)
727 test_report_failure_strerror();
728 test_report_failure("Failed accessing file");
731 test_report_success("File accessed");
732 test_report_success("SUCCESS");
742 report_progress("Starting tests");
744 reset_global_test_counter();
747 if (test_access_wrapper(F_OK
) != 0)
748 global_failure_indicator
= 1;
750 if (test_access_wrapper(R_OK
) != 0)
751 global_failure_indicator
= 1;
753 if (test_access_wrapper(W_OK
) != 0)
754 global_failure_indicator
= 1;
756 if (test_access_wrapper(X_OK
) != 0)
757 global_failure_indicator
= 1;
759 if (test_access_wrapper(R_OK
| W_OK
| X_OK
) != 0)
760 global_failure_indicator
= 1;
762 if (test_single_file_access_modes() != 0)
763 global_failure_indicator
= 1;
765 if (test_combined_file_access_modes() != 0)
766 global_failure_indicator
= 1;
768 if (global_failure_indicator
== 1)
769 report_failure("One of the tests FAILED");
771 report_progress("All tests SUCCEEDED");
773 report_progress("Tests finished");