From 7a177546b4f1b5d50c9dfe08ce0ba056c8e1d1a3 Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 4 Nov 2024 21:32:39 +1300 Subject: [PATCH] examples/marshalling: add test case for QMap<> marshalling --- examples/marshalling/marshalling_test.go | 33 ++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/examples/marshalling/marshalling_test.go b/examples/marshalling/marshalling_test.go index bc105433..15d5d8d0 100644 --- a/examples/marshalling/marshalling_test.go +++ b/examples/marshalling/marshalling_test.go @@ -3,6 +3,7 @@ package main import ( "os" "reflect" + "strings" "testing" "github.com/mappu/miqt/qt" @@ -91,9 +92,9 @@ func testMarshalling(t *testing.T) { t.Errorf("QList: expected %#v, got %#v", expect, got) } } - }) + // QByteArray t.Run("QByteArray", func(t *testing.T) { input := "foo bar baz" @@ -103,8 +104,36 @@ func testMarshalling(t *testing.T) { if 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) {