Update tests\core\encoding\cbor to use new test runner.

It was leaky and required a substantial number of `loc := #caller_location` additions to parts of the core library to make it easier to track down how and where it leaked.

The tests now run fine multi-threaded.
This commit is contained in:
Jeroen van Rijn
2024-06-02 14:47:07 -04:00
committed by Feoramund
parent 6a1649d8aa
commit a27b167218
11 changed files with 323 additions and 420 deletions
+21 -44
View File
@@ -1,61 +1,38 @@
package test_encoding_base64
import "base:intrinsics"
import "core:encoding/base64"
import "core:fmt"
import "core:os"
import "core:reflect"
import "core:testing"
TEST_count := 0
TEST_fail := 0
when ODIN_TEST {
expect_value :: testing.expect_value
} else {
expect_value :: proc(t: ^testing.T, value, expected: $T, loc := #caller_location) -> bool where intrinsics.type_is_comparable(T) {
TEST_count += 1
ok := value == expected || reflect.is_nil(value) && reflect.is_nil(expected)
if !ok {
TEST_fail += 1
fmt.printf("[%v] expected %v, got %v\n", loc, expected, value)
}
return ok
}
Test :: struct {
vector: string,
base64: string,
}
main :: proc() {
t := testing.T{}
test_encoding(&t)
test_decoding(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
os.exit(1)
}
tests :: []Test{
{"", ""},
{"f", "Zg=="},
{"fo", "Zm8="},
{"foo", "Zm9v"},
{"foob", "Zm9vYg=="},
{"fooba", "Zm9vYmE="},
{"foobar", "Zm9vYmFy"},
}
@(test)
test_encoding :: proc(t: ^testing.T) {
expect_value(t, base64.encode(transmute([]byte)string("")), "")
expect_value(t, base64.encode(transmute([]byte)string("f")), "Zg==")
expect_value(t, base64.encode(transmute([]byte)string("fo")), "Zm8=")
expect_value(t, base64.encode(transmute([]byte)string("foo")), "Zm9v")
expect_value(t, base64.encode(transmute([]byte)string("foob")), "Zm9vYg==")
expect_value(t, base64.encode(transmute([]byte)string("fooba")), "Zm9vYmE=")
expect_value(t, base64.encode(transmute([]byte)string("foobar")), "Zm9vYmFy")
for test in tests {
v := base64.encode(transmute([]byte)test.vector)
defer delete(v)
testing.expect_value(t, v, test.base64)
}
}
@(test)
test_decoding :: proc(t: ^testing.T) {
expect_value(t, string(base64.decode("")), "")
expect_value(t, string(base64.decode("Zg==")), "f")
expect_value(t, string(base64.decode("Zm8=")), "fo")
expect_value(t, string(base64.decode("Zm9v")), "foo")
expect_value(t, string(base64.decode("Zm9vYg==")), "foob")
expect_value(t, string(base64.decode("Zm9vYmE=")), "fooba")
expect_value(t, string(base64.decode("Zm9vYmFy")), "foobar")
for test in tests {
v := string(base64.decode(test.base64))
defer delete(v)
testing.expect_value(t, v, test.vector)
}
}