@@ -49,17 +49,92 @@ static void test_fname_absolute(void)
4949#undef T
5050}
5151
52- static void test_fname_relative (void )
52+ static void test_fname_absolute_with_cache (void )
5353{
5454 struct canonFnameCacheTable * ct ;
55-
55+ bool absoluteOnly ;
5656#define T (INPUT ,OUTPUT ) \
57- if (!TEST_CHECK(strcmp(canonicalizeRelativeFileName (ct, INPUT), \
57+ if (!TEST_CHECK(strcmp(canonicalizeFileName (ct, INPUT), \
5858 OUTPUT) == 0)) \
59- fprintf(stderr, " ACTUAL: %s\n", canonicalizeRelativeFileName (ct, INPUT))
59+ fprintf(stderr, " ACTUAL: %s (%s)\n", canonicalizeFileName (ct, INPUT), absoluteOnly? "absOnly": "relaOK")
60+
61+ absoluteOnly = true;
62+ ct = canonFnameCacheTableNew ("/abc" , absoluteOnly );
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" );
6074
75+ T ("input" , "/abc/input" );
76+ T ("./input" , "/abc/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+ absoluteOnly = true;
88+ ct = canonFnameCacheTableNew ("/abc/efg" , absoluteOnly );
89+ T ("input" , "/abc/efg/input" );
90+ T ("../input" , "/abc/input" );
91+ T ("..//input" , "/abc/input" );
92+ T (".././input" , "/abc/input" );
93+ T ("..//.//input" , "/abc/input" );
94+ T ("../d/input" , "/abc/d/input" );
95+ T ("../d/../input" , "/abc/input" );
96+ T ("../d/..//input" , "/abc/input" );
97+ T ("../d/..///./input" , "/abc/input" );
98+ T ("../d/..///./input/.././input" , "/abc/input" );
99+ T ("" , "/abc/efg" );
100+ T ("." , "/abc/efg" );
101+ T ("./" , "/abc/efg" );
102+ T ("./.." , "/abc" );
103+ T ("./." , "/abc/efg" );
104+ T ("././//" , "/abc/efg" );
105+ T ("././//." , "/abc/efg" );
106+ T ("././../efg/." , "/abc/efg" );
107+ T (".." , "/abc" );
108+ T ("../.." , "/" );
109+ T ("../../" , "/" );
110+ T ("../.." , "/" );
111+ T ("../../.." , "/" );
112+ T ("../../../.." , "/" );
113+ T ("../././.." , "/" );
114+ T ("./././.." , "/abc" );
115+ T ("..." , "/abc/efg/..." );
116+ T (".../" , "/abc/efg/..." );
117+ T ("...//" , "/abc/efg/..." );
118+ T ("..././" , "/abc/efg/..." );
119+ T ("...//./" , "/abc/efg/..." );
120+ T ("...//.//" , "/abc/efg/..." );
121+ T ("..././/" , "/abc/efg/..." );
122+ T ("..././.../" , "/abc/efg/.../..." );
123+ canonFnameCacheTableDelete (ct );
124+ #undef T
125+ }
126+
127+ static void test_fname_relative (void )
128+ {
129+ struct canonFnameCacheTable * ct ;
130+ bool absoluteOnly ;
131+ #define T (INPUT ,OUTPUT ) \
132+ if (!TEST_CHECK(strcmp(canonicalizeFileName (ct, INPUT), \
133+ OUTPUT) == 0)) \
134+ fprintf(stderr, " ACTUAL: %s (%s)\n", canonicalizeFileName (ct, INPUT), absoluteOnly? "absOnly": "relaOK")
61135
62- ct = canonFnameCacheTableNew ("/abc" );
136+ absoluteOnly = false;
137+ ct = canonFnameCacheTableNew ("/abc" , absoluteOnly );
63138 T ("/abc/input" , "/abc/input" );
64139 T ("/abc/../input" , "/input" );
65140 T ("/abc/../../input" , "/input" );
@@ -84,7 +159,8 @@ static void test_fname_relative(void)
84159 T ("../d/..///./input" , "/input" );
85160 canonFnameCacheTableDelete (ct );
86161
87- ct = canonFnameCacheTableNew ("/abc/efg" );
162+ absoluteOnly = false;
163+ ct = canonFnameCacheTableNew ("/abc/efg" , absoluteOnly );
88164 T ("input" , "input" );
89165 T ("../input" , "/abc/input" );
90166 T ("..//input" , "/abc/input" );
@@ -146,6 +222,7 @@ static void test_routines_strrstr(void)
146222
147223TEST_LIST = {
148224 { "fname/absolute" , test_fname_absolute },
225+ { "fname/absolute+cache" , test_fname_absolute_with_cache },
149226 { "fname/relative" , test_fname_relative },
150227 { "htable/update" , test_htable_update },
151228 { "routines/strrstr" , test_routines_strrstr },
0 commit comments