1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
package util
import (
"bytes"
"testing"
)
func TestParseValidUtf16String(t *testing.T) {
// This is "arch.efi", as encoded by a Dell laptop's firmware.
value := []byte{
97,
0,
114,
0,
99,
0,
104,
0,
46,
0,
101,
0,
102,
0,
105,
0,
0,
0,
}
buffer := bytes.NewBuffer(value)
expected := "arch.efi"
actual, err := ParseUtf16Var(buffer)
if err != nil {
t.Fatal(err)
}
if actual != expected {
t.Fatalf(
"ParseUtf16Var(%s) returned %v (%v), expected %v (%v).",
value,
actual,
[]byte(actual),
expected,
[]byte(expected),
)
}
}
func TestParseInvalidUtf16String(t *testing.T) {
// This is "arch.efi", missing the final null strings.
value := []byte{
97,
0,
114,
0,
99,
0,
104,
0,
46,
0,
101,
0,
102,
0,
105,
0,
}
buffer := bytes.NewBuffer(value)
_, err := ParseUtf16Var(buffer)
if err == nil {
t.Fatalf("ParseUtf16Var did not err with a non-null-terminated string.")
}
}
|