Go: add test for FinishWithFileIdentifier (#7905)

Co-authored-by: Michael Le <michael.le647@gmail.com>
This commit is contained in:
Jeroen Demeyer 2023-04-12 02:08:04 +02:00 committed by GitHub
parent fa3fa91936
commit 3fda20d7c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 75 additions and 2 deletions

View File

@ -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)