Skip to content

Commit

Permalink
Added IniFiles tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Sep 30, 2024
1 parent 08416ca commit d8ee3ba
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/cleo_tests/IniFiles/0AF0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AF0"
test("0AF0 (read_int_from_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@setup)
after_each(@cleanup)

it("should fail on not-existing file", test1)
it("should fail on invalid file", test2)
it("should fail on not existing value", test3)
it("should fail on invalid type", test4)
it("should read value", test5)

return

:setup
delete_file {path} Test_Path
write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test_int"
write_float_to_ini_file {value} 50.0 {path} Test_Path {section} "test" {key} "test_float"
write_string_to_ini_file {value} "value_one" {path} Test_Path {section} "test" {key} "test_string"
return

:cleanup
delete_file {path} Test_Path
return

function test1
int value = read_int_from_ini_file {path} "not_a_file.ini" {section} "test" {key} "test_int"
assert_result_false()
end

function test2
int value = read_int_from_ini_file {path} "cleo.asi" {section} "test" {key} "test_int"
assert_result_false()
end

function test3
int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "invalid_key"
assert_result_false()
end

function test4
int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test_string"
assert_result_false()
end

function test5
int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test_int"
assert_result_true()
assert_eq(value, 42)
end
end
81 changes: 81 additions & 0 deletions tests/cleo_tests/IniFiles/0AF1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AF1"
test("0AF1 (write_int_to_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail to overwrite file", test1)
it("should fail to overwrite directory", test2)
it("should create new file", test3)
it("should append to existing file", test4)
it("should overwrite value", test5)
return

:cleanup
delete_file {path} Test_Path
return

function test1
write_int_to_ini_file {value} 42 {path} "gta_sa.exe" {section} "test" {key} "test"
assert_result_false()
end

function test2
write_int_to_ini_file {value} 42 {path} "cleo" {section} "test" {key} "test"
assert_result_false()
end

function test3
does_file_exist {path} Test_Path
assert_result_false()

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()

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

function test4
does_file_exist {path} Test_Path
assert_result_false()

write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "testA"
assert_result_true()

write_int_to_ini_file {value} 50 {path} Test_Path {section} "test" {key} "testB"
assert_result_true()

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

value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "testB"
assert_eq(value, 50)
end

function test5
does_file_exist {path} Test_Path
assert_result_false()

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

write_int_to_ini_file {value} 50 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

int value = read_int_from_ini_file {path} Test_Path {section} "test" {key} "test"
assert_eq(value, 50)
end

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

script_name "0AF2"
test("0AF2 (read_float_from_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@setup)
after_each(@cleanup)

it("should fail on not-existing file", test1)
it("should fail on invalid file", test2)
it("should fail on not existing value", test3)
it("should fail on invalid type", test4)
it("should read value", test5)

return

:setup
delete_file {path} Test_Path
write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test_int"
write_float_to_ini_file {value} 50.0 {path} Test_Path {section} "test" {key} "test_float"
write_string_to_ini_file {value} "value_one" {path} Test_Path {section} "test" {key} "test_string"
return

:cleanup
delete_file {path} Test_Path
return

function test1
float value = read_float_from_ini_file {path} "not_a_file.ini" {section} "test" {key} "test_float"
assert_result_false()
end

function test2
float value = read_float_from_ini_file {path} "cleo.asi" {section} "test" {key} "test_float"
assert_result_false()
end

function test3
float value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "invalid_key"
assert_result_false()
end

function test4
float value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "test_string"
assert_result_false()
end

function test5
float value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "test_float"
assert_result_true()
assert_eqf(value, 50.0)
end
end
81 changes: 81 additions & 0 deletions tests/cleo_tests/IniFiles/0AF3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{$CLEO .s}
{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0AF3"
test("0AF3 (write_float_to_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@cleanup)
after_each(@cleanup)

it("should fail to overwrite file", test1)
it("should fail to overwrite directory", test2)
it("should create new file", test3)
it("should append to existing file", test4)
it("should overwrite value", test5)
return

:cleanup
delete_file {path} Test_Path
return

function test1
write_float_to_ini_file {value} 42.0 {path} "gta_sa.exe" {section} "test" {key} "test"
assert_result_false()
end

function test2
write_float_to_ini_file {value} 42.0 {path} "cleo" {section} "test" {key} "test"
assert_result_false()
end

function test3
does_file_exist {path} Test_Path
assert_result_false()

write_float_to_ini_file {value} 42.0 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

does_file_exist {path} Test_Path
assert_result_true()

int value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "test"
assert_eqf(value, 42.0)
end

function test4
does_file_exist {path} Test_Path
assert_result_false()

write_float_to_ini_file {value} 42.0 {path} Test_Path {section} "test" {key} "testA"
assert_result_true()

write_float_to_ini_file {value} 50.0 {path} Test_Path {section} "test" {key} "testB"
assert_result_true()

int value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "testA"
assert_eqf(value, 42.0)

value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "testB"
assert_eqf(value, 50.0)
end

function test5
does_file_exist {path} Test_Path
assert_result_false()

write_float_to_ini_file {value} 42.0 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

write_float_to_ini_file {value} 50.0 {path} Test_Path {section} "test" {key} "test"
assert_result_true()

int value = read_float_from_ini_file {path} Test_Path {section} "test" {key} "test"
assert_eqf(value, 50.0)
end

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

script_name "0AF4"
test("0AF4 (read_string_from_ini_file)", tests)
terminate_this_custom_script


const Test_Path = "cleo\\cleo_test_file.ini"

function tests
before_each(@setup)
after_each(@cleanup)

it("should fail on not-existing file", test1)
it("should fail on invalid file", test2)
it("should fail on not existing value", test3)
it("should read value", test4)

return

:setup
delete_file {path} Test_Path
write_int_to_ini_file {value} 42 {path} Test_Path {section} "test" {key} "test_int"
write_float_to_ini_file {value} 50.0 {path} Test_Path {section} "test" {key} "test_float"
write_string_to_ini_file {value} "value_one" {path} Test_Path {section} "test" {key} "test_string"
return

:cleanup
delete_file {path} Test_Path
return

function test1
longstring value = read_string_from_ini_file {path} "not_a_file.ini" {section} "test" {key} "test_string"
assert_result_false()
end

function test2
longstring value = read_string_from_ini_file {path} "cleo.asi" {section} "test" {key} "test_string"
assert_result_false()
end

function test3
longstring value = read_string_from_ini_file {path} Test_Path {section} "test" {key} "invalid_key"
assert_result_false()
end

function test4
longstring value = read_string_from_ini_file {path} Test_Path {section} "test" {key} "test_string"
assert_result_true()
assert_eqs(value, "value_one")
end
end
Loading

0 comments on commit d8ee3ba

Please sign in to comment.