public void SdbSchemaTypeTest() { const ushort ParticleIndex = 50; const ushort SimpleTypeIndex = 63; const ushort AttributesCount = 20; const ushort StartIndexOfAttributes = 10; var instance = new SdbSchemaType(ParticleIndex, SimpleTypeIndex, AttributesCount, StartIndexOfAttributes); Assert.Equal(ParticleIndex, instance.ParticleIndex); Assert.Equal(SimpleTypeIndex, instance.SimpleTypeIndex); Assert.Equal(AttributesCount, instance.AttributesCount); Assert.Equal(StartIndexOfAttributes, instance.StartIndexOfAttributes); var bytes = VerifyBytes(instance, new byte[] { 0x32, 0x00, 0x3F, 0x00, 0x14, 0x00, 0x0A, 0x00 }); var deserialized = Assert.Single(Deserialize <SdbSchemaType>(bytes)); Assert.Equal(ParticleIndex, deserialized.ParticleIndex); Assert.Equal(SimpleTypeIndex, deserialized.SimpleTypeIndex); Assert.Equal(AttributesCount, deserialized.AttributesCount); Assert.Equal(StartIndexOfAttributes, deserialized.StartIndexOfAttributes); Assert.Equal(instance, deserialized); }
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); }
/// <summary> /// Load the particle constraint from the specified data in binary database. /// </summary> /// <param name="sdbSchemaTpye">The data in binary database.</param> /// <returns>The particle constraint in ParticleConstraint.</returns> private ParticleConstraint BuildParticleConstraint(SdbSchemaType sdbSchemaTpye) { if (sdbSchemaTpye.IsCompositeType) { var particleConstraint = BuildParticleConstraint(sdbSchemaTpye.ParticleIndex); Debug.Assert(particleConstraint.ParticleType == ParticleType.All || particleConstraint.ParticleType == ParticleType.Any || particleConstraint.ParticleType == ParticleType.Choice || particleConstraint.ParticleType == ParticleType.Sequence || particleConstraint.ParticleType == ParticleType.Group); // <xsd:group ref="..." /> is valid under <xsd:complexType> Debug.Assert(particleConstraint.ElementId == SdbData.InvalidId); return(particleConstraint); } return(null); }
/// <summary> /// Load the attribute constraints and simple type constraint for attributes for the schema type. /// </summary> /// <param name="sdbSchemaTpye"></param> /// <returns></returns> private AttributeConstraint[] BuildAttributeConstraint(SdbSchemaType sdbSchemaTpye) { Debug.Assert(sdbSchemaTpye != null); if (sdbSchemaTpye.AttributesCount > 0) { int count = sdbSchemaTpye.AttributesCount; var attributeConstraints = new AttributeConstraint[count]; SdbIndex sdbIndex = sdbSchemaTpye.StartIndexOfAttributes; for (int i = 0; i < count; i++) { var sdbAttributeData = SdbAttributes[sdbIndex + i]; // then load the simple type constraint for this attribute var simpleTypeIndex = sdbAttributeData.SimpleTypeIndex; var simpleTypeConstraint = SimpleTypeRestrictions[simpleTypeIndex]; attributeConstraints[i] = new AttributeConstraint(sdbAttributeData.AttributeUse, simpleTypeConstraint, (FileFormatVersions)sdbAttributeData.FileFormatVersion); } return(attributeConstraints); } return(null); }