{$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 "2302" // write_block_to_file debug_on trace "2302 (write_block_to_file)" const Test_Filename = "cleo:\cleo_tests\test_file.dat" // delete old test file if presesnt wait 0 if does_file_exist Test_Filename then if not delete_file Test_Filename then breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), Failed to delete previous test's file '%s'!" Test_Filename end end // create new file wait 0 if 0@ = open_file Test_Filename {mode} "w" then trace "~g~~h~~h~2302 (write_block_to_file), #1 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #1 FAILED! Failed to create '%s' file." Test_Filename end // test file size wait 0 1@ = get_file_size 0@ if 1@ == 0 then trace "~g~~h~~h~2302 (write_block_to_file), #2 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #2 FAILED!~n~0 Expected~n~%d Occured" 1@ end // write 0 bytes wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 0 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 0 then trace "~g~~h~~h~2302 (write_block_to_file), #3 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #3 FAILED!~n~%d Expected~n~%d Occured" 0 1@ end // write 1 byte wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 1 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 1 then trace "~g~~h~~h~2302 (write_block_to_file), #4 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #4 FAILED!~n~%d Expected~n~%d Occured" 1 1@ end // write 2 bytes wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 2 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 3 then trace "~g~~h~~h~2302 (write_block_to_file), #5 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #5 FAILED!~n~%d Expected~n~%d Occured" 3 1@ end // write 3 bytes wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 3 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 6 then trace "~g~~h~~h~2302 (write_block_to_file), #6 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #6 FAILED!~n~%d Expected~n~%d Occured" 6 1@ end // write 4 bytes wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 4 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 10 then trace "~g~~h~~h~2302 (write_block_to_file), #7 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #7 FAILED!~n~%d Expected~n~%d Occured" 10 1@ end // write 5 bytes wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 5 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 15 then trace "~g~~h~~h~2302 (write_block_to_file), #8 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #8 FAILED!~n~%d Expected~n~%d Occured" 15 1@ end // write 9 bytes wait 0 2@ = 0x33221100 3@ = 0x77665544 4@ = 0xBBAA9988 5@ = 0xFFEECCDD 6@ = get_var_pointer 3@ 2302: write_block_to_file 0@ {size} 9 {source} 6@ // tested opcode 1@ = get_file_size 0@ if 1@ == 24 then trace "~g~~h~~h~2302 (write_block_to_file), #9 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #9 FAILED!~n~%d Expected~n~%d Occured" 24 1@ end // close file wait 0 close_file 0@ trace "~g~~h~~h~2302 (write_block_to_file), #10 PASSED" // reopen to read wait 0 if 0@ = open_file Test_Filename {mode} "r" then trace "~g~~h~~h~2302 (write_block_to_file), #11 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #11 FAILED! Failed to open '%s' file." Test_Filename end // read and verify the data wait 0 2@ = 0 3@ = 0 4@ = 0 5@ = 0 read_from_file 0@ {size} 24 {destination} 2@ if 2@ == 0x44554444 3@ == 0x55446655 4@ == 0x55447766 5@ == 0x44887766 then trace "~g~~h~~h~2302 (write_block_to_file), #12 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #12 FAILED!~n~%08x %08x %08x %08x Expected~n~%08x %08x %08x %08x Occured" 0x44554444 0x55446655 0x55447766 0x44887766 2@ 3@ 4@ 5@ end // close file wait 0 close_file 0@ trace "~g~~h~~h~2302 (write_block_to_file), #13 PASSED" // delete file wait 0 if delete_file Test_Filename then trace "~g~~h~~h~2302 (write_block_to_file), #14 PASSED" else breakpoint "~r~~h~~h~~h~2302 (write_block_to_file), #12 FAILED! Failed to delete '%s' file." Test_Filename end terminate_this_custom_script