Exemple #1
0
        /**
         * Prepare to be written Leon
         */

        public void PreWrite()
        {
            List <Property> properties = new List <Property>(_properties.Count);

            for (int i = 0; i < _properties.Count; i++)
            {
                properties.Add(_properties[i]);
            }


            // give each property its index
            for (int k = 0; k < properties.Count; k++)
            {
                properties[k].Index = k;
            }

            // allocate the blocks for the property table
            _blocks = PropertyBlock.CreatePropertyBlockArray(_bigBigBlockSize, properties);

            // prepare each property for writing
            for (int k = 0; k < properties.Count; k++)
            {
                properties[k].PreWrite();
            }
        }
        /**
         * Prepare to be written
         */

        public void PreWrite()
        {
            Property[] array = new Property[this._properties.Count];
            this._properties.CopyTo(array, 0);

            Property[] properties = array;

            // give each property its index
            for (int k = 0; k < properties.Length; k++)
            {
                properties[k].Index = k;
            }

            // allocate the blocks for the property table
            _blocks = PropertyBlock.CreatePropertyBlockArray(_properties);

            // prepare each property for writing
            for (int k = 0; k < properties.Length; k++)
            {
                properties[k].PreWrite();
            }
        }
        public void TestCreatePropertyBlocks()
        {
            // Test with 0 properties
            ArrayList properties = new ArrayList();

            BlockWritable[] blocks =
                PropertyBlock.CreatePropertyBlockArray(properties);

            Assert.AreEqual(0, blocks.Length);

            // Test with 1 property
            properties.Add(new LocalProperty("Root Entry"));
            blocks = PropertyBlock.CreatePropertyBlockArray(properties);
            Assert.AreEqual(1, blocks.Length);
            byte[] testblock = new byte[512];

            for (int j = 0; j < 4; j++)
            {
                SetDefaultBlock(testblock, j);
            }
            testblock[0x0000] = (byte)'R';
            testblock[0x0002] = (byte)'o';
            testblock[0x0004] = (byte)'o';
            testblock[0x0006] = (byte)'t';
            testblock[0x0008] = (byte)' ';
            testblock[0x000A] = (byte)'E';
            testblock[0x000C] = (byte)'n';
            testblock[0x000E] = (byte)'t';
            testblock[0x0010] = (byte)'r';
            testblock[0x0012] = (byte)'y';
            testblock[0x0040] = (byte)22;
            verifyCorrect(blocks, testblock);

            // Test with 3 properties
            properties.Add(new LocalProperty("workbook"));
            properties.Add(new LocalProperty("summary"));
            blocks = PropertyBlock.CreatePropertyBlockArray(properties);
            Assert.AreEqual(1, blocks.Length);
            testblock[0x0080] = (byte)'w';
            testblock[0x0082] = (byte)'o';
            testblock[0x0084] = (byte)'r';
            testblock[0x0086] = (byte)'k';
            testblock[0x0088] = (byte)'b';
            testblock[0x008A] = (byte)'o';
            testblock[0x008C] = (byte)'o';
            testblock[0x008E] = (byte)'k';
            testblock[0x00C0] = (byte)18;
            testblock[0x0100] = (byte)'s';
            testblock[0x0102] = (byte)'u';
            testblock[0x0104] = (byte)'m';
            testblock[0x0106] = (byte)'m';
            testblock[0x0108] = (byte)'a';
            testblock[0x010A] = (byte)'r';
            testblock[0x010C] = (byte)'y';
            testblock[0x0140] = (byte)16;
            verifyCorrect(blocks, testblock);

            // Test with 4 properties
            properties.Add(new LocalProperty("wintery"));
            blocks = PropertyBlock.CreatePropertyBlockArray(properties);
            Assert.AreEqual(1, blocks.Length);
            testblock[0x0180] = (byte)'w';
            testblock[0x0182] = (byte)'i';
            testblock[0x0184] = (byte)'n';
            testblock[0x0186] = (byte)'t';
            testblock[0x0188] = (byte)'e';
            testblock[0x018A] = (byte)'r';
            testblock[0x018C] = (byte)'y';
            testblock[0x01C0] = (byte)16;
            verifyCorrect(blocks, testblock);

            // Test with 5 properties
            properties.Add(new LocalProperty("foo"));
            blocks = PropertyBlock.CreatePropertyBlockArray(properties);
            Assert.AreEqual(2, blocks.Length);
            testblock = new byte[1024];
            for (int j = 0; j < 8; j++)
            {
                SetDefaultBlock(testblock, j);
            }
            testblock[0x0000] = (byte)'R';
            testblock[0x0002] = (byte)'o';
            testblock[0x0004] = (byte)'o';
            testblock[0x0006] = (byte)'t';
            testblock[0x0008] = (byte)' ';
            testblock[0x000A] = (byte)'E';
            testblock[0x000C] = (byte)'n';
            testblock[0x000E] = (byte)'t';
            testblock[0x0010] = (byte)'r';
            testblock[0x0012] = (byte)'y';
            testblock[0x0040] = (byte)22;
            testblock[0x0080] = (byte)'w';
            testblock[0x0082] = (byte)'o';
            testblock[0x0084] = (byte)'r';
            testblock[0x0086] = (byte)'k';
            testblock[0x0088] = (byte)'b';
            testblock[0x008A] = (byte)'o';
            testblock[0x008C] = (byte)'o';
            testblock[0x008E] = (byte)'k';
            testblock[0x00C0] = (byte)18;
            testblock[0x0100] = (byte)'s';
            testblock[0x0102] = (byte)'u';
            testblock[0x0104] = (byte)'m';
            testblock[0x0106] = (byte)'m';
            testblock[0x0108] = (byte)'a';
            testblock[0x010A] = (byte)'r';
            testblock[0x010C] = (byte)'y';
            testblock[0x0140] = (byte)16;
            testblock[0x0180] = (byte)'w';
            testblock[0x0182] = (byte)'i';
            testblock[0x0184] = (byte)'n';
            testblock[0x0186] = (byte)'t';
            testblock[0x0188] = (byte)'e';
            testblock[0x018A] = (byte)'r';
            testblock[0x018C] = (byte)'y';
            testblock[0x01C0] = (byte)16;
            testblock[0x0200] = (byte)'f';
            testblock[0x0202] = (byte)'o';
            testblock[0x0204] = (byte)'o';
            testblock[0x0240] = (byte)8;
            verifyCorrect(blocks, testblock);
        }