}
return VOffsetT(off)
}
+
+// MutateBool updates a bool at the given offset.
+func (t *Table) MutateBool(off UOffsetT, n bool) bool {
+ WriteBool(t.Bytes[off:], n)
+ return true
+}
+
+// MutateByte updates a Byte at the given offset.
+func (t *Table) MutateByte(off UOffsetT, n byte) bool {
+ WriteByte(t.Bytes[off:], n)
+ return true
+}
+
+// MutateUint8 updates a Uint8 at the given offset.
+func (t *Table) MutateUint8(off UOffsetT, n uint8) bool {
+ WriteUint8(t.Bytes[off:], n)
+ return true
+}
+
+// MutateUint16 updates a Uint16 at the given offset.
+func (t *Table) MutateUint16(off UOffsetT, n uint16) bool {
+ WriteUint16(t.Bytes[off:], n)
+ return true
+}
+
+// MutateUint32 updates a Uint32 at the given offset.
+func (t *Table) MutateUint32(off UOffsetT, n uint32) bool {
+ WriteUint32(t.Bytes[off:], n)
+ return true
+}
+
+// MutateUint64 updates a Uint64 at the given offset.
+func (t *Table) MutateUint64(off UOffsetT, n uint64) bool {
+ WriteUint64(t.Bytes[off:], n)
+ return true
+}
+
+// MutateInt8 updates a Int8 at the given offset.
+func (t *Table) MutateInt8(off UOffsetT, n int8) bool {
+ WriteInt8(t.Bytes[off:], n)
+ return true
+}
+
+// MutateInt16 updates a Int16 at the given offset.
+func (t *Table) MutateInt16(off UOffsetT, n int16) bool {
+ WriteInt16(t.Bytes[off:], n)
+ return true
+}
+
+// MutateInt32 updates a Int32 at the given offset.
+func (t *Table) MutateInt32(off UOffsetT, n int32) bool {
+ WriteInt32(t.Bytes[off:], n)
+ return true
+}
+
+// MutateInt64 updates a Int64 at the given offset.
+func (t *Table) MutateInt64(off UOffsetT, n int64) bool {
+ WriteInt64(t.Bytes[off:], n)
+ return true
+}
+
+// MutateFloat32 updates a Float32 at the given offset.
+func (t *Table) MutateFloat32(off UOffsetT, n float32) bool {
+ WriteFloat32(t.Bytes[off:], n)
+ return true
+}
+
+// MutateFloat64 updates a Float64 at the given offset.
+func (t *Table) MutateFloat64(off UOffsetT, n float64) bool {
+ WriteFloat64(t.Bytes[off:], n)
+ return true
+}
+
+// MutateUOffsetT updates a UOffsetT at the given offset.
+func (t *Table) MutateUOffsetT(off UOffsetT, n UOffsetT) bool {
+ WriteUOffsetT(t.Bytes[off:], n)
+ return true
+}
+
+// MutateVOffsetT updates a VOffsetT at the given offset.
+func (t *Table) MutateVOffsetT(off UOffsetT, n VOffsetT) bool {
+ WriteVOffsetT(t.Bytes[off:], n)
+ return true
+}
+
+// MutateSOffsetT updates a SOffsetT at the given offset.
+func (t *Table) MutateSOffsetT(off UOffsetT, n SOffsetT) bool {
+ WriteSOffsetT(t.Bytes[off:], n)
+ return true
+}
+
+// MutateBoolSlot updates the bool at given vtable location
+func (t *Table) MutateBoolSlot(slot VOffsetT, n bool) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateBool(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateByteSlot updates the byte at given vtable location
+func (t *Table) MutateByteSlot(slot VOffsetT, n byte) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateByte(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateInt8Slot updates the int8 at given vtable location
+func (t *Table) MutateInt8Slot(slot VOffsetT, n int8) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateInt8(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateUint8Slot updates the uint8 at given vtable location
+func (t *Table) MutateUint8Slot(slot VOffsetT, n uint8) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateUint8(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateInt16Slot updates the int16 at given vtable location
+func (t *Table) MutateInt16Slot(slot VOffsetT, n int16) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateInt16(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateUint16Slot updates the uint16 at given vtable location
+func (t *Table) MutateUint16Slot(slot VOffsetT, n uint16) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateUint16(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateInt32Slot updates the int32 at given vtable location
+func (t *Table) MutateInt32Slot(slot VOffsetT, n int32) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateInt32(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateUint32Slot updates the uint32 at given vtable location
+func (t *Table) MutateUint32Slot(slot VOffsetT, n uint32) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateUint32(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateInt64Slot updates the int64 at given vtable location
+func (t *Table) MutateInt64Slot(slot VOffsetT, n int64) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateInt64(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateUint64Slot updates the uint64 at given vtable location
+func (t *Table) MutateUint64Slot(slot VOffsetT, n uint64) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateUint64(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateFloat32Slot updates the float32 at given vtable location
+func (t *Table) MutateFloat32Slot(slot VOffsetT, n float32) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateFloat32(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
+
+// MutateFloat64Slot updates the float64 at given vtable location
+func (t *Table) MutateFloat64Slot(slot VOffsetT, n float64) bool {
+ if off := t.Offset(slot); off != 0 {
+ t.MutateFloat64(t.Pos+UOffsetT(off), n)
+ return true
+ }
+
+ return false
+}
return 150
}
+func (rcv *Monster) MutateMana(n int16) bool {
+ return rcv._tab.MutateInt16Slot(6, n)
+}
+
func (rcv *Monster) Hp() int16 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
return 100
}
+func (rcv *Monster) MutateHp(n int16) bool {
+ return rcv._tab.MutateInt16Slot(8, n)
+}
+
func (rcv *Monster) Name() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
if o != 0 {
return 8
}
+func (rcv *Monster) MutateColor(n int8) bool {
+ return rcv._tab.MutateInt8Slot(16, n)
+}
+
func (rcv *Monster) TestType() byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(18))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTestType(n byte) bool {
+ return rcv._tab.MutateByteSlot(18, n)
+}
+
func (rcv *Monster) Test(obj *flatbuffers.Table) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(20))
if o != 0 {
return 0
}
+/// an example documentation comment: this will end up in the generated code
+/// multiline too
func (rcv *Monster) Enemy(obj *Monster) *Monster {
o := flatbuffers.UOffsetT(rcv._tab.Offset(28))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTestbool(n byte) bool {
+ return rcv._tab.MutateByteSlot(34, n)
+}
+
func (rcv *Monster) Testhashs32Fnv1() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(36))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashs32Fnv1(n int32) bool {
+ return rcv._tab.MutateInt32Slot(36, n)
+}
+
func (rcv *Monster) Testhashu32Fnv1() uint32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(38))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashu32Fnv1(n uint32) bool {
+ return rcv._tab.MutateUint32Slot(38, n)
+}
+
func (rcv *Monster) Testhashs64Fnv1() int64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(40))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashs64Fnv1(n int64) bool {
+ return rcv._tab.MutateInt64Slot(40, n)
+}
+
func (rcv *Monster) Testhashu64Fnv1() uint64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(42))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashu64Fnv1(n uint64) bool {
+ return rcv._tab.MutateUint64Slot(42, n)
+}
+
func (rcv *Monster) Testhashs32Fnv1a() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(44))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashs32Fnv1a(n int32) bool {
+ return rcv._tab.MutateInt32Slot(44, n)
+}
+
func (rcv *Monster) Testhashu32Fnv1a() uint32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(46))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashu32Fnv1a(n uint32) bool {
+ return rcv._tab.MutateUint32Slot(46, n)
+}
+
func (rcv *Monster) Testhashs64Fnv1a() int64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(48))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashs64Fnv1a(n int64) bool {
+ return rcv._tab.MutateInt64Slot(48, n)
+}
+
func (rcv *Monster) Testhashu64Fnv1a() uint64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(50))
if o != 0 {
return 0
}
+func (rcv *Monster) MutateTesthashu64Fnv1a(n uint64) bool {
+ return rcv._tab.MutateUint64Slot(50, n)
+}
+
func (rcv *Monster) Testarrayofbools(j int) byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(52))
if o != 0 {
return 3.14159
}
+func (rcv *Monster) MutateTestf(n float32) bool {
+ return rcv._tab.MutateFloat32Slot(54, n)
+}
+
func (rcv *Monster) Testf2() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(56))
if o != 0 {
return 3.0
}
+func (rcv *Monster) MutateTestf2(n float32) bool {
+ return rcv._tab.MutateFloat32Slot(56, n)
+}
+
func (rcv *Monster) Testf3() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(58))
if o != 0 {
return 0.0
}
+func (rcv *Monster) MutateTestf3(n float32) bool {
+ return rcv._tab.MutateFloat32Slot(58, n)
+}
+
func (rcv *Monster) Testarrayofstring2(j int) []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(60))
if o != 0 {
// Verify that the Go FlatBuffers runtime library generates the
// expected bytes (does not use any schema):
CheckByteLayout(t.Fatalf)
+ CheckMutateMethods(t.Fatalf)
// Verify that panics are raised during exceptional conditions:
CheckNotInObjectError(t.Fatalf)
// Verify that the buffer generated by Go code is readable by the
// generated Go code:
CheckReadBuffer(generated, off, t.Fatalf)
+ CheckMutateBuffer(generated, off, t.Fatalf)
// Verify that the buffer generated by C++ code is readable by the
// generated Go code:
t.Fatal(err)
}
CheckReadBuffer(monsterDataCpp, 0, t.Fatalf)
+ CheckMutateBuffer(monsterDataCpp, 0, t.Fatalf)
// Verify that vtables are deduplicated when written:
CheckVtableDeduplication(t.Fatalf)
}
}
+// CheckMutateBuffer checks that the given buffer can be mutated correctly
+// as the example Monster. Only available scalar values are mutated.
+func CheckMutateBuffer(org []byte, offset flatbuffers.UOffsetT, fail func(string, ...interface{})) {
+ // make a copy to mutate
+ buf := make([]byte, len(org))
+ copy(buf, org)
+
+ // load monster data from the buffer
+ monster := example.GetRootAsMonster(buf, offset)
+
+ // test case struct
+ type testcase struct {
+ field string
+ testfn func() bool
+ }
+
+ testForOriginalValues := []testcase{
+ testcase{"Hp", func() bool { return monster.Hp() == 80 }},
+ testcase{"Mana", func() bool { return monster.Mana() == 150 }},
+ testcase{"Pos.X'", func() bool { return monster.Pos(nil).X() == float32(1.0) }},
+ testcase{"Pos.Y'", func() bool { return monster.Pos(nil).Y() == float32(2.0) }},
+ testcase{"Pos.Z'", func() bool { return monster.Pos(nil).Z() == float32(3.0) }},
+ testcase{"Pos.Test1'", func() bool { return monster.Pos(nil).Test1() == float64(3.0) }},
+ testcase{"Pos.Test2'", func() bool { return monster.Pos(nil).Test2() == int8(2) }},
+ testcase{"Pos.Test3.A", func() bool { return monster.Pos(nil).Test3(nil).A() == int16(5) }},
+ testcase{"Pos.Test3.B", func() bool { return monster.Pos(nil).Test3(nil).B() == int8(6) }},
+ }
+
+ testMutability := []testcase{
+ testcase{"Hp", func() bool { return monster.MutateHp(70) }},
+ testcase{"Mana", func() bool { return !monster.MutateMana(140) }},
+ testcase{"Pos.X", func() bool { return monster.Pos(nil).MutateX(10.0) }},
+ testcase{"Pos.Y", func() bool { return monster.Pos(nil).MutateY(20.0) }},
+ testcase{"Pos.Z", func() bool { return monster.Pos(nil).MutateZ(30.0) }},
+ testcase{"Pos.Test1", func() bool { return monster.Pos(nil).MutateTest1(30.0) }},
+ testcase{"Pos.Test2", func() bool { return monster.Pos(nil).MutateTest2(20) }},
+ testcase{"Pos.Test3.A", func() bool { return monster.Pos(nil).Test3(nil).MutateA(50) }},
+ testcase{"Pos.Test3.B", func() bool { return monster.Pos(nil).Test3(nil).MutateB(60) }},
+ }
+
+ testForMutatedValues := []testcase{
+ testcase{"Hp", func() bool { return monster.Hp() == 70 }},
+ testcase{"Mana", func() bool { return monster.Mana() == 150 }},
+ testcase{"Pos.X'", func() bool { return monster.Pos(nil).X() == float32(10.0) }},
+ testcase{"Pos.Y'", func() bool { return monster.Pos(nil).Y() == float32(20.0) }},
+ testcase{"Pos.Z'", func() bool { return monster.Pos(nil).Z() == float32(30.0) }},
+ testcase{"Pos.Test1'", func() bool { return monster.Pos(nil).Test1() == float64(30.0) }},
+ testcase{"Pos.Test2'", func() bool { return monster.Pos(nil).Test2() == int8(20) }},
+ testcase{"Pos.Test3.A", func() bool { return monster.Pos(nil).Test3(nil).A() == int16(50) }},
+ testcase{"Pos.Test3.B", func() bool { return monster.Pos(nil).Test3(nil).B() == int8(60) }},
+ }
+
+ // make sure original values are okay
+ for _, t := range testForOriginalValues {
+ if !t.testfn() {
+ fail("field '" + t.field + "' doesn't have the expected original value")
+ }
+ }
+
+ // try to mutate fields and check mutability
+ for _, t := range testMutability {
+ if !t.testfn() {
+ fail(FailString("field '"+t.field+"' failed mutability test", true, false))
+ }
+ }
+
+ // test whether values have changed
+ for _, t := range testForMutatedValues {
+ if !t.testfn() {
+ fail("field '" + t.field + "' doesn't have the expected mutated value")
+ }
+ }
+
+ // make sure the buffer has changed
+ if reflect.DeepEqual(buf, org) {
+ fail("mutate buffer failed")
+ }
+
+ // To make sure the buffer has changed accordingly
+ // Read data from the buffer and verify all fields
+ monster = example.GetRootAsMonster(buf, offset)
+ for _, t := range testForMutatedValues {
+ if !t.testfn() {
+ fail("field '" + t.field + "' doesn't have the expected mutated value")
+ }
+ }
+
+ // reverting all fields to original values should
+ // re-create the original buffer. Mutate all fields
+ // back to their original values and compare buffers.
+ // This test is done to make sure mutations do not do
+ // any unnecessary changes to the buffer.
+ monster = example.GetRootAsMonster(buf, offset)
+ monster.MutateHp(80)
+ monster.Pos(nil).MutateX(1.0)
+ monster.Pos(nil).MutateY(2.0)
+ monster.Pos(nil).MutateZ(3.0)
+ monster.Pos(nil).MutateTest1(3.0)
+ monster.Pos(nil).MutateTest2(2)
+ monster.Pos(nil).Test3(nil).MutateA(5)
+ monster.Pos(nil).Test3(nil).MutateB(6)
+
+ for _, t := range testForOriginalValues {
+ if !t.testfn() {
+ fail("field '" + t.field + "' doesn't have the expected original value")
+ }
+ }
+
+ // buffer should have original values
+ if !reflect.DeepEqual(buf, org) {
+ fail("revert changes failed")
+ }
+}
+
// Low level stress/fuzz test: serialize/deserialize a variety of
// different kinds of data in different combinations
func checkFuzz(fuzzFields, fuzzObjects int, fail func(string, ...interface{})) {
}
}
+// CheckMutateMethods checks all mutate methods one by one
+func CheckMutateMethods(fail func(string, ...interface{})) {
+ b := flatbuffers.NewBuilder(0)
+ b.StartObject(15)
+ b.PrependBoolSlot(0, true, false)
+ b.PrependByteSlot(1, 1, 0)
+ b.PrependUint8Slot(2, 2, 0)
+ b.PrependUint16Slot(3, 3, 0)
+ b.PrependUint32Slot(4, 4, 0)
+ b.PrependUint64Slot(5, 5, 0)
+ b.PrependInt8Slot(6, 6, 0)
+ b.PrependInt16Slot(7, 7, 0)
+ b.PrependInt32Slot(8, 8, 0)
+ b.PrependInt64Slot(9, 9, 0)
+ b.PrependFloat32Slot(10, 10, 0)
+ b.PrependFloat64Slot(11, 11, 0)
+
+ b.PrependUOffsetTSlot(12, 12, 0)
+ uoVal := b.Offset() - 12
+
+ b.PrependVOffsetT(13)
+ b.Slot(13)
+
+ b.PrependSOffsetT(14)
+ b.Slot(14)
+ soVal := flatbuffers.SOffsetT(b.Offset() - 14)
+
+ offset := b.EndObject()
+
+ t := &flatbuffers.Table{
+ Bytes: b.Bytes,
+ Pos: flatbuffers.UOffsetT(len(b.Bytes)) - offset,
+ }
+
+ calcVOffsetT := func(slot int) (vtableOffset flatbuffers.VOffsetT) {
+ return flatbuffers.VOffsetT((flatbuffers.VtableMetadataFields + slot) * flatbuffers.SizeVOffsetT)
+ }
+ calcUOffsetT := func(vtableOffset flatbuffers.VOffsetT) (valueOffset flatbuffers.UOffsetT) {
+ return t.Pos + flatbuffers.UOffsetT(t.Offset(vtableOffset))
+ }
+
+ type testcase struct {
+ field string
+ testfn func() bool
+ }
+
+ testForOriginalValues := []testcase{
+ testcase{"BoolSlot", func() bool { return t.GetBoolSlot(calcVOffsetT(0), true) == true }},
+ testcase{"ByteSlot", func() bool { return t.GetByteSlot(calcVOffsetT(1), 1) == 1 }},
+ testcase{"Uint8Slot", func() bool { return t.GetUint8Slot(calcVOffsetT(2), 2) == 2 }},
+ testcase{"Uint16Slot", func() bool { return t.GetUint16Slot(calcVOffsetT(3), 3) == 3 }},
+ testcase{"Uint32Slot", func() bool { return t.GetUint32Slot(calcVOffsetT(4), 4) == 4 }},
+ testcase{"Uint64Slot", func() bool { return t.GetUint64Slot(calcVOffsetT(5), 5) == 5 }},
+ testcase{"Int8Slot", func() bool { return t.GetInt8Slot(calcVOffsetT(6), 6) == 6 }},
+ testcase{"Int16Slot", func() bool { return t.GetInt16Slot(calcVOffsetT(7), 7) == 7 }},
+ testcase{"Int32Slot", func() bool { return t.GetInt32Slot(calcVOffsetT(8), 8) == 8 }},
+ testcase{"Int64Slot", func() bool { return t.GetInt64Slot(calcVOffsetT(9), 9) == 9 }},
+ testcase{"Float32Slot", func() bool { return t.GetFloat32Slot(calcVOffsetT(10), 10) == 10 }},
+ testcase{"Float64Slot", func() bool { return t.GetFloat64Slot(calcVOffsetT(11), 11) == 11 }},
+ testcase{"UOffsetTSlot", func() bool { return t.GetUOffsetT(calcUOffsetT(calcVOffsetT(12))) == uoVal }},
+ testcase{"VOffsetTSlot", func() bool { return t.GetVOffsetT(calcUOffsetT(calcVOffsetT(13))) == 13 }},
+ testcase{"SOffsetTSlot", func() bool { return t.GetSOffsetT(calcUOffsetT(calcVOffsetT(14))) == soVal }},
+ }
+
+ testMutability := []testcase{
+ testcase{"BoolSlot", func() bool { return t.MutateBoolSlot(calcVOffsetT(0), false) }},
+ testcase{"ByteSlot", func() bool { return t.MutateByteSlot(calcVOffsetT(1), 2) }},
+ testcase{"Uint8Slot", func() bool { return t.MutateUint8Slot(calcVOffsetT(2), 4) }},
+ testcase{"Uint16Slot", func() bool { return t.MutateUint16Slot(calcVOffsetT(3), 6) }},
+ testcase{"Uint32Slot", func() bool { return t.MutateUint32Slot(calcVOffsetT(4), 8) }},
+ testcase{"Uint64Slot", func() bool { return t.MutateUint64Slot(calcVOffsetT(5), 10) }},
+ testcase{"Int8Slot", func() bool { return t.MutateInt8Slot(calcVOffsetT(6), 12) }},
+ testcase{"Int16Slot", func() bool { return t.MutateInt16Slot(calcVOffsetT(7), 14) }},
+ testcase{"Int32Slot", func() bool { return t.MutateInt32Slot(calcVOffsetT(8), 16) }},
+ testcase{"Int64Slot", func() bool { return t.MutateInt64Slot(calcVOffsetT(9), 18) }},
+ testcase{"Float32Slot", func() bool { return t.MutateFloat32Slot(calcVOffsetT(10), 20) }},
+ testcase{"Float64Slot", func() bool { return t.MutateFloat64Slot(calcVOffsetT(11), 22) }},
+ testcase{"UOffsetTSlot", func() bool { return t.MutateUOffsetT(calcUOffsetT(calcVOffsetT(12)), 24) }},
+ testcase{"VOffsetTSlot", func() bool { return t.MutateVOffsetT(calcUOffsetT(calcVOffsetT(13)), 26) }},
+ testcase{"SOffsetTSlot", func() bool { return t.MutateSOffsetT(calcUOffsetT(calcVOffsetT(14)), 28) }},
+ }
+
+ testMutabilityWithoutSlot := []testcase{
+ testcase{"BoolSlot", func() bool { return t.MutateBoolSlot(calcVOffsetT(16), false) }},
+ testcase{"ByteSlot", func() bool { return t.MutateByteSlot(calcVOffsetT(16), 2) }},
+ testcase{"Uint8Slot", func() bool { return t.MutateUint8Slot(calcVOffsetT(16), 2) }},
+ testcase{"Uint16Slot", func() bool { return t.MutateUint16Slot(calcVOffsetT(16), 2) }},
+ testcase{"Uint32Slot", func() bool { return t.MutateUint32Slot(calcVOffsetT(16), 2) }},
+ testcase{"Uint64Slot", func() bool { return t.MutateUint64Slot(calcVOffsetT(16), 2) }},
+ testcase{"Int8Slot", func() bool { return t.MutateInt8Slot(calcVOffsetT(16), 2) }},
+ testcase{"Int16Slot", func() bool { return t.MutateInt16Slot(calcVOffsetT(16), 2) }},
+ testcase{"Int32Slot", func() bool { return t.MutateInt32Slot(calcVOffsetT(16), 2) }},
+ testcase{"Int64Slot", func() bool { return t.MutateInt64Slot(calcVOffsetT(16), 2) }},
+ testcase{"Float32Slot", func() bool { return t.MutateFloat32Slot(calcVOffsetT(16), 2) }},
+ testcase{"Float64Slot", func() bool { return t.MutateFloat64Slot(calcVOffsetT(16), 2) }},
+ }
+
+ testForMutatedValues := []testcase{
+ testcase{"BoolSlot", func() bool { return t.GetBoolSlot(calcVOffsetT(0), true) == false }},
+ testcase{"ByteSlot", func() bool { return t.GetByteSlot(calcVOffsetT(1), 1) == 2 }},
+ testcase{"Uint8Slot", func() bool { return t.GetUint8Slot(calcVOffsetT(2), 1) == 4 }},
+ testcase{"Uint16Slot", func() bool { return t.GetUint16Slot(calcVOffsetT(3), 1) == 6 }},
+ testcase{"Uint32Slot", func() bool { return t.GetUint32Slot(calcVOffsetT(4), 1) == 8 }},
+ testcase{"Uint64Slot", func() bool { return t.GetUint64Slot(calcVOffsetT(5), 1) == 10 }},
+ testcase{"Int8Slot", func() bool { return t.GetInt8Slot(calcVOffsetT(6), 1) == 12 }},
+ testcase{"Int16Slot", func() bool { return t.GetInt16Slot(calcVOffsetT(7), 1) == 14 }},
+ testcase{"Int32Slot", func() bool { return t.GetInt32Slot(calcVOffsetT(8), 1) == 16 }},
+ testcase{"Int64Slot", func() bool { return t.GetInt64Slot(calcVOffsetT(9), 1) == 18 }},
+ testcase{"Float32Slot", func() bool { return t.GetFloat32Slot(calcVOffsetT(10), 1) == 20 }},
+ testcase{"Float64Slot", func() bool { return t.GetFloat64Slot(calcVOffsetT(11), 1) == 22 }},
+ testcase{"UOffsetTSlot", func() bool { return t.GetUOffsetT(calcUOffsetT(calcVOffsetT(12))) == 24 }},
+ testcase{"VOffsetTSlot", func() bool { return t.GetVOffsetT(calcUOffsetT(calcVOffsetT(13))) == 26 }},
+ testcase{"SOffsetTSlot", func() bool { return t.GetSOffsetT(calcUOffsetT(calcVOffsetT(14))) == 28 }},
+ }
+
+ // make sure original values are okay
+ for _, t := range testForOriginalValues {
+ if !t.testfn() {
+ fail(t.field + "' field doesn't have the expected original value")
+ }
+ }
+
+ // try to mutate fields and check mutability
+ for _, t := range testMutability {
+ if !t.testfn() {
+ fail(FailString(t.field+"' field failed mutability test", "passed", "failed"))
+ }
+ }
+
+ // try to mutate fields and check mutability
+ // these have wrong slots so should fail
+ for _, t := range testMutabilityWithoutSlot {
+ if t.testfn() {
+ fail(FailString(t.field+"' field failed no slot mutability test", "failed", "passed"))
+ }
+ }
+
+ // test whether values have changed
+ for _, t := range testForMutatedValues {
+ if !t.testfn() {
+ fail(t.field + "' field doesn't have the expected mutated value")
+ }
+ }
+}
+
// BenchmarkVtableDeduplication measures the speed of vtable deduplication
// by creating prePop vtables, then populating b.N objects with a
// different single vtable.