Exemplo n.º 1
0
        public void SdbParticleConstraintTest()
        {
            const ParticleType ParticleType       = ParticleType.AnyWithUri;
            const ushort       ElementTypeId      = 18;
            const ushort       MinOccurs          = 2;
            const int          MaxOccurs          = 60;
            const ushort       ChildrenCount      = 80;
            const ushort       ChildrenStartIndex = 132;

            var instance = new SdbParticleConstraint(ParticleType, ElementTypeId, MinOccurs, MaxOccurs, ChildrenCount, ChildrenStartIndex);

            Assert.Equal(ParticleType, instance.ParticleType);
            Assert.Equal(ElementTypeId, instance.ElementTypeId);
            Assert.Equal(MinOccurs, instance.MinOccurs);
            Assert.Equal(MaxOccurs, instance.MaxOccurs);
            Assert.Equal(ChildrenCount, instance.ChildrenCount);
            Assert.Equal(ChildrenStartIndex, instance.ChildrenStartIndex);

            var bytes = VerifyBytes(instance, new byte[] { 0x06, 0x12, 0x00, 0x02, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x50, 0x00, 0x84, 0x00 });

            var deserialized = Assert.Single(Deserialize <SdbParticleConstraint>(bytes));

            Assert.Equal(ParticleType, deserialized.ParticleType);
            Assert.Equal(ElementTypeId, deserialized.ElementTypeId);
            Assert.Equal(MinOccurs, deserialized.MinOccurs);
            Assert.Equal(MaxOccurs, deserialized.MaxOccurs);
            Assert.Equal(ChildrenCount, deserialized.ChildrenCount);
            Assert.Equal(ChildrenStartIndex, deserialized.ChildrenStartIndex);

            Assert.Equal(instance, deserialized);
        }
