Search in sources :

Example 76 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testWritingWithImports.

// =========================================================================
@Test
public void testWritingWithImports() throws Exception {
    final int FRED_ID_OFFSET = systemMaxId();
    final int GINGER_ID_OFFSET = FRED_ID_OFFSET + FRED_MAX_IDS[1];
    SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
    SymbolTable ginger1 = Symtabs.register("ginger", 1, catalog());
    iw = makeWriter(fred1, ginger1);
    iw.writeSymbol("fred_2");
    iw.writeSymbol("g1");
    iw.writeSymbol("localSym");
    byte[] bytes = outputByteArray();
    IonDatagram dg = loader().load(bytes);
    assertEquals(5, dg.systemSize());
    IonValue f2sym = dg.systemGet(2);
    IonValue g1sym = dg.systemGet(3);
    IonValue local = dg.systemGet(4);
    checkSymbol("fred_2", FRED_ID_OFFSET + 2, f2sym);
    checkSymbol("g1", GINGER_ID_OFFSET + 1, g1sym);
    checkSymbol("localSym", local);
    SymbolTable symtab = f2sym.getSymbolTable();
    assertSame(symtab, g1sym.getSymbolTable());
    SymbolTable[] importedTables = symtab.getImportedTables();
    assertEquals(2, importedTables.length);
    assertSame(fred1, importedTables[0]);
    assertSame(ginger1, importedTables[1]);
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 77 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testAnnotationNotSetToIvmOnStartOfStream.

@Test
public void testAnnotationNotSetToIvmOnStartOfStream() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    IonValue value1 = oneValue("1");
    value1.addTypeAnnotation("some_annot");
    value1.writeTo(iw);
    // Expect: an annotation on value1
    expected.add(value1);
    IonValue value2 = oneValue("2");
    value2.writeTo(iw);
    iw.close();
    expected.add(value2);
    IonAssert.assertIonEquals(expected, reload());
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 78 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testWritingDatagram.

// TODO amzn/ion-java/issues/8 Inconsistencies between writers
@Test
public void testWritingDatagram() throws Exception {
    IonDatagram dg = loader().load("foo");
    iw = makeWriter();
    dg.writeTo(iw);
    iw.writeValue(dg);
    Iterator<IonValue> it = systemIterateOutput();
    checkSymbol(SystemSymbols.ION_1_0, it.next());
    if (myOutputForm != OutputForm.TEXT) {
        checkAnnotation(SystemSymbols.ION_SYMBOL_TABLE, it.next());
    }
    // TODO amzn/ion-java#14
    if (myOutputForm != OutputForm.TEXT) {
        checkSymbol(null, 10, it.next());
    } else {
        checkSymbol("foo", it.next());
    }
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 79 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testAnnotationNotSetToIvmAfterFinish.

@Test
public void testAnnotationNotSetToIvmAfterFinish() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    IonValue value1 = oneValue("1");
    value1.writeTo(iw);
    // Resets the stream context, the next TLV that is written must behave
    // as if it is preceded by an IVM, depending on the writer's config.
    iw.finish();
    expected.add(value1);
    IonValue value2 = oneValue("2");
    value2.addTypeAnnotation("some_annot");
    value2.writeTo(iw);
    iw.close();
    // Expect: an annotation on value2
    expected.add(value2);
    IonAssert.assertIonEquals(expected, reload());
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 80 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testWriteIVMExplicitly.

@Test
public void testWriteIVMExplicitly() throws Exception {
    iw = makeWriter();
    iw.writeSymbol("foo");
    ((_Private_IonWriter) iw).writeIonVersionMarker();
    iw.writeInt(1);
    IonDatagram dg = reload();
    assertEquals(2, dg.size());
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2