mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
Port tests\core\encoding\hxa
And fix a few leaks in `core:encoding/hxa` while at it.
This commit is contained in:
+16
-15
@@ -160,34 +160,35 @@ CONVENTION_SOFT_TRANSFORM :: "transform"
|
|||||||
|
|
||||||
/* destroy procedures */
|
/* destroy procedures */
|
||||||
|
|
||||||
meta_destroy :: proc(meta: Meta, allocator := context.allocator) {
|
meta_destroy :: proc(meta: Meta, allocator := context.allocator, loc := #caller_location) {
|
||||||
if nested, ok := meta.value.([]Meta); ok {
|
if nested, ok := meta.value.([]Meta); ok {
|
||||||
for m in nested {
|
for m in nested {
|
||||||
meta_destroy(m)
|
meta_destroy(m, loc=loc)
|
||||||
}
|
}
|
||||||
delete(nested, allocator)
|
delete(nested, allocator, loc=loc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nodes_destroy :: proc(nodes: []Node, allocator := context.allocator) {
|
nodes_destroy :: proc(nodes: []Node, allocator := context.allocator, loc := #caller_location) {
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
for meta in node.meta_data {
|
for meta in node.meta_data {
|
||||||
meta_destroy(meta)
|
meta_destroy(meta, loc=loc)
|
||||||
}
|
}
|
||||||
delete(node.meta_data, allocator)
|
delete(node.meta_data, allocator, loc=loc)
|
||||||
|
|
||||||
switch n in node.content {
|
switch n in node.content {
|
||||||
case Node_Geometry:
|
case Node_Geometry:
|
||||||
delete(n.corner_stack, allocator)
|
delete(n.corner_stack, allocator, loc=loc)
|
||||||
delete(n.edge_stack, allocator)
|
delete(n.vertex_stack, allocator, loc=loc)
|
||||||
delete(n.face_stack, allocator)
|
delete(n.edge_stack, allocator, loc=loc)
|
||||||
|
delete(n.face_stack, allocator, loc=loc)
|
||||||
case Node_Image:
|
case Node_Image:
|
||||||
delete(n.image_stack, allocator)
|
delete(n.image_stack, allocator, loc=loc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete(nodes, allocator)
|
delete(nodes, allocator, loc=loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
file_destroy :: proc(file: File) {
|
file_destroy :: proc(file: File, loc := #caller_location) {
|
||||||
nodes_destroy(file.nodes, file.allocator)
|
nodes_destroy(file.nodes, file.allocator, loc=loc)
|
||||||
delete(file.backing, file.allocator)
|
delete(file.backing, file.allocator, loc=loc)
|
||||||
}
|
}
|
||||||
+20
-22
@@ -11,24 +11,21 @@ Read_Error :: enum {
|
|||||||
Unable_To_Read_File,
|
Unable_To_Read_File,
|
||||||
}
|
}
|
||||||
|
|
||||||
read_from_file :: proc(filename: string, print_error := false, allocator := context.allocator) -> (file: File, err: Read_Error) {
|
read_from_file :: proc(filename: string, print_error := false, allocator := context.allocator, loc := #caller_location) -> (file: File, err: Read_Error) {
|
||||||
context.allocator = allocator
|
context.allocator = allocator
|
||||||
|
|
||||||
data, ok := os.read_entire_file(filename)
|
data, ok := os.read_entire_file(filename, allocator, loc)
|
||||||
if !ok {
|
if !ok {
|
||||||
err = .Unable_To_Read_File
|
err = .Unable_To_Read_File
|
||||||
|
delete(data, allocator, loc)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer if !ok {
|
file, err = read(data, filename, print_error, allocator, loc)
|
||||||
delete(data)
|
file.backing = data
|
||||||
} else {
|
|
||||||
file.backing = data
|
|
||||||
}
|
|
||||||
file, err = read(data, filename, print_error, allocator)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
read :: proc(data: []byte, filename := "<input>", print_error := false, allocator := context.allocator) -> (file: File, err: Read_Error) {
|
read :: proc(data: []byte, filename := "<input>", print_error := false, allocator := context.allocator, loc := #caller_location) -> (file: File, err: Read_Error) {
|
||||||
Reader :: struct {
|
Reader :: struct {
|
||||||
filename: string,
|
filename: string,
|
||||||
data: []byte,
|
data: []byte,
|
||||||
@@ -79,8 +76,8 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
|
|||||||
return string(data[:len]), nil
|
return string(data[:len]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
read_meta :: proc(r: ^Reader, capacity: u32le) -> (meta_data: []Meta, err: Read_Error) {
|
read_meta :: proc(r: ^Reader, capacity: u32le, allocator := context.allocator, loc := #caller_location) -> (meta_data: []Meta, err: Read_Error) {
|
||||||
meta_data = make([]Meta, int(capacity))
|
meta_data = make([]Meta, int(capacity), allocator=allocator)
|
||||||
count := 0
|
count := 0
|
||||||
defer meta_data = meta_data[:count]
|
defer meta_data = meta_data[:count]
|
||||||
for &m in meta_data {
|
for &m in meta_data {
|
||||||
@@ -111,10 +108,10 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
read_layer_stack :: proc(r: ^Reader, capacity: u32le) -> (layers: Layer_Stack, err: Read_Error) {
|
read_layer_stack :: proc(r: ^Reader, capacity: u32le, allocator := context.allocator, loc := #caller_location) -> (layers: Layer_Stack, err: Read_Error) {
|
||||||
stack_count := read_value(r, u32le) or_return
|
stack_count := read_value(r, u32le) or_return
|
||||||
layer_count := 0
|
layer_count := 0
|
||||||
layers = make(Layer_Stack, stack_count)
|
layers = make(Layer_Stack, stack_count, allocator=allocator, loc=loc)
|
||||||
defer layers = layers[:layer_count]
|
defer layers = layers[:layer_count]
|
||||||
for &layer in layers {
|
for &layer in layers {
|
||||||
layer.name = read_name(r) or_return
|
layer.name = read_name(r) or_return
|
||||||
@@ -170,7 +167,8 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
|
|||||||
|
|
||||||
node_count := 0
|
node_count := 0
|
||||||
file.header = header^
|
file.header = header^
|
||||||
file.nodes = make([]Node, header.internal_node_count)
|
file.nodes = make([]Node, header.internal_node_count, allocator=allocator, loc=loc)
|
||||||
|
file.allocator = allocator
|
||||||
defer if err != nil {
|
defer if err != nil {
|
||||||
nodes_destroy(file.nodes)
|
nodes_destroy(file.nodes)
|
||||||
file.nodes = nil
|
file.nodes = nil
|
||||||
@@ -198,15 +196,15 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
|
|||||||
case .Geometry:
|
case .Geometry:
|
||||||
g: Node_Geometry
|
g: Node_Geometry
|
||||||
|
|
||||||
g.vertex_count = read_value(r, u32le) or_return
|
g.vertex_count = read_value(r, u32le) or_return
|
||||||
g.vertex_stack = read_layer_stack(r, g.vertex_count) or_return
|
g.vertex_stack = read_layer_stack(r, g.vertex_count, loc=loc) or_return
|
||||||
g.edge_corner_count = read_value(r, u32le) or_return
|
g.edge_corner_count = read_value(r, u32le) or_return
|
||||||
g.corner_stack = read_layer_stack(r, g.edge_corner_count) or_return
|
g.corner_stack = read_layer_stack(r, g.edge_corner_count, loc=loc) or_return
|
||||||
if header.version > 2 {
|
if header.version > 2 {
|
||||||
g.edge_stack = read_layer_stack(r, g.edge_corner_count) or_return
|
g.edge_stack = read_layer_stack(r, g.edge_corner_count, loc=loc) or_return
|
||||||
}
|
}
|
||||||
g.face_count = read_value(r, u32le) or_return
|
g.face_count = read_value(r, u32le) or_return
|
||||||
g.face_stack = read_layer_stack(r, g.face_count) or_return
|
g.face_stack = read_layer_stack(r, g.face_count, loc=loc) or_return
|
||||||
|
|
||||||
node.content = g
|
node.content = g
|
||||||
|
|
||||||
@@ -233,4 +231,4 @@ read :: proc(data: []byte, filename := "<input>", print_error := false, allocato
|
|||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
+1
-1
@@ -48,7 +48,7 @@ encoding_test:
|
|||||||
$(ODIN) test encoding/base64 $(COMMON) -out:test_base64
|
$(ODIN) test encoding/base64 $(COMMON) -out:test_base64
|
||||||
$(ODIN) test encoding/cbor $(COMMON) -out:test_cbor
|
$(ODIN) test encoding/cbor $(COMMON) -out:test_cbor
|
||||||
$(ODIN) test encoding/hex $(COMMON) -out:test_hex
|
$(ODIN) test encoding/hex $(COMMON) -out:test_hex
|
||||||
$(ODIN) run encoding/hxa $(COMMON) $(COLLECTION) -out:test_hxa
|
$(ODIN) test encoding/hxa $(COMMON) -out:test_hxa
|
||||||
$(ODIN) run encoding/json $(COMMON) -out:test_json
|
$(ODIN) run encoding/json $(COMMON) -out:test_json
|
||||||
$(ODIN) run encoding/varint $(COMMON) -out:test_varint
|
$(ODIN) run encoding/varint $(COMMON) -out:test_varint
|
||||||
$(ODIN) run encoding/xml $(COMMON) -out:test_xml
|
$(ODIN) run encoding/xml $(COMMON) -out:test_xml
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ echo ---
|
|||||||
%PATH_TO_ODIN% test encoding/base64 %COMMON% -out:test_base64.exe || exit /b
|
%PATH_TO_ODIN% test encoding/base64 %COMMON% -out:test_base64.exe || exit /b
|
||||||
%PATH_TO_ODIN% test encoding/cbor %COMMON% -out:test_cbor.exe || exit /b
|
%PATH_TO_ODIN% test encoding/cbor %COMMON% -out:test_cbor.exe || exit /b
|
||||||
%PATH_TO_ODIN% test encoding/hex %COMMON% -out:test_hex.exe || exit /b
|
%PATH_TO_ODIN% test encoding/hex %COMMON% -out:test_hex.exe || exit /b
|
||||||
rem %PATH_TO_ODIN% run encoding/hxa %COMMON% %COLLECTION% -out:test_hxa.exe || exit /b
|
%PATH_TO_ODIN% test encoding/hxa %COMMON% -out:test_hxa.exe || exit /b
|
||||||
%PATH_TO_ODIN% run encoding/json %COMMON% -out:test_json.exe || exit /b
|
%PATH_TO_ODIN% run encoding/json %COMMON% -out:test_json.exe || exit /b
|
||||||
%PATH_TO_ODIN% run encoding/varint %COMMON% -out:test_varint.exe || exit /b
|
%PATH_TO_ODIN% run encoding/varint %COMMON% -out:test_varint.exe || exit /b
|
||||||
%PATH_TO_ODIN% run encoding/xml %COMMON% -out:test_xml.exe || exit /b
|
%PATH_TO_ODIN% run encoding/xml %COMMON% -out:test_xml.exe || exit /b
|
||||||
|
|||||||
@@ -6,127 +6,99 @@ package test_core_hxa
|
|||||||
import "core:encoding/hxa"
|
import "core:encoding/hxa"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
import tc "tests:common"
|
|
||||||
|
|
||||||
TEAPOT_PATH :: "core/assets/HXA/teapot.hxa"
|
TEAPOT_PATH :: ODIN_ROOT + "tests/core/assets/HXA/teapot.hxa"
|
||||||
|
|
||||||
main :: proc() {
|
import "core:os"
|
||||||
t := testing.T{}
|
|
||||||
|
|
||||||
test_read(&t)
|
|
||||||
test_write(&t)
|
|
||||||
|
|
||||||
tc.report(&t)
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
@test
|
||||||
test_read :: proc(t: ^testing.T) {
|
test_read :: proc(t: ^testing.T) {
|
||||||
filename := tc.get_data_path(t, TEAPOT_PATH)
|
data, _ := os.read_entire_file(TEAPOT_PATH)
|
||||||
defer delete(filename)
|
// file, err := hxa.read_from_file(TEAPOT_PATH)
|
||||||
|
file, err := hxa.read(data)
|
||||||
|
file.backing = data
|
||||||
|
file.allocator = context.allocator
|
||||||
|
hxa.file_destroy(file)
|
||||||
|
// fmt.printfln("%#v", file)
|
||||||
|
|
||||||
file, err := hxa.read_from_file(filename)
|
|
||||||
e :: hxa.Read_Error.None
|
e :: hxa.Read_Error.None
|
||||||
tc.expect(t, err == e, fmt.tprintf("%v: read_from_file(%v) -> %v != %v", #procedure, filename, err, e))
|
testing.expectf(t, err == e, "read_from_file(%v) -> %v != %v", TEAPOT_PATH, err, e)
|
||||||
defer hxa.file_destroy(file)
|
|
||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
tc.expect(t, file.magic_number == 0x417848, fmt.tprintf("%v: file.magic_number %v != %v",
|
testing.expectf(t, file.magic_number == 0x417848, "file.magic_number %v != %v", file.magic_number, 0x417848)
|
||||||
#procedure, file.magic_number, 0x417848))
|
testing.expectf(t, file.version == 1, "file.version %v != %v", file.version, 1)
|
||||||
tc.expect(t, file.version == 1, fmt.tprintf("%v: file.version %v != %v",
|
testing.expectf(t, file.internal_node_count == 1, "file.internal_node_count %v != %v", file.internal_node_count, 1)
|
||||||
#procedure, file.version, 1))
|
|
||||||
tc.expect(t, file.internal_node_count == 1, fmt.tprintf("%v: file.internal_node_count %v != %v",
|
|
||||||
#procedure, file.internal_node_count, 1))
|
|
||||||
|
|
||||||
/* Nodes (only one) */
|
/* Nodes (only one) */
|
||||||
tc.expect(t, len(file.nodes) == 1, fmt.tprintf("%v: len(file.nodes) %v != %v", #procedure, len(file.nodes), 1))
|
testing.expectf(t, len(file.nodes) == 1, "len(file.nodes) %v != %v", len(file.nodes), 1)
|
||||||
|
|
||||||
m := &file.nodes[0].meta_data
|
m := &file.nodes[0].meta_data
|
||||||
tc.expect(t, len(m^) == 38, fmt.tprintf("%v: len(m^) %v != %v", #procedure, len(m^), 38))
|
testing.expectf(t, len(m^) == 38, "len(m^) %v != %v", len(m^), 38)
|
||||||
{
|
{
|
||||||
e :: "Texture resolution"
|
e :: "Texture resolution"
|
||||||
tc.expect(t, m[0].name == e, fmt.tprintf("%v: m[0].name %v != %v", #procedure, m[0].name, e))
|
testing.expectf(t, m[0].name == e, "m[0].name %v != %v", m[0].name, e)
|
||||||
|
|
||||||
m_v, m_v_ok := m[0].value.([]i64le)
|
m_v, m_v_ok := m[0].value.([]i64le)
|
||||||
tc.expect(t, m_v_ok, fmt.tprintf("%v: m_v_ok %v != %v", #procedure, m_v_ok, true))
|
testing.expectf(t, m_v_ok, "m_v_ok %v != %v", m_v_ok, true)
|
||||||
tc.expect(t, len(m_v) == 1, fmt.tprintf("%v: len(m_v) %v != %v", #procedure, len(m_v), 1))
|
testing.expectf(t, len(m_v) == 1, "len(m_v) %v != %v", len(m_v), 1)
|
||||||
tc.expect(t, m_v[0] == 1024, fmt.tprintf("%v: m_v[0] %v != %v", #procedure, len(m_v), 1024))
|
testing.expectf(t, m_v[0] == 1024, "m_v[0] %v != %v", len(m_v), 1024)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
e :: "Validate"
|
e :: "Validate"
|
||||||
tc.expect(t, m[37].name == e, fmt.tprintf("%v: m[37].name %v != %v", #procedure, m[37].name, e))
|
testing.expectf(t, m[37].name == e, "m[37].name %v != %v", m[37].name, e)
|
||||||
|
|
||||||
m_v, m_v_ok := m[37].value.([]i64le)
|
m_v, m_v_ok := m[37].value.([]i64le)
|
||||||
tc.expect(t, m_v_ok, fmt.tprintf("%v: m_v_ok %v != %v", #procedure, m_v_ok, true))
|
testing.expectf(t, m_v_ok, "m_v_ok %v != %v", m_v_ok, true)
|
||||||
tc.expect(t, len(m_v) == 1, fmt.tprintf("%v: len(m_v) %v != %v", #procedure, len(m_v), 1))
|
testing.expectf(t, len(m_v) == 1, "len(m_v) %v != %v", len(m_v), 1)
|
||||||
tc.expect(t, m_v[0] == -2054847231, fmt.tprintf("%v: m_v[0] %v != %v", #procedure, len(m_v), -2054847231))
|
testing.expectf(t, m_v[0] == -2054847231, "m_v[0] %v != %v", len(m_v), -2054847231)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Node content */
|
/* Node content */
|
||||||
v, v_ok := file.nodes[0].content.(hxa.Node_Geometry)
|
v, v_ok := file.nodes[0].content.(hxa.Node_Geometry)
|
||||||
tc.expect(t, v_ok, fmt.tprintf("%v: v_ok %v != %v", #procedure, v_ok, true))
|
testing.expectf(t, v_ok, "v_ok %v != %v", v_ok, true)
|
||||||
|
|
||||||
tc.expect(t, v.vertex_count == 530, fmt.tprintf("%v: v.vertex_count %v != %v", #procedure, v.vertex_count, 530))
|
testing.expectf(t, v.vertex_count == 530, "v.vertex_count %v != %v", v.vertex_count, 530)
|
||||||
tc.expect(t, v.edge_corner_count == 2026, fmt.tprintf("%v: v.edge_corner_count %v != %v",
|
testing.expectf(t, v.edge_corner_count == 2026, "v.edge_corner_count %v != %v", v.edge_corner_count, 2026)
|
||||||
#procedure, v.edge_corner_count, 2026))
|
testing.expectf(t, v.face_count == 517, "v.face_count %v != %v", v.face_count, 517)
|
||||||
tc.expect(t, v.face_count == 517, fmt.tprintf("%v: v.face_count %v != %v", #procedure, v.face_count, 517))
|
|
||||||
|
|
||||||
/* Vertex stack */
|
/* Vertex stack */
|
||||||
tc.expect(t, len(v.vertex_stack) == 1, fmt.tprintf("%v: len(v.vertex_stack) %v != %v",
|
testing.expectf(t, len(v.vertex_stack) == 1, "len(v.vertex_stack) %v != %v", len(v.vertex_stack), 1)
|
||||||
#procedure, len(v.vertex_stack), 1))
|
|
||||||
{
|
{
|
||||||
e := "vertex"
|
e := "vertex"
|
||||||
tc.expect(t, v.vertex_stack[0].name == e, fmt.tprintf("%v: v.vertex_stack[0].name %v != %v",
|
testing.expectf(t, v.vertex_stack[0].name == e, "v.vertex_stack[0].name %v != %v", v.vertex_stack[0].name, e)
|
||||||
#procedure, v.vertex_stack[0].name, e))
|
|
||||||
}
|
}
|
||||||
tc.expect(t, v.vertex_stack[0].components == 3, fmt.tprintf("%v: v.vertex_stack[0].components %v != %v",
|
testing.expectf(t, v.vertex_stack[0].components == 3, "v.vertex_stack[0].components %v != %v", v.vertex_stack[0].components, 3)
|
||||||
#procedure, v.vertex_stack[0].components, 3))
|
|
||||||
|
|
||||||
/* Vertex stack data */
|
/* Vertex stack data */
|
||||||
vs_d, vs_d_ok := v.vertex_stack[0].data.([]f64le)
|
vs_d, vs_d_ok := v.vertex_stack[0].data.([]f64le)
|
||||||
tc.expect(t, vs_d_ok, fmt.tprintf("%v: vs_d_ok %v != %v", #procedure, vs_d_ok, true))
|
testing.expectf(t, vs_d_ok, "vs_d_ok %v != %v", vs_d_ok, true)
|
||||||
tc.expect(t, len(vs_d) == 1590, fmt.tprintf("%v: len(vs_d) %v != %v", #procedure, len(vs_d), 1590))
|
testing.expectf(t, len(vs_d) == 1590, "len(vs_d) %v != %v", len(vs_d), 1590)
|
||||||
|
testing.expectf(t, vs_d[0] == 4.06266, "vs_d[0] %v (%h) != %v (%h)", vs_d[0], vs_d[0], 4.06266, 4.06266)
|
||||||
tc.expect(t, vs_d[0] == 4.06266, fmt.tprintf("%v: vs_d[0] %v (%h) != %v (%h)",
|
testing.expectf(t, vs_d[1] == 2.83457, "vs_d[1] %v (%h) != %v (%h)", vs_d[1], vs_d[1], 2.83457, 2.83457)
|
||||||
#procedure, vs_d[0], vs_d[0], 4.06266, 4.06266))
|
testing.expectf(t, vs_d[2] == 0hbfbc5da6a4441787, "vs_d[2] %v (%h) != %v (%h)", vs_d[2], vs_d[2], 0hbfbc5da6a4441787, 0hbfbc5da6a4441787)
|
||||||
tc.expect(t, vs_d[1] == 2.83457, fmt.tprintf("%v: vs_d[1] %v (%h) != %v (%h)",
|
testing.expectf(t, vs_d[3] == 0h4010074fb549f948, "vs_d[3] %v (%h) != %v (%h)", vs_d[3], vs_d[3], 0h4010074fb549f948, 0h4010074fb549f948)
|
||||||
#procedure, vs_d[1], vs_d[1], 2.83457, 2.83457))
|
testing.expectf(t, vs_d[1587] == 0h400befa82e87d2c7, "vs_d[1587] %v (%h) != %v (%h)", vs_d[1587], vs_d[1587], 0h400befa82e87d2c7, 0h400befa82e87d2c7)
|
||||||
tc.expect(t, vs_d[2] == 0hbfbc5da6a4441787, fmt.tprintf("%v: vs_d[2] %v (%h) != %v (%h)",
|
testing.expectf(t, vs_d[1588] == 2.83457, "vs_d[1588] %v (%h) != %v (%h)", vs_d[1588], vs_d[1588], 2.83457, 2.83457)
|
||||||
#procedure, vs_d[2], vs_d[2],
|
testing.expectf(t, vs_d[1589] == -1.56121, "vs_d[1589] %v (%h) != %v (%h)", vs_d[1589], vs_d[1589], -1.56121, -1.56121)
|
||||||
0hbfbc5da6a4441787, 0hbfbc5da6a4441787))
|
|
||||||
tc.expect(t, vs_d[3] == 0h4010074fb549f948, fmt.tprintf("%v: vs_d[3] %v (%h) != %v (%h)",
|
|
||||||
#procedure, vs_d[3], vs_d[3],
|
|
||||||
0h4010074fb549f948, 0h4010074fb549f948))
|
|
||||||
tc.expect(t, vs_d[1587] == 0h400befa82e87d2c7, fmt.tprintf("%v: vs_d[1587] %v (%h) != %v (%h)",
|
|
||||||
#procedure, vs_d[1587], vs_d[1587],
|
|
||||||
0h400befa82e87d2c7, 0h400befa82e87d2c7))
|
|
||||||
tc.expect(t, vs_d[1588] == 2.83457, fmt.tprintf("%v: vs_d[1588] %v (%h) != %v (%h)",
|
|
||||||
#procedure, vs_d[1588], vs_d[1588], 2.83457, 2.83457))
|
|
||||||
tc.expect(t, vs_d[1589] == -1.56121, fmt.tprintf("%v: vs_d[1589] %v (%h) != %v (%h)",
|
|
||||||
#procedure, vs_d[1589], vs_d[1589], -1.56121, -1.56121))
|
|
||||||
|
|
||||||
/* Corner stack */
|
/* Corner stack */
|
||||||
tc.expect(t, len(v.corner_stack) == 1,
|
testing.expectf(t, len(v.corner_stack) == 1, "len(v.corner_stack) %v != %v", len(v.corner_stack), 1)
|
||||||
fmt.tprintf("%v: len(v.corner_stack) %v != %v", #procedure, len(v.corner_stack), 1))
|
|
||||||
{
|
{
|
||||||
e := "reference"
|
e := "reference"
|
||||||
tc.expect(t, v.corner_stack[0].name == e, fmt.tprintf("%v: v.corner_stack[0].name %v != %v",
|
testing.expectf(t, v.corner_stack[0].name == e, "v.corner_stack[0].name %v != %v", v.corner_stack[0].name, e)
|
||||||
#procedure, v.corner_stack[0].name, e))
|
|
||||||
}
|
}
|
||||||
tc.expect(t, v.corner_stack[0].components == 1, fmt.tprintf("%v: v.corner_stack[0].components %v != %v",
|
testing.expectf(t, v.corner_stack[0].components == 1, "v.corner_stack[0].components %v != %v", v.corner_stack[0].components, 1)
|
||||||
#procedure, v.corner_stack[0].components, 1))
|
|
||||||
|
|
||||||
/* Corner stack data */
|
/* Corner stack data */
|
||||||
cs_d, cs_d_ok := v.corner_stack[0].data.([]i32le)
|
cs_d, cs_d_ok := v.corner_stack[0].data.([]i32le)
|
||||||
tc.expect(t, cs_d_ok, fmt.tprintf("%v: cs_d_ok %v != %v", #procedure, cs_d_ok, true))
|
testing.expectf(t, cs_d_ok, "cs_d_ok %v != %v", cs_d_ok, true)
|
||||||
tc.expect(t, len(cs_d) == 2026, fmt.tprintf("%v: len(cs_d) %v != %v", #procedure, len(cs_d), 2026))
|
testing.expectf(t, len(cs_d) == 2026, "len(cs_d) %v != %v", len(cs_d), 2026)
|
||||||
tc.expect(t, cs_d[0] == 6, fmt.tprintf("%v: cs_d[0] %v != %v", #procedure, cs_d[0], 6))
|
testing.expectf(t, cs_d[0] == 6, "cs_d[0] %v != %v", cs_d[0], 6)
|
||||||
tc.expect(t, cs_d[2025] == -32, fmt.tprintf("%v: cs_d[2025] %v != %v", #procedure, cs_d[2025], -32))
|
testing.expectf(t, cs_d[2025] == -32, "cs_d[2025] %v != %v", cs_d[2025], -32)
|
||||||
|
|
||||||
/* Edge and face stacks (empty) */
|
/* Edge and face stacks (empty) */
|
||||||
tc.expect(t, len(v.edge_stack) == 0, fmt.tprintf("%v: len(v.edge_stack) %v != %v",
|
testing.expectf(t, len(v.edge_stack) == 0, "len(v.edge_stack) %v != %v", len(v.edge_stack), 0)
|
||||||
#procedure, len(v.edge_stack), 0))
|
testing.expectf(t, len(v.face_stack) == 0, "len(v.face_stack) %v != %v", len(v.face_stack), 0)
|
||||||
tc.expect(t, len(v.face_stack) == 0, fmt.tprintf("%v: len(v.face_stack) %v != %v",
|
|
||||||
#procedure, len(v.face_stack), 0))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test
|
@test
|
||||||
@@ -154,72 +126,72 @@ test_write :: proc(t: ^testing.T) {
|
|||||||
|
|
||||||
n, write_err := hxa.write(buf, w_file)
|
n, write_err := hxa.write(buf, w_file)
|
||||||
write_e :: hxa.Write_Error.None
|
write_e :: hxa.Write_Error.None
|
||||||
tc.expect(t, write_err == write_e, fmt.tprintf("%v: write_err %v != %v", #procedure, write_err, write_e))
|
testing.expectf(t, write_err == write_e, fmt.tprintf("write_err %v != %v", write_err, write_e))
|
||||||
tc.expect(t, n == required_size, fmt.tprintf("%v: n %v != %v", #procedure, n, required_size))
|
testing.expectf(t, n == required_size, fmt.tprintf("n %v != %v", n, required_size))
|
||||||
|
|
||||||
file, read_err := hxa.read(buf)
|
file, read_err := hxa.read(buf)
|
||||||
read_e :: hxa.Read_Error.None
|
read_e :: hxa.Read_Error.None
|
||||||
tc.expect(t, read_err == read_e, fmt.tprintf("%v: read_err %v != %v", #procedure, read_err, read_e))
|
testing.expectf(t, read_err == read_e, fmt.tprintf("read_err %v != %v", read_err, read_e))
|
||||||
defer hxa.file_destroy(file)
|
defer hxa.file_destroy(file)
|
||||||
|
|
||||||
tc.expect(t, file.magic_number == 0x417848, fmt.tprintf("%v: file.magic_number %v != %v",
|
testing.expectf(t, file.magic_number == 0x417848, fmt.tprintf("file.magic_number %v != %v",
|
||||||
#procedure, file.magic_number, 0x417848))
|
file.magic_number, 0x417848))
|
||||||
tc.expect(t, file.version == 3, fmt.tprintf("%v: file.version %v != %v", #procedure, file.version, 3))
|
testing.expectf(t, file.version == 3, fmt.tprintf("file.version %v != %v", file.version, 3))
|
||||||
tc.expect(t, file.internal_node_count == 1, fmt.tprintf("%v: file.internal_node_count %v != %v",
|
testing.expectf(t, file.internal_node_count == 1, fmt.tprintf("file.internal_node_count %v != %v",
|
||||||
#procedure, file.internal_node_count, 1))
|
file.internal_node_count, 1))
|
||||||
|
|
||||||
tc.expect(t, len(file.nodes) == len(w_file.nodes), fmt.tprintf("%v: len(file.nodes) %v != %v",
|
testing.expectf(t, len(file.nodes) == len(w_file.nodes), fmt.tprintf("len(file.nodes) %v != %v",
|
||||||
#procedure, len(file.nodes), len(w_file.nodes)))
|
len(file.nodes), len(w_file.nodes)))
|
||||||
|
|
||||||
m := &file.nodes[0].meta_data
|
m := &file.nodes[0].meta_data
|
||||||
w_m := &w_file.nodes[0].meta_data
|
w_m := &w_file.nodes[0].meta_data
|
||||||
tc.expect(t, len(m^) == len(w_m^), fmt.tprintf("%v: len(m^) %v != %v", #procedure, len(m^), len(w_m^)))
|
testing.expectf(t, len(m^) == len(w_m^), fmt.tprintf("len(m^) %v != %v", len(m^), len(w_m^)))
|
||||||
tc.expect(t, m[0].name == w_m[0].name, fmt.tprintf("%v: m[0].name %v != %v", #procedure, m[0].name, w_m[0].name))
|
testing.expectf(t, m[0].name == w_m[0].name, fmt.tprintf("m[0].name %v != %v", m[0].name, w_m[0].name))
|
||||||
|
|
||||||
m_v, m_v_ok := m[0].value.([]f64le)
|
m_v, m_v_ok := m[0].value.([]f64le)
|
||||||
tc.expect(t, m_v_ok, fmt.tprintf("%v: m_v_ok %v != %v", #procedure, m_v_ok, true))
|
testing.expectf(t, m_v_ok, fmt.tprintf("m_v_ok %v != %v", m_v_ok, true))
|
||||||
tc.expect(t, len(m_v) == len(n1_m1_value), fmt.tprintf("%v: %v != len(m_v) %v",
|
testing.expectf(t, len(m_v) == len(n1_m1_value), fmt.tprintf("%v != len(m_v) %v",
|
||||||
#procedure, len(m_v), len(n1_m1_value)))
|
len(m_v), len(n1_m1_value)))
|
||||||
for i := 0; i < len(m_v); i += 1 {
|
for i := 0; i < len(m_v); i += 1 {
|
||||||
tc.expect(t, m_v[i] == n1_m1_value[i], fmt.tprintf("%v: m_v[%d] %v != %v",
|
testing.expectf(t, m_v[i] == n1_m1_value[i], fmt.tprintf("m_v[%d] %v != %v",
|
||||||
#procedure, i, m_v[i], n1_m1_value[i]))
|
i, m_v[i], n1_m1_value[i]))
|
||||||
}
|
}
|
||||||
|
|
||||||
v, v_ok := file.nodes[0].content.(hxa.Node_Image)
|
v, v_ok := file.nodes[0].content.(hxa.Node_Image)
|
||||||
tc.expect(t, v_ok, fmt.tprintf("%v: v_ok %v != %v", #procedure, v_ok, true))
|
testing.expectf(t, v_ok, fmt.tprintf("v_ok %v != %v", v_ok, true))
|
||||||
tc.expect(t, v.type == n1_content.type, fmt.tprintf("%v: v.type %v != %v", #procedure, v.type, n1_content.type))
|
testing.expectf(t, v.type == n1_content.type, fmt.tprintf("v.type %v != %v", v.type, n1_content.type))
|
||||||
tc.expect(t, len(v.resolution) == 3, fmt.tprintf("%v: len(v.resolution) %v != %v",
|
testing.expectf(t, len(v.resolution) == 3, fmt.tprintf("len(v.resolution) %v != %v",
|
||||||
#procedure, len(v.resolution), 3))
|
len(v.resolution), 3))
|
||||||
tc.expect(t, len(v.image_stack) == len(n1_content.image_stack), fmt.tprintf("%v: len(v.image_stack) %v != %v",
|
testing.expectf(t, len(v.image_stack) == len(n1_content.image_stack), fmt.tprintf("len(v.image_stack) %v != %v",
|
||||||
#procedure, len(v.image_stack), len(n1_content.image_stack)))
|
len(v.image_stack), len(n1_content.image_stack)))
|
||||||
for i := 0; i < len(v.image_stack); i += 1 {
|
for i := 0; i < len(v.image_stack); i += 1 {
|
||||||
tc.expect(t, v.image_stack[i].name == n1_content.image_stack[i].name,
|
testing.expectf(t, v.image_stack[i].name == n1_content.image_stack[i].name,
|
||||||
fmt.tprintf("%v: v.image_stack[%d].name %v != %v",
|
fmt.tprintf("v.image_stack[%d].name %v != %v",
|
||||||
#procedure, i, v.image_stack[i].name, n1_content.image_stack[i].name))
|
i, v.image_stack[i].name, n1_content.image_stack[i].name))
|
||||||
tc.expect(t, v.image_stack[i].components == n1_content.image_stack[i].components,
|
testing.expectf(t, v.image_stack[i].components == n1_content.image_stack[i].components,
|
||||||
fmt.tprintf("%v: v.image_stack[%d].components %v != %v",
|
fmt.tprintf("v.image_stack[%d].components %v != %v",
|
||||||
#procedure, i, v.image_stack[i].components, n1_content.image_stack[i].components))
|
i, v.image_stack[i].components, n1_content.image_stack[i].components))
|
||||||
|
|
||||||
switch n1_t in n1_content.image_stack[i].data {
|
switch n1_t in n1_content.image_stack[i].data {
|
||||||
case []u8:
|
case []u8:
|
||||||
tc.expect(t, false, fmt.tprintf("%v: n1_content.image_stack[i].data []u8", #procedure))
|
testing.expectf(t, false, fmt.tprintf("n1_content.image_stack[i].data []u8", #procedure))
|
||||||
case []i32le:
|
case []i32le:
|
||||||
tc.expect(t, false, fmt.tprintf("%v: n1_content.image_stack[i].data []i32le", #procedure))
|
testing.expectf(t, false, fmt.tprintf("n1_content.image_stack[i].data []i32le", #procedure))
|
||||||
case []f32le:
|
case []f32le:
|
||||||
l, l_ok := v.image_stack[i].data.([]f32le)
|
l, l_ok := v.image_stack[i].data.([]f32le)
|
||||||
tc.expect(t, l_ok, fmt.tprintf("%v: l_ok %v != %v", #procedure, l_ok, true))
|
testing.expectf(t, l_ok, fmt.tprintf("l_ok %v != %v", l_ok, true))
|
||||||
tc.expect(t, len(l) == len(n1_t), fmt.tprintf("%v: len(l) %v != %v", #procedure, len(l), len(n1_t)))
|
testing.expectf(t, len(l) == len(n1_t), fmt.tprintf("len(l) %v != %v", len(l), len(n1_t)))
|
||||||
for j := 0; j < len(l); j += 1 {
|
for j := 0; j < len(l); j += 1 {
|
||||||
tc.expect(t, l[j] == n1_t[j], fmt.tprintf("%v: l[%d] %v (%h) != %v (%h)",
|
testing.expectf(t, l[j] == n1_t[j], fmt.tprintf("l[%d] %v (%h) != %v (%h)",
|
||||||
#procedure, j, l[j], l[j], n1_t[j], n1_t[j]))
|
j, l[j], l[j], n1_t[j], n1_t[j]))
|
||||||
}
|
}
|
||||||
case []f64le:
|
case []f64le:
|
||||||
l, l_ok := v.image_stack[i].data.([]f64le)
|
l, l_ok := v.image_stack[i].data.([]f64le)
|
||||||
tc.expect(t, l_ok, fmt.tprintf("%v: l_ok %v != %v", #procedure, l_ok, true))
|
testing.expectf(t, l_ok, fmt.tprintf("l_ok %v != %v", l_ok, true))
|
||||||
tc.expect(t, len(l) == len(n1_t), fmt.tprintf("%v: len(l) %v != %v", #procedure, len(l), len(n1_t)))
|
testing.expectf(t, len(l) == len(n1_t), fmt.tprintf("len(l) %v != %v", len(l), len(n1_t)))
|
||||||
for j := 0; j < len(l); j += 1 {
|
for j := 0; j < len(l); j += 1 {
|
||||||
tc.expect(t, l[j] == n1_t[j], fmt.tprintf("%v: l[%d] %v != %v", #procedure, j, l[j], n1_t[j]))
|
testing.expectf(t, l[j] == n1_t[j], fmt.tprintf("l[%d] %v != %v", j, l[j], n1_t[j]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user