Skip to content

Commit c4257f4

Browse files
authored
Added unit tests for file operation opcodes. (#216)
* Added unit test for file operation opcodes. * fixup! Added unit test for file operation opcodes. * fixup! Added unit test for file operation opcodes. * fixup! Added unit test for file operation opcodes.
1 parent b1c151b commit c4257f4

File tree

11 files changed

+421
-3
lines changed

11 files changed

+421
-3
lines changed

tests/cleo_tests/FilesystemOperations/0A9A.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function tests
1919

2020
function test2
2121
if
22-
0@ = open_file "cleo\\.cleo.log" {mode} "r" // tested opcode
22+
0@ = open_file "cleo\\.cleo_config.ini" {mode} "r" // tested opcode
2323
then
2424
assert(true)
2525
close_file 0@

tests/cleo_tests/FilesystemOperations/0A9B.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trace "0A9B (close_file)"
2323
wait 0
2424
// open file
2525
if
26-
0@ = open_file "cleo\.cleo.log" {mode} "r+"
26+
0@ = open_file "cleo\.cleo_config.ini" {mode} "r+"
2727
then
2828
trace "~g~~h~~h~0A9B (close_file), #0 PASSED"
2929
else
@@ -40,7 +40,7 @@ trace "~g~~h~~h~0A9B (close_file), #1 PASSED"
4040
wait 0
4141
// open file again
4242
if
43-
0@ = open_file "cleo\.cleo.log" {mode} "r+"
43+
0@ = open_file "cleo\.cleo_config.ini" {mode} "r+"
4444
then
4545
trace "~g~~h~~h~0A9B (close_file), #2 PASSED"
4646
else
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0AAB"
5+
test("0AAB (does_file_exist)", tests)
6+
terminate_this_custom_script
7+
8+
9+
function tests
10+
11+
it("should fail on a non-existing file", test1)
12+
it("should success on existing file", test2)
13+
return
14+
15+
function test1
16+
does_file_exist {path} "cleo\\not_a_file.txt" // tested opcode
17+
assert_result_false()
18+
end
19+
20+
function test2
21+
does_file_exist {path} "cleo\\.cleo_config.ini" // tested opcode
22+
assert_result_true()
23+
end
24+
25+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0AE4"
5+
test("0AE4 (does_directory_exist)", tests)
6+
terminate_this_custom_script
7+
8+
9+
function tests
10+
11+
it("should fail on a non-existing directory", test1)
12+
it("should success on existing directory", test2)
13+
return
14+
15+
function test1
16+
does_directory_exist {path} "cleo\\not_a_directory" // tested opcode
17+
assert_result_false()
18+
end
19+
20+
function test2
21+
does_directory_exist {path} "cleo\\cleo_tests" // tested opcode
22+
assert_result_true()
23+
end
24+
25+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0AE5"
5+
test("0AE5 (create_directory)", tests)
6+
terminate_this_custom_script
7+
8+
9+
const Test_Path = "cleo\\cleo_test_directory"
10+
11+
function tests
12+
13+
it("should create directory", test1)
14+
return
15+
16+
function test1
17+
does_directory_exist {path} Test_Path
18+
assert_result_false()
19+
20+
create_directory {path} Test_Path // tested opcode
21+
assert_result_true()
22+
23+
does_directory_exist {path} Test_Path
24+
assert_result_true()
25+
26+
// cleanup
27+
delete_directory {path} Test_Path {recursive} false
28+
end
29+
30+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0B00"
5+
test("0B00 (delete_file)", tests)
6+
terminate_this_custom_script
7+
8+
9+
const Test_Path = "cleo\\cleo_test_file.ini"
10+
11+
function tests
12+
13+
it("should fail on a non-existing file", test1)
14+
it("should delete existing file", test2)
15+
return
16+
17+
function test1
18+
delete_file {path} "cleo\\not_a_file.ini" // tested opcode
19+
assert_result_false()
20+
end
21+
22+
function test2
23+
write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test"
24+
assert_result_true()
25+
does_file_exist {path} Test_Path
26+
assert_result_true()
27+
28+
delete_file {path} Test_Path // tested opcode
29+
assert_result_true()
30+
does_file_exist {path} Test_Path
31+
assert_result_false()
32+
end
33+
34+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0B01"
5+
test("0B01 (delete_directory)", tests)
6+
terminate_this_custom_script
7+
8+
9+
const Test_Path = "cleo\\cleo_test_directory"
10+
11+
function tests
12+
13+
it("should fail on a non-existing directory", test1)
14+
it("should delete empty directory", test2)
15+
it("should delete directory with contents", test3)
16+
return
17+
18+
function test1
19+
delete_directory {dirPath} Test_Path {recursive} false // tested opcode
20+
assert_result_false()
21+
end
22+
23+
function test2
24+
create_directory {path} Test_Path
25+
assert_result_true()
26+
does_directory_exist {dirPath} Test_Path
27+
assert_result_true()
28+
29+
delete_directory {dirPath} Test_Path {recursive} false // tested opcode
30+
assert_result_true()
31+
does_directory_exist {dirPath} Test_Path
32+
assert_result_false()
33+
end
34+
35+
function test3
36+
create_directory {path} Test_Path
37+
assert_result_true()
38+
does_directory_exist {dirPath} Test_Path
39+
assert_result_true()
40+
41+
set_current_directory {path} Test_Path
42+
create_directory {path} "Test_Sub_Dir"
43+
write_int_to_ini_file {value} 42 {path} "Test_File.ini" {section} "test" {key} "test"
44+
set_current_directory {path} 0
45+
46+
// check if file was actually created in desired location
47+
int str = allocate_memory {size} 260
48+
string_format str = "%s\\Test_File.ini" Test_Path
49+
int value = read_int_from_ini_file {path} str {section} "test" {key} "test"
50+
assert_eq(value, 42)
51+
free_memory str
52+
53+
delete_directory {dirPath} Test_Path {recursive} false // tested opcode
54+
assert_result_false()
55+
does_directory_exist {dirPath} Test_Path
56+
assert_result_true()
57+
58+
delete_directory {dirPath} Test_Path {recursive} true // tested opcode
59+
assert_result_true()
60+
does_directory_exist {dirPath} Test_Path
61+
assert_result_false()
62+
end
63+
64+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0B02"
5+
test("0B02 (move_file)", tests)
6+
terminate_this_custom_script
7+
8+
9+
const Test_Path_Src = "cleo\\cleo_test_file.ini"
10+
const Test_Path_Dst = "_test_file_B.ini"
11+
12+
function tests
13+
14+
it("should fail on a non-existing file", test1)
15+
it("should move file", test2)
16+
return
17+
18+
function test1
19+
does_file_exist {dirPath} Test_Path_Src
20+
assert_result_false()
21+
22+
move_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
23+
assert_result_false()
24+
end
25+
26+
function test2
27+
// setup
28+
write_int_to_ini_file {value} 42 {path} Test_Path_Src {section} "test" {key} "test"
29+
assert_result_true()
30+
does_file_exist {dirPath} Test_Path_Src
31+
assert_result_true()
32+
does_file_exist {dirPath} Test_Path_Dst
33+
assert_result_false()
34+
35+
// act
36+
move_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
37+
assert_result_true()
38+
does_file_exist {dirPath} Test_Path_Src
39+
assert_result_false()
40+
does_file_exist {dirPath} Test_Path_Dst
41+
assert_result_true()
42+
43+
int value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
44+
assert_eq(value, 42)
45+
46+
// cleanup
47+
delete_file {fileName} Test_Path_Dst
48+
end
49+
50+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0B03"
5+
test("0B03 (move_directory)", tests)
6+
terminate_this_custom_script
7+
8+
9+
const Test_Path_Src = "cleo\\cleo_test_dir"
10+
const Test_Path_Dst = "test_directory"
11+
12+
function tests
13+
14+
it("should fail on a non-existing directory", test1)
15+
it("should move directory", test2)
16+
return
17+
18+
function test1
19+
does_directory_exist {dirPath} Test_Path_Src
20+
assert_result_false()
21+
22+
move_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
23+
assert_result_false()
24+
end
25+
26+
function test2
27+
// setup
28+
create_directory {path} Test_Path_Src
29+
set_current_directory {path} Test_Path_Src
30+
create_directory {path} "Test_Sub_Dir"
31+
write_int_to_ini_file {value} 42 {path} "Test_File.ini" {section} "test" {key} "test"
32+
set_current_directory {path} 0
33+
assert_result_true()
34+
does_directory_exist {dirPath} Test_Path_Src
35+
assert_result_true()
36+
does_directory_exist {dirPath} Test_Path_Dst
37+
assert_result_false()
38+
39+
// check if file was actually created in desired location
40+
int str = allocate_memory {size} 260
41+
string_format str = "%s\\Test_File.ini" Test_Path_Src
42+
int value = read_int_from_ini_file {path} str {section} "test" {key} "test"
43+
assert_eq(value, 42)
44+
free_memory str
45+
46+
// act
47+
move_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
48+
assert_result_true()
49+
does_directory_exist {dirPath} Test_Path_Src
50+
assert_result_false()
51+
does_directory_exist {dirPath} Test_Path_Dst
52+
assert_result_true()
53+
54+
// check contents
55+
set_current_directory {path} Test_Path_Dst
56+
does_directory_exist {path} "Test_Sub_Dir"
57+
assert_result_true()
58+
value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
59+
assert_eq(value, 42)
60+
set_current_directory {path} 0
61+
62+
// cleanup
63+
delete_directory {dirPath} Test_Path_Dst {recursive} true
64+
end
65+
66+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{$CLEO .s}
2+
{$INCLUDE_ONCE ../cleo_tester.inc}
3+
4+
script_name "0B04"
5+
test("0B04 (copy_file)", tests)
6+
terminate_this_custom_script
7+
8+
9+
const Test_Path_Src = "cleo\\cleo_test_file.ini"
10+
const Test_Path_Dst = "_test_file_B.ini"
11+
12+
function tests
13+
14+
it("should fail on a non-existing file", test1)
15+
it("should copy file", test2)
16+
return
17+
18+
function test1
19+
does_file_exist {dirPath} Test_Path_Src
20+
assert_result_false()
21+
22+
copy_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
23+
assert_result_false()
24+
end
25+
26+
function test2
27+
// setup
28+
write_int_to_ini_file {value} 42 {path} Test_Path_Src {section} "test" {key} "test"
29+
assert_result_true()
30+
does_file_exist {dirPath} Test_Path_Src
31+
assert_result_true()
32+
does_file_exist {dirPath} Test_Path_Dst
33+
assert_result_false()
34+
35+
// act
36+
copy_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
37+
assert_result_true()
38+
39+
int value = read_int_from_ini_file {path} Test_Path_Src {section} "test" {key} "test"
40+
assert_eq(value, 42)
41+
42+
value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
43+
assert_eq(value, 42)
44+
45+
// cleanup
46+
delete_file {fileName} Test_Path_Src
47+
delete_file {fileName} Test_Path_Dst
48+
end
49+
50+
end

0 commit comments

Comments
 (0)