Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
48322387
Commit
48322387
authored
Jan 07, 2016
by
Dan Ring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for GetRootAs* in Go and Python
parent
1f8e3c13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
go_test.go
tests/go_test.go
+28
-0
py_test.py
tests/py_test.py
+17
-0
No files found.
tests/go_test.go
View file @
48322387
...
...
@@ -75,6 +75,9 @@ func TestAll(t *testing.T) {
CheckStructIsNotInlineError
(
t
.
Fatalf
)
CheckFinishedBytesError
(
t
.
Fatalf
)
// Verify that GetRootAs works for non-root tables
CheckGetRootAsForNonRootTable
(
t
.
Fatalf
)
// Verify that using the generated Go code builds a buffer without
// returning errors:
generated
,
off
:=
CheckGeneratedBuild
(
t
.
Fatalf
)
...
...
@@ -964,6 +967,31 @@ func CheckManualBuild(fail func(string, ...interface{})) ([]byte, flatbuffers.UO
return
b
.
Bytes
,
b
.
Head
()
}
func
CheckGetRootAsForNonRootTable
(
fail
func
(
string
,
...
interface
{}))
{
b
:=
flatbuffers
.
NewBuilder
(
0
)
str
:=
b
.
CreateString
(
"MyStat"
)
example
.
StatStart
(
b
)
example
.
StatAddId
(
b
,
str
)
example
.
StatAddVal
(
b
,
12345678
)
example
.
StatAddCount
(
b
,
12345
)
stat_end
:=
example
.
StatEnd
(
b
)
b
.
Finish
(
stat_end
)
stat
:=
example
.
GetRootAsStat
(
b
.
Bytes
,
b
.
Head
())
if
got
:=
stat
.
Id
();
!
bytes
.
Equal
([]
byte
(
"MyStat"
),
got
)
{
fail
(
FailString
(
"stat.Id()"
,
"MyStat"
,
got
))
}
if
got
:=
stat
.
Val
();
12345678
!=
got
{
fail
(
FailString
(
"stat.Val()"
,
12345678
,
got
))
}
if
got
:=
stat
.
Count
();
12345
!=
got
{
fail
(
FailString
(
"stat.Count()"
,
12345
,
got
))
}
}
// CheckGeneratedBuild uses generated code to build the example Monster.
func
CheckGeneratedBuild
(
fail
func
(
string
,
...
interface
{}))
([]
byte
,
flatbuffers
.
UOffsetT
)
{
b
:=
flatbuffers
.
NewBuilder
(
0
)
...
...
tests/py_test.py
View file @
48322387
...
...
@@ -1033,6 +1033,23 @@ class TestAllCodePathsOfExampleSchema(unittest.TestCase):
self
.
assertEqual
(
7
,
mon2
.
Testhashs64Fnv1a
())
self
.
assertEqual
(
8
,
mon2
.
Testhashu64Fnv1a
())
def
test_getrootas_for_nonroot_table
(
self
):
b
=
flatbuffers
.
Builder
(
0
)
string
=
b
.
CreateString
(
"MyStat"
)
MyGame
.
Example
.
Stat
.
StatStart
(
b
)
MyGame
.
Example
.
Stat
.
StatAddId
(
b
,
string
)
MyGame
.
Example
.
Stat
.
StatAddVal
(
b
,
12345678
)
MyGame
.
Example
.
Stat
.
StatAddCount
(
b
,
12345
)
stat
=
MyGame
.
Example
.
Stat
.
StatEnd
(
b
)
b
.
Finish
(
stat
)
stat2
=
MyGame
.
Example
.
Stat
.
Stat
.
GetRootAsStat
(
b
.
Bytes
,
b
.
Head
())
self
.
assertEqual
(
b
"MyStat"
,
stat2
.
Id
())
self
.
assertEqual
(
12345678
,
stat2
.
Val
())
self
.
assertEqual
(
12345
,
stat2
.
Count
())
class
TestVtableDeduplication
(
unittest
.
TestCase
):
''' TestVtableDeduplication verifies that vtables are deduplicated. '''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment