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
7fbd9b8d
Commit
7fbd9b8d
authored
Dec 24, 2015
by
Shuhei Tanuma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(PHP) improve indirect buffer test
parent
c9198dbb
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
17 deletions
+23
-17
generate_code.bat
tests/generate_code.bat
+0
-2
generate_code.sh
tests/generate_code.sh
+0
-2
monsterdata_indirect.json
tests/monsterdata_indirect.json
+0
-7
monsterdata_indirect.mon
tests/monsterdata_indirect.mon
+0
-0
monsterdata_test.json
tests/monsterdata_test.json
+3
-0
monsterdata_test.mon
tests/monsterdata_test.mon
+0
-0
phpTest.php
tests/phpTest.php
+20
-6
No files found.
tests/generate_code.bat
View file @
7fbd9b8d
..\flatc.exe -c -j -n -g -b -p --php -s --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
..\flatc.exe -b --schema monster_test.fbs
..\flatc.exe -b .\monster_test.fbs .\monsterdata_indirect.json
\ No newline at end of file
tests/generate_code.sh
View file @
7fbd9b8d
../flatc
--cpp
--java
--csharp
--go
--binary
--python
--js
--php
--gen-mutable
--no-includes
monster_test.fbs monsterdata_test.json
../flatc
--binary
--schema
monster_test.fbs
../flatc
--binary
monster_test.fbs monsterdata_indirect.json
\ No newline at end of file
tests/monsterdata_indirect.json
deleted
100644 → 0
View file @
c9198dbb
{
"name"
:
"Gob"
,
"enemy"
:
{
"name"
:
"Awk"
}
}
\ No newline at end of file
tests/monsterdata_indirect.mon
deleted
100644 → 0
View file @
c9198dbb
File deleted
tests/monsterdata_test.json
View file @
7fbd9b8d
...
...
@@ -37,6 +37,9 @@
"test1"
,
"test2"
],
enemy
:
{
name
:
"Fred"
},
testarrayofbools
:[
true
,
false
,
true
],
...
...
tests/monsterdata_test.mon
View file @
7fbd9b8d
No preview for this file type
tests/phpTest.php
View file @
7fbd9b8d
...
...
@@ -30,6 +30,10 @@ function main()
// We set up the same values as monsterdata.json:
$str
=
$fbb
->
createString
(
"MyMonster"
);
$name
=
$fbb
->
createString
(
'Fred'
);
\MyGame\Example\Monster
::
startMonster
(
$fbb
);
\MyGame\Example\Monster
::
addName
(
$fbb
,
$name
);
$enemy
=
\MyGame\Example\Monster
::
endMonster
(
$fbb
);
$inv
=
\MyGame\Example\Monster
::
CreateInventoryVector
(
$fbb
,
array
(
0
,
1
,
2
,
3
,
4
));
...
...
@@ -62,6 +66,7 @@ function main()
\MyGame\Example\Monster
::
AddTest
(
$fbb
,
$mon2
);
\MyGame\Example\Monster
::
AddTest4
(
$fbb
,
$test4
);
\MyGame\Example\Monster
::
AddTestarrayofstring
(
$fbb
,
$testArrayOfString
);
\MyGame\Example\Monster
::
AddEnemy
(
$fbb
,
$enemy
);
\MyGame\Example\Monster
::
AddTestbool
(
$fbb
,
false
);
$mon
=
\MyGame\Example\Monster
::
EndMonster
(
$fbb
);
...
...
@@ -75,7 +80,7 @@ function main()
// testUnicode($assert);
test
Indirect
Buffer
(
$assert
);
test
Any
Buffer
(
$assert
);
echo
'FlatBuffers php test: completed successfully'
.
PHP_EOL
;
}
...
...
@@ -135,6 +140,10 @@ function test_buffer(Assert $assert, Google\FlatBuffers\ByteBuffer $bb) {
$assert
->
strictEqual
(
$monster
->
GetTestarrayofstringLength
(),
2
);
$assert
->
strictEqual
(
$monster
->
GetTestarrayofstring
(
0
),
'test1'
);
$assert
->
strictEqual
(
$monster
->
GetTestarrayofstring
(
1
),
'test2'
);
$fred
=
$monster
->
getEnemy
();
$assert
->
Equal
(
'Fred'
,
$fred
->
getName
());
$assert
->
strictEqual
(
$monster
->
GetTestbool
(),
false
);
}
...
...
@@ -590,15 +599,20 @@ function testByteBuffer(Assert $assert) {
$assert
->
Equal
(
0x0D0C0B0A
,
$uut
->
readLittleEndian
(
0
,
4
,
true
));
}
function
testIndirectBuffer
(
Assert
$assert
)
function
testAnyBuffer
(
Assert
$assert
)
{
$js
=
json_decode
(
file_get_contents
(
'monsterdata_indirect.json'
),
true
);
$data
=
file_get_contents
(
'monsterdata_indirect.mon'
);
// PHP needs double quote. for now, use Fred directly
// $js = json_decode(file_get_contents('monsterdata_test.json'), true);
$data
=
file_get_contents
(
'monsterdata_test.mon'
);
$bb
=
Google\FlatBuffers\ByteBuffer
::
wrap
(
$data
);
$mons
=
\MyGame\Example\Monster
::
getRootAsMonster
(
$bb
);
$assert
->
Equal
(
$js
[
"name"
],
$mons
->
getName
());
$assert
->
Equal
(
$js
[
"enemy"
][
"name"
],
$mons
->
getEnemy
()
->
getName
());
$indirect_monster
=
new
\MyGame\Example\Monster
();
$assert
->
Equal
(
$mons
->
getTestType
(),
\MyGame\Example\Any
::
Monster
);
$mons
->
getTest
(
$indirect_monster
);
$assert
->
Equal
(
"Fred"
,
$indirect_monster
->
getName
());
}
class
Assert
{
public
function
ok
(
$result
,
$message
=
""
)
{
if
(
!
$result
){
...
...
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