mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 04:10:07 +00:00
Merge remote-tracking branch 'upstream/master' into sys-windows-2
# Conflicts: # core/sys/windows/shell32.odin
This commit is contained in:
@@ -12,8 +12,6 @@ import "core:crypto/sha2"
|
||||
test_aes :: proc(t: ^testing.T) {
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||
|
||||
log.info("Testing AES")
|
||||
|
||||
impls := make([dynamic]aes.Implementation, 0, 2)
|
||||
defer delete(impls)
|
||||
append(&impls, aes.Implementation.Portable)
|
||||
@@ -29,7 +27,7 @@ test_aes :: proc(t: ^testing.T) {
|
||||
}
|
||||
|
||||
test_aes_ecb :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
log.infof("Testing AES-ECB/%v", impl)
|
||||
log.debugf("Testing AES-ECB/%v", impl)
|
||||
|
||||
test_vectors := []struct {
|
||||
key: string,
|
||||
@@ -136,7 +134,7 @@ test_aes_ecb :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
}
|
||||
|
||||
test_aes_ctr :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
log.infof("Testing AES-CTR/%v", impl)
|
||||
log.debugf("Testing AES-CTR/%v", impl)
|
||||
|
||||
test_vectors := []struct {
|
||||
key: string,
|
||||
@@ -200,7 +198,7 @@ test_aes_ctr :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
ctx: aes.Context_CTR
|
||||
key: [aes.KEY_SIZE_256]byte
|
||||
nonce: [aes.CTR_IV_SIZE]byte
|
||||
aes.init_ctr(&ctx, key[:], nonce[:])
|
||||
aes.init_ctr(&ctx, key[:], nonce[:], impl)
|
||||
|
||||
h_ctx: sha2.Context_512
|
||||
sha2.init_512_256(&h_ctx)
|
||||
@@ -226,7 +224,7 @@ test_aes_ctr :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
}
|
||||
|
||||
test_aes_gcm :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
log.infof("Testing AES-GCM/%v", impl)
|
||||
log.debugf("Testing AES-GCM/%v", impl)
|
||||
|
||||
// NIST did a reorg of their site, so the source of the test vectors
|
||||
// is only available from an archive. The commented out tests are
|
||||
@@ -431,7 +429,7 @@ test_aes_gcm :: proc(t: ^testing.T, impl: aes.Implementation) {
|
||||
testing.expectf(
|
||||
t,
|
||||
ok && dst_str == v.plaintext,
|
||||
"AES-GCM/%v: Expected: (%s, true) for open(%s, %s, %s, %s, %s), but got (%s, %s) instead",
|
||||
"AES-GCM/%v: Expected: (%s, true) for open(%s, %s, %s, %s, %s), but got (%s, %v) instead",
|
||||
impl,
|
||||
v.plaintext,
|
||||
v.key,
|
||||
|
||||
@@ -58,9 +58,9 @@ test_sqrt_ratio_m1 :: proc(t: ^testing.T) {
|
||||
v_bytes, _ := hex.decode(transmute([]byte)(v.v), context.temp_allocator)
|
||||
r_bytes, _ := hex.decode(transmute([]byte)(v.r), context.temp_allocator)
|
||||
|
||||
u_ := transmute(^[32]byte)(raw_data(u_bytes))
|
||||
v_ := transmute(^[32]byte)(raw_data(v_bytes))
|
||||
r_ := transmute(^[32]byte)(raw_data(r_bytes))
|
||||
u_ := (^[32]byte)(raw_data(u_bytes))
|
||||
v_ := (^[32]byte)(raw_data(v_bytes))
|
||||
r_ := (^[32]byte)(raw_data(r_bytes))
|
||||
|
||||
u, vee, r: field.Tight_Field_Element
|
||||
field.fe_from_bytes(&u, u_)
|
||||
|
||||
@@ -161,7 +161,7 @@ test_pbkdf2 :: proc(t: ^testing.T) {
|
||||
testing.expectf(
|
||||
t,
|
||||
dst_str == v.dk,
|
||||
"HMAC-%s: Expected: %s for input of (%s, %s, %d), but got %s instead",
|
||||
"PBKDF2-%s: Expected: %s for input of (%s, %s, %d), but got %s instead",
|
||||
algo_name,
|
||||
v.dk,
|
||||
v.password,
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
package test_core_ini
|
||||
|
||||
import "base:runtime"
|
||||
import "core:encoding/ini"
|
||||
import "core:mem/virtual"
|
||||
import "core:strings"
|
||||
import "core:testing"
|
||||
|
||||
@test
|
||||
parse_ini :: proc(t: ^testing.T) {
|
||||
ini_data := `
|
||||
[LOG]
|
||||
level = "devel"
|
||||
file = "/var/log/testing.log"
|
||||
|
||||
[USER]
|
||||
first_name = "John"
|
||||
surname = "Smith"
|
||||
`
|
||||
|
||||
m, err := ini.load_map_from_string(ini_data, context.allocator)
|
||||
defer ini.delete_map(m)
|
||||
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(m["LOG"]["level"], "devel"),
|
||||
"Expected m[\"LOG\"][\"level\"] to be equal to 'devel' instead got %v",
|
||||
m["LOG"]["level"],
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(m["LOG"]["file"], "/var/log/testing.log"),
|
||||
"Expected m[\"LOG\"][\"file\"] to be equal to '/var/log/testing.log' instead got %v",
|
||||
m["LOG"]["file"],
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(m["USER"]["first_name"], "John"),
|
||||
"Expected m[\"USER\"][\"first_name\"] to be equal to 'John' instead got %v",
|
||||
m["USER"]["first_name"],
|
||||
)
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(m["USER"]["surname"], "Smith"),
|
||||
"Expected m[\"USER\"][\"surname\"] to be equal to 'Smith' instead got %v",
|
||||
m["USER"]["surname"],
|
||||
)
|
||||
|
||||
testing.expectf(t, err == nil, "Expected `ini.load_map_from_string` to return a nil error, got %v", err)
|
||||
}
|
||||
|
||||
@test
|
||||
ini_to_string :: proc(t: ^testing.T) {
|
||||
m := ini.Map{
|
||||
"LEVEL" = {
|
||||
"LOG" = "debug",
|
||||
},
|
||||
}
|
||||
|
||||
str := ini.save_map_to_string(m, context.allocator)
|
||||
defer delete(str)
|
||||
delete(m["LEVEL"])
|
||||
delete(m)
|
||||
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(str, "[LEVEL]LOG = debug"),
|
||||
"Expected `ini.save_map_to_string` to return a string equal to \"[LEVEL]LOG = debug\", got %v",
|
||||
str,
|
||||
)
|
||||
}
|
||||
|
||||
@test
|
||||
ini_iterator :: proc(t: ^testing.T) {
|
||||
ini_data := `
|
||||
[LOG]
|
||||
level = "devel"
|
||||
file = "/var/log/testing.log"
|
||||
|
||||
[USER]
|
||||
first_name = "John"
|
||||
surname = "Smith"
|
||||
`
|
||||
|
||||
i := 0
|
||||
iterator := ini.iterator_from_string(ini_data)
|
||||
for key, value in ini.iterate(&iterator) {
|
||||
if strings.contains(key, "level") {
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(value, "devel"),
|
||||
"Expected 'level' to be equal to 'devel' instead got '%v'",
|
||||
value,
|
||||
)
|
||||
} else if strings.contains(key, "file") {
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(value, "/var/log/testing.log"),
|
||||
"Expected 'file' to be equal to '/var/log/testing.log' instead got '%v'",
|
||||
value,
|
||||
)
|
||||
} else if strings.contains(key, "first_name") {
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(value, "John"),
|
||||
"Expected 'first_name' to be equal to 'John' instead got '%v'",
|
||||
value,
|
||||
)
|
||||
} else if strings.contains(key, "surname") {
|
||||
testing.expectf(
|
||||
t,
|
||||
strings.contains(value, "Smith"),
|
||||
"Expected 'surname' to be equal to 'Smith' instead got '%v'",
|
||||
value,
|
||||
)
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
testing.expectf(t, i == 4, "Expected to loop 4 times, only looped %v times", i)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package test_core_json
|
||||
import "core:encoding/json"
|
||||
import "core:testing"
|
||||
import "core:mem/virtual"
|
||||
import "base:runtime"
|
||||
|
||||
@test
|
||||
parse_json :: proc(t: ^testing.T) {
|
||||
@@ -348,6 +349,24 @@ unmarshal_json :: proc(t: ^testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
unmarshal_empty_struct :: proc(t: ^testing.T) {
|
||||
TestStruct :: struct {}
|
||||
test := make(map[string]TestStruct)
|
||||
input: = `{
|
||||
"test_1": {},
|
||||
"test_2": {}
|
||||
}`
|
||||
err := json.unmarshal(transmute([]u8)input, &test)
|
||||
defer {
|
||||
for k in test {
|
||||
delete(k)
|
||||
}
|
||||
delete(test)
|
||||
}
|
||||
testing.expect(t, err == nil, "Expected empty struct to unmarshal without error")
|
||||
}
|
||||
|
||||
@test
|
||||
surrogate :: proc(t: ^testing.T) {
|
||||
input := `+ + * 😃 - /`
|
||||
@@ -368,4 +387,60 @@ utf8_string_of_multibyte_characters :: proc(t: ^testing.T) {
|
||||
val, err := json.parse_string(`"🐛✅"`)
|
||||
defer json.destroy_value(val)
|
||||
testing.expectf(t, err == nil, "Expected `json.parse` to return nil, got %v", err)
|
||||
}
|
||||
|
||||
@test
|
||||
struct_with_ignore_tags :: proc(t: ^testing.T) {
|
||||
My_Struct :: struct {
|
||||
a: string `json:"-"`,
|
||||
}
|
||||
|
||||
my_struct := My_Struct{
|
||||
a = "test",
|
||||
}
|
||||
|
||||
my_struct_marshaled, marshal_err := json.marshal(my_struct)
|
||||
defer delete(my_struct_marshaled)
|
||||
|
||||
testing.expectf(t, marshal_err == nil, "Expected `json.marshal` to return nil error, got %v", marshal_err)
|
||||
|
||||
my_struct_json := transmute(string)my_struct_marshaled
|
||||
expected_json := `{}`
|
||||
|
||||
testing.expectf(t, expected_json == my_struct_json, "Expected `json.marshal` to return %s, got %s", expected_json, my_struct_json)
|
||||
}
|
||||
|
||||
@test
|
||||
map_with_integer_keys :: proc(t: ^testing.T) {
|
||||
my_map := make(map[i32]string)
|
||||
defer delete_map(my_map)
|
||||
|
||||
my_map[-1] = "a"
|
||||
my_map[0] = "b"
|
||||
my_map[42] = "c"
|
||||
my_map[99999999] = "d"
|
||||
|
||||
marshaled_data, marshal_err := json.marshal(my_map)
|
||||
defer delete(marshaled_data)
|
||||
|
||||
testing.expectf(t, marshal_err == nil, "Expected `json.marshal` to return nil error, got %v", marshal_err)
|
||||
|
||||
my_map2 := make(map[i32]string)
|
||||
defer delete_map(my_map2)
|
||||
|
||||
unmarshal_err := json.unmarshal(marshaled_data, &my_map2)
|
||||
defer for key, item in my_map2 {
|
||||
runtime.delete_string(item)
|
||||
}
|
||||
testing.expectf(t, unmarshal_err == nil, "Expected `json.unmarshal` to return nil, got %v", unmarshal_err)
|
||||
|
||||
testing.expectf(t, len(my_map) == len(my_map2), "Expected %v map items to have been unmarshaled, got %v", len(my_map), len(my_map2))
|
||||
|
||||
for key, item in my_map {
|
||||
testing.expectf(t, key in my_map2, "Expected key %v to be present in unmarshaled map", key)
|
||||
|
||||
if key in my_map2 {
|
||||
testing.expectf(t, runtime.string_eq(item, my_map2[key]), "Expected value %s to be present in unmarshaled map", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,6 +372,22 @@ test_odin_value_export :: proc(t: ^testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
leaking_struct_tag :: proc(t: ^testing.T) {
|
||||
My_Struct :: struct {
|
||||
names: [^]string `fmt:"v,name_count"`,
|
||||
name_count: int,
|
||||
}
|
||||
|
||||
name := "hello?"
|
||||
foo := My_Struct {
|
||||
names = &name,
|
||||
name_count = 1,
|
||||
}
|
||||
|
||||
check(t, "My_Struct{names = [\"hello?\"], name_count = 1}", "%v", foo)
|
||||
}
|
||||
|
||||
@(private)
|
||||
check :: proc(t: ^testing.T, exp: string, format: string, args: ..any, loc := #caller_location) {
|
||||
got := fmt.tprintf(format, ..args)
|
||||
|
||||
Reference in New Issue
Block a user