summaryrefslogtreecommitdiff
path: root/tix/tests/general/fs.tcl
blob: d2f1e86ca62b3377b91df860943bd5c1dd41df27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# fs.tcl --
#
#	Test the portable file handling ("FS") routines.
#
# Copyright (c) 1996, Expert Interface Technologies
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

proc About {} {
    return "Testing portable file handling routines"
}

proc Test {} {
    global tixPriv errorInfo

    TestBlock fs-1.1 {tixFSPath command} {
	if {$tixPriv(test:platform) == "windows"} {
	    #   PATHNAME		     expected VPATH result
	    #-------------------------------------------------------
	    set list [list \
	        [list :px:\\C:	      C:\\	0] \
	        [list :px:\\c:	       ""       1] \
	    ]
	    regsub -all :px: $list $tixPriv(WinPrefix) list

	    foreach item "$list" {
		set vpath [lindex $item 0]
		set want  [lindex $item 1]
		set experr [lindex $item 2]
		

		TestBlock fs-1.1.1 "tixFSPath $vpath" {
		    set err [catch {
			set got [tixFSPath $vpath]
		    }]

		    if $experr {
			Assert {$err == $experr}
		    } else {
			Assert {[tixStrEq $want $got]}
		    }
		}
	    }
	}
    }

    TestBlock fs-1.2 {tixFSIsNorm command} {
	if {$tixPriv(test:platform) == "unix"} {

	    #   PATHNAME to TEST		     expected result
	    #-------------------------------------------------------
	    set list {
		{/home/ioi			1}
		{/foo.bar			1}
		{/.../foo			1}
		{/.../foo/bar/...		1}
		{/.../.foo/bar/...		1}
		{/.../.f./bar/...		1}
		{/.../.f./bar/...		1}
		{/..a/...			1}
		{"/. / "			1}
		{//a				0}
		{/a/b/				0}
		{/a/b//				0}
		{/a/b/.				0}
		{a/b				0}
		{a/b/.				0}
		{/./b				0}
		{/../b				0}
		{/../../b			0}
		{/./a/../b/..			0}
		{~ioi				0}
		{/~ioi				1}
		{/				1}
	    }
	} else {
	    set list {
		{C:/				0}
		{foo				0}
		{c:				0}
		{C:				1}
		{C:\\Windows			1}
		{C:\\				0}
		{C:\\..\\Windows		0}
		{C:\\...\\Windows		1}
		{C:\\.../Windows		1}
		{C:\\.\\Windows			0}
		{..				0}
		{..\\..				0}
		{..\\				0}
		{.				0}
		{.\\.				0}
		{.\\				0}
		{C:\\.				0}
		{C:Windows			0}
		{C:\\Windows\\App		1}
		{"C:\\My Programs\\~App"	1}
	    }
	}

	foreach item $list {
	    set text [lindex $item 0]
	    set want [lindex $item 1]


	    TestBlock fs-1.2.1 "tixFSIsNorm $text" {
		Assert {[tixFSIsNorm $text] == $want}
	    }
	}
    }

    TestBlock fs-1.3 {tixFSNormDir command} {
	foreach item [GetCases_FsNormDir] {
	    set text    [lindex $item 0]
	    set want    [lindex $item 1]
	    set wanterr [lindex $item 2]

	    if !$wanterr {
		# Check test case error
		Assert {[tixFSIsNorm $want]}
	    }

	    TestBlock fs-1.3.1 "tixFSNormDir $text" {
		set err [catch {
		    set got [tixFSNormDir $text]
		}]
		
		Assert {$err == $wanterr}
		if {!$err} {
		    Assert {[tixStrEq $want $got]}
		}
	    }
	}
    }

    TestBlock fs-1.4 {tixFSNorm command} {
	set list [GetCases_FSNorm]

	set appPWD [pwd]
	foreach item $list {
	    set text    [lindex $item 0]
	    set context [lindex $item 1]
	    set want    [lindex $item 2]

	    TestBlock fs-1.4.1 "tixFSNorm $context $text" {
		set lst [tixFSNorm $context $text]
		set dir [lindex $lst 1]
		Assert {[tixStrEq $want $dir]}
		Assert {[tixStrEq [pwd] $appPWD]}
	    }
	}
    }

    TestBlock fs-1.5 {tilde handling} {
	if {$tixPriv(test:platform) == "unix"} {
	    set who "nobody"
	    if {[string comp $who "nobody"] == 0} {
		catch {set who [exec whoami]}
	    }
	    if {[string comp $who "nobody"] == 0} {
		catch {set who [exec logname]}
	    }
	    set home /
	    catch {
		set home [glob ~$who]
	    }
	    set list {
		{~$who		{$home		    $home   ""  ""}}
		{~		{$home		    $home   ""  ""}}
		{~/*.*		{$home/*.*	    $home   ""  "*.*"}}
		{"~/*.* *.tcl"	{"$home/*.* *.tcl"  $home   ""  "*.* *.tcl"}}
	    }

	    foreach item $list {
		set item [subst $item]
		set text [lindex $item 0]
		set want [lindex $item 1]

		TestBlock fs-1.5.1 "tixFSNorm \[pwd\] $text" {
		    set list [tixFSNorm [pwd] $text]

		    Assert {
			[tixStrEq [lindex $list 0] [lindex $want 0]] &&
			[tixStrEq [lindex $list 1] [lindex $want 1]] &&
			[tixStrEq [lindex $list 2] [lindex $want 2]] &&
			[tixStrEq [lindex $list 3] [lindex $want 3]]
		    }
		}
	    }
	}
    }

    TestBlock fs-1.6 {tixFSVPath} {
	if {$tixPriv(test:platform) == "unix"} {

	    #   PATHNAME to TEST	    expected     Causes error for
	    #				    result	  tixFSVPath?
	    #----------------------------------------------------------------
	    set list {
		{.				""		1}
		{foo				""		1}
		{./				""		1}
	    }
	} else {
	    set list {
		{.				""		1}
	    }
	    regsub -all ^:px: $list $tixPriv(WinPrefix) list
	}

	# (ToDo): write the test
	#
    }

    TestBlock fs-2.1 {obsolete tests} {
	# Some obsolete test. Should be taken out.
	#
	if {$tixPriv(test:platform) == "unix"} {
	    set home [glob ~]
	    if {$home == "/"} {
		set homeprefix {}
	    } else {
		set homeprefix $home
	    }

	    # it shouldn't do itemname substitution
	    #
	    Assert {[tixFileIntName *] == "*"}
	    Assert {[tixFileIntName ~/*] == "$homeprefix/*"}

	    Assert {[tixFileIntName /home/ioi/../foo/bar/..] == "/home/foo"}
	}
    }
}