00001
00011 #include "op_file.h"
00012
00013 #include <stdlib.h>
00014 #include <unistd.h>
00015 #include <stdio.h>
00016 #include <string.h>
00017 #include <limits.h>
00018
00019 static char * tests[][2] = {
00020 { "/usr/bin/../bin", "/usr/bin" },
00021 { "/../usr/bin/", "/usr/bin" },
00022 { "/../../usr/bin/", "/usr/bin" },
00023 { "/../../usr/bin/.", "/usr/bin" },
00024 { "/../../usr/bin/./", "/usr/bin" },
00025 { "/usr/./bin", "/usr/bin" },
00026 { "/usr/././bin", "/usr/bin" },
00027 { "/usr///", "/usr" },
00028 { "../", "/" },
00029 { "./", "/usr" },
00030 { ".", "/usr" },
00031 { "./../", "/" },
00032 { "bin/../bin/../", "/usr" },
00033 { "../../../../../", "/" },
00034 { "/usr/bin/../../..", "/" },
00035 { "/usr/bin/../../../", "/" },
00036 { "././.", "/usr" },
00037
00038 { "//", "/" },
00039 { "//usr", "/usr" },
00040 { "///", "/" },
00041 { NULL, NULL },
00042 };
00043
00044 int main(void)
00045 {
00046 char tmp[PATH_MAX];
00047 size_t i = 0;
00048
00049 if (chdir("/usr")) {
00050 fprintf(stderr, "chdir(\"/usr\") failed for %s\n", tests[i][0]);
00051 exit(EXIT_FAILURE);
00052 }
00053
00054 while (tests[i][0]) {
00055 if (!realpath(tests[i][0], tmp)) {
00056 fprintf(stderr, "NULL return for %s\n", tests[i][0]);
00057 exit(EXIT_FAILURE);
00058 }
00059
00060 if (strcmp(tmp, tests[i][1])) {
00061 fprintf(stderr, "%s does not match %s given %s\n",
00062 tmp, tests[i][1], tests[i][0]);
00063 exit(EXIT_FAILURE);
00064 }
00065 ++i;
00066 }
00067
00068 return EXIT_SUCCESS;
00069 }