summaryrefslogtreecommitdiff
path: root/tests/JavaTest.java
diff options
context:
space:
mode:
authorKamil Rojewski <krojew@users.noreply.github.com>2019-02-21 19:50:13 +0100
committerWouter van Oortmerssen <aardappel@gmail.com>2019-02-21 19:50:13 +0100
commit8f8fb2b3677f55529f126f1adcc70b5dcdcd3290 (patch)
tree88c5c71fa1ee56f6c24e3b0a3ce0c8ff0b75f6f2 /tests/JavaTest.java
parent69d761d15e36bb05cf20b846a048894c72342ebf (diff)
downloadflatbuffers-8f8fb2b3677f55529f126f1adcc70b5dcdcd3290.tar.gz
flatbuffers-8f8fb2b3677f55529f126f1adcc70b5dcdcd3290.tar.bz2
flatbuffers-8f8fb2b3677f55529f126f1adcc70b5dcdcd3290.zip
Fixed vector of unions crash in java (#5190)
* Fixed vector of unions crash in java * Regenerated test code * Fixed windows tests
Diffstat (limited to 'tests/JavaTest.java')
-rw-r--r--tests/JavaTest.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/JavaTest.java b/tests/JavaTest.java
index bc263a01..1a9b7018 100644
--- a/tests/JavaTest.java
+++ b/tests/JavaTest.java
@@ -73,6 +73,8 @@ class JavaTest {
TestSizedInputStream();
+ TestVectorOfUnions();
+
System.out.println("FlatBuffers test: completed successfully");
}
@@ -415,6 +417,40 @@ class JavaTest {
TestEq(pos.x(), 1.0f);
}
+ static void TestVectorOfUnions() {
+ final FlatBufferBuilder fbb = new FlatBufferBuilder();
+
+ final int swordAttackDamage = 1;
+
+ final int[] characterVector = new int[] {
+ Attacker.createAttacker(fbb, swordAttackDamage),
+ };
+
+ final byte[] characterTypeVector = new byte[]{
+ Character.MuLan,
+ };
+
+ Movie.finishMovieBuffer(
+ fbb,
+ Movie.createMovie(
+ fbb,
+ (byte)0,
+ (byte)0,
+ Movie.createCharactersTypeVector(fbb, characterTypeVector),
+ Movie.createCharactersVector(fbb, characterVector)
+ )
+ );
+
+ final Movie movie = Movie.getRootAsMovie(fbb.dataBuffer());
+
+ TestEq(movie.charactersTypeLength(), characterTypeVector.length);
+ TestEq(movie.charactersLength(), characterVector.length);
+
+ TestEq(movie.charactersType(0), characterTypeVector[0]);
+
+ TestEq(((Attacker)movie.characters(new Attacker(), 0)).swordAttackDamage(), swordAttackDamage);
+ }
+
static <T> void TestEq(T a, T b) {
if (!a.equals(b)) {
System.out.println("" + a.getClass().getName() + " " + b.getClass().getName());