Add even more tests and some impl improvements from their results
This commit is contained in:
+85
-19
@@ -13,8 +13,9 @@ TEST_OUTPUT_DIR :: "./build/tests/out"
|
||||
// -----------------------------------------
|
||||
|
||||
Test_State :: struct {
|
||||
input_dir: string,
|
||||
output_dir: string,
|
||||
input_dir: string,
|
||||
output_dir: string,
|
||||
working_dir: string,
|
||||
}
|
||||
|
||||
// -----------------------------------------
|
||||
@@ -36,9 +37,13 @@ test_state_init :: proc(
|
||||
temp_output_path, err2 := os.mkdir_temp(TEST_OUTPUT_DIR, name, allocator)
|
||||
testing.expect(t, err2 == nil, os.error_string(err2))
|
||||
|
||||
working_dir, err3 := os.get_working_directory(context.allocator)
|
||||
testing.expect(t, err3 == nil, os.error_string(err3))
|
||||
|
||||
return Test_State {
|
||||
input_dir = temp_input_path,
|
||||
output_dir = temp_output_path,
|
||||
working_dir = working_dir,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,9 +77,13 @@ create_file :: proc(
|
||||
t: ^testing.T,
|
||||
path: string,
|
||||
content: string,
|
||||
is_output_file := false,
|
||||
allocator := context.allocator,
|
||||
) {
|
||||
relpath, err := os.join_path({ts.input_dir, path}, allocator)
|
||||
relpath, err := os.join_path(
|
||||
{!is_output_file ? ts.input_dir : ts.output_dir, path},
|
||||
allocator,
|
||||
)
|
||||
testing.expect(t, err == nil, os.error_string(err))
|
||||
defer delete(relpath, allocator)
|
||||
|
||||
@@ -106,27 +115,48 @@ delete_path :: proc(
|
||||
}
|
||||
}
|
||||
|
||||
pack :: proc(ts: ^Test_State, t: ^testing.T, size: u64) {
|
||||
wd, err := os.get_working_directory(context.allocator)
|
||||
testing.expect(t, err == nil, os.error_string(err))
|
||||
entries, err2 := file.list_dir_recursive_by_path(ts.input_dir, wd)
|
||||
testing.expect(t, err2 == nil, file.format_error(err2))
|
||||
pack :: proc(
|
||||
ts: ^Test_State,
|
||||
t: ^testing.T,
|
||||
size: u64,
|
||||
compression: u16 = 0,
|
||||
) -> (
|
||||
wa_err: chunks.Error,
|
||||
wm_err: chunks.Error,
|
||||
) {
|
||||
entries, err := file.list_dir_recursive_by_path(
|
||||
ts.input_dir,
|
||||
ts.working_dir,
|
||||
)
|
||||
testing.expect(t, err == nil, file.error_string(err))
|
||||
|
||||
w := chunks.writer_init(cast(u64)len(entries))
|
||||
defer chunks.writer_destroy(&w)
|
||||
|
||||
output_file, err3 := os.open(ts.output_dir, {.Read})
|
||||
testing.expect(t, err3 == nil, os.error_string(err3))
|
||||
output_file, err2 := os.open(ts.output_dir, {.Read})
|
||||
testing.expect(t, err2 == nil, os.error_string(err2))
|
||||
defer os.close(output_file)
|
||||
|
||||
err4 := chunks.write_assets(&w, output_file, entries[:], size, 0)
|
||||
testing.expect(t, err4 == nil, chunks.format_error(err4))
|
||||
wa_err = chunks.write_assets(
|
||||
&w,
|
||||
output_file,
|
||||
entries[:],
|
||||
size,
|
||||
compression,
|
||||
)
|
||||
if wa_err != nil do return wa_err, nil
|
||||
|
||||
err5 := chunks.write_metadata(&w, output_file, entries[:], size, 0)
|
||||
testing.expect(t, err5 == nil, chunks.format_error(err5))
|
||||
wm_err = chunks.write_metadata(
|
||||
&w,
|
||||
output_file,
|
||||
entries[:],
|
||||
size,
|
||||
compression,
|
||||
)
|
||||
return wa_err, wm_err
|
||||
}
|
||||
|
||||
read :: proc(
|
||||
read_asset :: proc(
|
||||
ts: ^Test_State,
|
||||
t: ^testing.T,
|
||||
path: string,
|
||||
@@ -139,22 +169,58 @@ read :: proc(
|
||||
testing.expect(t, err == nil, os.error_string(err))
|
||||
defer delete(relpath, allocator)
|
||||
|
||||
file, err2 := os.open(ts.output_dir)
|
||||
file, err2 := os.open(ts.output_dir, {.Read})
|
||||
testing.expect(t, err2 == nil, os.error_string(err2))
|
||||
defer os.close(file)
|
||||
|
||||
r, err3 := chunks.reader_init(file)
|
||||
testing.expect(t, err3 == nil, chunks.format_error(err3))
|
||||
testing.expect(t, err3 == nil, chunks.error_string(err3))
|
||||
defer chunks.reader_destroy(&r)
|
||||
|
||||
exists, i, err4 := chunks.asset_exists(&r, relpath)
|
||||
testing.expect(t, err4 == nil, chunks.format_error(err4))
|
||||
testing.expect(t, err4 == nil, chunks.error_string(err4))
|
||||
|
||||
if exists {
|
||||
bytes, err5 := chunks.read_asset(&r, relpath)
|
||||
testing.expect(t, err5 == nil, chunks.format_error(err5))
|
||||
testing.expect(t, err5 == nil, chunks.error_string(err5))
|
||||
return true, string(bytes)
|
||||
}
|
||||
|
||||
return false, {}
|
||||
}
|
||||
|
||||
read_asset_raw :: proc(
|
||||
ts: ^Test_State,
|
||||
t: ^testing.T,
|
||||
path: string,
|
||||
allocator := context.allocator,
|
||||
) -> (
|
||||
bytes: []u8,
|
||||
err: chunks.Error,
|
||||
) {
|
||||
relpath, err2 := os.join_path({ts.input_dir, path}, allocator)
|
||||
testing.expect(t, err2 == nil, os.error_string(err2))
|
||||
defer delete(relpath, allocator)
|
||||
|
||||
output_file, err3 := os.open(ts.output_dir, {.Read})
|
||||
testing.expect(t, err3 == nil, os.error_string(err3))
|
||||
defer os.close(output_file)
|
||||
|
||||
r, err4 := chunks.reader_init(output_file)
|
||||
testing.expect(t, err4 == nil, chunks.error_string(err4))
|
||||
defer chunks.reader_destroy(&r)
|
||||
|
||||
bytes, err = chunks.read_asset(&r, relpath)
|
||||
return bytes, err
|
||||
}
|
||||
|
||||
reader_init_raw :: proc(ts: ^Test_State, t: ^testing.T) -> chunks.Error {
|
||||
output_file, err2 := os.open(ts.output_dir, {.Read})
|
||||
testing.expect(t, err2 == nil, os.error_string(err2))
|
||||
defer os.close(output_file)
|
||||
|
||||
r, err := chunks.reader_init(output_file)
|
||||
defer chunks.reader_destroy(&r)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user