mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
examples/marshalling: replace QByteArray test case
This commit is contained in:
parent
bb0132e0d5
commit
48fa315a22
@ -3,9 +3,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mappu/miqt/qt"
|
||||
)
|
||||
@ -98,26 +96,14 @@ func TestMarshalling(t *testing.T) {
|
||||
|
||||
})
|
||||
|
||||
t.Run("QByteArray::split", func(t *testing.T) {
|
||||
phrase := "the quick brown fox jumps over the lazy dog"
|
||||
expect := strings.Split(phrase, " ")
|
||||
t.Run("QByteArray", func(t *testing.T) {
|
||||
|
||||
qba := qt.NewQByteArray2(phrase)
|
||||
got := qba.Split(' ')
|
||||
if len(expect) != len(got) {
|
||||
t.Fatalf("split: expected len=%d, got len=%d", len(expect), len(got))
|
||||
}
|
||||
input := "foo bar baz"
|
||||
ba := qt.QFile_EncodeName(input)
|
||||
got := qt.QFile_DecodeName(ba)
|
||||
|
||||
for i := 0; i < len(expect); i++ {
|
||||
if got[i].Length() != len(expect[i]) {
|
||||
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])
|
||||
}
|
||||
if input != got {
|
||||
t.Fatalf("QByteArray: expected %q, got %q", input, got)
|
||||
}
|
||||
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user