@@ -49,6 +49,80 @@ static void test_fname_absolute(void)
4949#undef T
5050}
5151
52+ static void test_fname_relative (void )
53+ {
54+ struct canonFnameCacheTable * ct ;
55+
56+ #define T (INPUT ,OUTPUT ) \
57+ if (!TEST_CHECK(strcmp(canonicalizeRelativeFileName (ct, INPUT), \
58+ OUTPUT) == 0)) \
59+ fprintf(stderr, " ACTUAL: %s\n", canonicalizeRelativeFileName (ct, INPUT))
60+
61+
62+ ct = canonFnameCacheTableNew ("/abc" );
63+ T ("/abc/input" , "/abc/input" );
64+ T ("/abc/../input" , "/input" );
65+ T ("/abc/../../input" , "/input" );
66+ T ("/abc/.././../input" , "/input" );
67+ T ("/abc/./input" , "/abc/input" );
68+ T ("/abc/.//input" , "/abc/input" );
69+ T ("/abc/.//.//input" , "/abc/input" );
70+ T ("/input" , "/input" );
71+ T ("/./input" , "/input" );
72+ T ("/../z/../input" , "/input" );
73+ T ("/../z/../..input" , "/..input" );
74+
75+ T ("input" , "input" );
76+ T ("./input" , "input" );
77+ T ("../input" , "/input" );
78+ T ("..//input" , "/input" );
79+ T (".././input" , "/input" );
80+ T ("..//.//input" , "/input" );
81+ T ("../d/input" , "/d/input" );
82+ T ("../d/../input" , "/input" );
83+ T ("../d/..//input" , "/input" );
84+ T ("../d/..///./input" , "/input" );
85+ canonFnameCacheTableDelete (ct );
86+
87+ ct = canonFnameCacheTableNew ("/abc/efg" );
88+ T ("input" , "input" );
89+ T ("../input" , "/abc/input" );
90+ T ("..//input" , "/abc/input" );
91+ T (".././input" , "/abc/input" );
92+ T ("..//.//input" , "/abc/input" );
93+ T ("../d/input" , "/abc/d/input" );
94+ T ("../d/../input" , "/abc/input" );
95+ T ("../d/..//input" , "/abc/input" );
96+ T ("../d/..///./input" , "/abc/input" );
97+ T ("../d/..///./input/.././input" , "/abc/input" );
98+ T ("" , "." );
99+ T ("." , "." );
100+ T ("./" , "." );
101+ T ("./.." , "/abc" );
102+ T ("./." , "." );
103+ T ("././//" , "." );
104+ T ("././//." , "." );
105+ T ("././../efg/." , "." );
106+ T (".." , "/abc" );
107+ T ("../.." , "/" );
108+ T ("../../" , "/" );
109+ T ("../.." , "/" );
110+ T ("../../.." , "/" );
111+ T ("../../../.." , "/" );
112+ T ("../././.." , "/" );
113+ T ("./././.." , "/abc" );
114+ T ("..." , "..." );
115+ T (".../" , "..." );
116+ T ("...//" , "..." );
117+ T ("..././" , "..." );
118+ T ("...//./" , "..." );
119+ T ("...//.//" , "..." );
120+ T ("..././/" , "..." );
121+ T ("..././.../" , ".../..." );
122+ canonFnameCacheTableDelete (ct );
123+ #undef T
124+ }
125+
52126static void test_htable_update (void )
53127{
54128 hashTable * htable = hashTableNew (3 , hashCstrhash , hashCstreq ,
@@ -72,6 +146,7 @@ static void test_routines_strrstr(void)
72146
73147TEST_LIST = {
74148 { "fname/absolute" , test_fname_absolute },
149+ { "fname/relative" , test_fname_relative },
75150 { "htable/update" , test_htable_update },
76151 { "routines/strrstr" , test_routines_strrstr },
77152 { NULL , NULL } /* zeroed record marking the end of the list */
0 commit comments