OSDN Git Service

Add grep -B -C
[android-x86/external-toybox.git] / tests / lsattr.test
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 #testing "name" "command" "result" "infile" "stdin"
6
7 # chattr - Testcases
8
9 mkdir testattr
10 IN="cd testattr"
11 OUT="cd .."
12 _t="abcdefghijklmnopqrstuvwxyz"
13
14 testing "chattr [-/+]i FILE[write]" "$IN && echo "$_t" > testFile &&
15          chattr +i testFile && lsattr testFile && echo "$_t" > testFile; 
16          chattr -i testFile; rm -rf testFile; $OUT " "----i-------- testFile\n" "" ""
17 testing "chattr [-/+]i FILE[re-write]" "$IN && echo "$_t" > testFile && 
18          chattr +i testFile && echo \"$_t\" > testFile || chattr -i testFile && 
19          echo \"$_t\" > testFile && lsattr testFile; rm -rf testFile; $OUT" \
20          "------------- testFile\n" "" ""
21 testing "chattr [-/+]i FILE[append]" "$IN && echo "$_t" > testFile && 
22          chattr +i testFile && echo \"$_t\" >> testFile || lsattr testFile && 
23          chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
24 testing "chattr [-/+]i FILE[move]" "$IN && echo "$_t" > testFile && 
25          chattr +i testFile && mv testFile testFile1 || lsattr testFile && 
26          chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
27 testing "chattr [-/+]i FILE[delete]" "$IN && echo "$_t" > testFile && 
28          chattr +i testFile && rm -f testFile || lsattr testFile && 
29          chattr -i testFile; rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
30 testing "chattr [-/+]i FILE[read]" "$IN && echo "$_t" > testFile && 
31          chattr +i testFile && cat testFile && lsattr testFile && 
32          chattr -i testFile; rm -rf testFile; $OUT" "$_t\n----i-------- testFile\n" "" ""
33 testing "chattr [-/+]a FILE[write]" "$IN && echo "$_t" > testFile && 
34          chattr +a testFile && echo $_t > testFile || lsattr testFile && 
35          chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
36 testing "chattr [-/+]a FILE[re-write]" "$IN && echo "$_t" > testFile && 
37          chattr +a testFile && echo $_t > testFile || lsattr testFile && 
38          chattr -a testFile && echo $_t > testFile && cat testFile && 
39          lsattr testFile; rm -rf testFile; 
40          $OUT" "-----a------- testFile\n$_t\n------------- testFile\n" "" ""
41 testing "chattr [-/+]a FILE[append]" "$IN && echo "$_t" > testFile && 
42          chattr +a testFile && echo $_t >> testFile && cat testFile && 
43          lsattr testFile && chattr -a testFile; rm -rf testFile; $OUT" \
44          "$_t\n$_t\n-----a------- testFile\n" "" ""
45 testing "chattr [-/+]a FILE[move]" "$IN && echo "$_t" > testFile && 
46          chattr +a testFile && mv testFile testFile1 || lsattr testFile && 
47          chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
48 testing "chattr [-/+]a FILE[delete]" "$IN && echo "$_t" > testFile && 
49          chattr +a testFile && rm -f testFile || lsattr testFile && 
50          chattr -a testFile; rm -rf testFile; $OUT" "-----a------- testFile\n" "" ""
51 testing "chattr [-/+]a FILE[read]" "$IN && echo "$_t" > testFile && 
52          chattr +a testFile && cat testFile && lsattr testFile && chattr -a testFile; 
53          rm -rf testFile; $OUT" "$_t\n-----a------- testFile\n" "" ""
54
55 for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u"
56 do
57   testing "chattr [-/+]$attr FILE" "$IN && echo "$_t" > testFile && 
58            chattr +$attr testFile && cat testFile && chattr -$attr testFile && 
59            lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
60 done
61
62 for attr in "A" "a" "c" "D" "d" "i" "j" "s" "S" "t" "T" "u"
63 do
64   testing "chattr -$attr FILE" "$IN && echo "$_t" > testFile && chattr -$attr testFile &&
65            cat testFile && lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
66 done
67
68 testing "chattr [-/+]AacDdijsStTu FILE" "$IN && echo "$_t" > testFile && 
69          chattr +AacDdijsStTu testFile && cat testFile && chattr -AacDdijsStTu testFile && 
70          lsattr testFile; rm -rf testFile; $OUT" "$_t\n------------- testFile\n" "" ""
71 testing "chattr [-/+]AacDdijsStTu(random) FILE" \
72         "$IN && echo "$_t" > testFile && 
73         chattr +AacDdijsStTu testFile && cat testFile && chattr -A testFile &&
74         chattr -a testFile && chattr -c testFile && chattr -D testFile &&
75         chattr -d testFile && chattr -i testFile && chattr -j testFile &&
76         chattr -s testFile && chattr -S testFile && chattr -t testFile &&
77         chattr -T testFile && chattr -u testFile && lsattr testFile &&
78         chattr -AacDdijsStTu testFile; rm -rf testFile; $OUT" \
79         "$_t\n------------- testFile\n" "" ""
80 testing "chattr [-/+]AacDdijsStTu FILE*" "$IN && 
81         echo "$_t" > testFile && echo "$_t" > testFile1 &&
82         echo "$_t" > testFile2 && echo "$_t" > testFile3 &&
83         echo "$_t" > testFile4 && echo "$_t" > testFile5 &&
84         echo "$_t" > testFile6 && echo "$_t" > testFile7 &&
85         echo "$_t" > testFile8 && echo "$_t" > testFile9 &&
86         echo "$_t" > testFile10 && echo "$_t" > testFile11 &&
87        chattr +AacDdijsStTu testFile* &&
88        cat testFile9 && chattr -AacDdijsStTu testFile* && lsattr testFile*; rm -rf testFile*; $OUT" \
89        "$_t\n------------- testFile\n------------- testFile1\n------------- testFile10\n------------- testFile11\n------------- testFile2\n------------- testFile3\n------------- testFile4\n------------- testFile5\n------------- testFile6\n------------- testFile7\n------------- testFile8\n------------- testFile9\n" "" ""
90 testing "chattr [-/+]AacDdijsStTu(random) FILE*" \
91         "$IN && echo "$_t" > testFile &&
92         chattr +AacDdijsStTu testFile* && cat testFile && chattr -A testFile* &&
93         chattr -a testFile* && chattr -c testFile* && chattr -D testFile* &&
94         chattr -d testFile* && chattr -i testFile* && chattr -j testFile* &&
95         chattr -s testFile* && chattr -S testFile* && chattr -t testFile* &&
96         chattr -T testFile* && chattr -u testFile* && lsattr testFile;
97         rm -rf testFile; $OUT" \
98         "$_t\n------------- testFile\n" "" ""
99 testing "chattr [-/+]i FILE[write]" \
100         "$IN && echo "$_t" > testFile &&
101         chattr +i testFile &&
102         echo \"$_t\" > testFile || lsattr testFile && chattr -i testFile;
103         rm -rf testFile; $OUT" "----i-------- testFile\n" "" ""
104 testing "chattr [-/+]A FILE[write]" \
105         "$IN && echo "$_t" > testFile && chattr +A testFile &&
106         echo \"$_t\" > testFile && lsattr testFile && chattr -A testFile;
107         rm -rf testFile; $OUT" "-------A----- testFile\n" "" ""
108 testing "chattr [-/+]s FILE[write]" \
109         "$IN && echo "$_t" > testFile && chattr +s testFile &&
110         echo \"$_t\" > testFile && lsattr testFile && chattr -s testFile
111         rm -rf testFile; $OUT" "s------------ testFile\n" "" ""
112 testing "chattr -v version FILE[write]" \
113         "$IN && echo "$_t" > testFile &&
114         chattr -v 1234 testFile && echo \"$_t\" > testFile && 
115         lsattr -v testFile; rm -rf testFile" \
116         " 1234 ------------- testFile\n" "" ""
117
118 _a="-------A-----"
119 testing "chattr -R [-/+]a FILE" "$IN && touch aa && chattr -R +A aa && lsattr aa &&
120         chattr -R -A aa; rm -rf aa; $OUT" "$_a aa\n" "" ""
121 testing "chattr -R [-/+]a FILE.." "$IN && touch aa bb &&
122         chattr -R +A aa bb && lsattr aa bb &&
123         chattr -R -A aa bb; rm -rf aa bb; $OUT" "$_a aa\n$_a bb\n" "" ""
124
125 # Clean up
126 rm -rf testattr
127
128 # lsattr - Testcases
129 mkdir dir && cd dir && touch file
130 chattr +A file &>/dev/null
131
132 _p=$PWD
133 _b="-------------"
134 _A="-------A-----"
135
136 testing "lsattr file" "lsattr file" "$_A file\n" "" ""
137 testing "lsattr file_path" "lsattr $_p/file" "$_A $_p/file\n" "" ""
138 testing "lsattr -R file" "lsattr -R file" "$_A file\n" "" ""
139 testing "lsattr -R file_path" "lsattr -R $_p/file" "$_A $_p/file\n" "" ""
140 testing "lsattr -a file" "lsattr -a file" "$_A file\n" "" ""
141 testing "lsattr -a file_path" "lsattr -a $_p/file" "$_A $_p/file\n" "" ""
142 testing "lsattr -d ." "lsattr -d ." "$_b .\n" "" ""
143 testing "lsattr -d dir_path" "lsattr -d $_p" "$_b $_p\n" "" ""
144 testing "lsattr -d file" "lsattr -d file" "$_A file\n" "" ""
145 testing "lsattr -d file_path" "lsattr -d $_p/file" "$_A $_p/file\n" "" ""
146 sp_44="                                            "
147 testing "lsattr -l file" "lsattr -l file" "file  $sp_44 No_Atime\n" "" ""
148 _v="12345"
149 testing "lsattr -v file" "chattr -v $_v * && lsattr -v file" \
150   "$_v $_A file\n" "" ""
151 testing "lsattr -v file_path" "chattr -v $_v * && lsattr -v $_p/file" \
152   "$_v $_A $_p/file\n" "" ""
153 testing "lsattr -Radlv file1 file2" "chattr -v $_v * &&
154    lsattr -Radlv file input" \
155   "$_v file  $sp_44 No_Atime\n$_v input $sp_44 ---\n" "" ""
156
157 # Cleanup
158 chattr -AacDdijsStTu file && cd ..
159 rm -rf dir