Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Property"/> class.
        /// </summary>
        protected Property()
        {
            _raw_data = new byte[POIFSConstants.PROPERTY_SIZE];
            for (int i = 0; i < this._raw_data.Length; i++)
            {
                this._raw_data[i] = _default_fill;
            }
            _name_size         = new ShortField(_name_size_offset);
            _property_type     =
                new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET);
            _node_color        = new ByteField(_node_color_offset);
            _previous_property = new IntegerField(_previous_property_offset,
                                                  _NO_INDEX, _raw_data);
            _next_property     = new IntegerField(_next_property_offset,
                                                  _NO_INDEX, _raw_data);
            _child_property    = new IntegerField(_child_property_offset,
                                                  _NO_INDEX, _raw_data);
            _storage_clsid     = new ClassID(_raw_data,_storage_clsid_offset);
            _user_flags        = new IntegerField(_user_flags_offset, 0, _raw_data);
            _seconds_1         = new IntegerField(_seconds_1_offset, 0,
                                                  _raw_data);
            _days_1            = new IntegerField(_days_1_offset, 0, _raw_data);
            _seconds_2         = new IntegerField(_seconds_2_offset, 0,
                                                  _raw_data);
            _days_2            = new IntegerField(_days_2_offset, 0, _raw_data);
            _start_block       = new IntegerField(_start_block_offset);
            _size              = new IntegerField(_size_offset, 0, _raw_data);
            _index             = _NO_INDEX;

            this.Name="";
            this.NextChild=null;
            this.PreviousChild=null;
        }
Пример #2
0
        /// <summary>
        /// Constructor from byte data
        /// </summary>
        /// <param name="index">index number</param>
        /// <param name="array">byte data</param>
        /// <param name="offset">offset into byte data</param>
        protected Property(int index, byte [] array, int offset)
        {
            _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ];
            System.Array.Copy(array, offset, _raw_data, 0,
                             POIFSConstants.PROPERTY_SIZE);
            _name_size         = new ShortField(_name_size_offset, _raw_data);
            _property_type     =
                new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data);
            _node_color        = new ByteField(_node_color_offset, _raw_data);
            _previous_property = new IntegerField(_previous_property_offset,
                                                  _raw_data);
            _next_property     = new IntegerField(_next_property_offset,
                                                  _raw_data);
            _child_property    = new IntegerField(_child_property_offset,
                                                  _raw_data);
            _storage_clsid     = new ClassID(_raw_data,_storage_clsid_offset);
            _user_flags        = new IntegerField(_user_flags_offset, 0, _raw_data);
            _seconds_1         = new IntegerField(_seconds_1_offset, _raw_data);
            _days_1            = new IntegerField(_days_1_offset, _raw_data);
            _seconds_2         = new IntegerField(_seconds_2_offset, _raw_data);
            _days_2            = new IntegerField(_days_2_offset, _raw_data);
            _start_block       = new IntegerField(_start_block_offset, _raw_data);
            _size              = new IntegerField(_size_offset, _raw_data);
            _index             = index;
            int name_length = (_name_size.Value / LittleEndianConstants.SHORT_SIZE)
                              - 1;

            if (name_length < 1)
            {
                _name = "";
            }
            else
            {
                char[] char_array  = new char[ name_length ];
                int    name_offset = 0;

                for (int j = 0; j < name_length; j++)
                {
                    char_array[ j ] = ( char ) new ShortField(name_offset,
                                                              _raw_data).Value;
                    name_offset     += LittleEndianConstants.SHORT_SIZE;
                }
                _name = new String(char_array, 0, name_length);
            }
            _next_child     = null;
            _previous_child = null;
        }
Пример #3
0
        public void TestConstructors()
        {
            try
            {
                new ShortField(-1);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
            ShortField field = new ShortField(2);

            Assert.AreEqual(0, field.Value);
            try
            {
                new ShortField(-1, ( short ) 1);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
            field = new ShortField(2, ( short ) 0x1234);
            Assert.AreEqual(0x1234, field.Value);
            byte[] array = new byte[ 4 ];

            try
            {
                new ShortField(-1, ( short ) 1, ref array);
                Assert.Fail("Should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
            field = new ShortField(2, ( short ) 0x1234, ref array);
            Assert.AreEqual(( short ) 0x1234, field.Value);
            Assert.AreEqual(( byte ) 0x34, array[ 2 ]);
            Assert.AreEqual(( byte ) 0x12, array[ 3 ]);
            array = new byte[ 3 ];
            try
            {
                new ShortField(2, ( short ) 5, ref array);
                Assert.Fail("should have gotten IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
            for (int j = 0; j < _test_array.Length; j++)
            {
                array = new byte[ 2 ];
                new ShortField(0, _test_array[ j ], ref array);
                Assert.AreEqual(_test_array[ j ], new ShortField(0, array).Value);
            }
        }
Пример #4
0
        public void TestWriteToBytes()
        {
            ShortField field = new ShortField(0);
            byte[] array = new byte[2];

            for (int j = 0; j < _test_array.Length; j++)
            {
                field.Value = _test_array[j];
                field.WriteToBytes(array);
                short val = (short)(array[1] << 8);

                val &= unchecked((short)0xFF00);
                val += (short)(array[0] & 0x00FF);
                Assert.AreEqual(_test_array[j], val, "testing ");
            }
        }
Пример #5
0
        public void TestSet()
        {
            ShortField field = new ShortField(0);
            byte[]     array = new byte[ 2 ];

            for (int j = 0; j < _test_array.Length; j++)
            {
                field.Value=_test_array[ j ];
                Assert.AreEqual(_test_array[j], field.Value, "testing _1 " + j.ToString());
                field = new ShortField(0);
                field.Set(_test_array[ j ], ref array);
                Assert.AreEqual(_test_array[ j ], field.Value,
                    "testing _2 ");
                Assert.AreEqual(( byte ) (_test_array[ j ] % 256), array[ 0 ],
                    "testing _3.0 " + _test_array[j]);
                Assert.AreEqual(( byte ) ((_test_array[ j ] >> 8) % 256),
                             array[1], "testing _3.1 " + _test_array[j]);
            }
        }
Пример #6
0
        public void TestReadFromStream()
        {
            ShortField field  = new ShortField(0);
            byte[]     buffer = new byte[ _test_array.Length * 2 ];

            for (int j = 0; j < _test_array.Length; j++)
            {
                buffer[ (j * 2) + 0 ] = ( byte ) (_test_array[ j ] % 256);
                buffer[ (j * 2) + 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256);
            }
            MemoryStream stream = new MemoryStream(buffer);

            for (int j = 0; j < buffer.Length / 2; j++)
            {
                field.ReadFromStream(stream);
                Assert.AreEqual(_test_array[ j ], field.Value,"Testing " + j);
            }
        }
Пример #7
0
        public void TestReadFromBytes()
        {
            ShortField field = new ShortField(1);
            byte[]     array = new byte[ 2 ];

            try
            {
                field.ReadFromBytes(array);
                Assert.Fail("should have caught IndexOutOfRangeException");
            }
            catch (IndexOutOfRangeException)
            {

                // as expected
            }
            field = new ShortField(0);
            for (int j = 0; j < _test_array.Length; j++)
            {
                array[ 0 ] = ( byte ) (_test_array[ j ] % 256);
                array[ 1 ] = ( byte ) ((_test_array[ j ] >> 8) % 256);
                field.ReadFromBytes(array);
                Assert.AreEqual(_test_array[j], field.Value, "testing " + j);
            }
        }