examples/marshalling: replace QByteArray test case

This commit is contained in:
mappu 2024-10-19 12:46:15 +13:00
parent bb0132e0d5
commit 48fa315a22

View File

@ -3,9 +3,7 @@ package main
import ( import (
"os" "os"
"reflect" "reflect"
"strings"
"testing" "testing"
"unsafe"
"github.com/mappu/miqt/qt" "github.com/mappu/miqt/qt"
) )
@ -98,26 +96,14 @@ func TestMarshalling(t *testing.T) {
}) })
t.Run("QByteArray::split", func(t *testing.T) { t.Run("QByteArray", func(t *testing.T) {
phrase := "the quick brown fox jumps over the lazy dog"
expect := strings.Split(phrase, " ")
qba := qt.NewQByteArray2(phrase) input := "foo bar baz"
got := qba.Split(' ') ba := qt.QFile_EncodeName(input)
if len(expect) != len(got) { got := qt.QFile_DecodeName(ba)
t.Fatalf("split: expected len=%d, got len=%d", len(expect), len(got))
}
for i := 0; i < len(expect); i++ { if input != got {
if got[i].Length() != len(expect[i]) { t.Fatalf("QByteArray: expected %q, got %q", input, got)
t.Errorf("split/idx=%d: expected len=%d, got %d", i, len(expect[i]), got[i].Length())
}
// TODO add more ergnomic QByteArray<-->string conversion
var rawData []byte = unsafe.Slice((*byte)(got[i].Data()), got[i].Length())
if string(rawData) != expect[i] {
t.Errorf("split/idx=%d: expected %#v, got %#v", i, string(rawData), expect[i])
}
} }
}) })