From f9b2a90864b1e551dedca31be19960ca115a7060 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Sat, 26 Mar 2022 10:52:38 +0000 Subject: [PATCH] Add types TestStructWrapped. --- v2alpha/go.mod | 2 + v2alpha/go.sum | 4 ++ v2alpha/soap/types/types_test.go | 72 ++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 v2alpha/go.sum diff --git a/v2alpha/go.mod b/v2alpha/go.mod index 7cad51a..130c55f 100644 --- a/v2alpha/go.mod +++ b/v2alpha/go.mod @@ -1,3 +1,5 @@ module github.com/huin/goupnp/v2alpha go 1.18 + +require github.com/google/go-cmp v0.5.7 diff --git a/v2alpha/go.sum b/v2alpha/go.sum new file mode 100644 index 0000000..a6ca3a4 --- /dev/null +++ b/v2alpha/go.sum @@ -0,0 +1,4 @@ +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/v2alpha/soap/types/types_test.go b/v2alpha/soap/types/types_test.go index 74ac48f..4478b24 100644 --- a/v2alpha/soap/types/types_test.go +++ b/v2alpha/soap/types/types_test.go @@ -2,10 +2,13 @@ package types import ( "bytes" + "encoding/xml" "fmt" "math" "testing" "time" + + "github.com/google/go-cmp/cmp" ) var dummyLoc = time.FixedZone("DummyTZ", 6*3600) @@ -536,3 +539,72 @@ func (dtz DateTimeTZ) equal(o DateTimeTZ) bool { func (tzd TZD) equal(o TZD) bool { return tzd.Offset == o.Offset && tzd.HasTZ == o.HasTZ } + +func TestStructWrapped(t *testing.T) { + type wrapper struct { + UI1Field UI1 + UI2Field UI2 + UI4Field UI4 + UI8Field UI8 + I1Field I1 + I2Field I2 + I4Field I4 + I8Field I8 + R4Field R4 + R8Field R8 + Fixed14_4Field Fixed14_4 + CharField Char + TimeOfDayField TimeOfDay + TimeOfDayTZField TimeOfDayTZ + DateField Date + DateTimeField DateTime + DateTimeTZField DateTimeTZ + BooleanField Boolean + BinBase64Field BinBase64 + BinHexField BinHex + URIField URI + } + + f144, err := Fixed14_4FromParts(12, 3456) + if err != nil { + t.Fatal(err) + } + tod := TimeOfDay{12, 34, 56} + date := Date{2001, 2, 3} + tzd := TZD{3600, true} + original := &wrapper{ + UI1Field: 1, + UI2Field: 2, + UI4Field: 4, + UI8Field: 8, + I1Field: -1, + I2Field: -2, + I4Field: -4, + I8Field: -8, + R4Field: 4.0, + R8Field: 8.0, + Fixed14_4Field: f144, + CharField: 'c', + TimeOfDayField: tod, + TimeOfDayTZField: TimeOfDayTZ{tod, tzd}, + DateField: date, + DateTimeField: DateTime{date, tod}, + DateTimeTZField: DateTimeTZ{date, tod, tzd}, + BooleanField: true, + BinBase64Field: BinBase64{1, 2, 3, 4}, + BinHexField: BinHex{1, 2, 3, 4}, + } + + marshalled, err := xml.Marshal(original) + if err != nil { + t.Fatal(err) + } + + got := &wrapper{} + if err := xml.Unmarshal(marshalled, got); err != nil { + t.Fatal(err) + } + if diff := cmp.Diff(original, got); diff != "" { + t.Errorf("\ngot %#v\nwant %#v\ndiff:\n%s", got, original, diff) + } +}