summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Demeyer <jeroen.k.demeyer@gmail.com>2023-04-12 02:08:04 +0200
committerGitHub <noreply@github.com>2023-04-11 17:08:04 -0700
commit3fda20d7c7fe1f8006210bddae8cb55bc7a74c3b (patch)
tree6af6c6d1a945bc4ccbf00b6fe9a3882970390a30
parentfa3fa91936fe42a1d687c332c7b84412a21f64a6 (diff)
downloadflatbuffers-3fda20d7c7fe1f8006210bddae8cb55bc7a74c3b.tar.gz
flatbuffers-3fda20d7c7fe1f8006210bddae8cb55bc7a74c3b.tar.bz2
flatbuffers-3fda20d7c7fe1f8006210bddae8cb55bc7a74c3b.zip
Go: add test for FinishWithFileIdentifier (#7905)
Co-authored-by: Michael Le <michael.le647@gmail.com>
-rw-r--r--tests/go_test.go77
1 files changed, 75 insertions, 2 deletions
diff --git a/tests/go_test.go b/tests/go_test.go
index 7cbac1e5..1a46b272 100644
--- a/tests/go_test.go
+++ b/tests/go_test.go
@@ -17,12 +17,12 @@
package main
import (
- order "order"
- pizza "Pizza"
mygame "MyGame" // refers to generated code
example "MyGame/Example" // refers to generated code
+ pizza "Pizza"
"encoding/json"
optional_scalars "optional_scalars" // refers to generated code
+ order "order"
"bytes"
"flag"
@@ -1067,6 +1067,79 @@ func CheckByteLayout(fail func(string, ...interface{})) {
33, // value 0
})
+ // test 16b: same as test 16, size prefixed
+ b = flatbuffers.NewBuilder(0)
+ b.StartObject(2)
+ b.PrependInt8Slot(0, 33, 0)
+ b.PrependInt16Slot(1, 66, 0)
+ off = b.EndObject()
+ b.FinishSizePrefixed(off)
+
+ check([]byte{
+ 20, 0, 0, 0, // size prefix
+ 12, 0, 0, 0, // root of table: points to vtable offset
+
+ 8, 0, // vtable bytes
+ 8, 0, // end of object from here
+ 7, 0, // start of value 0
+ 4, 0, // start of value 1
+
+ 8, 0, 0, 0, // offset for start of vtable (int32)
+
+ 66, 0, // value 1
+ 0, // padding
+ 33, // value 0
+ })
+
+ // test 16c: same as test 16, with file identifier
+ b = flatbuffers.NewBuilder(0)
+ b.StartObject(2)
+ b.PrependInt8Slot(0, 33, 0)
+ b.PrependInt16Slot(1, 66, 0)
+ off = b.EndObject()
+ b.FinishWithFileIdentifier(off, []byte("TEST"))
+
+ check([]byte{
+ 16, 0, 0, 0, // root of table: points to vtable offset
+ 'T', 'E', 'S', 'T', // file identifier
+
+ 8, 0, // vtable bytes
+ 8, 0, // end of object from here
+ 7, 0, // start of value 0
+ 4, 0, // start of value 1
+
+ 8, 0, 0, 0, // offset for start of vtable (int32)
+
+ 66, 0, // value 1
+ 0, // padding
+ 33, // value 0
+ })
+
+ // test 16d: same as test 16, size prefixed with file identifier
+ b = flatbuffers.NewBuilder(0)
+ b.StartObject(2)
+ b.PrependInt8Slot(0, 33, 0)
+ b.PrependInt16Slot(1, 66, 0)
+ off = b.EndObject()
+ b.FinishSizePrefixedWithFileIdentifier(off, []byte("TEST"))
+
+ check([]byte{
+ 24, 0, 0, 0, // size prefix
+ 16, 0, 0, 0, // root of table: points to vtable offset
+ 'T', 'E', 'S', 'T', // file identifier
+
+ 8, 0, // vtable bytes
+ 8, 0, // end of object from here
+ 7, 0, // start of value 0
+ 4, 0, // start of value 1
+
+ 8, 0, 0, 0, // offset for start of vtable (int32)
+
+ 66, 0, // value 1
+ 0, // padding
+ 33, // value 0
+ })
+
// test 17: one unfinished table and one finished table
b = flatbuffers.NewBuilder(0)
b.StartObject(2)