From c4257f4c92d9871e19fb59f6a31b5078178a36fc Mon Sep 17 00:00:00 2001 From: MiranDMC Date: Sun, 29 Sep 2024 07:26:04 +0200 Subject: [PATCH] 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. --- .../cleo_tests/FilesystemOperations/0A9A.txt | 2 +- .../cleo_tests/FilesystemOperations/0A9B.txt | 4 +- .../cleo_tests/FilesystemOperations/0AAB.txt | 25 +++++++ .../cleo_tests/FilesystemOperations/0AE4.txt | 25 +++++++ .../cleo_tests/FilesystemOperations/0AE5.txt | 30 ++++++++ .../cleo_tests/FilesystemOperations/0B00.txt | 34 +++++++++ .../cleo_tests/FilesystemOperations/0B01.txt | 64 ++++++++++++++++ .../cleo_tests/FilesystemOperations/0B02.txt | 50 +++++++++++++ .../cleo_tests/FilesystemOperations/0B03.txt | 66 +++++++++++++++++ .../cleo_tests/FilesystemOperations/0B04.txt | 50 +++++++++++++ .../cleo_tests/FilesystemOperations/0B05.txt | 74 +++++++++++++++++++ 11 files changed, 421 insertions(+), 3 deletions(-) create mode 100644 tests/cleo_tests/FilesystemOperations/0AAB.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0AE4.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0AE5.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0B00.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0B01.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0B02.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0B03.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0B04.txt create mode 100644 tests/cleo_tests/FilesystemOperations/0B05.txt diff --git a/tests/cleo_tests/FilesystemOperations/0A9A.txt b/tests/cleo_tests/FilesystemOperations/0A9A.txt index 8416d34b..a911c7ec 100644 --- a/tests/cleo_tests/FilesystemOperations/0A9A.txt +++ b/tests/cleo_tests/FilesystemOperations/0A9A.txt @@ -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@ diff --git a/tests/cleo_tests/FilesystemOperations/0A9B.txt b/tests/cleo_tests/FilesystemOperations/0A9B.txt index 4a22737e..4d8a78b9 100644 --- a/tests/cleo_tests/FilesystemOperations/0A9B.txt +++ b/tests/cleo_tests/FilesystemOperations/0A9B.txt @@ -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 @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0AAB.txt b/tests/cleo_tests/FilesystemOperations/0AAB.txt new file mode 100644 index 00000000..5d4c16be --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0AAB.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0AE4.txt b/tests/cleo_tests/FilesystemOperations/0AE4.txt new file mode 100644 index 00000000..55ff5fd9 --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0AE4.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0AE5.txt b/tests/cleo_tests/FilesystemOperations/0AE5.txt new file mode 100644 index 00000000..ee35ebb0 --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0AE5.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0B00.txt b/tests/cleo_tests/FilesystemOperations/0B00.txt new file mode 100644 index 00000000..2e9ba50d --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B00.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0B01.txt b/tests/cleo_tests/FilesystemOperations/0B01.txt new file mode 100644 index 00000000..56eea860 --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B01.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0B02.txt b/tests/cleo_tests/FilesystemOperations/0B02.txt new file mode 100644 index 00000000..94b5c6cd --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B02.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0B03.txt b/tests/cleo_tests/FilesystemOperations/0B03.txt new file mode 100644 index 00000000..be094d3b --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B03.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0B04.txt b/tests/cleo_tests/FilesystemOperations/0B04.txt new file mode 100644 index 00000000..19679aee --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B04.txt @@ -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 diff --git a/tests/cleo_tests/FilesystemOperations/0B05.txt b/tests/cleo_tests/FilesystemOperations/0B05.txt new file mode 100644 index 00000000..d157602f --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B05.txt @@ -0,0 +1,74 @@ +{$CLEO .s} +{$INCLUDE_ONCE ../cleo_tester.inc} + +script_name "0B05" +test("0B05 (copy_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() + + copy_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 + copy_directory {path} Test_Path_Src {newPath} Test_Path_Dst // tested opcode + assert_result_true() + does_directory_exist {dirPath} Test_Path_Src + assert_result_true() + does_directory_exist {dirPath} Test_Path_Dst + assert_result_true() + + // check contents + set_current_directory {path} Test_Path_Src + 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 + + 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_Src {recursive} true + delete_directory {dirPath} Test_Path_Dst {recursive} true + end + +end