summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/JavaTest.bat4
-rw-r--r--tests/JavaTest.java36
-rwxr-xr-xtests/JavaTest.sh2
-rw-r--r--tests/MyGame/Example/Ability.java3
-rw-r--r--tests/MyGame/Example/Monster.java3
-rw-r--r--tests/MyGame/Example/Referrable.java3
-rw-r--r--tests/MyGame/Example/Stat.java3
-rw-r--r--tests/MyGame/Example/Test.java3
-rw-r--r--tests/MyGame/Example/TestSimpleTableWithEnum.java3
-rw-r--r--tests/MyGame/Example/TypeAliases.java3
-rw-r--r--tests/MyGame/Example/Vec3.java3
-rw-r--r--tests/MyGame/Example2/Monster.java3
-rw-r--r--tests/MyGame/InParentNamespace.java3
-rw-r--r--tests/MyGame/MonsterExtra.java3
-rw-r--r--tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java3
-rw-r--r--tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java3
-rw-r--r--tests/namespace_test/NamespaceA/SecondTableInA.java3
-rw-r--r--tests/namespace_test/NamespaceA/TableInFirstNS.java3
-rw-r--r--tests/namespace_test/NamespaceC/TableInC.java3
-rw-r--r--tests/union_vector/Movie.java2
20 files changed, 72 insertions, 20 deletions
diff --git a/tests/JavaTest.bat b/tests/JavaTest.bat
index aa726130..921815a1 100644
--- a/tests/JavaTest.bat
+++ b/tests/JavaTest.bat
@@ -17,5 +17,5 @@ rem Compile then run the Java test.
set batch_file_dir=%~d0%~p0
-javac -g -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test JavaTest.java
-java -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test JavaTest
+javac -g -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test;%batch_file_dir%\union_vector JavaTest.java
+java -classpath %batch_file_dir%\..\java;%batch_file_dir%;%batch_file_dir%\namespace_test;%batch_file_dir%\union_vector JavaTest
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());
diff --git a/tests/JavaTest.sh b/tests/JavaTest.sh
index a5a049e7..58d84429 100755
--- a/tests/JavaTest.sh
+++ b/tests/JavaTest.sh
@@ -36,7 +36,7 @@ if ! find "${testdir}/../java" -type f -name "*.class" -delete; then
exit 1
fi
-javac -d "${targetdir}" -classpath "${testdir}/../java:${testdir}:${testdir}/namespace_test" "${testdir}/JavaTest.java"
+javac -d "${targetdir}" -classpath "${testdir}/../java:${testdir}:${testdir}/namespace_test:${testdir}/union_vector" "${testdir}/JavaTest.java"
(cd "${testdir}" && java -classpath "${targetdir}" JavaTest )
diff --git a/tests/MyGame/Example/Ability.java b/tests/MyGame/Example/Ability.java
index 0bd614c2..5e1c90e0 100644
--- a/tests/MyGame/Example/Ability.java
+++ b/tests/MyGame/Example/Ability.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class Ability extends Struct {
+@SuppressWarnings("unused")
+public final class Ability extends Struct {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public Ability __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
diff --git a/tests/MyGame/Example/Monster.java b/tests/MyGame/Example/Monster.java
index 6feddb33..c7339750 100644
--- a/tests/MyGame/Example/Monster.java
+++ b/tests/MyGame/Example/Monster.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")/**
+@SuppressWarnings("unused")
+/**
* an example documentation comment: monster object
*/
public final class Monster extends Table {
diff --git a/tests/MyGame/Example/Referrable.java b/tests/MyGame/Example/Referrable.java
index e164256d..9398597e 100644
--- a/tests/MyGame/Example/Referrable.java
+++ b/tests/MyGame/Example/Referrable.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class Referrable extends Table {
+@SuppressWarnings("unused")
+public final class Referrable extends Table {
public static Referrable getRootAsReferrable(ByteBuffer _bb) { return getRootAsReferrable(_bb, new Referrable()); }
public static Referrable getRootAsReferrable(ByteBuffer _bb, Referrable obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/MyGame/Example/Stat.java b/tests/MyGame/Example/Stat.java
index 8f480363..73e2bc8f 100644
--- a/tests/MyGame/Example/Stat.java
+++ b/tests/MyGame/Example/Stat.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class Stat extends Table {
+@SuppressWarnings("unused")
+public final class Stat extends Table {
public static Stat getRootAsStat(ByteBuffer _bb) { return getRootAsStat(_bb, new Stat()); }
public static Stat getRootAsStat(ByteBuffer _bb, Stat obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/MyGame/Example/Test.java b/tests/MyGame/Example/Test.java
index 34b095a0..f584c463 100644
--- a/tests/MyGame/Example/Test.java
+++ b/tests/MyGame/Example/Test.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class Test extends Struct {
+@SuppressWarnings("unused")
+public final class Test extends Struct {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public Test __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
diff --git a/tests/MyGame/Example/TestSimpleTableWithEnum.java b/tests/MyGame/Example/TestSimpleTableWithEnum.java
index 545c0ad3..ded3be49 100644
--- a/tests/MyGame/Example/TestSimpleTableWithEnum.java
+++ b/tests/MyGame/Example/TestSimpleTableWithEnum.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")final class TestSimpleTableWithEnum extends Table {
+@SuppressWarnings("unused")
+final class TestSimpleTableWithEnum extends Table {
public static TestSimpleTableWithEnum getRootAsTestSimpleTableWithEnum(ByteBuffer _bb) { return getRootAsTestSimpleTableWithEnum(_bb, new TestSimpleTableWithEnum()); }
public static TestSimpleTableWithEnum getRootAsTestSimpleTableWithEnum(ByteBuffer _bb, TestSimpleTableWithEnum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/MyGame/Example/TypeAliases.java b/tests/MyGame/Example/TypeAliases.java
index 497d7760..f74a3231 100644
--- a/tests/MyGame/Example/TypeAliases.java
+++ b/tests/MyGame/Example/TypeAliases.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class TypeAliases extends Table {
+@SuppressWarnings("unused")
+public final class TypeAliases extends Table {
public static TypeAliases getRootAsTypeAliases(ByteBuffer _bb) { return getRootAsTypeAliases(_bb, new TypeAliases()); }
public static TypeAliases getRootAsTypeAliases(ByteBuffer _bb, TypeAliases obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/MyGame/Example/Vec3.java b/tests/MyGame/Example/Vec3.java
index 66dfcd08..2e43f051 100644
--- a/tests/MyGame/Example/Vec3.java
+++ b/tests/MyGame/Example/Vec3.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class Vec3 extends Struct {
+@SuppressWarnings("unused")
+public final class Vec3 extends Struct {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public Vec3 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
diff --git a/tests/MyGame/Example2/Monster.java b/tests/MyGame/Example2/Monster.java
index 433d4c58..69a15624 100644
--- a/tests/MyGame/Example2/Monster.java
+++ b/tests/MyGame/Example2/Monster.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class Monster extends Table {
+@SuppressWarnings("unused")
+public final class Monster extends Table {
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/MyGame/InParentNamespace.java b/tests/MyGame/InParentNamespace.java
index f933fb93..5ac27c20 100644
--- a/tests/MyGame/InParentNamespace.java
+++ b/tests/MyGame/InParentNamespace.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class InParentNamespace extends Table {
+@SuppressWarnings("unused")
+public final class InParentNamespace extends Table {
public static InParentNamespace getRootAsInParentNamespace(ByteBuffer _bb) { return getRootAsInParentNamespace(_bb, new InParentNamespace()); }
public static InParentNamespace getRootAsInParentNamespace(ByteBuffer _bb, InParentNamespace obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/MyGame/MonsterExtra.java b/tests/MyGame/MonsterExtra.java
index 6070efdc..8c5679a1 100644
--- a/tests/MyGame/MonsterExtra.java
+++ b/tests/MyGame/MonsterExtra.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class MonsterExtra extends Table {
+@SuppressWarnings("unused")
+public final class MonsterExtra extends Table {
public static MonsterExtra getRootAsMonsterExtra(ByteBuffer _bb) { return getRootAsMonsterExtra(_bb, new MonsterExtra()); }
public static MonsterExtra getRootAsMonsterExtra(ByteBuffer _bb, MonsterExtra obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
index 883913b7..42d47c13 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
+++ b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class StructInNestedNS extends Struct {
+@SuppressWarnings("unused")
+public final class StructInNestedNS extends Struct {
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
public StructInNestedNS __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
index bdd3f3a3..415fa693 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class TableInNestedNS extends Table {
+@SuppressWarnings("unused")
+public final class TableInNestedNS extends Table {
public static TableInNestedNS getRootAsTableInNestedNS(ByteBuffer _bb) { return getRootAsTableInNestedNS(_bb, new TableInNestedNS()); }
public static TableInNestedNS getRootAsTableInNestedNS(ByteBuffer _bb, TableInNestedNS obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.java b/tests/namespace_test/NamespaceA/SecondTableInA.java
index 542fbb4c..7c56b882 100644
--- a/tests/namespace_test/NamespaceA/SecondTableInA.java
+++ b/tests/namespace_test/NamespaceA/SecondTableInA.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class SecondTableInA extends Table {
+@SuppressWarnings("unused")
+public final class SecondTableInA extends Table {
public static SecondTableInA getRootAsSecondTableInA(ByteBuffer _bb) { return getRootAsSecondTableInA(_bb, new SecondTableInA()); }
public static SecondTableInA getRootAsSecondTableInA(ByteBuffer _bb, SecondTableInA obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.java b/tests/namespace_test/NamespaceA/TableInFirstNS.java
index 09f66772..b03c4623 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.java
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class TableInFirstNS extends Table {
+@SuppressWarnings("unused")
+public final class TableInFirstNS extends Table {
public static TableInFirstNS getRootAsTableInFirstNS(ByteBuffer _bb) { return getRootAsTableInFirstNS(_bb, new TableInFirstNS()); }
public static TableInFirstNS getRootAsTableInFirstNS(ByteBuffer _bb, TableInFirstNS obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/namespace_test/NamespaceC/TableInC.java b/tests/namespace_test/NamespaceC/TableInC.java
index 8a3a2a41..56d49545 100644
--- a/tests/namespace_test/NamespaceC/TableInC.java
+++ b/tests/namespace_test/NamespaceC/TableInC.java
@@ -7,7 +7,8 @@ import java.lang.*;
import java.util.*;
import com.google.flatbuffers.*;
-@SuppressWarnings("unused")public final class TableInC extends Table {
+@SuppressWarnings("unused")
+public final class TableInC extends Table {
public static TableInC getRootAsTableInC(ByteBuffer _bb) { return getRootAsTableInC(_bb, new TableInC()); }
public static TableInC getRootAsTableInC(ByteBuffer _bb, TableInC obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
public void __init(int _i, ByteBuffer _bb) { bb_pos = _i; bb = _bb; }
diff --git a/tests/union_vector/Movie.java b/tests/union_vector/Movie.java
index 8e214b93..18d13ce1 100644
--- a/tests/union_vector/Movie.java
+++ b/tests/union_vector/Movie.java
@@ -19,7 +19,7 @@ public final class Movie extends Table {
public int charactersTypeLength() { int o = __offset(8); return o != 0 ? __vector_len(o) : 0; }
public ByteBuffer charactersTypeAsByteBuffer() { return __vector_as_bytebuffer(8, 1); }
public ByteBuffer charactersTypeInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 8, 1); }
- public Table characters(Table obj, int j) { int o = __offset(10); return o != 0 ? __union(obj, __vector(o) + j * 4) : null; }
+ public Table characters(Table obj, int j) { int o = __offset(10); return o != 0 ? __union(obj, __vector(o) + j * 4 - bb_pos) : null; }
public int charactersLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; }
public static int createMovie(FlatBufferBuilder builder,