| 1 |
;;; |
| 2 |
;;; file commands |
| 3 |
;;; |
| 4 |
call test_macrodir |
| 5 |
call test_open |
| 6 |
call test_filecommands |
| 7 |
call test_filesearch |
| 8 |
call test_filestat |
| 9 |
call test_find |
| 10 |
call test_folder |
| 11 |
call test_password |
| 12 |
messagebox "finish all tests" "test_file.ttl" |
| 13 |
end |
| 14 |
|
| 15 |
|
| 16 |
;;; |
| 17 |
;;; test folder |
| 18 |
;;; |
| 19 |
:test_macrodir |
| 20 |
:retry |
| 21 |
getdir macro_dir |
| 22 |
dirnamebox "test_file.ttl folder for test" macro_dir |
| 23 |
s = "folder for test:\n" |
| 24 |
strspecial s |
| 25 |
strconcat s macro_dir |
| 26 |
yesnobox s "test_file.ttl" |
| 27 |
if result == 0 goto retry |
| 28 |
setdir macro_dir |
| 29 |
return |
| 30 |
|
| 31 |
;;; |
| 32 |
;;; test fileopen |
| 33 |
;;; |
| 34 |
:test_open |
| 35 |
filenamebox 'ŤÝt@C' 1 |
| 36 |
if result == 0 goto test_open |
| 37 |
fname = inputstr |
| 38 |
fileopen fh fname 1 1 |
| 39 |
if fh <> -1 messagebox "check fileopen" "test_file.ttl" |
| 40 |
fileopen fh fname 1 |
| 41 |
filewrite fh "test hello"#13#10 |
| 42 |
filewriteln fh "test hello"#13#10 |
| 43 |
fileclose fh |
| 44 |
filedelete fname |
| 45 |
return |
| 46 |
|
| 47 |
;;; |
| 48 |
;;; fileopen (create) |
| 49 |
;;; filewrite |
| 50 |
;;; filewriteln |
| 51 |
;;; fileclose |
| 52 |
;;; filerename |
| 53 |
;;; filecreate |
| 54 |
;;; filedelete |
| 55 |
;;; filecopy |
| 56 |
;;; fileconcat |
| 57 |
;;; |
| 58 |
:test_filecommands |
| 59 |
fname_1 = "01_hello.txt" |
| 60 |
fileopen fh fname_1 1 |
| 61 |
filewrite fh "test1 hello"#13#10 |
| 62 |
fileclose fh |
| 63 |
fname_2 = "02_hello.txt" |
| 64 |
filerename fname_1 fname_2 |
| 65 |
if result <> 0 messagebox "filerename error" "test_file.ttl" |
| 66 |
filecreate fh fname_1 |
| 67 |
filewriteln fh "test2 hello" |
| 68 |
fileclose fh |
| 69 |
messagebox "checkfiles 1" "test_file.ttl" |
| 70 |
fileconcat fname_1 fname_2 |
| 71 |
messagebox "checkfiles 2" "test_file.ttl" |
| 72 |
|
| 73 |
if result <> 0 messagebox "fileconcat error" "test_file.ttl" |
| 74 |
fname_3 = "03_hello.txt" |
| 75 |
filecopy fname_1 fname_3 |
| 76 |
if result <> 0 messagebox "filecopy error" "test_file.ttl" |
| 77 |
filetruncate fname_1 1024 |
| 78 |
if result <> 0 messagebox "filetruncate error" "test_file.ttl" |
| 79 |
filestat fname_1 size |
| 80 |
if result = -1 messagebox "filestat error" "test_file.ttl" |
| 81 |
if size <> 1024 messagebox "file size?" "test_file.ttl" |
| 82 |
messagebox "checkfiles 3" "test_file.ttl" |
| 83 |
filedelete fname_1 |
| 84 |
if result <> 0 messagebox "filedelete error" "test_file.ttl" |
| 85 |
filedelete fname_2 |
| 86 |
if result <> 0 messagebox "filedelete error" "test_file.ttl" |
| 87 |
filedelete fname_3 |
| 88 |
if result <> 0 messagebox "filedelete error" "test_file.ttl" |
| 89 |
messagebox "checkfiles 4" "test_file.ttl" |
| 90 |
return |
| 91 |
|
| 92 |
;;; |
| 93 |
;;; filesearch |
| 94 |
;;; |
| 95 |
:test_filesearch |
| 96 |
fname = "hello world.bin" |
| 97 |
filesearch fname |
| 98 |
if result = 1 messagebox "check filesearch 1" "test_file.ttl" |
| 99 |
fileopen fh fname 1 |
| 100 |
if fh = -1 messagebox "check fileopen" "test_file.ttl" |
| 101 |
filewriteln fh "this is hello world" |
| 102 |
fileclose fh |
| 103 |
filesearch fname |
| 104 |
if result = 0 messagebox "check filesearch 2" "test_file.ttl" |
| 105 |
filedelete fname |
| 106 |
filesearch fname |
| 107 |
if result = 1 messagebox "check filesearch 3" "test_file.ttl" |
| 108 |
return |
| 109 |
|
| 110 |
;;; |
| 111 |
;;; filestat |
| 112 |
;;; |
| 113 |
:test_filestat |
| 114 |
fname = "stat_test.bin" |
| 115 |
filetruncate fname 10240 |
| 116 |
filestat fname size |
| 117 |
if result = -1 messagebox "check filestat 1" "test_file.ttl" |
| 118 |
if size <> 10240 messagebox "check filestat 2" "test_file.ttl" |
| 119 |
filedelete fname |
| 120 |
return |
| 121 |
|
| 122 |
;;; |
| 123 |
;;; findfirst |
| 124 |
;;; findnext |
| 125 |
;;; findclose |
| 126 |
;;; |
| 127 |
:test_find |
| 128 |
n = 0 |
| 129 |
filelist = "" |
| 130 |
findfirst dh "*.ttl" filename |
| 131 |
if result = 1 then |
| 132 |
while result |
| 133 |
strconcat filelist filename |
| 134 |
strconcat filelist "\n" |
| 135 |
n = n + 1 |
| 136 |
findnext dh filename |
| 137 |
endwhile |
| 138 |
endif |
| 139 |
findclose dh |
| 140 |
strspecial filelist |
| 141 |
messagebox filelist "test_file.ttl" |
| 142 |
return |
| 143 |
|
| 144 |
;;; |
| 145 |
;;; foldercreate |
| 146 |
;;; folderdelete |
| 147 |
;;; foldersearch |
| 148 |
;;; setfileattr |
| 149 |
;;; getfileattr |
| 150 |
;;; |
| 151 |
:test_folder |
| 152 |
dname = "folder_aa" |
| 153 |
foldersearch dname |
| 154 |
if result == 1 messagebox "check foldersearch 1" "test_file.ttl" |
| 155 |
foldercreate "folder_aa" |
| 156 |
fname = "folder_aa/test.txt" |
| 157 |
filecreate fh fname |
| 158 |
filewriteln fh "hello" |
| 159 |
fileclose fh |
| 160 |
getfileattr fname |
| 161 |
if result == -1 messagebox "check getfileattr" "test_file.ttl" |
| 162 |
foldersearch dname |
| 163 |
if result == 0 messagebox "check foldersearch 2" "test_file.ttl" |
| 164 |
folderdelete dname |
| 165 |
if result == 0 messagebox "check folderdelete 1" "test_file.ttl" |
| 166 |
setfileattr fname $1 |
| 167 |
if result == 0 messagebox "check setfileattr 1" "test_file.ttl" |
| 168 |
setfileattr fname $80 |
| 169 |
if result == 0 messagebox "check setfileattr 2" "test_file.ttl" |
| 170 |
filedelete fname |
| 171 |
folderdelete dname |
| 172 |
if result <> 0 messagebox "check folderdelete 2" "test_file.ttl" |
| 173 |
foldersearch dname |
| 174 |
if result == 1 messagebox "check foldersearch 3" "test_file.ttl" |
| 175 |
return |
| 176 |
|
| 177 |
;;; |
| 178 |
;;; setpassword |
| 179 |
;;; getpassword |
| 180 |
;;; ispassword |
| 181 |
;;; delpassword |
| 182 |
;;; |
| 183 |
:test_password |
| 184 |
pwfile = "password.txt" |
| 185 |
filedelete pwfile |
| 186 |
pw1 = "password" |
| 187 |
setpassword pwfile "password1" pw1 |
| 188 |
if result == 0 messagebox "check setpassword 1" "test_file.ttl" |
| 189 |
getpassword pwfile "password1" pw2 |
| 190 |
if result == 0 messagebox "check getpassword 2" "test_file.ttl" |
| 191 |
strcompare pw1 pw2 |
| 192 |
if result <> 0 messagebox "check setpassword 3" "test_file.ttl" |
| 193 |
getpassword pwfile "password2" pw1 |
| 194 |
if result == 0 messagebox "check getpassword 4" "test_file.ttl" |
| 195 |
getpassword pwfile "password2" pw2 |
| 196 |
if result == 0 messagebox "check getpassword 5" "test_file.ttl" |
| 197 |
strcompare pw1 pw2 |
| 198 |
if result <> 0 messagebox "check setpassword 6" "test_file.ttl" |
| 199 |
ispassword pwfile "password2" |
| 200 |
if result <> 1 messagebox "check ispassword 7" "test_file.ttl" |
| 201 |
delpassword pwfile "password2" |
| 202 |
ispassword pwfile "password2" |
| 203 |
if result <> 0 messagebox "check ispassword 8" "test_file.ttl" |
| 204 |
filedelete pwfile |
| 205 |
return |