Search in sources :

Example 1 with TestSerializationContext

use of org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext in project milo by eclipse.

the class BinaryDecoderTest method testDecodeNullArray.

@Test(description = "a null array, once encoded, should decode to a null array")
public void testDecodeNullArray() {
    Argument argument = new Argument("test", Identifiers.Int16, 1, null, LocalizedText.NULL_VALUE);
    @SuppressWarnings("unchecked") OpcUaBinaryDataTypeCodec<Argument> codec = (OpcUaBinaryDataTypeCodec<Argument>) OpcUaDataTypeManager.getInstance().getCodec(OpcUaDefaultBinaryEncoding.ENCODING_NAME, Argument.TYPE_ID.toNodeId(new NamespaceTable()).get());
    assertNotNull(codec);
    codec.encode(new TestSerializationContext(), writer, argument);
    Argument decoded = codec.decode(new TestSerializationContext(), reader);
    assertEquals(decoded.getName(), argument.getName());
    assertNull(decoded.getArrayDimensions());
}
Also used : Argument(org.eclipse.milo.opcua.stack.core.types.structured.Argument) NamespaceTable(org.eclipse.milo.opcua.stack.core.NamespaceTable) TestSerializationContext(org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext) OpcUaBinaryDataTypeCodec(org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaBinaryDataTypeCodec) Test(org.testng.annotations.Test)

Example 2 with TestSerializationContext

use of org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext in project milo by eclipse.

the class BinarySerializationFixture method setUp.

@BeforeMethod
public void setUp() {
    buffer = Unpooled.buffer();
    writer = new OpcUaBinaryStreamEncoder(new TestSerializationContext()).setBuffer(buffer);
    reader = new OpcUaBinaryStreamDecoder(new TestSerializationContext()).setBuffer(buffer);
}
Also used : OpcUaBinaryStreamDecoder(org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamDecoder) TestSerializationContext(org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext) OpcUaBinaryStreamEncoder(org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 3 with TestSerializationContext

use of org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext in project milo by eclipse.

the class VariantSerializationTest method testNullArrayEncodedWithNegativeArraySize.

@Test(description = "Test that a Variant containing a null array encoded with a negative array size to indicate a null value decodes properly.")
public void testNullArrayEncodedWithNegativeArraySize() {
    ByteBuf buffer = Unpooled.buffer();
    buffer.writeByte(BuiltinDataType.Int16.getTypeId() | (1 << 7));
    buffer.writeIntLE(-1);
    OpcUaBinaryStreamDecoder reader = new OpcUaBinaryStreamDecoder(new TestSerializationContext());
    reader.setBuffer(buffer);
    Variant v = reader.readVariant();
    assertNotNull(v);
    assertNull(v.getValue());
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) OpcUaBinaryStreamDecoder(org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamDecoder) TestSerializationContext(org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext) ByteBuf(io.netty.buffer.ByteBuf) Test(org.testng.annotations.Test)

Example 4 with TestSerializationContext

use of org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext in project milo by eclipse.

the class OpcUaBinaryStreamEncoderTest method initializeTest.

@BeforeTest
public void initializeTest() {
    buffer = Unpooled.buffer();
    writer = new OpcUaBinaryStreamEncoder(new TestSerializationContext()).setBuffer(buffer);
}
Also used : TestSerializationContext(org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext) OpcUaBinaryStreamEncoder(org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with TestSerializationContext

use of org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext in project milo by eclipse.

the class VariantSerializationTest method testVariant_UaStructure.

@Test
public void testVariant_UaStructure() {
    ServiceCounterDataType sc1 = new ServiceCounterDataType(uint(1), uint(2));
    Variant v = new Variant(sc1);
    writer.writeVariant(v);
    Variant decoded = reader.readVariant();
    ExtensionObject extensionObject = (ExtensionObject) decoded.getValue();
    ServiceCounterDataType sc2 = (ServiceCounterDataType) extensionObject.decode(new TestSerializationContext());
    Assert.assertEquals(sc1.getTotalCount(), sc2.getTotalCount());
    Assert.assertEquals(sc1.getErrorCount(), sc2.getErrorCount());
}
Also used : Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) ExtensionObject(org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject) TestSerializationContext(org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext) ServiceCounterDataType(org.eclipse.milo.opcua.stack.core.types.structured.ServiceCounterDataType) Test(org.testng.annotations.Test)

Aggregations

TestSerializationContext (org.eclipse.milo.opcua.stack.core.serialization.TestSerializationContext)5 Test (org.testng.annotations.Test)3 OpcUaBinaryStreamDecoder (org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamDecoder)2 OpcUaBinaryStreamEncoder (org.eclipse.milo.opcua.stack.core.serialization.OpcUaBinaryStreamEncoder)2 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)2 ByteBuf (io.netty.buffer.ByteBuf)1 NamespaceTable (org.eclipse.milo.opcua.stack.core.NamespaceTable)1 OpcUaBinaryDataTypeCodec (org.eclipse.milo.opcua.stack.core.serialization.codecs.OpcUaBinaryDataTypeCodec)1 ExtensionObject (org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject)1 Argument (org.eclipse.milo.opcua.stack.core.types.structured.Argument)1 ServiceCounterDataType (org.eclipse.milo.opcua.stack.core.types.structured.ServiceCounterDataType)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 BeforeTest (org.testng.annotations.BeforeTest)1