From 2560b1ac345e0b7ad297eb4caec4baecc2185c1d Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Sep 2024 22:28:35 +0200 Subject: [PATCH 1/4] 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 | 57 ++++++++++++++++ .../cleo_tests/FilesystemOperations/0B02.txt | 50 ++++++++++++++ .../cleo_tests/FilesystemOperations/0B03.txt | 59 ++++++++++++++++ .../cleo_tests/FilesystemOperations/0B04.txt | 50 ++++++++++++++ .../cleo_tests/FilesystemOperations/0B05.txt | 67 +++++++++++++++++++ 11 files changed, 400 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..3d58772b --- /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 file", test1) + it("should success on existing file", 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..a9a970f0 --- /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 {dirPath} Test_Path + assert_result_true() + + delete_file {path} Test_Path // tested opcode + assert_result_true() + does_file_exist {dirPath} 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..a64d584c --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B01.txt @@ -0,0 +1,57 @@ +{$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 + + 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..eb7b6d0c --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B03.txt @@ -0,0 +1,59 @@ +{$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() + + // 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() + int 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..440fdcd2 --- /dev/null +++ b/tests/cleo_tests/FilesystemOperations/0B05.txt @@ -0,0 +1,67 @@ +{$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() + + // 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() + int 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 From 4296ee0569c71697d58aa126598285d97eac3945 Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Sep 2024 22:45:59 +0200 Subject: [PATCH 2/4] fixup! Added unit test for file operation opcodes. --- tests/cleo_tests/FilesystemOperations/0AE4.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cleo_tests/FilesystemOperations/0AE4.txt b/tests/cleo_tests/FilesystemOperations/0AE4.txt index 3d58772b..55ff5fd9 100644 --- a/tests/cleo_tests/FilesystemOperations/0AE4.txt +++ b/tests/cleo_tests/FilesystemOperations/0AE4.txt @@ -8,8 +8,8 @@ terminate_this_custom_script function tests - it("should fail on a non-existing file", test1) - it("should success on existing file", test2) + it("should fail on a non-existing directory", test1) + it("should success on existing directory", test2) return function test1 From 3d9c037ccbb33fd09b1f966a3fd33c8ba4fc636f Mon Sep 17 00:00:00 2001 From: Miran Date: Sat, 28 Sep 2024 22:48:56 +0200 Subject: [PATCH 3/4] fixup! Added unit test for file operation opcodes. --- tests/cleo_tests/FilesystemOperations/0B00.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cleo_tests/FilesystemOperations/0B00.txt b/tests/cleo_tests/FilesystemOperations/0B00.txt index a9a970f0..2e9ba50d 100644 --- a/tests/cleo_tests/FilesystemOperations/0B00.txt +++ b/tests/cleo_tests/FilesystemOperations/0B00.txt @@ -22,12 +22,12 @@ function tests function test2 write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test" assert_result_true() - does_file_exist {dirPath} Test_Path + does_file_exist {path} Test_Path assert_result_true() delete_file {path} Test_Path // tested opcode assert_result_true() - does_file_exist {dirPath} Test_Path + does_file_exist {path} Test_Path assert_result_false() end From 241be09d35154ad00346762a918ee45cd0e62f74 Mon Sep 17 00:00:00 2001 From: Miran Date: Sun, 29 Sep 2024 07:15:57 +0200 Subject: [PATCH 4/4] fixup! Added unit test for file operation opcodes. --- tests/cleo_tests/FilesystemOperations/0B01.txt | 7 +++++++ tests/cleo_tests/FilesystemOperations/0B03.txt | 9 ++++++++- tests/cleo_tests/FilesystemOperations/0B05.txt | 9 ++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/cleo_tests/FilesystemOperations/0B01.txt b/tests/cleo_tests/FilesystemOperations/0B01.txt index a64d584c..56eea860 100644 --- a/tests/cleo_tests/FilesystemOperations/0B01.txt +++ b/tests/cleo_tests/FilesystemOperations/0B01.txt @@ -42,6 +42,13 @@ function tests 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() diff --git a/tests/cleo_tests/FilesystemOperations/0B03.txt b/tests/cleo_tests/FilesystemOperations/0B03.txt index eb7b6d0c..be094d3b 100644 --- a/tests/cleo_tests/FilesystemOperations/0B03.txt +++ b/tests/cleo_tests/FilesystemOperations/0B03.txt @@ -35,6 +35,13 @@ function tests 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 @@ -48,7 +55,7 @@ function tests set_current_directory {path} Test_Path_Dst does_directory_exist {path} "Test_Sub_Dir" assert_result_true() - int value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test" + value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test" assert_eq(value, 42) set_current_directory {path} 0 diff --git a/tests/cleo_tests/FilesystemOperations/0B05.txt b/tests/cleo_tests/FilesystemOperations/0B05.txt index 440fdcd2..d157602f 100644 --- a/tests/cleo_tests/FilesystemOperations/0B05.txt +++ b/tests/cleo_tests/FilesystemOperations/0B05.txt @@ -35,6 +35,13 @@ function tests 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 @@ -48,7 +55,7 @@ function tests set_current_directory {path} Test_Path_Src does_directory_exist {path} "Test_Sub_Dir" assert_result_true() - int value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test" + value = read_int_from_ini_file {path} "Test_File.ini" {section} "test" {key} "test" assert_eq(value, 42) set_current_directory {path} 0