예제 #1
0
        public void Set()
        {
            BitMapField bitmap = new BitMapField( 0, 1, 64);
            for ( int i = 0; i < firstFields.Length; i++) {
                bitmap.Set( firstFields[i], true);
            }
            byte[] bitmapBytes = bitmap.GetBytes();
            for ( int i = 0; i < firstBitmap.Length; i++) {
                Assert.IsTrue( bitmapBytes[i] == firstBitmap[i]);
            }

            bitmap = new BitMapField( 0, 22, 48);
            for ( int i = 0; i < secondFields.Length; i++) {
                bitmap.Set( secondFields[i], true);
            }
            bitmapBytes = ( byte[])bitmap.Value;
            for ( int i = 0; i < secondBitmap.Length; i++) {
                Assert.IsTrue( bitmapBytes[i] == secondBitmap[i]);
            }

            try {
                bitmap.Set( 49, true);
                Assert.Fail();
            } catch ( ArgumentOutOfRangeException e) {
                Assert.IsTrue( e.ParamName.Equals( "fieldNumber"));
            }
        }
        public void Parse()
        {
            ParserContext parserContext = new ParserContext(
                ParserContext.DefaultBufferSize);
            BitMapFieldFormatter bitmapFormatter = new BitMapFieldFormatter(
                0, 1, 64, HexadecimalBinaryEncoder.GetInstance());

            BitMapField bitmap = ( BitMapField)bitmapFormatter.Parse(
                ref parserContext);

            Assert.IsNull(bitmap);
            parserContext.Write("12082020");
            bitmap = ( BitMapField)bitmapFormatter.Parse(ref parserContext);
            Assert.IsTrue(parserContext.DataLength == 8);
            Assert.IsNull(bitmap);
            parserContext.Write("10CA118");
            bitmap = ( BitMapField)bitmapFormatter.Parse(ref parserContext);
            Assert.IsTrue(parserContext.DataLength == 15);
            Assert.IsNull(bitmap);
            parserContext.Write("3");
            bitmap = ( BitMapField)bitmapFormatter.Parse(ref parserContext);
            Assert.IsTrue(parserContext.DataLength == 0);
            Assert.IsNotNull(bitmap);

            byte[] referenceBitmap = { 0x12, 0x08, 0x20, 0x20, 0x10, 0xCA, 0x11, 0x83 };
            byte[] bitmapValue     = bitmap.GetBytes();

            for (int i = 0; i < bitmapValue.Length; i++)
            {
                Assert.IsTrue(bitmapValue[i] == referenceBitmap[i]);
            }
        }
예제 #3
0
        public void GetBytes()
        {
            BitMapField bitmap = new BitMapField( 0, 1, 64);
            for ( int i = 0; i < firstFields.Length; i++) {
                bitmap.Set( firstFields[i], true);
            }

            byte[] bytes = bitmap.GetBytes();

            Assert.IsTrue( bytes.Length == firstBitmap.Length);
            for ( int i = 0; i < bytes.Length; i++) {
                Assert.IsTrue( bytes[i] == firstBitmap[i]);
            }
        }
예제 #4
0
        public void TestClone()
        {
            BitMapField bitmap = new BitMapField( 0, 1, 64);
            for ( int i = 0; i < firstFields.Length; i++) {
                bitmap.Set( firstFields[i], true);
            }
            BitMapField clonedBitmap = ( BitMapField)( bitmap.Clone());

            Assert.IsTrue( bitmap.FieldNumber == clonedBitmap.FieldNumber);
            byte[] firstBitmapBytes = bitmap.GetBytes();
            byte[] clonedBitmapBytes = clonedBitmap.GetBytes();
            for ( int i = 0; i < firstBitmapBytes.Length; i++) {
                Assert.IsTrue( firstBitmapBytes[i] == clonedBitmapBytes[i]);
            }
        }
예제 #5
0
        public void Constructors()
        {
            BitMapField bitmap = new BitMapField( 0, 1, 64);
            Assert.IsTrue( bitmap.FieldNumber == 0);
            Assert.IsTrue( bitmap.LowerFieldNumber == 1);
            Assert.IsTrue( bitmap.UpperFieldNumber == 64);
            Assert.IsTrue( bitmap.GetBytes().Length == 8);
            byte[] bytes = ( byte[])bitmap.Value;
            for ( int i = 0; i < bytes.Length; i++) {
                Assert.IsTrue( bytes[i] == 0);
            }

            bitmap = new BitMapField( 0, 1, 64, firstBitmap);
            bytes = ( byte[])bitmap.Value;
            for ( int i = 0; i < firstBitmap.Length; i++) {
                Assert.IsTrue( bytes[i] == firstBitmap[i]);
            }

            bitmap = new BitMapField( 1, bitmap);
            Assert.IsTrue( bitmap.FieldNumber == 1);
            Assert.IsTrue( bitmap.LowerFieldNumber == 1);
            Assert.IsTrue( bitmap.UpperFieldNumber == 64);
            Assert.IsTrue( bitmap.GetBytes().Length == 8);
            bytes = ( byte[])bitmap.Value;
            for ( int i = 0; i < bytes.Length; i++) {
                Assert.IsTrue( bytes[i] == firstBitmap[i]);
            }

            bitmap = new BitMapField( 65, 129, 150);
            Assert.IsTrue( bitmap.FieldNumber == 65);
            Assert.IsTrue( bitmap.LowerFieldNumber == 129);
            Assert.IsTrue( bitmap.UpperFieldNumber == 150);
            Assert.IsTrue( bitmap.GetBytes().Length == 3);
            bytes = ( byte[])bitmap.Value;
            for ( int i = 0; i < bytes.Length; i++) {
                Assert.IsTrue( bytes[i] == 0);
            }

            bitmap = new BitMapField( 0, 30, 30);
            Assert.IsTrue( bitmap.FieldNumber == 0);
            Assert.IsTrue( bitmap.LowerFieldNumber == 30);
            Assert.IsTrue( bitmap.UpperFieldNumber == 30);
            Assert.IsTrue( bitmap.GetBytes().Length == 1);

            bitmap = new BitMapField( 0, 1, 65);
            Assert.IsTrue( bitmap.FieldNumber == 0);
            Assert.IsTrue( bitmap.LowerFieldNumber == 1);
            Assert.IsTrue( bitmap.UpperFieldNumber == 65);
            Assert.IsTrue( bitmap.GetBytes().Length == 9);

            try {
                bitmap = new BitMapField( 65, 150, 129);
                Assert.Fail();
            } catch ( ArgumentOutOfRangeException e) {
                Assert.IsTrue( e.ParamName.Equals( "lowerFieldNumber"));
            }

            try {
                bitmap = new BitMapField( 0, 1, 64, secondBitmap);
                Assert.Fail();
            } catch ( ArgumentException e) {
                Assert.IsTrue( e.ParamName.Equals( "value"));
            }
        }