|
| 1 | +package org.opcfoundation.ua.encoding.binary; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | +import org.opcfoundation.ua.builtintypes.DataValue; |
| 7 | +import org.opcfoundation.ua.builtintypes.DateTime; |
| 8 | +import org.opcfoundation.ua.builtintypes.StatusCode; |
| 9 | +import org.opcfoundation.ua.builtintypes.UnsignedShort; |
| 10 | +import org.opcfoundation.ua.builtintypes.Variant; |
| 11 | + |
| 12 | +public class BinaryEncoderTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void encodeDecodeDataValue() throws Exception { |
| 16 | + //For GH#112 |
| 17 | + //Test that encoded and then decoded DataValue are equal |
| 18 | + //NOTE this should be later refactored to check the raw binary form as well |
| 19 | + |
| 20 | + //Setting values that force encoding, i.e. not default values that are handed by the encoding mask |
| 21 | + DateTime dt = DateTime.fromMillis(100000); //some time that is not min or max |
| 22 | + UnsignedShort tenPicoSeconds = UnsignedShort.valueOf(10); //100 picoseconds, something that is not 0 |
| 23 | + final DataValue dv = new DataValue(new Variant(Integer.valueOf(1)), StatusCode.BAD, dt, tenPicoSeconds, dt, tenPicoSeconds); |
| 24 | + EncoderCalc calc = new EncoderCalc(); |
| 25 | + calc.putDataValue(null, dv); |
| 26 | + int len = calc.length; |
| 27 | + byte[] buf = new byte[len]; |
| 28 | + BinaryEncoder enc = new BinaryEncoder(buf); |
| 29 | + enc.putDataValue(null, dv); |
| 30 | + |
| 31 | + //System.out.println(CryptoUtil.toHex(buf)); |
| 32 | + |
| 33 | + BinaryDecoder dec = new BinaryDecoder(buf); |
| 34 | + final DataValue dv2 = dec.getDataValue(null); |
| 35 | + |
| 36 | + //System.out.println(dv); |
| 37 | + //System.out.println(dv2); |
| 38 | + assertEquals(dv, dv2); |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | +} |
0 commit comments