MCPcopy Create free account
hub / github.com/alibaba/MNN / TestBuffer

Method TestBuffer

3rd_party/flatbuffers/tests/JavaTest.java:85–134  ·  view source on GitHub ↗
(ByteBuffer bb)

Source from the content-addressed store, hash-verified

83 }
84
85 static void TestBuffer(ByteBuffer bb) {
86 TestEq(Monster.MonsterBufferHasIdentifier(bb), true);
87
88 Monster monster = Monster.getRootAsMonster(bb);
89
90 TestEq(monster.hp(), (short)80);
91 TestEq(monster.mana(), (short)150); // default
92
93 TestEq(monster.name(), "MyMonster");
94 // monster.friendly() // can't access, deprecated
95
96 Vec3 pos = monster.pos();
97 TestEq(pos.x(), 1.0f);
98 TestEq(pos.y(), 2.0f);
99 TestEq(pos.z(), 3.0f);
100 TestEq(pos.test1(), 3.0);
101 TestEq(pos.test2(), Color.Green);
102 Test t = pos.test3();
103 TestEq(t.a(), (short)5);
104 TestEq(t.b(), (byte)6);
105
106 TestEq(monster.testType(), (byte)Any.Monster);
107 Monster monster2 = new Monster();
108 TestEq(monster.test(monster2) != null, true);
109 TestEq(monster2.name(), "Fred");
110
111 TestEq(monster.inventoryLength(), 5);
112 int invsum = 0;
113 for (int i = 0; i < monster.inventoryLength(); i++)
114 invsum += monster.inventory(i);
115 TestEq(invsum, 10);
116
117 // Alternative way of accessing a vector:
118 ByteBuffer ibb = monster.inventoryAsByteBuffer();
119 invsum = 0;
120 while (ibb.position() < ibb.limit())
121 invsum += ibb.get();
122 TestEq(invsum, 10);
123
124 Test test_0 = monster.test4(0);
125 Test test_1 = monster.test4(1);
126 TestEq(monster.test4Length(), 2);
127 TestEq(test_0.a() + test_0.b() + test_1.a() + test_1.b(), 100);
128
129 TestEq(monster.testarrayofstringLength(), 2);
130 TestEq(monster.testarrayofstring(0),"test1");
131 TestEq(monster.testarrayofstring(1),"test2");
132
133 TestEq(monster.testbool(), true);
134 }
135
136 // this method checks additional fields not present in the binary buffer read from file
137 // these new tests are performed on top of the regular tests

Callers 2

mainMethod · 0.95
TestExtendedBufferMethod · 0.95

Calls 15

TestEqMethod · 0.95
getRootAsMonsterMethod · 0.95
hpMethod · 0.95
manaMethod · 0.95
nameMethod · 0.95
posMethod · 0.95
xMethod · 0.95
yMethod · 0.95
zMethod · 0.95
test1Method · 0.95
test2Method · 0.95

Tested by

no test coverage detected