forked from cleolibrary/CLEO4
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
11 changed files
with
421 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.