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());
}
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);
}
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());
}
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);
}
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());
}
Aggregations