1/** 2 * @file file_tests.c 3 * 4 * @remark Copyright 2002 OProfile authors 5 * @remark Read the file COPYING 6 * 7 * @author John Levon 8 * @author Philippe Elie 9 */ 10 11#include "op_file.h" 12 13#include <stdlib.h> 14#include <unistd.h> 15#include <stdio.h> 16#include <string.h> 17#include <limits.h> 18 19static char * tests[][2] = { 20 { "/usr/bin/../bin", "/usr/bin" }, 21 { "/../usr/bin/", "/usr/bin" }, 22 { "/../../usr/bin/", "/usr/bin" }, 23 { "/../../usr/bin/.", "/usr/bin" }, 24 { "/../../usr/bin/./", "/usr/bin" }, 25 { "/usr/./bin", "/usr/bin" }, 26 { "/usr/././bin", "/usr/bin" }, 27 { "/usr///", "/usr" }, 28 { "../", "/" }, 29 { "./", "/usr" }, 30 { ".", "/usr" }, 31 { "./../", "/" }, 32 { "bin/../bin/../", "/usr" }, 33 { "../../../../../", "/" }, 34 { "/usr/bin/../../..", "/" }, 35 { "/usr/bin/../../../", "/" }, 36 { "././.", "/usr" }, 37 /* POSIX namespace ignored by realpath(3) */ 38 { "//", "/" }, 39 { "//usr", "/usr" }, 40 { "///", "/" }, 41 { NULL, NULL }, 42}; 43 44int main(void) 45{ 46 char tmp[PATH_MAX]; 47 size_t i = 0; 48 49 if (chdir("/usr")) { 50 fprintf(stderr, "chdir(\"/usr\") failed for %s\n", tests[i][0]); 51 exit(EXIT_FAILURE); 52 } 53 54 while (tests[i][0]) { 55 if (!realpath(tests[i][0], tmp)) { 56 fprintf(stderr, "NULL return for %s\n", tests[i][0]); 57 exit(EXIT_FAILURE); 58 } 59 60 if (strcmp(tmp, tests[i][1])) { 61 fprintf(stderr, "%s does not match %s given %s\n", 62 tmp, tests[i][1], tests[i][0]); 63 exit(EXIT_FAILURE); 64 } 65 ++i; 66 } 67 68 return EXIT_SUCCESS; 69} 70