mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 00:48:38 +00:00
examples/marshalling: add test case for QMap<> marshalling
This commit is contained in:
parent
90e1695b6a
commit
7a177546b4
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mappu/miqt/qt"
|
"github.com/mappu/miqt/qt"
|
||||||
@ -91,9 +92,9 @@ func testMarshalling(t *testing.T) {
|
|||||||
t.Errorf("QList<Q*>: expected %#v, got %#v", expect, got)
|
t.Errorf("QList<Q*>: expected %#v, got %#v", expect, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// QByteArray
|
||||||
t.Run("QByteArray", func(t *testing.T) {
|
t.Run("QByteArray", func(t *testing.T) {
|
||||||
|
|
||||||
input := "foo bar baz"
|
input := "foo bar baz"
|
||||||
@ -103,8 +104,36 @@ func testMarshalling(t *testing.T) {
|
|||||||
if input != got {
|
if input != got {
|
||||||
t.Fatalf("QByteArray: expected %q, got %q", input, got)
|
t.Fatalf("QByteArray: expected %q, got %q", input, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// QMap
|
||||||
|
t.Run("QMap", func(t *testing.T) {
|
||||||
|
input := make(map[string]qt.QVariant)
|
||||||
|
input["foo"] = *qt.NewQVariant14("FOO")
|
||||||
|
input["bar"] = *qt.NewQVariant14("BAR")
|
||||||
|
input["baz"] = *qt.NewQVariant14("BAZ")
|
||||||
|
|
||||||
|
qtobj := qt.QJsonObject_FromVariantMap(input)
|
||||||
|
got := qtobj.ToVariantMap()
|
||||||
|
|
||||||
|
if len(got) != len(input) {
|
||||||
|
t.Fatalf("QMap: expected len %d, got len %d", len(input), len(got))
|
||||||
|
}
|
||||||
|
|
||||||
|
for src_key, _ := range input {
|
||||||
|
qvalue, ok := got[src_key]
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("QMap: missing entry %q", src_key)
|
||||||
|
}
|
||||||
|
|
||||||
|
gotValue := qvalue.ToString()
|
||||||
|
expectValue := strings.ToUpper(src_key)
|
||||||
|
if gotValue != expectValue {
|
||||||
|
t.Fatalf("QMap: single value expected %q, got %q", expectValue, gotValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshalling(t *testing.T) {
|
func TestMarshalling(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user