Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0A99 tests rewritten #241

Merged
merged 1 commit into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 73 additions & 99 deletions tests/cleo_tests/FilesystemOperations/0A99.txt
Original file line number Diff line number Diff line change
@@ -1,109 +1,83 @@
{$CLEO .s}
{$USE debug}
{$USE file}
{$USE bitwise}
var 0@ : Integer
var 1@ : Integer
var 2@ : Integer
var 3@ : Integer
var 4@ : Integer
var 5@ : Integer
var 6@ : Integer
var 7@ : Integer
var 8@ : Integer
var 9@ : Integer
var 10@ : Integer

script_name "0A99" // set_current_directory
debug_on

trace "0A99 (set_current_directory)"


wait 0
// set current script location as work dir
0A99: set_current_directory ".\\" // tested opcode

0@ = allocate_memory 260
string_format 0@ {format} ""
resolve_filepath 0@ {store_to} 0@

cleo_call @TEXT_LENGTH {args} 1 0@ {result} 1@
if
cleo_call @TEXT_ENDS_WITH {args} 2 0@ "\cleo\cleo_tests\FilesystemOperations"
then
trace "~g~~h~~h~0A99 (set_current_directory), #0 PASSED"
else
breakpoint "~r~~h~~h~~h~0A99 (set_current_directory), #0 FAILED! Current script dir: %s" 0@
end
free_memory 0@


wait 0
// set virtual absolute path
0A99: set_current_directory "cleo:" // tested opcode

0@ = allocate_memory 260
string_format 0@ {format} ""
resolve_filepath 0@ {store_to} 0@

cleo_call @TEXT_LENGTH {args} 1 0@ {result} 1@
if
cleo_call @TEXT_ENDS_WITH {args} 2 0@ "\cleo"
then
trace "~g~~h~~h~0A99 (set_current_directory), #1 PASSED"
else
breakpoint "~r~~h~~h~~h~0A99 (set_current_directory), #1 FAILED! Current script dir: %s" 0@
end
free_memory 0@


wait 0
// predefined number
0A99: set_current_directory 1 // tested opcode

0@ = allocate_memory 260
string_format 0@ {format} ""
resolve_filepath 0@ {store_to} 0@

cleo_call @TEXT_LENGTH {args} 1 0@ {result} 1@
if
cleo_call @TEXT_ENDS_WITH {args} 2 0@ "\GTA San Andreas User Files"
then
trace "~g~~h~~h~0A99 (set_current_directory), #2 PASSED"
else
breakpoint "~r~~h~~h~~h~0A99 (set_current_directory), #2 FAILED! Current script dir: %s" 0@
end
free_memory 0@

{$INCLUDE_ONCE ../cleo_tester.inc}

script_name "0A99"
test("0A99 (set_current_directory)", tests)
terminate_this_custom_script


:TEXT_LENGTH
call_function_return 0x00826330 args 1 pop 1 0@ result 5@
cleo_return_with true 5@


:TEXT_ENDS_WITH
cleo_call @TEXT_LENGTH {args} 1 0@ {result} 5@
cleo_call @TEXT_LENGTH {args} 1 1@ {result} 6@
if
5@ < 6@
then
cleo_return_with false
function tests
before_each(@setup)
after_each(@cleanup)

it("should set param 0", test1)
it("should set param 1", test2)
it("should set virtual paths", test3)
it("should set script path", test4)
it("should enter relative sub-path", test5)
return


:setup
0@ = allocate_memory {size} 512
set_current_directory {path} 0 // game root
return


:cleanup
free_memory {address} 0@
return


function test1
set_current_directory {path} 0 // game root
0@ = resolve_filepath ""
assert_eqs(0@, "") // relative to root, so empty
end

5@ -= 6@
0@ += 5@

call_function_return 0x0081E568 num_params 2 pop 0 0@ 1@ result 5@ // int lstrcmpiA(char* str, char* str)
if
5@ == 0
then
5@ = true
else
5@ = false
function test2
set_current_directory {path} 1 // user files
0@ = resolve_filepath ""
assert_suffix(0@, "\GTA San Andreas User Files", true)
end
cleo_return_with 5@


function test3
set_current_directory {path} "root:" // game root
0@ = resolve_filepath ""
assert_eqs(0@, "") // relative to root, so empty

set_current_directory {path} "user:" // user files
0@ = resolve_filepath ""
assert_suffix(0@, "\GTA San Andreas User Files", true)

set_current_directory {path} "cleo:" // cleo directory
0@ = resolve_filepath ""
assert_eqs(0@, "cleo") // relative to root

set_current_directory {path} "cleo:\cleo_plugins" // cleo sub-directory
0@ = resolve_filepath ""
assert_eqs(0@, "cleo\cleo_plugins") // relative to root
end


function test4
set_current_directory {path} ".\\" // this script's location
0@ = resolve_filepath ""
assert_eqs(0@, "cleo\cleo_tests\FilesystemOperations") // relative to root
end


function test5
set_current_directory {path} "root:"
set_current_directory {path} "data"
set_current_directory {path} "script"

0@ = resolve_filepath ""
assert_eqs(0@, "data\script") // relative to root

does_file_exist {path} "main.scm"
assert_result_true()
end
end
26 changes: 26 additions & 0 deletions tests/cleo_tests/cleo_tester.inc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ function assert_neqs(actual: string, expected: string)
end
end

/// checks if string starts with prefix, otherwise stops the test execution
function assert_prefix(actual: string, expectedPrefix: string, ignoreCase: int)
_cleo_tester_increment_assert()
if
not is_text_prefix {text} actual {prefix} expectedPrefix {ignoreCase} ignoreCase
then
_cleo_tester_fail()
trace "`~g~~h~~h~%s~s~` prefix expected~n~`~r~~h~~h~%s~s~` text occured" expectedPrefix actual
breakpoint
terminate_this_custom_script
end
end

/// checks if string ends with suffix, otherwise stops the test execution
function assert_suffix(actual: string, expectedSuffix: string, ignoreCase: int)
_cleo_tester_increment_assert()
if
not is_text_suffix {text} actual {prefix} expectedSuffix {ignoreCase} ignoreCase
then
_cleo_tester_fail()
trace "`~g~~h~~h~%s~s~` suffix expected~n~`~r~~h~~h~%s~s~` text occured" expectedSuffix actual
breakpoint
terminate_this_custom_script
end
end

/// registers a callback that runs before each unit test (test setup)
function before_each(callback: int)
_cleo_tester_write_var(VAR_BEFORE_EACH, callback)
Expand Down