(String[] args)
| 27 | |
| 28 | class JavaTest { |
| 29 | public static void main(String[] args) { |
| 30 | |
| 31 | // First, let's test reading a FlatBuffer generated by C++ code: |
| 32 | // This file was generated from monsterdata_test.json |
| 33 | |
| 34 | byte[] data = null; |
| 35 | File file = new File("monsterdata_test.mon"); |
| 36 | RandomAccessFile f = null; |
| 37 | try { |
| 38 | f = new RandomAccessFile(file, "r"); |
| 39 | data = new byte[(int)f.length()]; |
| 40 | f.readFully(data); |
| 41 | f.close(); |
| 42 | } catch(java.io.IOException e) { |
| 43 | System.out.println("FlatBuffers test: couldn't read file"); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | // Now test it: |
| 48 | |
| 49 | ByteBuffer bb = ByteBuffer.wrap(data); |
| 50 | TestBuffer(bb); |
| 51 | |
| 52 | // Second, let's create a FlatBuffer from scratch in Java, and test it also. |
| 53 | // We use an initial size of 1 to exercise the reallocation algorithm, |
| 54 | // normally a size larger than the typical FlatBuffer you generate would be |
| 55 | // better for performance. |
| 56 | FlatBufferBuilder fbb = new FlatBufferBuilder(1); |
| 57 | |
| 58 | TestBuilderBasics(fbb, true); |
| 59 | TestBuilderBasics(fbb, false); |
| 60 | |
| 61 | TestExtendedBuffer(fbb.dataBuffer().asReadOnlyBuffer()); |
| 62 | |
| 63 | TestNamespaceNesting(); |
| 64 | |
| 65 | TestNestedFlatBuffer(); |
| 66 | |
| 67 | TestCreateByteVector(); |
| 68 | |
| 69 | TestCreateUninitializedVector(); |
| 70 | |
| 71 | TestByteBufferFactory(); |
| 72 | |
| 73 | TestSizedInputStream(); |
| 74 | |
| 75 | System.out.println("FlatBuffers test: completed successfully"); |
| 76 | } |
| 77 | |
| 78 | static void TestEnums() { |
| 79 | TestEq(Color.name(Color.Red), "Red"); |
no test coverage detected