Skip to content

Commit aa377fe

Browse files
committed
tutil: add a case fo testing canonicalizeAbsoluteFileName
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 1658c65 commit aa377fe

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

extra-cmds/utiltest.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,46 @@
88
#include "general.h"
99

1010
#include "acutest.h"
11+
#include "fname.h"
1112
#include "htable.h"
1213
#include "routines.h"
1314
#include <string.h>
1415

16+
static void test_fname_absolute(void)
17+
{
18+
char *str;
19+
char *in;
20+
21+
#define T(INPUT,OUTPUT) \
22+
TEST_CHECK((in = eStrdup (INPUT), \
23+
strcmp((str = canonicalizeAbsoluteFileName (in)), OUTPUT) == 0)); \
24+
eFree (in); \
25+
eFree (str)
26+
27+
T("/abc/efg/..", "/abc");
28+
T("/abc/efg/hij/..", "/abc/efg");
29+
T("/abc/efg/../", "/abc");
30+
T("/abc/efg/./", "/abc/efg");
31+
T("/abc/efg/./../.", "/abc");
32+
T("/abc/..", "/");
33+
34+
T("..", "/");
35+
T(".", "/");
36+
T("a", "/a");
37+
T("abc", "/abc");
38+
T("", "/");
39+
40+
T("../a", "/a");
41+
T("../abc", "/abc");
42+
T("./a", "/a");
43+
T("./abc", "/abc");
44+
T("a/../b", "/b");
45+
T("abc/../efg", "/efg");
46+
47+
T("..//////a", "/a");
48+
T("..//..//..//a", "/a");
49+
}
50+
1551
static void test_htable_update(void)
1652
{
1753
hashTable *htable = hashTableNew (3, hashCstrhash, hashCstreq,
@@ -34,6 +70,7 @@ static void test_routines_strrstr(void)
3470
}
3571

3672
TEST_LIST = {
73+
{ "fname/absolute", test_fname_absolute },
3774
{ "htable/update", test_htable_update },
3875
{ "routines/strrstr", test_routines_strrstr },
3976
{ NULL, NULL } /* zeroed record marking the end of the list */

0 commit comments

Comments
 (0)