Exemplo n.º 2
0
        public void SdbDataHeadTest()
        {
            const FileFormatVersions FileFormat = FileFormatVersions.Office2010;
            var classIds                = new SdbClassIdToSchemaTypeIndex[5];
            var schemaTypes             = new SdbSchemaType[8];
            var particleConstraints     = new SdbParticleConstraint[2];
            var particleChildrenIndexes = new SdbParticleChildrenIndex[11];
            var attributes              = new SdbAttributeConstraint[4];

            var instance = new SdbDataHead(
                FileFormat,
                classIds,
                schemaTypes,
                particleConstraints,
                particleChildrenIndexes,
                attributes);

            Assert.Equal(FileFormat, instance.FileFormat);

            Assert.Equal(SdbSpan.Create(instance.ClassIds.Offset, classIds), instance.ClassIds);
            Assert.Equal(instance.ClassIds.End, instance.SchemaType.Offset);

            Assert.Equal(SdbSpan.Create(instance.SchemaType.Offset, schemaTypes), instance.SchemaType);
            Assert.Equal(instance.SchemaType.End, instance.Particles.Offset);

            Assert.Equal(SdbSpan.Create(instance.Particles.Offset, particleConstraints), instance.Particles);
            Assert.Equal(instance.Particles.End, instance.ParticleChildren.Offset);

            Assert.Equal(SdbSpan.Create(instance.ParticleChildren.Offset, particleChildrenIndexes), instance.ParticleChildren);
            Assert.Equal(instance.ParticleChildren.End, instance.Attributes.Offset);

            Assert.Equal(SdbSpan.Create(instance.Attributes.Offset, attributes), instance.Attributes);
            Assert.Equal(instance.Attributes.End, instance.End);

            var expected = new byte[]
            {
                0xB7, 0x55, 0xDD, 0x06, 0x4D, 0xEF, 0xEE, 0x46, 0xA6, 0x18, 0x04, 0x2A, 0xF4,
                0xC3, 0x90, 0x4E, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x05, 0x00,
                0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00,
                0x00, 0x08, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
                0x0D, 0x00, 0x00, 0x00, 0xBE, 0x00, 0x00, 0x00, 0x0B, 0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0xD4, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00,
                0x00, 0x00,
            };

            var bytes = VerifyBytes(instance, expected);

            var deserialized = Assert.Single(Deserialize <SdbDataHead>(bytes));

            Assert.Equal(instance, deserialized);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load the particle constraint from the specified data in binary database.
        /// </summary>
        /// <param name="particleIndex">The index of the particle constraint data in the binary database.</param>
        /// <returns>The particle constraint in ParticleConstraint.</returns>
        private ParticleConstraint BuildParticleConstraint(ushort particleIndex)
        {
            Debug.Assert(particleIndex >= 0);
            Debug.Assert(particleIndex < Particles.Length);

            SdbParticleConstraint sdbParticleConstraint = Particles[particleIndex];
            var particleConstraint = ParticleConstraint.CreateParticleConstraint(sdbParticleConstraint.ParticleType);

            particleConstraint.ParticleType = sdbParticleConstraint.ParticleType;
            particleConstraint.MaxOccurs    = sdbParticleConstraint.MaxOccurs;
            particleConstraint.MinOccurs    = sdbParticleConstraint.MinOccurs;
            particleConstraint.ElementId    = sdbParticleConstraint.ElementTypeId;

            if (sdbParticleConstraint.ChildrenCount > 0)
            {
                Debug.Assert(sdbParticleConstraint.ParticleType == ParticleType.All ||
                             sdbParticleConstraint.ParticleType == ParticleType.Choice ||
                             sdbParticleConstraint.ParticleType == ParticleType.Group ||
                             sdbParticleConstraint.ParticleType == ParticleType.Sequence);
                particleConstraint.ChildrenParticles = new ParticleConstraint[sdbParticleConstraint.ChildrenCount];
                for (ushort i = 0; i < sdbParticleConstraint.ChildrenCount; i++)
                {
                    ushort childIndex = ParticleIndexes[(ushort)(sdbParticleConstraint.ChildrenStartIndex + i)].ParticleIndex;
                    particleConstraint.ChildrenParticles[i] = BuildParticleConstraint(childIndex);
                }
            }
            else if (sdbParticleConstraint.ParticleType == ParticleType.All ||
                     sdbParticleConstraint.ParticleType == ParticleType.Choice ||
                     sdbParticleConstraint.ParticleType == ParticleType.Group ||
                     sdbParticleConstraint.ParticleType == ParticleType.Sequence)
            {
                particleConstraint.ChildrenParticles = Cached.Array <ParticleConstraint>();
            }

            return(particleConstraint);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load the particle constraint from the specified data in binary database.
        /// </summary>
        /// <param name="particleIndex">The index of the particle constraint data in the binary database.</param>
        /// <returns>The particle constraint in ParticleConstraint.</returns>
        private ParticleConstraint BuildParticleConstraint(SdbIndex particleIndex)
        {
            Debug.Assert(particleIndex >= 0);
            Debug.Assert(particleIndex < SdbDataHead.ParticleCount);

            SdbParticleConstraint sdbParticleConstraint = SdbParticles[particleIndex];
            var particleConstraint = ParticleConstraint.CreateParticleConstraint(sdbParticleConstraint.ParticleType);

            particleConstraint.ParticleType = sdbParticleConstraint.ParticleType;
            particleConstraint.MaxOccurs    = sdbParticleConstraint.MaxOccurs;
            particleConstraint.MinOccurs    = sdbParticleConstraint.MinOccurs;
            particleConstraint.ElementId    = sdbParticleConstraint.ElementTypeId;

            if (sdbParticleConstraint.ChildrenCount > 0)
            {
                Debug.Assert(sdbParticleConstraint.ParticleType == ParticleType.All ||
                             sdbParticleConstraint.ParticleType == ParticleType.Choice ||
                             sdbParticleConstraint.ParticleType == ParticleType.Group ||
                             sdbParticleConstraint.ParticleType == ParticleType.Sequence);
                particleConstraint.ChildrenParticles = new ParticleConstraint[sdbParticleConstraint.ChildrenCount];
                for (SdbIndex i = 0; i < sdbParticleConstraint.ChildrenCount; i++)
                {
                    SdbIndex childIndex = SdbParticleIndexs[(SdbIndex)(sdbParticleConstraint.ChildrenStartIndex + i)].ParticleIndex;
                    particleConstraint.ChildrenParticles[i] = BuildParticleConstraint(childIndex);
                }
            }
            else if (sdbParticleConstraint.ParticleType == ParticleType.All ||
                     sdbParticleConstraint.ParticleType == ParticleType.Choice ||
                     sdbParticleConstraint.ParticleType == ParticleType.Group ||
                     sdbParticleConstraint.ParticleType == ParticleType.Sequence)
            {
                particleConstraint.ChildrenParticles = EmptyChildrenParticles;
            }

            return(particleConstraint);
        }