Skip to content

Commit

Permalink
Added unit tests for file operation opcodes. (#216)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
MiranDMC authored Sep 29, 2024
1 parent b1c151b commit c4257f4
Show file tree
Hide file tree
Showing 11 changed files with 421 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/cleo_tests/FilesystemOperations/0A9A.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function tests

function test2
if
0@ = open_file "cleo\\.cleo.log" {mode} "r" // tested opcode
0@ = open_file "cleo\\.cleo_config.ini" {mode} "r" // tested opcode
then
assert(true)
close_file 0@
Expand Down
4 changes: 2 additions & 2 deletions tests/cleo_tests/FilesystemOperations/0A9B.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trace "0A9B (close_file)"
wait 0
// open file
if
0@ = open_file "cleo\.cleo.log" {mode} "r+"
0@ = open_file "cleo\.cleo_config.ini" {mode} "r+"
then
trace "~g~~h~~h~0A9B (close_file), #0 PASSED"
else
Expand All @@ -40,7 +40,7 @@ trace "~g~~h~~h~0A9B (close_file), #1 PASSED"
wait 0
// open file again
if
0@ = open_file "cleo\.cleo.log" {mode} "r+"
0@ = open_file "cleo\.cleo_config.ini" {mode} "r+"
then
trace "~g~~h~~h~0A9B (close_file), #2 PASSED"
else
Expand Down
25 changes: 25 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0AAB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AAB"
test("0AAB (does_file_exist)", tests)
terminate_this_custom_script


function tests

it("should fail on a non-existing file", test1)
it("should success on existing file", test2)
return

function test1
does_file_exist {path} "cleo\\not_a_file.txt" // tested opcode
assert_result_false()
end

function test2
does_file_exist {path} "cleo\\.cleo_config.ini" // tested opcode
assert_result_true()
end

end
25 changes: 25 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0AE4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AE4"
test("0AE4 (does_directory_exist)", tests)
terminate_this_custom_script


function tests

it("should fail on a non-existing directory", test1)
it("should success on existing directory", test2)
return

function test1
does_directory_exist {path} "cleo\\not_a_directory" // tested opcode
assert_result_false()
end

function test2
does_directory_exist {path} "cleo\\cleo_tests" // tested opcode
assert_result_true()
end

end
30 changes: 30 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0AE5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AE5"
test("0AE5 (create_directory)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_directory"

function tests

it("should create directory", test1)
return

function test1
does_directory_exist {path} Test_Path
assert_result_false()

create_directory {path} Test_Path // tested opcode
assert_result_true()

does_directory_exist {path} Test_Path
assert_result_true()

// cleanup
delete_directory {path} Test_Path {recursive} false
end

end
34 changes: 34 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B00.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0B00"
test("0B00 (delete_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests

it("should fail on a non-existing file", test1)
it("should delete existing file", test2)
return

function test1
delete_file {path} "cleo\\not_a_file.ini" // tested opcode
assert_result_false()
end

function test2
write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test"
assert_result_true()
does_file_exist {path} Test_Path
assert_result_true()

delete_file {path} Test_Path // tested opcode
assert_result_true()
does_file_exist {path} Test_Path
assert_result_false()
end

end
64 changes: 64 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B01.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0B01"
test("0B01 (delete_directory)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_directory"

function tests

it("should fail on a non-existing directory", test1)
it("should delete empty directory", test2)
it("should delete directory with contents", test3)
return

function test1
delete_directory {dirPath} Test_Path {recursive} false // tested opcode
assert_result_false()
end

function test2
create_directory {path} Test_Path
assert_result_true()
does_directory_exist {dirPath} Test_Path
assert_result_true()

delete_directory {dirPath} Test_Path {recursive} false // tested opcode
assert_result_true()
does_directory_exist {dirPath} Test_Path
assert_result_false()
end

function test3
create_directory {path} Test_Path
assert_result_true()
does_directory_exist {dirPath} Test_Path
assert_result_true()

set_current_directory {path} Test_Path
create_directory {path} "Test_Sub_Dir"
write_int_to_ini_file {value} 42 {path} "Test_File.ini" {section} "test" {key} "test"
set_current_directory {path} 0

// check if file was actually created in desired location
int str = allocate_memory {size} 260
string_format str = "%s\\Test_File.ini" Test_Path
int value = read_int_from_ini_file {path} str {section} "test" {key} "test"
assert_eq(value, 42)
free_memory str

delete_directory {dirPath} Test_Path {recursive} false // tested opcode
assert_result_false()
does_directory_exist {dirPath} Test_Path
assert_result_true()

delete_directory {dirPath} Test_Path {recursive} true // tested opcode
assert_result_true()
does_directory_exist {dirPath} Test_Path
assert_result_false()
end

end
50 changes: 50 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0B02"
test("0B02 (move_file)", tests)
terminate_this_custom_script


const Test_Path_Src = "cleo\\cleo_test_file.ini"
const Test_Path_Dst = "_test_file_B.ini"

function tests

it("should fail on a non-existing file", test1)
it("should move file", test2)
return

function test1
does_file_exist {dirPath} Test_Path_Src
assert_result_false()

move_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
assert_result_false()
end

function test2
// setup
write_int_to_ini_file {value} 42 {path} Test_Path_Src {section} "test" {key} "test"
assert_result_true()
does_file_exist {dirPath} Test_Path_Src
assert_result_true()
does_file_exist {dirPath} Test_Path_Dst
assert_result_false()

// act
move_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
assert_result_true()
does_file_exist {dirPath} Test_Path_Src
assert_result_false()
does_file_exist {dirPath} Test_Path_Dst
assert_result_true()

int value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
assert_eq(value, 42)

// cleanup
delete_file {fileName} Test_Path_Dst
end

end
66 changes: 66 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B03.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0B03"
test("0B03 (move_directory)", tests)
terminate_this_custom_script


const Test_Path_Src = "cleo\\cleo_test_dir"
const Test_Path_Dst = "test_directory"

function tests

it("should fail on a non-existing directory", test1)
it("should move directory", test2)
return

function test1
does_directory_exist {dirPath} Test_Path_Src
assert_result_false()

move_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
assert_result_false()
end

function test2
// setup
create_directory {path} Test_Path_Src
set_current_directory {path} Test_Path_Src
create_directory {path} "Test_Sub_Dir"
write_int_to_ini_file {value} 42 {path} "Test_File.ini" {section} "test" {key} "test"
set_current_directory {path} 0
assert_result_true()
does_directory_exist {dirPath} Test_Path_Src
assert_result_true()
does_directory_exist {dirPath} Test_Path_Dst
assert_result_false()

// check if file was actually created in desired location
int str = allocate_memory {size} 260
string_format str = "%s\\Test_File.ini" Test_Path_Src
int value = read_int_from_ini_file {path} str {section} "test" {key} "test"
assert_eq(value, 42)
free_memory str

// act
move_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
assert_result_true()
does_directory_exist {dirPath} Test_Path_Src
assert_result_false()
does_directory_exist {dirPath} Test_Path_Dst
assert_result_true()

// check contents
set_current_directory {path} Test_Path_Dst
does_directory_exist {path} "Test_Sub_Dir"
assert_result_true()
value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test"
assert_eq(value, 42)
set_current_directory {path} 0

// cleanup
delete_directory {dirPath} Test_Path_Dst {recursive} true
end

end
50 changes: 50 additions & 0 deletions tests/cleo_tests/FilesystemOperations/0B04.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0B04"
test("0B04 (copy_file)", tests)
terminate_this_custom_script


const Test_Path_Src = "cleo\\cleo_test_file.ini"
const Test_Path_Dst = "_test_file_B.ini"

function tests

it("should fail on a non-existing file", test1)
it("should copy file", test2)
return

function test1
does_file_exist {dirPath} Test_Path_Src
assert_result_false()

copy_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
assert_result_false()
end

function test2
// setup
write_int_to_ini_file {value} 42 {path} Test_Path_Src {section} "test" {key} "test"
assert_result_true()
does_file_exist {dirPath} Test_Path_Src
assert_result_true()
does_file_exist {dirPath} Test_Path_Dst
assert_result_false()

// act
copy_file {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode
assert_result_true()

int value = read_int_from_ini_file {path} Test_Path_Src {section} "test" {key} "test"
assert_eq(value, 42)

value = read_int_from_ini_file {path} Test_Path_Dst {section} "test" {key} "test"
assert_eq(value, 42)

// cleanup
delete_file {fileName} Test_Path_Src
delete_file {fileName} Test_Path_Dst
end

end
Loading

0 comments on commit c4257f4

Please sign in to comment.