示例#1
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);
        }
示例#2
0
        public void SdbAttributeConstraintTest()
        {
            const XsdAttributeUse AttributeUse      = XsdAttributeUse.Prohibited;
            const ushort          SimpleTypeIndex   = 53;
            const byte            FileFormatVersion = 32;

            var instance = new SdbAttributeConstraint(AttributeUse, SimpleTypeIndex, FileFormatVersion);

            Assert.Equal(AttributeUse, instance.AttributeUse);
            Assert.Equal(SimpleTypeIndex, instance.SimpleTypeIndex);
            Assert.Equal(FileFormatVersion, instance.FileFormatVersion);

            var bytes        = VerifyBytes(instance, new byte[] { 0x02, 0x35, 0x00, 0x20 });
            var deserialized = Assert.Single(Deserialize <SdbAttributeConstraint>(bytes));

            Assert.Equal(AttributeUse, deserialized.AttributeUse);
            Assert.Equal(SimpleTypeIndex, deserialized.SimpleTypeIndex);
            Assert.Equal(FileFormatVersion, deserialized.FileFormatVersion);

            Assert.Equal(instance, deserialized);
        }