github.com/iDigitalFlame/xmt@v0.5.4/device/winapi/utf16_test.go (about) 1 // Copyright (C) 2020 - 2023 iDigitalFlame 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License as published by 5 // the Free Software Foundation, either version 3 of the License, or 6 // any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program. If not, see <https://www.gnu.org/licenses/>. 15 // 16 17 package winapi 18 19 import "testing" 20 21 func TestFnv(t *testing.T) { 22 v := [...]struct { 23 Value string 24 Hash uint32 25 }{ 26 {"NtTraceEvent", 0x89F984CE}, 27 {"NtCancelIoFileEx", 0xD4909C18}, 28 {"RtlCopyMappedMemory", 0x381752E6}, 29 {"NtUnmapViewOfSection", 0x19B022D}, 30 {"NtWriteVirtualMemory", 0x2012F428}, 31 } 32 for i := range v { 33 if r := FnvHash(v[i].Value); r != v[i].Hash { 34 t.Fatalf(`TestFnv(): FnvHash result for "%s" "0x%X" did not match "0x%X" !`, v[i].Value, r, v[i].Hash) 35 } 36 } 37 } 38 func TestStrings(t *testing.T) { 39 v := [...]string{ 40 "hello test1", 41 "test1234", 42 "example12345", 43 "string value123", 44 } 45 for i := range v { 46 r, err := UTF16FromString(v[i]) 47 if err != nil { 48 t.Fatalf(`TestStrings(): UTF16FromString failed for string "%s": %s!`, v[i], err.Error()) 49 } 50 if len(r) != len(v[i])+1 { 51 t.Fatalf(`TestStrings(): UTF16FromString result for string "%s" / "%d" was not the expected size "%d"!`, v[i], len(r), len(v[i])+1) 52 } 53 if k := UTF16ToString(r); k != v[i] { 54 t.Fatalf(`TestStrings(): UTF16ToString result "%s" does not match "%s"!`, k, v[i]) 55 } 56 p, err := UTF16PtrFromString(v[i]) 57 if err != nil { 58 t.Fatalf(`TestStrings(): UTF16PtrFromString failed for string "%s": %s!`, v[i], err.Error()) 59 } 60 if k := UTF16PtrToString(p); k != v[i] { 61 t.Fatalf(`TestStrings(): UTF16PtrToString result "%s" does not match "%s"!`, k, v[i]) 62 } 63 } 64 }