예제 #1
0
        private static void WriteArrayOneDimension(int rank)
        {
            byte[] _EncodedValue = null;
            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    Int32[] _value   = new Int32[] { 0, 1, 2, 3, 4 };
                    Variant _variant = new Variant {
                        UATypeInfo = new UATypeInfo(BuiltInType.Int32, rank, new int[] { _value.Length }), Value = _value
                    };
                    _buffer.Write(_buffer, _variant);
                    _buffer.Close();
                    _EncodedValue = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedValue);
            string _EncodedValueString = String.Join(", ", _EncodedValue);
            string _expectedString     = "134, 5, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0";

            Assert.AreEqual <string>(_expectedString, _EncodedValueString);
            Assert.AreEqual <int>(25, _EncodedValue.Length);
            Assert.AreEqual <int>(0, _EncodedValue[5]);
            Assert.AreEqual <int>(1, _EncodedValue[9]);
            Assert.AreEqual <int>(2, _EncodedValue[13]);
            Assert.AreEqual <int>(3, _EncodedValue[17]);
            Assert.AreEqual <int>(4, _EncodedValue[21]);
        }
예제 #2
0
        public void ArrayMultiDimensionTest()
        {
            byte[] _EncodedValue = null;
            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    Int32[] _dimensions = new Int32[] { 2, 2 };
                    Int32[,] _array = new Int32[, ] {
                        { 0, 1 }, { 2, 3 }
                    };
                    Assert.AreEqual <int>(2, _array.Rank);
                    Assert.AreEqual <int>(4, _array.Length);
                    Assert.AreEqual <int>(_dimensions.Length, _array.Rank);
                    UATypeInfo _uaTypeInfo = new UATypeInfo(BuiltInType.Int32, _dimensions.Length, _dimensions);
                    Variant    _variant    = new Variant {
                        UATypeInfo = _uaTypeInfo, Value = _array
                    };
                    _buffer.Write(_buffer, _variant);
                    _buffer.Close();
                    _EncodedValue = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedValue);
            Assert.AreEqual <int>(33, _EncodedValue.Length);
            string _content = String.Join(", ", _EncodedValue);

            Assert.AreEqual <string>("198, 4, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0", _content);
        }
예제 #3
0
 public void WriteByteStringTest()
 {
     using (var _stream = new MemoryStream())
         using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
         {
             _buffer.Write(_buffer, new byte[10]);
             _buffer.Close();
             byte[] _Encoded = _stream.ToArray();
             Assert.AreEqual <int>(14, _Encoded.Length);
         }
 }
예제 #4
0
        public void GuidTestMethod()
        {
            byte[] _EncodedGuid = null;
            Guid   _Guid        = Guid.NewGuid();

            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    _buffer.Write(_Guid);
                    _buffer.Close();
                    _EncodedGuid = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedGuid);
            Assert.AreEqual <int>(16, _EncodedGuid.Length);
            Guid _recoveredGuid = new Guid(_EncodedGuid);

            Assert.AreEqual <Guid>(_Guid, _recoveredGuid);
        }
예제 #5
0
 public void VariantDateTimeTestMethod()
 {
     foreach (CommonDefinitions.DateTimeVariantEncoding _dtx in CommonDefinitions.DateTimeTestingValues)
     {
         MemoryStream     _stream = new MemoryStream();
         TestBinaryWriter _buffer = new TestBinaryWriter(_stream);
         Assert.IsNotNull(_buffer);
         Variant _variant = new Variant {
             UATypeInfo = new UATypeInfo(BuiltInType.DateTime), Value = _dtx.dateTime
         };
         _buffer.Write(_buffer, _variant);
         _buffer.Close();
         byte[] _EncodedVariant = _stream.ToArray();
         Assert.IsNotNull(_EncodedVariant);
         Assert.AreEqual <int>(9, _EncodedVariant.Length);
         Assert.AreEqual <byte>((byte)BuiltInType.DateTime, _EncodedVariant[0]);
         CollectionAssert.AreEqual(_dtx.encoding, _EncodedVariant.ToList <byte>());
     }
 }
예제 #6
0
        public void VariantArrayOfByteStringsTestMethod()
        {
            byte[] _EncodedValue = null;
            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    Variant _variant = new Variant {
                        UATypeInfo = new UATypeInfo(BuiltInType.ByteString, 1), Value = new byte[][] { new byte[] { 0, 1, 2, 3, 4 }, new byte[] { 5, 6, 7, 8, 9 } }
                    };
                    _buffer.Write(_buffer, _variant);
                    _buffer.Close();
                    _EncodedValue = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedValue);
            Assert.AreEqual <int>(23, _EncodedValue.Length);
            Assert.AreEqual <byte>((byte)((byte)BuiltInType.ByteString | (byte)VariantEncodingMask.IsArray), _EncodedValue[0]);
            string _content = String.Join(", ", _EncodedValue);

            Assert.AreEqual <string>("143, 2, 0, 0, 0, 5, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 5, 6, 7, 8, 9", _content);
        }
예제 #7
0
        public void VariantByteStringTestMethod()
        {
            byte[] _EncodedValue = null;
            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    Variant _variant = new Variant {
                        UATypeInfo = new UATypeInfo(BuiltInType.ByteString), Value = new byte[] { 0, 1, 2, 3, 4 }
                    };
                    _buffer.Write(_buffer, _variant);
                    _buffer.Close();
                    _EncodedValue = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedValue);
            Assert.AreEqual <int>(10, _EncodedValue.Length);
            Assert.AreEqual <byte>((byte)BuiltInType.ByteString, _EncodedValue[0]);
            string _content = String.Join(", ", _EncodedValue);

            Assert.AreEqual <string>("15, 5, 0, 0, 0, 0, 1, 2, 3, 4", _content);
        }
예제 #8
0
        public void VariantGuidTestMethod()
        {
            byte[] _EncodedVGuid = null;
            using (MemoryStream _stream = new MemoryStream())
                using (TestBinaryWriter _buffer = new TestBinaryWriter(_stream))
                {
                    Assert.IsNotNull(_buffer);
                    Variant _variant = new Variant {
                        UATypeInfo = new UATypeInfo(BuiltInType.Guid), Value = CommonDefinitions.TestGuid
                    };
                    _buffer.Write(_buffer, _variant);
                    _buffer.Close();
                    _EncodedVGuid = _stream.ToArray();
                }
            Assert.IsNotNull(_EncodedVGuid);
            Assert.AreEqual <int>(17, _EncodedVGuid.Length);
            ArraySegment <byte> _segment = new ArraySegment <byte>(_EncodedVGuid, 1, 16);

            Assert.AreEqual <byte>((byte)BuiltInType.Guid, _EncodedVGuid[0]);
            CollectionAssert.AreEqual(CommonDefinitions.TestGuid.ToByteArray(), _segment.ToList <byte>());
        }