OSDN Git Service

Fix file for Java class files, improve script detection, and add tests.
[android-x86/external-toybox.git] / tests / chattr.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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]$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 "-$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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "[-/+]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 "-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 "-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 "-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