예제 #1
0
        /// <summary>
        /// Checks whether this ClassID is equal to another
        /// object.
        /// </summary>
        /// <param name="o">the object to compare this PropertySet with</param>
        /// <returns>true if the objects are equal, else
        /// false</returns>
        public override bool Equals(Object o)
        {
            if (o == null || !(o is ClassID))
            {
                return(false);
            }
            ClassID cid = (ClassID)o;

            if (bytes.Length != cid.bytes.Length)
            {
                return(false);
            }
            for (int i = 0; i < bytes.Length; i++)
            {
                if (bytes[i] != cid.bytes[i])
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
 public void TestEquals()
 {
     ClassID clsidTest1 = new ClassID(
           new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                   0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
         , 0
     );
     ClassID clsidTest2 = new ClassID(
           new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                   0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
         , 0
     );
     ClassID clsidTest3 = new ClassID(
           new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                   0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x11 }
         , 0
     );
     Assert.AreEqual(clsidTest1, clsidTest1);
     Assert.AreEqual(clsidTest1, clsidTest2);
     Assert.IsFalse(clsidTest1.Equals(clsidTest3));
     Assert.IsFalse(clsidTest1.Equals(null));
 }
예제 #3
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;
        }
예제 #4
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 / LittleEndianConsts.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     += LittleEndianConsts.SHORT_SIZE;
                }
                _name = new String(char_array, 0, name_length);
            }
            _next_child     = null;
            _previous_child = null;
        }
예제 #5
0
        public void TestWriteArrayStoreException()
        {
            ClassID clsidTest = new ClassID(
                  new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                          0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
                , 0
            );
            bool bExceptionOccurred = false;
            try
            {
                clsidTest.Write(new byte[15], 0);
            }
            catch (Exception)
            {
                bExceptionOccurred = true;
            }
            Assert.IsTrue(bExceptionOccurred);

            bExceptionOccurred = false;
            try
            {
                clsidTest.Write(new byte[16], 1);
            }
            catch (Exception)
            {
                bExceptionOccurred = true;
            }
            Assert.IsTrue(bExceptionOccurred);

            // These should work without throwing an Exception
            bExceptionOccurred = false;
            try
            {
                clsidTest.Write(new byte[16], 0);
                clsidTest.Write(new byte[17], 1);
            }
            catch (Exception)
            {
                bExceptionOccurred = true;
            }
            Assert.IsFalse(bExceptionOccurred);
        }
예제 #6
0
 public void TestClassID1()
 {
     ClassID clsidTest = new ClassID(
           new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                   0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
         , 0
     );
     Assert.AreEqual(clsidTest.ToString().ToUpper(),
                         "{04030201-0605-0807-090A-0B0C0D0E0F10}"
     );
 }