1#
2# chmod.test
3#
4# Tests for the chmod, chown and chgrp commands.
5#---------------------------------------------------------------------------
6# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
7#
8# Permission to use, copy, modify, and distribute this software and its
9# documentation for any purpose and without fee is hereby granted, provided
10# that the above copyright notice appear in all copies.  Karl Lehenbauer and
11# Mark Diekhans make no representations about the suitability of this
12# software for any purpose.  It is provided "as is" without express or
13# implied warranty.
14#------------------------------------------------------------------------------
15# $Id: chmod.test,v 1.3 2002/04/04 06:10:30 hobbs Exp $
16#------------------------------------------------------------------------------
17#
18
19if {[lsearch [namespace children] ::tcltest] == -1} {
20    package require tcltest
21    namespace import ::tcltest::*
22}
23
24if {[cequal [info procs Test] {}]} {
25    source [file join [file dirname [info script]] testlib.tcl]
26}
27
28if [cequal $tcl_platform(platform) windows] {
29    echo "    * The chmod, chown and chgrp commands have not been ported to Win32" 
30    return
31}
32
33#-----------------------------------------------------------------------------
34# This routine to the the mode of a file.  It is returned formated in octal.
35 
36proc GetMode {filename} {
37    file stat $filename stat
38    return [format "%o" [expr {$stat(mode) & 07777}]]
39}
40
41#-----------------------------------------------------------------------------
42# Certain Unix systems don't handle chmod the same.  This routine test if the
43# system chmod produces the expected results.
44#   o mode - symbolic mode to set the file to.
45#   o args - list of valid expected result from ls.
46#
47proc CheckChmod {mode args} {
48    global chmodTestsSkipped
49
50    set stat 0
51    if {[catch {
52        chmod 000 CHECK.TMP
53        exec chmod $mode CHECK.TMP
54        set sysMode [lindex [exec ls -l CHECK.TMP] 0]
55    }] == 0} {
56        if {[lsearch -exact $args $sysMode] >= 0} {
57            set stat 1
58        }
59    }
60    if !$stat {
61        incr chmodTestsSkipped
62    }
63    return $stat
64}
65
66global chmodTestsSkipped
67set chmodTestsSkipped 0
68
69#-----------------------------------------------------------------------------
70# Procedure to return the uid of a file.
71
72proc GetUID {file} {
73    file stat $file stat
74    return $stat(uid)
75}
76
77#-----------------------------------------------------------------------------
78# Procedure to return the gid of a file.
79
80proc GetGID {file} {
81    file stat $file stat
82    return $stat(gid)
83}
84
85#-----------------------------------------------------------------------------
86# Procedure to return the uid and gid of a file.
87
88proc GetUIDGID {file} {
89    file stat $file stat
90    return [list $stat(uid) $stat(gid)]
91}
92
93
94#-----------------------------------------------------------------------------
95# If a user does not have a group name assigned, then some tests will not work,
96# just blow off the tests and let the user make things right. 
97
98if {[catch {id group}] != 0} {
99    echo "User '[id user]' does not have group name. Chmod tests skipped"
100    return
101}
102
103#-----------------------------------------------------------------------------
104# Purge existing test files and recreate them.
105#
106proc SetUpTestFiles {} {
107    foreach f {CHECK.TMP CHMOD.TMP CHMOD2.TMP} {
108        catch {
109            chmod a+w $f
110            file delete $f
111        }
112        close [open $f w]
113    }
114}
115
116SetUpTestFiles
117
118# Set the umask so that no bits are masked.  Some system chmods use umask
119# if u, g, o or a are not specified in a symbolic chmod.
120
121umask 000
122
123test chmod-1.1 {chmod absolute mode tests} {
124    chmod 0000 CHMOD.TMP
125    chmod 0101 CHMOD.TMP
126    GetMode    CHMOD.TMP
127} {101}
128
129test chmod-1.2 {chmod absolute mode tests} {
130    chmod 0000 CHMOD.TMP
131    chmod 0010 CHMOD.TMP
132    GetMode    CHMOD.TMP
133} {10}
134
135test chmod-1.3 {chmod absolute mode tests} {
136    chmod 0000 CHMOD.TMP
137    chmod 0777 CHMOD.TMP
138    GetMode    CHMOD.TMP
139} {777}
140
141test chmod-1.4 {chmod absolute mode tests} {
142    chmod 0000 CHMOD.TMP
143    chmod 0666 CHMOD.TMP
144    GetMode    CHMOD.TMP
145} {666}
146
147test chmod-1.5 {chmod absolute mode tests} {
148    chmod 0000 CHMOD.TMP
149    chmod 0705 CHMOD.TMP
150    GetMode    CHMOD.TMP
151} {705}
152
153test chmod-1.7 {chmod absolute mode tests} {
154    chmod  0000 CHMOD.TMP
155    chmod 04111 CHMOD.TMP
156    GetMode     CHMOD.TMP
157} {4111}
158
159test chmod-1.9 {chmod absolute mode tests} {need_fchmod} {
160    chmod 0600 CHMOD.TMP
161    set fh [open CHMOD.TMP w]
162    chmod -fileid 0000 $fh
163    chmod -fileid 0101 $fh
164    close $fh
165    GetMode CHMOD.TMP
166} {101}
167
168test chmod-1.10 {chmod absolute mode tests} {need_fchmod} {
169    chmod 0600 CHMOD.TMP
170    set fh [open CHMOD.TMP w]
171    chmod -fileid 0000 $fh
172    chmod -fileid 0010 $fh
173    close $fh
174    GetMode CHMOD.TMP
175} {10}
176
177test chmod-1.11 {chmod absolute mode tests} {need_fchmod} {
178    chmod 0600 CHMOD.TMP
179    set fh [open CHMOD.TMP w]
180    chmod -fileid 0000 $fh
181    chmod -fileid 0777 $fh
182    close $fh
183    GetMode CHMOD.TMP
184} {777}
185
186test chmod-1.12 {chmod absolute mode tests} {need_fchmod} {
187    chmod 0600 CHMOD.TMP
188    set fh [open CHMOD.TMP w]
189    chmod -fileid 0000 $fh
190    chmod -fileid 0666 $fh
191    close $fh
192    GetMode CHMOD.TMP
193} {666}
194
195test chmod-1.13 {chmod absolute mode tests} {need_fchmod} {
196    chmod 0600 CHMOD.TMP
197    set fh [open CHMOD.TMP w]
198    chmod -fileid 0000 $fh
199    chmod -fileid 0705 $fh
200    close $fh
201    GetMode CHMOD.TMP
202} {705}
203
204test chmod-1.14 {chmod absolute mode tests} {need_fchmod} {
205    chmod 0600 CHMOD.TMP
206    set fh [open CHMOD.TMP w]
207    chmod -fileid 0000 $fh
208    chmod -fileid 04111 $fh
209    close $fh
210    GetMode CHMOD.TMP
211} {4111}
212
213test chmod-2.1 {chmod absolute integer mode tests} {
214    chmod   0 {CHMOD.TMP CHMOD2.TMP}
215    chmod  65 {CHMOD.TMP CHMOD2.TMP}
216    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
217} {101 101}
218
219test chmod-2.2 {chmod absolute integer mode tests} {
220    chmod 0 {CHMOD.TMP CHMOD2.TMP}
221    chmod 8 {CHMOD.TMP CHMOD2.TMP}
222    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
223} {10 10}
224
225test chmod-2.3 {chmod absolute integer mode tests} {
226    chmod   0 {CHMOD.TMP CHMOD2.TMP}
227    chmod 511 {CHMOD.TMP CHMOD2.TMP}
228    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
229} {777 777}
230
231test chmod-2.4 {chmod absolute integer mode tests} {
232    chmod   0 {CHMOD.TMP CHMOD2.TMP}
233    chmod 438 {CHMOD.TMP CHMOD2.TMP}
234    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
235} {666 666}
236
237test chmod-2.5 {chmod absolute integer mode tests} {
238    chmod   0 {CHMOD.TMP CHMOD2.TMP}
239    chmod 453 {CHMOD.TMP  CHMOD2.TMP}
240    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
241} {705 705}
242
243test chmod-2.6 {chmod absolute integer mode tests} {
244    chmod 0    CHMOD.TMP
245    chmod 2121 CHMOD.TMP
246    GetMode    CHMOD.TMP
247} {4111}
248
249test chmod-2.7 {chmod absolute integer mode tests} {need_fchmod} {
250    chmod 0600 {CHMOD.TMP CHMOD2.TMP}
251    set fh1 [open CHMOD.TMP w]
252    set fh2 [open CHMOD2.TMP w]
253    chmod -fileid   0 [list $fh1 $fh2]
254    chmod -fileid  65 [list $fh1 $fh2]
255    close $fh1
256    close $fh2
257    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
258} {101 101}
259
260test chmod-2.8 {chmod absolute integer mode tests} {need_fchmod} {
261    chmod 0600 {CHMOD.TMP CHMOD2.TMP}
262    set fh1 [open CHMOD.TMP w]
263    set fh2 [open CHMOD2.TMP w]
264    chmod -fileid 0 [list $fh1 $fh2]
265    chmod -fileid 8 [list $fh1 $fh2]
266    close $fh1
267    close $fh2
268    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
269} {10 10}
270
271test chmod-2.9 {chmod absolute integer mode tests} {need_fchmod} {
272    chmod 0600 {CHMOD.TMP CHMOD2.TMP}
273    set fh1 [open CHMOD.TMP w]
274    set fh2 [open CHMOD2.TMP w]
275    chmod -fileid   0 [list $fh1 $fh2]
276    chmod -fileid 511 [list $fh1 $fh2]
277    close $fh1
278    close $fh2
279    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
280} {777 777}
281
282test chmod-2.10 {chmod absolute integer mode tests} {need_fchmod} {
283    chmod 0600 {CHMOD.TMP CHMOD2.TMP}
284    set fh1 [open CHMOD.TMP w]
285    set fh2 [open CHMOD2.TMP w]
286    chmod -fileid   0 [list $fh1 $fh2]
287    chmod -fileid 438 [list $fh1 $fh2]
288    close $fh1
289    close $fh2
290    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
291} {666 666}
292
293test chmod-2.11 {chmod absolute integer mode tests} {need_fchmod} {
294    chmod 0600 {CHMOD.TMP CHMOD2.TMP}
295    set fh1 [open CHMOD.TMP w]
296    set fh2 [open CHMOD2.TMP w]
297    chmod -fileid   0 [list $fh1 $fh2]
298    chmod -fileid 453 [list $fh1 $fh2]
299    close $fh1
300    close $fh2
301    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
302} {705 705}
303
304test chmod-2.12 {chmod absolute integer mode tests} {need_fchmod} {
305    chmod 0600 {CHMOD.TMP CHMOD2.TMP}
306    set fh [open CHMOD.TMP w]
307    chmod -fileid 0    $fh
308    chmod -fileid 2121 $fh
309    close $fh
310    GetMode CHMOD.TMP
311} {4111}
312
313# Test symbolic mode.
314
315test chmod-3.1 {chmod symbolic mode tests} {
316    chmod 000 CHMOD.TMP
317    chmod +r  CHMOD.TMP
318    GetMode   CHMOD.TMP
319} {444}
320
321test chmod-3.2 {chmod symbolic mode tests} {
322    chmod 000 CHMOD.TMP
323    chmod +r  CHMOD.TMP
324    chmod +w  CHMOD.TMP
325    GetMode   CHMOD.TMP
326} {666}
327
328test chmod-3.3 {chmod symbolic mode tests} {
329    chmod 000 CHMOD.TMP
330    chmod +r  CHMOD.TMP
331    chmod +w  CHMOD.TMP
332    chmod +x  CHMOD.TMP
333    GetMode   CHMOD.TMP
334} {777}
335
336test chmod-3.4 {chmod symbolic mode tests} {
337    chmod 000 CHMOD.TMP
338    chmod +r  CHMOD.TMP
339    chmod +w  CHMOD.TMP
340    chmod +x  CHMOD.TMP
341    chmod -r  CHMOD.TMP
342    GetMode   CHMOD.TMP
343} {333}
344
345test chmod-3.5 {chmod symbolic mode tests} {
346    chmod 000 CHMOD.TMP
347    chmod +r  CHMOD.TMP
348    chmod +w  CHMOD.TMP
349    chmod +x  CHMOD.TMP
350    chmod -r  CHMOD.TMP
351    chmod -w  CHMOD.TMP
352    GetMode   CHMOD.TMP
353} {111}
354
355test chmod-3.6 {chmod symbolic mode tests} {
356    chmod 000 {CHMOD.TMP CHMOD2.TMP}
357    chmod +r  {CHMOD.TMP CHMOD2.TMP}
358    chmod +w  {CHMOD.TMP CHMOD2.TMP}
359    chmod +x  {CHMOD.TMP CHMOD2.TMP}
360    chmod -r  {CHMOD.TMP CHMOD2.TMP}
361    chmod -w  {CHMOD.TMP CHMOD2.TMP}
362    chmod -x  {CHMOD.TMP  CHMOD2.TMP}
363    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
364} {0 0}
365
366test chmod-3.7 {chmod symbolic mode tests} {
367    chmod 000     CHMOD.TMP
368    chmod u+x,g+x CHMOD.TMP
369    GetMode       CHMOD.TMP
370} {110}
371
372test chmod-3.8 {chmod symbolic mode tests} {
373    chmod 000     {CHMOD.TMP CHMOD2.TMP}
374    chmod u+x,g+x {CHMOD.TMP CHMOD2.TMP}
375    chmod u-x,g-x {CHMOD.TMP CHMOD2.TMP}
376    list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
377} {0 0}
378
379# Can't +s on some systems
380
381if [CheckChmod "ugo+x,ug+s" "---s--s--x"] {
382    test chmod-3.9 {chmod symbolic mode tests} {
383        chmod 000        CHMOD.TMP
384        chmod ugo+x,ug+s CHMOD.TMP
385        GetMode          CHMOD.TMP
386    } {6111}
387}
388
389test chmod-3.10 {chmod symbolic mode tests} {
390    chmod 000   CHMOD.TMP
391    chmod a+rwx CHMOD.TMP
392    GetMode     CHMOD.TMP
393} {777}
394
395test chmod-3.11 {chmod symbolic mode tests} {
396    chmod 000   CHMOD.TMP
397    chmod a+rwx CHMOD.TMP
398    chmod a-rw  CHMOD.TMP
399    GetMode     CHMOD.TMP
400} {111}
401
402test chmod-3.12 {chmod symbolic mode tests} {
403    chmod 000   CHMOD.TMP
404    chmod a=rwx CHMOD.TMP
405    GetMode     CHMOD.TMP
406} {777}
407
408test chmod-3.13 {chmod symbolic mode tests} {
409    chmod 000         CHMOD.TMP
410    chmod u=rwx,go=rx CHMOD.TMP
411    GetMode           CHMOD.TMP
412} {755}
413
414test chmod-3.14 {chmod symbolic mode tests} {need_fchmod} {
415    chmod 0600 CHMOD.TMP
416    set fh [open CHMOD.TMP w]
417    chmod -fileid 000 $fh
418    chmod -fileid +r  $fh
419    close $fh
420    GetMode   CHMOD.TMP
421} {444}
422
423test chmod-3.2 {chmod symbolic mode tests} {need_fchmod} {
424    chmod 0600 CHMOD.TMP
425    set fh [open CHMOD.TMP w]
426    chmod -fileid 000 $fh
427    chmod -fileid +r  $fh
428    chmod -fileid +w  $fh
429    close $fh
430    GetMode   CHMOD.TMP
431} {666}
432
433test chmod-3.15 {chmod symbolic mode tests} {need_fchmod} {
434    chmod 0600 CHMOD.TMP
435    set fh [open CHMOD.TMP w]
436    chmod -fileid 000 $fh
437    chmod -fileid +r  $fh
438    chmod -fileid +w  $fh
439    chmod -fileid +x  $fh
440    close $fh
441    GetMode   CHMOD.TMP
442} {777}
443
444test chmod-3.16 {chmod symbolic mode tests} {need_fchmod} {
445    chmod 0600 CHMOD.TMP
446    set fh [open CHMOD.TMP w]
447    chmod -fileid 000 $fh
448    chmod -fileid +r  $fh
449    chmod -fileid +w  $fh
450    chmod -fileid +x  $fh
451    chmod -fileid -r  $fh
452    close $fh
453    GetMode   CHMOD.TMP
454} {333}
455
456test chmod-3.17 {chmod symbolic mode tests} {need_fchmod} {
457    chmod 0600 CHMOD.TMP
458    set fh [open CHMOD.TMP w]
459    chmod -fileid 000 $fh
460    chmod -fileid +r  $fh
461    chmod -fileid +w  $fh
462    chmod -fileid +x  $fh
463    chmod -fileid -r  $fh
464    chmod -fileid -w  $fh
465    close $fh
466    GetMode   CHMOD.TMP
467} {111}
468
469# +t is dificult to test if not root, just make sure it execute and hope
470# for the best.  Doesn't even work on some systems
471
472if [CheckChmod "u+t" "----------" "---------T"] {
473
474    test chmod-3.14 {chmod symbolic mode tests} {
475        chmod 000 CHMOD.TMP
476        chmod u+x CHMOD.TMP
477        chmod u+t CHMOD.TMP
478        set mode [GetMode CHMOD.TMP]
479        expr "($mode == 100) || ($mode == 1100)"
480    } {1}
481
482    test chmod-3.14 {chmod symbolic mode tests} {
483        chmod 000 CHMOD.TMP
484        chmod u+x CHMOD.TMP
485        chmod u+t CHMOD.TMP
486    } {}
487
488    test chmod-3.15 {chmod symbolic mode tests} {
489        chmod 000   CHMOD.TMP
490        chmod u+x   CHMOD.TMP
491        chmod u+t   CHMOD.TMP
492        chmod u-t   CHMOD.TMP
493    } {}
494}
495
496test chmod-3.16 {chmod symbolic mode tests} {
497    chmod 000         CHMOD.TMP
498    chmod a+rwx       CHMOD.TMP
499    chmod u-r,g-w,o-x CHMOD.TMP
500    GetMode           CHMOD.TMP
501} {356}
502
503test chmod-4.1 {chmod error tests} {
504    list [catch {chmod +z CHMOD.TMP} msg] $msg
505} {1 {invalid file mode "+z"}}
506
507test chmod-4.2 {chmod error tests} {
508    list [catch {chmod} msg] $msg
509} {1 {wrong # args: chmod [-fileid] mode filelist}}
510
511test chmod-4.3 {chmod error tests} {need_fchmod} {
512    list [catch {chmod -fileid +w BAD} msg] $msg
513} {1 {can not find channel named "BAD"}}
514
515test chmod-4.4 {chmod error tests} {need_fchmod} {
516    list [catch {chmod -file -w CHMOD.TMP} msg] $msg
517} {1 {wrong # args: chmod [-fileid] mode filelist}}
518
519# chown and chgrp tests
520
521set myUID [id userid]
522set myGID [id groupid]
523
524
525#
526# Some machines have problems with changing group ids on files (even to your
527# own) if you are not root. On some it works for chown but not fchown (Ultix).
528#
529
530SetUpTestFiles
531
532set ::tcltest::testConstraints(chownWorks) 1
533if {[catch {chown [id userid]  CHMOD.TMP} msg ] ||
534    [catch {chgrp [id groupid] CHMOD.TMP} msg ]} {
535    puts "********************************************************************"
536    puts "Can't do chown or chgrp even when current and new group id are"
537    puts "ours.  You probably have to be root.  Some chown/chgrp tests skipped"
538    puts "on this system."
539    puts "    $msg"
540    puts "********************************************************************"
541    set ::tcltest::testConstraints(chownWorks) 0
542}
543
544if [infox have_fchown] {
545    set ::tcltest::testConstraints(fchownWorks) 1
546    set fh [open CHMOD.TMP w]
547    if {[catch {chown -fileid [id userid]  $fh} msg ] ||
548        [catch {chgrp -fileid [id groupid] $fh} msg ]} {
549        puts "****************************************************************"
550        puts "Can't do chown or chgrp with -fileid even when current and new"
551        puts "groupid are ours. You probably have to be root. Some chown/chgrp"
552        puts "tests skipped on this system."
553        puts "    $msg"
554        puts "****************************************************************"
555        set ::tcltest::testConstraints(fchownWorks) 0
556    }
557    close $fh
558}
559
560test chmod-5.1 {chown tests} {chownWorks} {
561    SetUpTestFiles
562    chown [id user] {CHMOD.TMP CHMOD2.TMP}
563    list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
564} [list $myUID $myUID]
565
566test chmod-5.2 {chown tests} {chownWorks} {
567    chown [id userid] {CHMOD.TMP CHMOD2.TMP}
568    list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
569} [list $myUID $myUID]
570
571test chmod-5.3 {chown tests} {chownWorks} {
572    chown [list [id userid] [id groupid]] {CHMOD.TMP CHMOD2.TMP}
573    list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
574} [list [list $myUID $myGID] [list $myUID $myGID]]
575
576test chmod-5.4 {chown tests} {chownWorks} {
577    chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
578    list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
579} [list [list $myUID $myGID] [list $myUID $myGID]]
580
581test chmod-5.5 {chown tests} {chownWorks} {
582    chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
583    list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
584} [list [list $myUID $myGID] [list $myUID $myGID]]
585
586test chmod-5.6 {chown tests} {need_fchown && fchownWorks} {
587    SetUpTestFiles
588    set fh1 [open CHMOD.TMP w]
589    set fh2 [open CHMOD2.TMP w]
590    chown -fileid [id user] [list $fh1 $fh2]
591    close $fh1
592    close $fh2
593    list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
594} [list $myUID $myUID]
595
596test chmod-5.7 {chown tests} {need_fchown && fchownWorks} {
597    set fh1 [open CHMOD.TMP w]
598    set fh2 [open CHMOD2.TMP w]
599    chown -fileid [id userid] [list $fh1 $fh2]
600    close $fh1
601    close $fh2
602    list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
603} [list $myUID $myUID]
604
605test chmod-5.8 {chown tests} {need_fchown && fchownWorks} {
606    set fh1 [open CHMOD.TMP w]
607    set fh2 [open CHMOD2.TMP w]
608    chown -fileid [list [id userid] [id groupid]] [list $fh1 $fh2]
609    close $fh1
610    close $fh2
611    list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
612} [list [list $myUID $myGID] [list $myUID $myGID]]
613
614test chmod-5.9 {chown tests} {need_fchown && fchownWorks} {
615    set fh1 [open CHMOD.TMP w]
616    set fh2 [open CHMOD2.TMP w]
617    chown -fileid [list [id user] [id group]] [list $fh1 $fh2]
618    close $fh1
619    close $fh2
620    list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
621} [list [list $myUID $myGID] [list $myUID $myGID]]
622
623test chmod-5.10 {chown tests} {need_fchown && fchownWorks} {
624    set fh1 [open CHMOD.TMP w]
625    set fh2 [open CHMOD2.TMP w]
626    chown -fileid [list [id user] [id group]] [list $fh1 $fh2]
627    close $fh1
628    close $fh2
629    list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
630} [list [list $myUID $myGID] [list $myUID $myGID]]
631
632SetUpTestFiles
633
634test chmod-6.1 {chown error tests} {
635    list [catch {chown XXXXXXXXX CHMOD.TMP} msg] $msg
636} {1 {unknown user id: XXXXXXXXX}}
637
638test chmod-6.2 {chown error tests} {
639    list [catch {chown [list XXXXXXXXX [id groupid]] CHMOD.TMP} msg] $msg
640} {1 {unknown user id: XXXXXXXXX}}
641
642test chmod-6.3 {chown error tests} {
643    list [catch {chown [list [id user] XXXXXXXXX] CHMOD.TMP} msg] $msg
644} {1 {unknown group id: XXXXXXXXX}}
645
646test chmod-6.4 {chown error tests} {
647    list [catch {chown {XXXXXXXXX YYYY} CHMOD.TMP} msg] $msg
648} {1 {unknown user id: XXXXXXXXX}}
649
650test chmod-6.5 {chown error tests} {
651    list [catch {chown} msg] $msg
652} {1 {wrong # args: chown [-fileid] user|{user group} filelist}}
653
654test chmod-6.6 {chown error tests} {need_fchown} {
655    list [catch {chown -fileid $myUID BAD} msg] $msg
656} {1 {can not find channel named "BAD"}}
657
658test chmod-6.6 {chown error tests} {need_fchown} {
659    list [catch {chown -fid $myUID CHMOD.TMP} msg] $msg
660} {1 {Invalid option "-fid", expected "-fileid"}}
661
662test chmod-7.1 {chgrp tests} {chownWorks} {
663    chgrp [id group]  {CHMOD.TMP CHMOD2.TMP}
664    list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
665} [list $myGID $myGID]
666
667test chmod-7.2 {chgrp tests} {chownWorks} {
668    chgrp [id groupid] {CHMOD.TMP CHMOD2.TMP}
669    list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
670} [list $myGID $myGID]
671
672test chmod-7.3 {chgrp tests} {need_fchown && fchownWorks} {
673    set fh1 [open CHMOD.TMP w]
674    set fh2 [open CHMOD2.TMP w]
675    chgrp -fileid [id group] [list $fh1 $fh2]
676    close $fh1
677    close $fh2
678    list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
679} [list $myGID $myGID]
680
681test chmod-7.4 {chgrp tests} {need_fchown && fchownWorks} {
682    set fh1 [open CHMOD.TMP w]
683    set fh2 [open CHMOD2.TMP w]
684    chgrp -fileid [id groupid] [list $fh1 $fh2]
685    close $fh1
686    close $fh2
687    list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
688} [list $myGID $myGID]
689
690test chmod-8.1 {chgrp error tests} {
691    list [catch {chgrp} msg] $msg
692} {1 {wrong # args: chgrp [-fileid] group filelist}}
693
694test chmod-8.2 {chgrp error tests} {
695    list [catch {chgrp XXXXXXXXX CHMOD.TMP} msg] $msg
696} {1 {unknown group id: XXXXXXXXX}}
697
698test chmod-8.3 {chown error tests} {need_fchown} {
699    list [catch {chgrp -fileid $myGID BAD} msg] $msg
700} {1 {can not find channel named "BAD"}}
701
702test chmod-8.4 {chown error tests} {need_fchown} {
703    list [catch {chgrp -fid $myGID CHMOD.TMP} msg] $msg
704} {1 {Invalid option "-fid", expected "-fileid"}}
705
706
707TestRemove CHECK.TMP CHMOD.TMP CHMOD2.TMP
708
709# cleanup
710::tcltest::cleanupTests
711return
712