Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the SchemaValidator. 
        /// </summary>
        /// <param name="fileFormat">The target Open XML format.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the "fileFormat" parameter is not FileFormat.Office2007, FileFormat.Office2010 or FileFormat.O15.</exception>
        internal SchemaValidator(FileFormatVersions fileFormat)
        {
            if (fileFormat == FileFormatVersions.Office2007)
            {
                this._sdbSchemaDatas = SdbSchemaDatas.GetOffice2007SchemaDatas();
            }
            else if(fileFormat == FileFormatVersions.Office2010)
            {
                this._sdbSchemaDatas = SdbSchemaDatas.GetOffice2010SchemaDatas();
            }
            else if (fileFormat == FileFormatVersions.Office2013)
            {
                this._sdbSchemaDatas = SdbSchemaDatas.GetOffice2013SchemaDatas();
            }
            else
            {
                string message = String.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                                    ExceptionMessages.FileFormatNotSupported,
                                                    fileFormat);
                throw new ArgumentOutOfRangeException("fileFormat", message);
            }

            this._schemaTypeValidator = new SchemaTypeValidator(this._sdbSchemaDatas);
#if DEBUG
            this._fileFormat = fileFormat;
#endif
        }
Ejemplo n.º 2
0
        private void ParagraphConstraintTest(SdbSchemaDatas actual)
        {

            //<xsd:complexType name="CT_P">
            //  <xsd:sequence>
            //    <xsd:element name="pPr" type="CT_PPr" minOccurs="0" />
            //    <xsd:group ref="EG_PContent" minOccurs="0" maxOccurs="unbounded" />
            //  </xsd:sequence>
            //  <xsd:attribute name="rsidRPr" type="ST_LongHexNumber" />
            //  <xsd:attribute name="rsidR" type="ST_LongHexNumber" />
            //  <xsd:attribute name="rsidDel" type="ST_LongHexNumber" />
            //  <xsd:attribute name="rsidP" type="ST_LongHexNumber" />
            //  <xsd:attribute name="rsidRDefault" type="ST_LongHexNumber" />
            //</xsd:complexType>
            var paragraph = new Paragraph();

            var paragraphData = actual.GetSchemaTypeData(paragraph);
            Assert.Equal(paragraph.ElementTypeId, paragraphData.OpenXmlTypeId);
            Assert.True(paragraphData.HasAttributeConstraints);
            Assert.Equal(8, paragraphData.AttributeConstraintsCount);
            Assert.Null(paragraphData.SimpleTypeConstraint);
            Assert.True(paragraphData.IsCompositeType);
            Assert.False(paragraphData.IsSimpleContent);

            var particle = paragraphData.ParticleConstraint;
            Assert.Equal(ParticleType.Sequence, particle.ParticleType);
            Assert.Equal(1, particle.MinOccurs);
            Assert.Equal(1, particle.MaxOccurs);
            Assert.Equal(2, particle.ChildrenParticles.Length);
            Assert.False(particle.UnboundedMaxOccurs);
            Assert.False(particle.IsSimple());
            {
                // the first element of paragraph is pPr
                var elementParticle = paragraphData.ParticleConstraint.ChildrenParticles[0] as ElementParticle;
                Assert.NotNull(elementParticle);
                Assert.Equal(ParticleType.Element, elementParticle.ParticleType);
                Assert.Equal(0, elementParticle.MinOccurs);
                Assert.Equal(1, elementParticle.MaxOccurs);
                Assert.Equal((new ParagraphProperties()).ElementTypeId, elementParticle.ElementId);
                Assert.Null(elementParticle.ChildrenParticles);
                Assert.False(elementParticle.UnboundedMaxOccurs);

                // the second child of paragraph is a group EG_PContent
                particle = paragraphData.ParticleConstraint.ChildrenParticles[1];
                Assert.Equal(ParticleType.Group, particle.ParticleType);
                Assert.Equal(0, particle.MinOccurs);
                Assert.True(particle.UnboundedMaxOccurs);
                Assert.Equal(1, particle.ChildrenParticles.Length);
                Assert.False(particle.IsSimple());
            }


        }
Ejemplo n.º 3
0
        private void DocumentConstraintTest(SdbSchemaDatas actual)
        {
            ElementParticle elementParticle;
            // CT_Document 
            //<xsd:complexType name="CT_DocumentBase">
            //  <xsd:sequence>
            //    <xsd:element name="background" type="CT_Background" minOccurs="0"/>
            //  </xsd:sequence>
            //</xsd:complexType>
            //<xsd:complexType name="CT_Document">
            //  <xsd:complexContent>
            //    <xsd:extension base="CT_DocumentBase">
            //      <xsd:sequence>
            //        <xsd:element name="body" type="CT_Body" minOccurs="0" maxOccurs="1"/>
            //      </xsd:sequence>
            //      <xsd:attribute name="conformance" type="ST_DocumentConformance" />
            //    </xsd:extension>
            //  </xsd:complexContent>
            //</xsd:complexType>  
            var document = new Document();
            var body = new Body();
            var documentData = actual.GetSchemaTypeData(document.ElementTypeId);
            Assert.Equal(document.ElementTypeId, documentData.OpenXmlTypeId);
            Assert.True(documentData.HasAttributeConstraints);
            Assert.Null(documentData.SimpleTypeConstraint);
            Assert.True(documentData.IsCompositeType);
            Assert.False(documentData.IsSimpleContent);

            var particle = documentData.ParticleConstraint;
            Assert.Equal(ParticleType.Sequence, particle.ParticleType);
            Assert.Equal(1, particle.MinOccurs);
            Assert.Equal(1, particle.MaxOccurs);
            Assert.Equal(2, particle.ChildrenParticles.Length);
            Assert.False(particle.UnboundedMaxOccurs);
            Assert.False(particle.IsSimple());

            {
                // the sequence of CT_DocumentBase
                particle = documentData.ParticleConstraint.ChildrenParticles[0];
                Assert.Equal(ParticleType.Sequence, particle.ParticleType);
                Assert.Equal(1, particle.MinOccurs);
                Assert.Equal(1, particle.MaxOccurs);
                Assert.Equal(1, particle.ChildrenParticles.Length);
                Assert.False(particle.UnboundedMaxOccurs);
                Assert.True(particle.IsSimple());

                {
                    // the element <w:background>
                    elementParticle = particle.ChildrenParticles[0] as ElementParticle;
                    Assert.NotNull(elementParticle);
                    Assert.Equal(ParticleType.Element, elementParticle.ParticleType);
                    Assert.Equal(0, elementParticle.MinOccurs);
                    Assert.Equal(1, elementParticle.MaxOccurs);
                    Assert.Equal((new DocumentBackground()).ElementTypeId, elementParticle.ElementId);
                    Assert.Null(elementParticle.ChildrenParticles);
                    Assert.False(elementParticle.UnboundedMaxOccurs);
                }

                // the sequence of CT_Document
                particle = documentData.ParticleConstraint.ChildrenParticles[1];
                Assert.Equal(ParticleType.Sequence, particle.ParticleType);
                Assert.Equal(1, particle.MinOccurs);
                Assert.Equal(1, particle.MaxOccurs);
                Assert.Equal(1, particle.ChildrenParticles.Length);
                Assert.False(particle.UnboundedMaxOccurs);
                Assert.True(particle.IsSimple());

                {
                    // the element <w:body>
                    elementParticle = particle.ChildrenParticles[0] as ElementParticle;
                    Assert.NotNull(elementParticle);
                    Assert.Equal(ParticleType.Element, elementParticle.ParticleType);
                    Assert.Equal(0, elementParticle.MinOccurs);
                    Assert.Equal(1, elementParticle.MaxOccurs);
                    Assert.Equal(body.ElementTypeId, elementParticle.ElementId);
                    Assert.Null(elementParticle.ChildrenParticles);
                    Assert.False(elementParticle.UnboundedMaxOccurs);
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the SchemaTypeValidator.
 /// </summary>
 /// <param name="sdbSchemaDatas"></param>
 internal SchemaTypeValidator(SdbSchemaDatas sdbSchemaDatas)
 {
     this._sdbSchemaDatas = sdbSchemaDatas;
 }
        private void TestSimpleSequence(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;

            //<xsd:complexType name="CT_FFDDList">
            //  <xsd:sequence>
            //    <xsd:element name="result" type="CT_DecimalNumber" minOccurs="0">
            //    <xsd:element name="default" type="CT_DecimalNumber" minOccurs="0">
            //    <xsd:element name="listEntry" type="CT_String" minOccurs="0" maxOccurs="unbounded">
            //  </xsd:sequence>
            //</xsd:complexType>
            DropDownListFormField ddList = new DropDownListFormField();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(ddList).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as SequenceParticleValidator;

            validationContext.Element = ddList;

            // ***** good case ******
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ddList.AppendChild(new DropDownListSelection());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ddList.AppendChild(new DefaultDropDownListItemIndex());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ddList.AppendChild(new ListEntryFormField());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ddList.AppendChild(new ListEntryFormField());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******
            ddList = new DropDownListFormField();
            validationContext.Element = ddList;
            var expected = ddList;

            // invalid child
            OpenXmlElement errorChild = ddList.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":result"));

            actual.Clear();
            // 2nd child is invalid
            ddList.PrependChild(new DropDownListSelection());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // the sequence of the first 2 children are wrong
            errorChild = ddList.FirstChild;
            ddList.PrependChild(new DefaultDropDownListItemIndex());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // 1st and 2nd are same type, maxOccurs error
            errorChild = ddList.FirstChild;
            ddList.PrependChild(new DefaultDropDownListItemIndex());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // the 2nd and 3rd are same type, maxOccurs error
            ddList.PrependChild(new DropDownListSelection());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // expectedNode are now the 4th, the first 3 are OK.
            ddList.InsertAfter(new ListEntryFormField(), errorChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
        }
        private void ValidatePpr(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            ParagraphProperties pPr = new ParagraphProperties();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(pPr).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ParticleValidator;
            validationContext.Element = pPr;
            var expected = pPr;

              //<xsd:complexType name="CT_PPr">
              //  <xsd:complexContent>
              //    <xsd:extension base="CT_PPrBase">
              //      <xsd:sequence>
              //        <xsd:element name="rPr" type="CT_ParaRPr" minOccurs="0">
              //        <xsd:element name="sectPr" type="CT_SectPr" minOccurs="0">
              //        <xsd:element name="pPrChange" type="CT_PPrChange" minOccurs="0">
              //      </xsd:sequence>
              //    </xsd:extension>
              //  </xsd:complexContent>
              //</xsd:complexType>

              //<xsd:complexType name="CT_PPrBase">
              //  <xsd:sequence>
              //    <xsd:element name="pStyle" type="CT_String" minOccurs="0">
              //    <xsd:element name="keepNext" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="keepLines" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="pageBreakBefore" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="framePr" type="CT_FramePr" minOccurs="0">
              //    <xsd:element name="widowControl" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="numPr" type="CT_NumPr" minOccurs="0">
              //    <xsd:element name="suppressLineNumbers" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="pBdr" type="CT_PBdr" minOccurs="0">
              //    <xsd:element name="shd" type="CT_Shd" minOccurs="0">
              //    <xsd:element name="tabs" type="CT_Tabs" minOccurs="0">
              //    <xsd:element name="suppressAutoHyphens" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="kinsoku" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="wordWrap" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="overflowPunct" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="topLinePunct" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="autoSpaceDE" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="autoSpaceDN" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="bidi" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="adjustRightInd" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="snapToGrid" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="spacing" type="CT_Spacing" minOccurs="0">
              //    <xsd:element name="ind" type="CT_Ind" minOccurs="0">
              //    <xsd:element name="contextualSpacing" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="mirrorIndents" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="suppressOverlap" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="jc" type="CT_Jc" minOccurs="0">
              //    <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0">
              //    <xsd:element name="textAlignment" type="CT_TextAlignment" minOccurs="0">
              //    <xsd:element name="textboxTightWrap" type="CT_TextboxTightWrap" minOccurs="0">
              //    <xsd:element name="outlineLvl" type="CT_DecimalNumber" minOccurs="0">
              //    <xsd:element name="divId" type="CT_DecimalNumber" minOccurs="0">
              //    <xsd:element name="cnfStyle" type="CT_Cnf" minOccurs="0" maxOccurs="1">
              //  </xsd:sequence>
              //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new KeepLines());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new Tabs());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new Kinsoku());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new OutlineLevel());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new ConditionalFormatStyle());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new ParagraphMarkRunProperties());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            pPr.AppendChild(new ParagraphPropertiesChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // SectionProperties dup error
            errorChild = pPr.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            pPr.RemoveChild(errorChild);

            actual.Clear();
            // SectionProperties order wrong
            errorChild = pPr.FirstChild;
            pPr.PrependChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            pPr.RemoveChild(pPr.FirstChild);

        }
        private void ValidateBody(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            Body body = new Body();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(body).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ParticleValidator;
            validationContext.Element = body;
            var expected = body;

              //<xsd:complexType name="CT_Body">
              //  <xsd:sequence>
              //    <xsd:group ref="EG_BlockLevelElts" minOccurs="0" maxOccurs="unbounded" />
              //    <xsd:element name="sectPr" minOccurs="0" maxOccurs="1" type="CT_SectPr">
              //  </xsd:sequence>
              //</xsd:complexType>

              //<xs:group name="EG_BlockLevelEltsBase">
              //  <xs:choice>
              //    <xs:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"></xs:element>
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_BlockLevelElts">
              //  <xs:choice>
              //    <xs:group ref="EG_BlockLevelEltsBase" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" />
              //  </xs:choice>
              //</xs:group>
      
              //<xsd:group name="EG_BlockLevelChunkElts">
              //  <xsd:choice>
              //    <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded" />
              //  </xsd:choice>
              //</xsd:group>

              //<xs:group name="EG_ContentBlockContent">
              //  <xs:choice>
              //    <xs:group ref="EG_ContentBlockContentBase" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:group ref="EG_RunLevelElts" minOccurs="0" maxOccurs="unbounded" />
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_ContentBlockContentBase">
              //  <xs:choice>
              //    <xs:element name="customXml" type="CT_CustomXmlBlock"></xs:element>
              //    <xs:element name="sdt" type="CT_SdtBlock"></xs:element>
              //    <xs:element name="p" type="CT_P" minOccurs="0" maxOccurs="unbounded"></xs:element>
              //    <xs:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="unbounded"></xs:element>
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_RunLevelElts">
              //  <xs:choice>
              //    <xs:group ref="EG_RunLevelEltsBase" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:group ref="EG_RangeMarkupElements" minOccurs="0" maxOccurs="unbounded"></xs:group>
              //    <xs:element name="ins" type="CT_RunTrackChange" minOccurs="0">
              //    <xs:element name="del" type="CT_RunTrackChange" minOccurs="0">
              //    <xs:element name="moveFrom" type="CT_RunTrackChange">
              //    <xs:element name="moveTo" type="CT_RunTrackChange">
              //    <xs:element name="contentPart" type="CT_ContentPart" minOccurs="0" maxOccurs="unbounded" ofapi:available="o14" />
              //    <xs:group ref="w14:EG_RunLevelConflicts" minOccurs="0" />
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_RunLevelEltsBase">
              //  <xs:choice>
              //    <xs:element name="proofErr" minOccurs="0" type="CT_ProofErr"></xs:element>
              //    <xs:element name="permStart" minOccurs="0" type="CT_PermStart"></xs:element>
              //    <xs:element name="permEnd" minOccurs="0" type="CT_Perm"></xs:element>
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_RangeMarkupElements">
              //  <xs:choice>
              //    <xs:group ref="EG_RangeMarkupElementsNoRev" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:group ref="EG_RangeMarkupElementsRev" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:element ref="w14:customXmlConflictInsRangeStart" minOccurs="0" />
              //    <xs:element ref="w14:customXmlConflictInsRangeEnd" minOccurs="0" />
              //    <xs:element ref="w14:customXmlConflictDelRangeStart" minOccurs="0" />
              //    <xs:element ref="w14:customXmlConflictDelRangeEnd" minOccurs="0" />
              //  </xs:choice>
              //</xs:group>

              //<xsd:group name="EG_MathContent">
              //  <xsd:choice>
              //    <xsd:element ref="m:oMathPara"></xsd:element>
              //    <xsd:element ref="m:oMath"></xsd:element>
              //  </xsd:choice>
              //</xsd:group>

            // ################ the above schema has been changed by EcmaD ##############

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            body.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new AltChunk());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // multiple AltChunk is ok
            body.PrependChild(new AltChunk());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.InsertAfter(new Paragraph(), body.FirstChild);
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRangeStart());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRun());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            //body.PrependChild(new DocumentFormat.OpenXml.Math.OfficeMath());
            //target.Validate(validationContext);
            //Assert.True(actual.Valid);

            //body.PrependChild(new DocumentFormat.OpenXml.Math.OfficeMath());
            //target.Validate(validationContext);
            //Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRun());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.PrependChild(new MoveFromRangeStart());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            body.InsertAfter(new Paragraph(), body.FirstChild);
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******
            // sectProperties can not be the first
            errorChild = body.FirstChild;
            body.PrependChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(body.FirstChild);

            actual.Clear();
            // can only have one sectProperties at last
            errorChild = body.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(errorChild);

            actual.Clear();
            // paragrap can be after sectProperties at last
            errorChild = body.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(errorChild);

            actual.Clear();
            // first is invalid
            errorChild = body.PrependChild(new Run());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":altChunk"));
            body.RemoveChild(errorChild);

            actual.Clear();
            // invalid child in middle
            errorChild = body.InsertBefore(new Run(), body.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            body.RemoveChild(errorChild);
        }
        private void TestSimpleAll(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            Properties properties         = new Properties();
            var        particleConstraint = sdbSchemaDatas.GetSchemaTypeData(properties).ParticleConstraint;
            var        target             = particleConstraint.ParticleValidator as AllParticleValidator;

            validationContext.Element = properties;
            var expected = properties;

            //<xsd:complexType name="CT_Properties">
            //  <xsd:all>
            //    <xsd:element name="Template" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Manager" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Company" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Pages" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Words" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Characters" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="PresentationFormat" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Lines" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Paragraphs" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Slides" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Notes" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="TotalTime" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="HiddenSlides" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="MMClips" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="ScaleCrop" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="HeadingPairs" minOccurs="0" maxOccurs="1" type="CT_VectorVariant">
            //    <xsd:element name="TitlesOfParts" minOccurs="0" maxOccurs="1" type="CT_VectorLpstr">
            //    <xsd:element name="LinksUpToDate" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="CharactersWithSpaces" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="SharedDoc" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="HyperlinkBase" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="HLinks" minOccurs="0" maxOccurs="1" type="CT_VectorVariant">
            //    <xsd:element name="HyperlinksChanged" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="DigSig" minOccurs="0" maxOccurs="1" type="CT_DigSigBlob">
            //    <xsd:element name="Application" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="AppVersion" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="DocSecurity" minOccurs="0" maxOccurs="1" type="xsd:int">
            //  </xsd:all>
            //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any one is ok
            properties.AppendChild(new Company());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            properties.AppendChild(new Template());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            properties.AppendChild(new DocumentSecurity());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            properties.AppendChild(new HyperlinkBase());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // first is invlaid
            errorChild = properties.PrependChild(new Properties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":Template", actual.Errors[0].Description);
            Assert.Contains(":DocSecurity", actual.Errors[0].Description);
            properties.RemoveChild(errorChild);

            actual.Clear();
            //invalid child in middle
            errorChild = properties.InsertBefore(new Properties(), properties.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.DoesNotContain(":Template", actual.Errors[0].Description);
            Assert.Contains(":AppVersion", actual.Errors[0].Description);
            properties.RemoveChild(errorChild);

            actual.Clear();
            // dup
            errorChild = properties.FirstChild;
            properties.PrependChild(new Company());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_AllElement", actual.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, actual.Errors[0].Description);
            properties.RemoveChild(errorChild);
        }
        private void TestSimpleAll2(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            ShapeLayout shapeLayout = new ShapeLayout();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(shapeLayout).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as AllParticleValidator;
            validationContext.Element = shapeLayout;
            var expected = shapeLayout;

            //<xsd:complexType name="CT_ShapeLayout">
            //  <xsd:all>
            //    <xsd:element name="idmap" type="CT_IdMap" minOccurs="0">
            //    <xsd:element name="regrouptable" type="CT_RegroupTable" minOccurs="0">
            //    <xsd:element name="rules" type="CT_Rules" minOccurs="0">
            //  </xsd:all>
            //  <xsd:attributeGroup ref="v:AG_Ext" />
            //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any one is ok
            shapeLayout.AppendChild(new RegroupTable());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            shapeLayout.AppendChild(new ShapeIdMap());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            shapeLayout.AppendChild(new Rules());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // first is invlaid
            errorChild = shapeLayout.PrependChild(new Paragraphs());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":idmap"));
            Assert.True(actual.Errors[0].Description.Contains(":rules"));
            shapeLayout.RemoveChild(errorChild);

            actual.Clear();
            //invalid child in middle
            errorChild = shapeLayout.InsertBefore(new Paragraphs(), shapeLayout.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rules"));
            shapeLayout.RemoveChild(errorChild);

            actual.Clear();
            // dup 
            errorChild = shapeLayout.FirstChild;
            shapeLayout.PrependChild(new RegroupTable());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_AllElement", actual.Errors[0].Id);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            shapeLayout.RemoveChild(errorChild);

        }
Ejemplo n.º 10
0
 static void Main(string[] args)
 {
     Write("Office2007Schema", SdbSchemaDatas.GetOffice2007SchemaDatas());
     Write("Office2010Schema", SdbSchemaDatas.GetOffice2010SchemaDatas());
     Write("Office2013Schema", SdbSchemaDatas.GetOffice2013SchemaDatas());
 }
Ejemplo n.º 11
0
        private void ValidateBlip(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            OpenXmlElement    errorChild;

            Drawing.Blip blip = new Drawing.Blip();
            var          particleConstraint = sdbSchemaDatas.GetSchemaTypeData(blip).ParticleConstraint;
            var          target             = particleConstraint.ParticleValidator as ParticleValidator;

            validationContext.Element = blip;
            var expected = blip;

            //<xsd:complexType name="CT_Blip">
            //  <xsd:sequence>
            //    <xsd:choice minOccurs="0" maxOccurs="unbounded">
            //      <xsd:element name="alphaBiLevel" type="CT_AlphaBiLevelEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="alphaCeiling" type="CT_AlphaCeilingEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaFloor" type="CT_AlphaFloorEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaInv" type="CT_AlphaInverseEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaMod" type="CT_AlphaModulateEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaModFix" type="CT_AlphaModulateFixedEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="alphaRepl" type="CT_AlphaReplaceEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="biLevel" type="CT_BiLevelEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="blur" type="CT_BlurEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="clrChange" type="CT_ColorChangeEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="clrRepl" type="CT_ColorReplaceEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="duotone" type="CT_DuotoneEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="fillOverlay" type="CT_FillOverlayEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="grayscl" type="CT_GrayscaleEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="hsl" type="CT_HSLEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="lum" type="CT_LuminanceEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="tint" type="CT_TintEffect" minOccurs="1" maxOccurs="1">
            //    </xsd:choice>
            //    <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"></xsd:element>
            //  </xsd:sequence>
            //  <xsd:attributeGroup ref="AG_Blob"></xsd:attributeGroup>
            //  <xsd:attribute name="cstate" type="ST_BlipCompression" use="optional" default="none">
            //</xsd:complexType>
            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            blip.AppendChild(new Drawing.LuminanceEffect());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            blip.AppendChild(new Drawing.LuminanceEffect());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            blip.AppendChild(new Drawing.AlphaBiLevel());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            blip.AppendChild(new Drawing.Blur());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            blip.AppendChild(new Drawing.BiLevel());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            blip.AppendChild(new Drawing.BlipExtensionList());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            // ***** error case ******
            // ExtensionList can not be the first
            errorChild = blip.FirstChild;
            blip.PrependChild(new Drawing.BlipExtensionList());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            blip.RemoveChild(blip.FirstChild);

            validationContext.Clear();
            // can only have one ExtensionList at last
            errorChild = blip.AppendChild(new Drawing.BlipExtensionList());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            blip.RemoveChild(errorChild);
        }
Ejemplo n.º 12
0
        private void ValidatePpr(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            OpenXmlElement    errorChild;

            ParagraphProperties pPr = new ParagraphProperties();
            var particleConstraint  = sdbSchemaDatas.GetSchemaTypeData(pPr).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ParticleValidator;

            validationContext.Element = pPr;
            var expected = pPr;

            //<xsd:complexType name="CT_PPr">
            //  <xsd:complexContent>
            //    <xsd:extension base="CT_PPrBase">
            //      <xsd:sequence>
            //        <xsd:element name="rPr" type="CT_ParaRPr" minOccurs="0">
            //        <xsd:element name="sectPr" type="CT_SectPr" minOccurs="0">
            //        <xsd:element name="pPrChange" type="CT_PPrChange" minOccurs="0">
            //      </xsd:sequence>
            //    </xsd:extension>
            //  </xsd:complexContent>
            //</xsd:complexType>

            //<xsd:complexType name="CT_PPrBase">
            //  <xsd:sequence>
            //    <xsd:element name="pStyle" type="CT_String" minOccurs="0">
            //    <xsd:element name="keepNext" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="keepLines" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="pageBreakBefore" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="framePr" type="CT_FramePr" minOccurs="0">
            //    <xsd:element name="widowControl" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="numPr" type="CT_NumPr" minOccurs="0">
            //    <xsd:element name="suppressLineNumbers" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="pBdr" type="CT_PBdr" minOccurs="0">
            //    <xsd:element name="shd" type="CT_Shd" minOccurs="0">
            //    <xsd:element name="tabs" type="CT_Tabs" minOccurs="0">
            //    <xsd:element name="suppressAutoHyphens" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="kinsoku" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="wordWrap" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="overflowPunct" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="topLinePunct" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="autoSpaceDE" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="autoSpaceDN" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="bidi" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="adjustRightInd" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="snapToGrid" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="spacing" type="CT_Spacing" minOccurs="0">
            //    <xsd:element name="ind" type="CT_Ind" minOccurs="0">
            //    <xsd:element name="contextualSpacing" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="mirrorIndents" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="suppressOverlap" type="CT_OnOff" minOccurs="0">
            //    <xsd:element name="jc" type="CT_Jc" minOccurs="0">
            //    <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0">
            //    <xsd:element name="textAlignment" type="CT_TextAlignment" minOccurs="0">
            //    <xsd:element name="textboxTightWrap" type="CT_TextboxTightWrap" minOccurs="0">
            //    <xsd:element name="outlineLvl" type="CT_DecimalNumber" minOccurs="0">
            //    <xsd:element name="divId" type="CT_DecimalNumber" minOccurs="0">
            //    <xsd:element name="cnfStyle" type="CT_Cnf" minOccurs="0" maxOccurs="1">
            //  </xsd:sequence>
            //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new KeepLines());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new Tabs());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new Kinsoku());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new OutlineLevel());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new ConditionalFormatStyle());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new ParagraphMarkRunProperties());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            pPr.AppendChild(new ParagraphPropertiesChange());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            // ***** error case ******

            // SectionProperties dup error
            errorChild = pPr.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            pPr.RemoveChild(errorChild);

            validationContext.Clear();
            // SectionProperties order wrong
            errorChild = pPr.FirstChild;
            pPr.PrependChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            pPr.RemoveChild(pPr.FirstChild);
        }
Ejemplo n.º 13
0
        private void ValidateBody(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            OpenXmlElement    errorChild;

            Body body = new Body();
            var  particleConstraint = sdbSchemaDatas.GetSchemaTypeData(body).ParticleConstraint;
            var  target             = particleConstraint.ParticleValidator as ParticleValidator;

            validationContext.Element = body;
            var expected = body;

            //<xsd:complexType name="CT_Body">
            //  <xsd:sequence>
            //    <xsd:group ref="EG_BlockLevelElts" minOccurs="0" maxOccurs="unbounded" />
            //    <xsd:element name="sectPr" minOccurs="0" maxOccurs="1" type="CT_SectPr">
            //  </xsd:sequence>
            //</xsd:complexType>

            //<xs:group name="EG_BlockLevelEltsBase">
            //  <xs:choice>
            //    <xs:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"></xs:element>
            //  </xs:choice>
            //</xs:group>

            //<xs:group name="EG_BlockLevelElts">
            //  <xs:choice>
            //    <xs:group ref="EG_BlockLevelEltsBase" minOccurs="0" maxOccurs="unbounded" />
            //    <xs:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" />
            //  </xs:choice>
            //</xs:group>

            //<xsd:group name="EG_BlockLevelChunkElts">
            //  <xsd:choice>
            //    <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded" />
            //  </xsd:choice>
            //</xsd:group>

            //<xs:group name="EG_ContentBlockContent">
            //  <xs:choice>
            //    <xs:group ref="EG_ContentBlockContentBase" minOccurs="0" maxOccurs="unbounded" />
            //    <xs:group ref="EG_RunLevelElts" minOccurs="0" maxOccurs="unbounded" />
            //  </xs:choice>
            //</xs:group>

            //<xs:group name="EG_ContentBlockContentBase">
            //  <xs:choice>
            //    <xs:element name="customXml" type="CT_CustomXmlBlock"></xs:element>
            //    <xs:element name="sdt" type="CT_SdtBlock"></xs:element>
            //    <xs:element name="p" type="CT_P" minOccurs="0" maxOccurs="unbounded"></xs:element>
            //    <xs:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="unbounded"></xs:element>
            //  </xs:choice>
            //</xs:group>

            //<xs:group name="EG_RunLevelElts">
            //  <xs:choice>
            //    <xs:group ref="EG_RunLevelEltsBase" minOccurs="0" maxOccurs="unbounded" />
            //    <xs:group ref="EG_RangeMarkupElements" minOccurs="0" maxOccurs="unbounded"></xs:group>
            //    <xs:element name="ins" type="CT_RunTrackChange" minOccurs="0">
            //    <xs:element name="del" type="CT_RunTrackChange" minOccurs="0">
            //    <xs:element name="moveFrom" type="CT_RunTrackChange">
            //    <xs:element name="moveTo" type="CT_RunTrackChange">
            //    <xs:element name="contentPart" type="CT_ContentPart" minOccurs="0" maxOccurs="unbounded" ofapi:available="o14" />
            //    <xs:group ref="w14:EG_RunLevelConflicts" minOccurs="0" />
            //  </xs:choice>
            //</xs:group>

            //<xs:group name="EG_RunLevelEltsBase">
            //  <xs:choice>
            //    <xs:element name="proofErr" minOccurs="0" type="CT_ProofErr"></xs:element>
            //    <xs:element name="permStart" minOccurs="0" type="CT_PermStart"></xs:element>
            //    <xs:element name="permEnd" minOccurs="0" type="CT_Perm"></xs:element>
            //  </xs:choice>
            //</xs:group>

            //<xs:group name="EG_RangeMarkupElements">
            //  <xs:choice>
            //    <xs:group ref="EG_RangeMarkupElementsNoRev" minOccurs="0" maxOccurs="unbounded" />
            //    <xs:group ref="EG_RangeMarkupElementsRev" minOccurs="0" maxOccurs="unbounded" />
            //    <xs:element ref="w14:customXmlConflictInsRangeStart" minOccurs="0" />
            //    <xs:element ref="w14:customXmlConflictInsRangeEnd" minOccurs="0" />
            //    <xs:element ref="w14:customXmlConflictDelRangeStart" minOccurs="0" />
            //    <xs:element ref="w14:customXmlConflictDelRangeEnd" minOccurs="0" />
            //  </xs:choice>
            //</xs:group>

            //<xsd:group name="EG_MathContent">
            //  <xsd:choice>
            //    <xsd:element ref="m:oMathPara"></xsd:element>
            //    <xsd:element ref="m:oMath"></xsd:element>
            //  </xsd:choice>
            //</xsd:group>

            // ################ the above schema has been changed by EcmaD ##############

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            //
            body.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.PrependChild(new AltChunk());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            // multiple AltChunk is ok
            body.PrependChild(new AltChunk());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.InsertAfter(new Paragraph(), body.FirstChild);
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.PrependChild(new MoveFromRangeStart());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.PrependChild(new MoveFromRun());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.PrependChild(new MoveFromRun());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.PrependChild(new MoveFromRangeStart());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            body.InsertAfter(new Paragraph(), body.FirstChild);
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            // ***** error case ******
            // sectProperties can not be the first
            errorChild = body.FirstChild;
            body.PrependChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            body.RemoveChild(body.FirstChild);

            validationContext.Clear();
            // can only have one sectProperties at last
            errorChild = body.AppendChild(new SectionProperties());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            body.RemoveChild(errorChild);

            validationContext.Clear();
            // paragrap can be after sectProperties at last
            errorChild = body.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            body.RemoveChild(errorChild);

            validationContext.Clear();
            // first is invalid
            errorChild = body.PrependChild(new Run());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":altChunk", validationContext.Errors[0].Description);
            body.RemoveChild(errorChild);

            validationContext.Clear();
            // invalid child in middle
            errorChild = body.InsertBefore(new Run(), body.LastChild);
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
            body.RemoveChild(errorChild);
        }
        private void TestSimpleChoice4(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            RevisionRowColumn rRowColumn = new RevisionRowColumn();
            var particleConstraint       = sdbSchemaDatas.GetSchemaTypeData(rRowColumn).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = rRowColumn;
            var expected = rRowColumn;

            //<xsd:complexType name="CT_RevisionRowColumn">
            //  <xsd:choice minOccurs="0" maxOccurs="unbounded">
            //    <xsd:element name="undo" type="CT_UndoInfo" minOccurs="0" maxOccurs="unbounded">
            //    <xsd:element name="rcc" type="CT_RevisionCellChange" minOccurs="0" maxOccurs="unbounded">
            //    <xsd:element name="rfmt" type="CT_RevisionFormatting" minOccurs="0" maxOccurs="unbounded">
            //  </xsd:choice>
            //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            //
            rRowColumn.AppendChild(new RevisionCellChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // dup is ok
            rRowColumn.AppendChild(new RevisionCellChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more is ok
            rRowColumn.AppendChild(new RevisionFormat());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more is ok
            rRowColumn.AppendChild(new Undo());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            //first is invalid
            errorChild = rRowColumn.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":undo", actual.Errors[0].Description);
            Assert.Contains(":rfmt", actual.Errors[0].Description);

            actual.Clear();
            //invalid child in middle
            rRowColumn.RemoveChild(errorChild);
            errorChild = rRowColumn.InsertBefore(new Paragraph(), rRowColumn.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":undo", actual.Errors[0].Description);
            Assert.Contains(":rfmt", actual.Errors[0].Description);

            actual.Clear();
            //invalid child in last
            rRowColumn.RemoveChild(errorChild);
            errorChild = rRowColumn.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":undo", actual.Errors[0].Description);
            Assert.Contains(":rfmt", actual.Errors[0].Description);
        }
Ejemplo n.º 15
0
        // ****** The CT_PictureBase has been changed to not use "xsd:any" in deviation.
        //private void EmbeddedObjectConstraintTest(SdbSchemaDatas actual)
        //{
        //    // test xsd:any

        //    //<xsd:complexType name="CT_PictureBase">
        //    //  <xsd:sequence maxOccurs="unbounded">
        //    //    <xsd:any processContents="lax" namespace="urn:schemas-microsoft-com:vml" minOccurs="0" />
        //    //    <xsd:any processContents="lax" namespace="urn:schemas-microsoft-com:office:office" minOccurs="0" />
        //    //  </xsd:sequence>
        //    //</xsd:complexType>
        //    //<xsd:complexType name="CT_Object">
        //    //  <xsd:complexContent>
        //    //    <xsd:extension base="CT_PictureBase">
        //    //      <xsd:sequence>
        //    //        <xsd:element name="control" type="CT_Control" minOccurs="0" />
        //    //      </xsd:sequence>
        //    //      <xsd:attribute name="dxaOrig" type="ST_TwipsMeasure" use="optional" />
        //    //      <xsd:attribute name="dyaOrig" type="ST_TwipsMeasure" use="optional" />
        //    //    </xsd:extension>
        //    //  </xsd:complexContent>
        //    //</xsd:complexType>

        //    EmbeddedObject embededObject = new EmbeddedObject();
        //    var embededObjectData = actual.GetSchemaTypeData(embededObject);
        //    Assert.Equal(embededObject.ElementTypeId, embededObjectData.OpenXmlTypeId);
        //    Assert.True(embededObjectData.HasAttributeConstraints);
        //    Assert.Equal(2, embededObjectData.AttributeConstraintsCount);
        //    Assert.Null(embededObjectData.SimpleTypeConstraint);
        //    Assert.True(embededObjectData.IsCompositeType);
        //    Assert.False(embededObjectData.IsSimpleContent);

        //    var particle = embededObjectData.ParticleConstraint;
        //    Assert.Equal(ParticleType.Sequence, particle.ParticleType);
        //    Assert.Equal(1, particle.MinOccurs);
        //    Assert.Equal(1, particle.MaxOccurs);
        //    Assert.Equal(2, particle.ChildrenParticles.Length);
        //    Assert.False(particle.UnboundedMaxOccurs);
        //    Assert.False(particle.IsSimple());
        //    {
        //        // the sequence in CT_PictureBase
        //        particle = embededObjectData.ParticleConstraint.ChildrenParticles[0];
        //        Assert.Equal(ParticleType.Sequence, particle.ParticleType);
        //        Assert.Equal(1, particle.MinOccurs);
        //        Assert.True(particle.UnboundedMaxOccurs);
        //        Assert.Equal(2, particle.ChildrenParticles.Length);
        //        Assert.True(particle.IsSimple());

        //        NsAnyParticle anyParticle = particle.ChildrenParticles[0] as NsAnyParticle;
        //        Assert.Equal(ParticleType.AnyWithUri, anyParticle.ParticleType);
        //        Assert.Equal(0, anyParticle.MinOccurs);
        //        Assert.False(anyParticle.UnboundedMaxOccurs);
        //        Assert.Equal(1, anyParticle.MaxOccurs);
        //        Assert.Null(anyParticle.ChildrenParticles);
        //        Assert.True(anyParticle.IsSimple());
        //        Assert.Equal(NamespaceIdMap.GetNamespaceId("urn:schemas-microsoft-com:vml"), anyParticle.NamespaceId);

        //        anyParticle = particle.ChildrenParticles[1] as NsAnyParticle;
        //        Assert.Equal(ParticleType.AnyWithUri, anyParticle.ParticleType);
        //        Assert.Equal(0, anyParticle.MinOccurs);
        //        Assert.False(anyParticle.UnboundedMaxOccurs);
        //        Assert.Equal(1, anyParticle.MaxOccurs);
        //        Assert.Null(anyParticle.ChildrenParticles);
        //        Assert.True(anyParticle.IsSimple());
        //        Assert.Equal(NamespaceIdMap.GetNamespaceId("urn:schemas-microsoft-com:office:office"), anyParticle.NamespaceId);
        //    }
        //}

        private void SimpleTypeConstraintTest(SdbSchemaDatas actual)
        {
            // <Bibliography:SourceType /> is a simple type
            // <xsd:element name="SourceType" type="ST_SourceType">

            SourceType sourceType = new SourceType();
            var schemaTypeData = actual.GetSchemaTypeData(sourceType.ElementTypeId);
            Assert.Equal(sourceType.ElementTypeId, schemaTypeData.OpenXmlTypeId);
            Assert.False(schemaTypeData.HasAttributeConstraints);
            Assert.NotNull(schemaTypeData.SimpleTypeConstraint);
            Assert.False(schemaTypeData.IsCompositeType);
            Assert.True(schemaTypeData.IsSimpleContent);

            Assert.Null(schemaTypeData.ParticleConstraint);

            // ST_SourceType is ST_String255 based enum
            Assert.IsType(typeof(EnumValueRestriction), schemaTypeData.SimpleTypeConstraint);
            Assert.Equal(XsdType.Enum, schemaTypeData.SimpleTypeConstraint.XsdType);
            Assert.Equal(RestrictionField.None, schemaTypeData.SimpleTypeConstraint.RestrictionField);
            Assert.True(schemaTypeData.SimpleTypeConstraint.IsEnum);
            Assert.False(schemaTypeData.SimpleTypeConstraint.IsList);
            Assert.Null(schemaTypeData.SimpleTypeConstraint.Pattern);

            // <Bibliography:ConferenceName /> is a simple type
            //<xsd:element name="ConferenceName" type="ST_String255">
            ConferenceName conferenceName = new ConferenceName();

            schemaTypeData = actual.GetSchemaTypeData(conferenceName.ElementTypeId);
            Assert.Equal(conferenceName.ElementTypeId, schemaTypeData.OpenXmlTypeId);
            Assert.False(schemaTypeData.HasAttributeConstraints);
            Assert.NotNull(schemaTypeData.SimpleTypeConstraint);
            Assert.False(schemaTypeData.IsCompositeType);
            Assert.True(schemaTypeData.IsSimpleContent);

            Assert.Null(schemaTypeData.ParticleConstraint);

            //<xsd:simpleType name="ST_String255">
            //  <xsd:restriction base="xsd:string">
            //    <xsd:minLength value="0" />
            //    <xsd:maxLength value="255" />
            //  </xsd:restriction>
            //</xsd:simpleType>
            Assert.IsType(typeof(StringRestriction), schemaTypeData.SimpleTypeConstraint);
            Assert.Equal(XsdType.String, schemaTypeData.SimpleTypeConstraint.XsdType);
            Assert.False(schemaTypeData.SimpleTypeConstraint.IsEnum);
            Assert.False(schemaTypeData.SimpleTypeConstraint.IsList);
            Assert.Null(schemaTypeData.SimpleTypeConstraint.Pattern);

            var stringConstraint = schemaTypeData.SimpleTypeConstraint as StringRestriction;
            Assert.Equal(RestrictionField.MinLength | RestrictionField.MaxLength, stringConstraint.RestrictionField);
            Assert.Equal(0, stringConstraint.MinLength);
            Assert.Equal(255, stringConstraint.MaxLength);
        }
        private void TestSimpleAny(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            TextBox textBox = new TextBox();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(textBox).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;
            validationContext.Element = textBox;
            var expected = textBox;
              //<xsd:complexType name="CT_Textbox">
              //  <xsd:choice>
              //    <xsd:element ref="w:txbxContent" minOccurs="0" />
              //    <xsd:any namespace="##local" processContents="skip" />
              //  </xsd:choice>
              //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any element without namespace is ok
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("test"));
            Assert.True(string.IsNullOrEmpty(errorChild.NamespaceUri));
            target.Validate(validationContext);
            Assert.True(actual.Valid);
            textBox.RemoveChild(errorChild);

            // ***** error case ******

            // any element with namespace is invlaid
            errorChild = textBox.AppendChild(new TextBox());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":txbxContent"));
            Assert.True(actual.Errors[0].Description.Contains("##local"));
            textBox.RemoveChild(errorChild);

            actual.Clear();
            // any element with namespace is invlaid
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("", "test", "http://test"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":txbxContent"));
            Assert.True(actual.Errors[0].Description.Contains("##local"));
            textBox.RemoveChild(errorChild);

            actual.Clear();
            // any element with namespace is invlaid
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("t", "test", "http://test"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":txbxContent"));
            Assert.True(actual.Errors[0].Description.Contains("##local"));
            textBox.RemoveChild(errorChild);

            actual.Clear();
            // only one element without namespace is allowed
            textBox.AppendChild(new OpenXmlUnknownElement("test"));
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("errorElement"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            textBox.RemoveAllChildren();

            actual.Clear();
            // only one element without namespace is allowed
            textBox.AppendChild(new OpenXmlUnknownElement("test"));
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("test"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            textBox.RemoveAllChildren();
        }
        private void TestSimpleAll(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            Properties properties = new Properties();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(properties).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as AllParticleValidator;
            validationContext.Element = properties;
            var expected = properties;

            //<xsd:complexType name="CT_Properties">
            //  <xsd:all>
            //    <xsd:element name="Template" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Manager" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Company" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Pages" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Words" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Characters" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="PresentationFormat" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="Lines" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Paragraphs" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Slides" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="Notes" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="TotalTime" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="HiddenSlides" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="MMClips" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="ScaleCrop" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="HeadingPairs" minOccurs="0" maxOccurs="1" type="CT_VectorVariant">
            //    <xsd:element name="TitlesOfParts" minOccurs="0" maxOccurs="1" type="CT_VectorLpstr">
            //    <xsd:element name="LinksUpToDate" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="CharactersWithSpaces" minOccurs="0" maxOccurs="1" type="xsd:int">
            //    <xsd:element name="SharedDoc" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="HyperlinkBase" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="HLinks" minOccurs="0" maxOccurs="1" type="CT_VectorVariant">
            //    <xsd:element name="HyperlinksChanged" minOccurs="0" maxOccurs="1" type="xsd:boolean">
            //    <xsd:element name="DigSig" minOccurs="0" maxOccurs="1" type="CT_DigSigBlob">
            //    <xsd:element name="Application" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="AppVersion" minOccurs="0" maxOccurs="1" type="xsd:string">
            //    <xsd:element name="DocSecurity" minOccurs="0" maxOccurs="1" type="xsd:int">
            //  </xsd:all>
            //</xsd:complexType> 

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any one is ok
            properties.AppendChild(new Company());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            properties.AppendChild(new Template());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            properties.AppendChild(new DocumentSecurity());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            properties.AppendChild(new HyperlinkBase());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // first is invlaid
            errorChild = properties.PrependChild(new Properties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":Template"));
            Assert.True(actual.Errors[0].Description.Contains(":DocSecurity"));
            properties.RemoveChild(errorChild);

            actual.Clear();
            //invalid child in middle
            errorChild = properties.InsertBefore(new Properties(), properties.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(":Template"));
            Assert.True(actual.Errors[0].Description.Contains(":AppVersion"));
            properties.RemoveChild(errorChild);

            actual.Clear();
            // dup 
            errorChild = properties.FirstChild;
            properties.PrependChild(new Company());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_AllElement", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            properties.RemoveChild(errorChild);

        }
        private void TestSimpleChoice4(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            RevisionRowColumn rRowColumn = new RevisionRowColumn();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(rRowColumn).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;
            validationContext.Element = rRowColumn;
            var expected = rRowColumn;
              
              //<xsd:complexType name="CT_RevisionRowColumn">
              //  <xsd:choice minOccurs="0" maxOccurs="unbounded">
              //    <xsd:element name="undo" type="CT_UndoInfo" minOccurs="0" maxOccurs="unbounded">
              //    <xsd:element name="rcc" type="CT_RevisionCellChange" minOccurs="0" maxOccurs="unbounded">
              //    <xsd:element name="rfmt" type="CT_RevisionFormatting" minOccurs="0" maxOccurs="unbounded">
              //  </xsd:choice>   
              //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            rRowColumn.AppendChild(new RevisionCellChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // dup is ok
            rRowColumn.AppendChild(new RevisionCellChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more is ok
            rRowColumn.AppendChild(new RevisionFormat());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more is ok
            rRowColumn.AppendChild(new Undo());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            //first is invalid
            errorChild = rRowColumn.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":undo"));
            Assert.True(actual.Errors[0].Description.Contains(":rfmt"));

            actual.Clear();
            //invalid child in middle
            rRowColumn.RemoveChild(errorChild);
            errorChild = rRowColumn.InsertBefore(new Paragraph(), rRowColumn.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":undo"));
            Assert.True(actual.Errors[0].Description.Contains(":rfmt"));

            actual.Clear();
            //invalid child in last
            rRowColumn.RemoveChild(errorChild);
            errorChild = rRowColumn.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":undo"));
            Assert.True(actual.Errors[0].Description.Contains(":rfmt"));

        }
Ejemplo n.º 19
0
        private void TestSimpleAny(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            TextBox textBox            = new TextBox();
            var     particleConstraint = sdbSchemaDatas.GetSchemaTypeData(textBox).ParticleConstraint;
            var     target             = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = textBox;
            var expected = textBox;

            //<xsd:complexType name="CT_Textbox">
            //  <xsd:choice>
            //    <xsd:element ref="w:txbxContent" minOccurs="0" />
            //    <xsd:any namespace="##local" processContents="skip" />
            //  </xsd:choice>
            //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any element without namespace is ok
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("test"));
            Assert.True(string.IsNullOrEmpty(errorChild.NamespaceUri));
            target.Validate(validationContext);
            Assert.True(actual.Valid);
            textBox.RemoveChild(errorChild);

            // ***** error case ******

            // any element with namespace is invlaid
            errorChild = textBox.AppendChild(new TextBox());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":txbxContent", actual.Errors[0].Description);
            Assert.Contains("##local", actual.Errors[0].Description);
            textBox.RemoveChild(errorChild);

            actual.Clear();
            // any element with namespace is invalid
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("", "test", "http://test"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":txbxContent", actual.Errors[0].Description);
            Assert.Contains("##local", actual.Errors[0].Description);
            textBox.RemoveChild(errorChild);

            actual.Clear();
            // any element with namespace is invlaid
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("t", "test", "http://test"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":txbxContent", actual.Errors[0].Description);
            Assert.Contains("##local", actual.Errors[0].Description);
            textBox.RemoveChild(errorChild);

            actual.Clear();
            // only one element without namespace is allowed
            textBox.AppendChild(new OpenXmlUnknownElement("test"));
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("errorElement"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, actual.Errors[0].Description);
            textBox.RemoveAllChildren();

            actual.Clear();
            // only one element without namespace is allowed
            textBox.AppendChild(new OpenXmlUnknownElement("test"));
            errorChild = textBox.AppendChild(new OpenXmlUnknownElement("test"));
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, actual.Errors[0].Description);
            textBox.RemoveAllChildren();
        }
        private void ValidateBlip(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            Drawing.Blip blip = new Drawing.Blip();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(blip).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ParticleValidator;
            validationContext.Element = blip;
            var expected = blip;

            //<xsd:complexType name="CT_Blip">
            //  <xsd:sequence>
            //    <xsd:choice minOccurs="0" maxOccurs="unbounded">
            //      <xsd:element name="alphaBiLevel" type="CT_AlphaBiLevelEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="alphaCeiling" type="CT_AlphaCeilingEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaFloor" type="CT_AlphaFloorEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaInv" type="CT_AlphaInverseEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaMod" type="CT_AlphaModulateEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="alphaModFix" type="CT_AlphaModulateFixedEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="alphaRepl" type="CT_AlphaReplaceEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="biLevel" type="CT_BiLevelEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="blur" type="CT_BlurEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="clrChange" type="CT_ColorChangeEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="clrRepl" type="CT_ColorReplaceEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="duotone" type="CT_DuotoneEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="fillOverlay" type="CT_FillOverlayEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="grayscl" type="CT_GrayscaleEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="hsl" type="CT_HSLEffect" minOccurs="1" maxOccurs="1" />
            //      <xsd:element name="lum" type="CT_LuminanceEffect" minOccurs="1" maxOccurs="1">
            //      <xsd:element name="tint" type="CT_TintEffect" minOccurs="1" maxOccurs="1">
            //    </xsd:choice>
            //    <xsd:element name="extLst" type="CT_OfficeArtExtensionList" minOccurs="0" maxOccurs="1"></xsd:element>
            //  </xsd:sequence>
            //  <xsd:attributeGroup ref="AG_Blob"></xsd:attributeGroup>
            //  <xsd:attribute name="cstate" type="ST_BlipCompression" use="optional" default="none">
            //</xsd:complexType>
            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 
            blip.AppendChild(new Drawing.LuminanceEffect());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            blip.AppendChild(new Drawing.LuminanceEffect());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            blip.AppendChild(new Drawing.AlphaBiLevel());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            blip.AppendChild(new Drawing.Blur());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            blip.AppendChild(new Drawing.BiLevel());
            target.Validate(validationContext);
            Assert.True(actual.Valid);
            
            blip.AppendChild(new Drawing.BlipExtensionList());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******
            // ExtensionList can not be the first
            errorChild = blip.FirstChild;
            blip.PrependChild(new Drawing.BlipExtensionList());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            blip.RemoveChild(blip.FirstChild);

            actual.Clear();
            // can only have one ExtensionList at last
            errorChild = blip.AppendChild(new Drawing.BlipExtensionList());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            blip.RemoveChild(errorChild);
        }
Ejemplo n.º 21
0
        private void TestSimpleChoice3(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            FormFieldData ffData             = new FormFieldData();
            var           particleConstraint = sdbSchemaDatas.GetSchemaTypeData(ffData).ParticleConstraint;
            var           target             = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = ffData;
            var expected = ffData;

            //<xs:complexType name="CT_FFData">
            //  <xs:choice maxOccurs="unbounded">
            //    <xs:element name="name" type="CT_FFName">
            //    <xs:element name="enabled" type="CT_OnOff">
            //    <xs:element name="calcOnExit" type="CT_OnOff">
            //    <xs:element name="entryMacro" type="CT_MacroName" minOccurs="0" maxOccurs="1">
            //    <xs:element name="exitMacro" type="CT_MacroName" minOccurs="0" maxOccurs="1">
            //    <xs:element name="helpText" type="CT_FFHelpText" minOccurs="0" maxOccurs="1">
            //    <xs:element name="statusText" type="CT_FFStatusText" minOccurs="0" maxOccurs="1">
            //    <xs:choice>
            //      <xs:element name="checkBox" type="CT_FFCheckBox">
            //      <xs:element name="ddList" type="CT_FFDDList">
            //      <xs:element name="textInput" type="CT_FFTextInput">
            //    </xs:choice>
            //  </xs:choice>
            //</xs:complexType>

            // ***** good case ******

            // empty is ok, as there are child with minOccurs="0"
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ffData.AppendChild(new FormFieldName());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // dup element
            ffData.AppendChild(new FormFieldName());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ffData.RemoveAllChildren();
            ffData.AppendChild(new StatusText());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 2 element
            ffData.AppendChild(new HelpText());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // dup element
            ffData.AppendChild(new HelpText());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more element
            ffData.AppendChild(new Enabled());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more element
            ffData.AppendChild(new CheckBox());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more element
            ffData.AppendChild(new TextInput());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******
            ffData.RemoveAllChildren();
            ffData.AppendChild(new HelpText());
            ffData.AppendChild(new CheckBox());

            //first is invalid
            errorChild = ffData.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":name"));
            Assert.True(actual.Errors[0].Description.Contains(":textInput"));

            actual.Clear();
            //invalid child in middle
            ffData.RemoveChild(errorChild);
            errorChild = ffData.InsertBefore(new Paragraph(), ffData.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":name"));
            Assert.True(actual.Errors[0].Description.Contains(":textInput"));

            actual.Clear();
            //invalid child in last
            ffData.RemoveChild(errorChild);
            errorChild = ffData.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":name"));
            Assert.True(actual.Errors[0].Description.Contains(":textInput"));
        }
        private void TestSimpleSequence2(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            Ruby ruby = new Ruby();
            OpenXmlElement errorChild;

            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(ruby).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as SequenceParticleValidator;
            validationContext.Element = ruby;
            var expected = ruby;
            //<xsd:complexType name="CT_Ruby">
            //  <xsd:sequence>
            //    <xsd:element name="rubyPr" type="CT_RubyPr">
            //    <xsd:element name="rt" type="CT_RubyContent">
            //    <xsd:element name="rubyBase" type="CT_RubyContent">
            //  </xsd:sequence>
            //</xsd:complexType>}

            // ***** good case ******
            ruby.Append(new RubyProperties(), new RubyContent(), new RubyBase());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // No RubyBase child, incomplete error
            ruby.RemoveChild(ruby.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rubyBase"));

            actual.Clear();
            // No RubyContent child, incomplete error
            ruby.RemoveChild(ruby.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rt"));

            actual.Clear();
            // Empty, incomplete error
            ruby.RemoveChild(ruby.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rubyPr"));

            actual.Clear();
            // No RubyContent child, incomplete error
            ruby.Append(new RubyProperties(), new RubyBase());
            errorChild = ruby.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rt"));

            actual.Clear();
            // No RubyProperties child, incomplete error
            ruby.RemoveAllChildren();
            ruby.Append(new RubyContent(), new RubyBase());
            errorChild = ruby.FirstChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rubyPr"));

            actual.Clear();
            // first should be RubyProperties()
            ruby.PrependChild(new RubyContent());
            errorChild = ruby.FirstChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rubyPr"));

            actual.Clear();
            // 2nd and 3rd are same element, error
            errorChild = ruby.FirstChild.NextSibling();
            ruby.PrependChild(new RubyProperties());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":rt"));
        }
Ejemplo n.º 23
0
        private void TestSimpleChoice2(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            BuildSubElement bldSub             = new BuildSubElement();
            var             particleConstraint = sdbSchemaDatas.GetSchemaTypeData(bldSub).ParticleConstraint;
            var             target             = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = bldSub;
            var expected = bldSub;

            //<xsd:complexType name="CT_AnimationGraphicalObjectBuildProperties">
            //  <xsd:choice>
            //    <xsd:element name="bldDgm" type="CT_AnimationDgmBuildProperties">
            //    <xsd:element name="bldChart" type="CT_AnimationChartBuildProperties">
            //  </xsd:choice>
            //</xsd:complexType>

            // ***** good case ******
            bldSub.AppendChild(new Drawing.BuildChart());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            bldSub.RemoveAllChildren();
            bldSub.AppendChild(new Drawing.BuildDiagram());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // empty
            bldSub.RemoveAllChildren();
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":bldDgm"));
            Assert.True(actual.Errors[0].Description.Contains(":bldChart"));

            actual.Clear();
            // both element are exist
            bldSub.Append(new Drawing.BuildChart(), new Drawing.BuildDiagram());
            errorChild = bldSub.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            //first is invalid
            errorChild = bldSub.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":bldDgm"));
            Assert.True(actual.Errors[0].Description.Contains(":bldChart"));
        }
        private void TestSimpleSequence4(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;
            ColorTransformCategories categories = new ColorTransformCategories();
            var expected = categories;
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(categories).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as SequenceParticleValidator;
            validationContext.Element = categories;

              //<xsd:complexType name="CT_CTCategories">
              //  <xsd:sequence minOccurs="0" maxOccurs="unbounded">
              //    <xsd:element name="cat" type="CT_CTCategory" minOccurs="0" maxOccurs="unbounded">
              //  </xsd:sequence>
              //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            categories.AppendChild(new ColorTransformCategory());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            categories.AppendChild(new ColorTransformCategory());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            categories.AppendChild(new ColorTransformCategory());
            target.Validate(validationContext);
            Assert.True(actual.Valid);


            // ***** error case ******

            // 1st child is invalid
            errorChild = categories.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":cat"));

            actual.Clear();
            // last child is invalid
            categories.RemoveChild(errorChild);
            errorChild = categories.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":cat"));

            actual.Clear();
            // 2nd child is invalid
            categories.RemoveChild(errorChild);
            errorChild = categories.InsertAfter(new Paragraph(), categories.FirstChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":cat"));

            actual.Clear();
            // 3rd child is invalid
            categories.RemoveChild(errorChild);
            errorChild = categories.InsertBefore(new Paragraph(), categories.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":cat"));

            actual.Clear();
            // only one invalid child
            categories.RemoveAllChildren();
            errorChild = categories.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":cat"));
        }
Ejemplo n.º 25
0
        private void TestSimpleChoice(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            FieldChar fldChar            = new FieldChar();
            var       particleConstraint = sdbSchemaDatas.GetSchemaTypeData(fldChar).ParticleConstraint;
            var       target             = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = fldChar;
            var expected = fldChar;

            //<xsd:complexType name="CT_FldChar">
            //  <xsd:choice>
            //    <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1">
            //    <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1">
            //    <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0">
            //  </xsd:choice>
            //</xsd:complexType>

            // ***** good case ******
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.AppendChild(new FieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new FormFieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new NumberingChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // 1st is invalid
            errorChild = fldChar.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":fldData"));
            Assert.True(actual.Errors[0].Description.Contains(":ffData"));
            Assert.True(actual.Errors[0].Description.Contains(":numberingChange"));

            actual.Clear();
            // second is invalid
            fldChar.RemoveChild(errorChild);
            errorChild = fldChar.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // dup first child
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FormFieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different
            fldChar.RemoveAllChildren();
            fldChar.Append(new FormFieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
        }
Ejemplo n.º 26
0
        private void SimpleLoadTest(SdbSchemaDatas actual)
        {
            var schemaTypeData = actual.GetSchemaTypeData(RunProperties.ElementTypeIdConst);
            Assert.True(schemaTypeData.IsCompositeType);
            Assert.False(schemaTypeData.IsSimpleContent);

            schemaTypeData = actual.GetSchemaTypeData(Bold.ElementTypeIdConst);
            Assert.False(schemaTypeData.IsCompositeType);
            Assert.False(schemaTypeData.IsSimpleContent);
        }
        private void TestSimpleGroup2(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            SectionProperties sectPr = new SectionProperties();
            var expected = sectPr;
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(sectPr).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as SequenceParticleValidator;
            validationContext.Element = sectPr;
                          
              //<xsd:complexType name="CT_SectPr">
              //  <xsd:sequence>
              //    <xsd:group ref="EG_HdrFtrReferences" minOccurs="0" maxOccurs="6"></xsd:group>
              //    <xsd:group ref="EG_SectPrContents" minOccurs="0"></xsd:group>
              //    <xsd:element name="sectPrChange" type="CT_SectPrChange" minOccurs="0">
              //  </xsd:sequence>
              //  <xsd:attributeGroup ref="AG_SectPrAttributes"></xsd:attributeGroup>
              //</xsd:complexType>

              //<xsd:group name="EG_HdrFtrReferences">
              //  <xsd:choice>
              //    <xsd:element name="headerReference" type="CT_HdrFtrRef" minOccurs="0">
              //    <xsd:element name="footerReference" type="CT_HdrFtrRef" minOccurs="0">
              //  </xsd:choice>
              //</xsd:group>

              //<xsd:group name="EG_SectPrContents">
              //  <xsd:sequence>
              //    <xsd:element name="footnotePr" type="CT_FtnProps" minOccurs="0">
              //    <xsd:element name="endnotePr" type="CT_EdnProps" minOccurs="0">
              //    <xsd:element name="type" type="CT_SectType" minOccurs="0">
              //    <xsd:element name="pgSz" type="CT_PageSz" minOccurs="0">
              //    <xsd:element name="pgMar" type="CT_PageMar" minOccurs="0">
              //    <xsd:element name="paperSrc" type="CT_PaperSource" minOccurs="0">
              //    <xsd:element name="pgBorders" type="CT_PageBorders" minOccurs="0">
              //    <xsd:element name="lnNumType" type="CT_LineNumber" minOccurs="0">
              //    <xsd:element name="pgNumType" type="CT_PageNumber" minOccurs="0">
              //    <xsd:element name="cols" type="CT_Columns" minOccurs="0">
              //    <xsd:element name="formProt" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="vAlign" type="CT_VerticalJc" minOccurs="0">
              //    <xsd:element name="noEndnote" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="titlePg" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="textDirection" type="CT_TextDirection" minOccurs="0">
              //    <xsd:element name="bidi" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="rtlGutter" type="CT_OnOff" minOccurs="0">
              //    <xsd:element name="docGrid" type="CT_DocGrid" minOccurs="0">
              //    <xsd:element name="printerSettings" type="CT_Rel" minOccurs="0">
              //  </xsd:sequence>
              //</xsd:group>

            // ***** good case ******
            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // headerReference is ok
            sectPr.Append(new HeaderReference());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // headerReference and footerReference
            sectPr.Append(new FooterReference());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // footerReference
            sectPr.RemoveChild(sectPr.FirstChild);
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 3 group <= 6, ok
            sectPr.Append(new HeaderReference(), new HeaderReference());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 5 group <= 6, ok
            sectPr.Append(new HeaderReference(), new HeaderReference());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 6 group <= 6, ok
            sectPr.Append(new HeaderReference());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // no EG_SectPrContents is ok
            sectPr.RemoveAllChildren();
            sectPr.Append(new HeaderReference(), new FooterReference(), new SectionPropertiesChange());
            Assert.True(actual.Valid);

            // test EG_SectPrContents
            sectPr.RemoveAllChildren();
            sectPr.Append(new HeaderReference(), new FooterReference(), new SectionType());
            Assert.True(actual.Valid);

            // 
            sectPr.AppendChild(new PaperSource());
            Assert.True(actual.Valid);

            sectPr.AppendChild(new TitlePage());
            Assert.True(actual.Valid);

            sectPr.AppendChild(new PrinterSettingsReference());
            Assert.True(actual.Valid);

            sectPr.AppendChild(new SectionPropertiesChange());
            Assert.True(actual.Valid);

            sectPr.RemoveAllChildren();
            sectPr.Append(new SectionPropertiesChange());
            Assert.True(actual.Valid);

            // ***** error case ******

            // 7 group > 6, error
            sectPr.RemoveAllChildren();
            sectPr.Append(new HeaderReference(), new HeaderReference(), new FooterReference(), new FooterReference(), new HeaderReference(), new HeaderReference());
            errorChild = sectPr.AppendChild(new HeaderReference());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            sectPr.RemoveChild(errorChild);

            actual.Clear();
            //first is invalid
            errorChild = sectPr.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":headerReference"));
            Assert.True(actual.Errors[0].Description.Contains(":footerReference"));
            Assert.False(actual.Errors[0].Description.Contains(":footnotePr"));
            Assert.False(actual.Errors[0].Description.Contains(":sectPrChange"));
            sectPr.RemoveChild(errorChild);

            actual.Clear();
            //invalid child in middle
            errorChild = sectPr.InsertBefore(new Paragraph(), sectPr.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            sectPr.RemoveChild(errorChild);

            actual.Clear();
            // order wrong
            errorChild = sectPr.FirstChild;
            sectPr.PrependChild(new SectionType());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // dup error
            sectPr.RemoveAllChildren();
            sectPr.Append(new HeaderReference(), new PaperSource());
            errorChild = sectPr.AppendChild( new PaperSource());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            sectPr.RemoveChild(errorChild);

            actual.Clear();
            // out of order error
            errorChild = sectPr.AppendChild(new SectionType());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            sectPr.RemoveChild(errorChild);

            actual.Clear();
            // out of order error
            sectPr.AppendChild(new SectionPropertiesChange());
            errorChild = sectPr.AppendChild(new SectionType());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
        }
Ejemplo n.º 28
0
        private void BodyConstraintTest(SdbSchemaDatas actual)
        {
            ElementParticle elementParticle;
            
            //<xsd:complexType name="CT_Body">
            //  <xsd:sequence>
            //    <xsd:group ref="EG_BlockLevelElts" minOccurs="0" maxOccurs="unbounded" />
            //    <xsd:element name="sectPr" minOccurs="0" maxOccurs="1" type="CT_SectPr" />
            //  </xsd:sequence>
            //</xsd:complexType>
            //<xsd:group name="EG_BlockLevelElts">
            //  <xsd:choice>
            //    <xsd:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" />
            //    <xsd:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded" />
            //  </xsd:choice>
            //</xsd:group>

            //************ changed in EcmaD
          //<xsd:group name="EG_BlockLevelChunkElts">
          //  <xsd:choice>
          //    <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded" />
          //  </xsd:choice>
          //</xsd:group>
          //<xsd:group name="EG_BlockLevelChunkEltsNoRev">
          //  <xsd:choice>
          //    <xsd:group ref="EG_ContentBlockContentNoRev" minOccurs="0" maxOccurs="unbounded" />
          //  </xsd:choice>
          //</xsd:group>
          //<xsd:group name="EG_BlockLevelEltsBase">
          //  <xsd:choice>
          //    <xsd:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"></xsd:element>
          //  </xsd:choice>
          //</xsd:group>
          //<xsd:group name="EG_BlockLevelElts">
          //  <xsd:choice>
          //    <xsd:group ref="EG_BlockLevelEltsBase" minOccurs="0" maxOccurs="unbounded" />
          //    <xsd:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" />
          //  </xsd:choice>


            var body = new Body();
            var bodyData = actual.GetSchemaTypeData(body.ElementTypeId);
            Assert.Equal(body.ElementTypeId, bodyData.OpenXmlTypeId);
            Assert.False(bodyData.HasAttributeConstraints);
            Assert.Null(bodyData.SimpleTypeConstraint);
            Assert.True(bodyData.IsCompositeType);
            Assert.False(bodyData.IsSimpleContent);

            var particle = bodyData.ParticleConstraint;
            Assert.Equal(ParticleType.Sequence, particle.ParticleType);
            Assert.Equal(1, particle.MinOccurs);
            Assert.Equal(1, particle.MaxOccurs);
            Assert.Equal(2, particle.ChildrenParticles.Length);
            Assert.False(particle.UnboundedMaxOccurs);
            Assert.False(particle.IsSimple());
            {
                // the first child of body is a group EG_BlockLevelElts
                particle = bodyData.ParticleConstraint.ChildrenParticles[0];
                Assert.Equal(ParticleType.Group, particle.ParticleType);
                Assert.Equal(0, particle.MinOccurs);
                Assert.True(particle.UnboundedMaxOccurs);
                Assert.Equal(1, particle.ChildrenParticles.Length);
                Assert.False(particle.IsSimple());

                {
                    // the group EG_BlockLevelElts contains 1 child - choice particle
                    particle = particle.ChildrenParticles[0];
                    Assert.Equal(ParticleType.Choice, particle.ParticleType);
                    Assert.Equal(1, particle.MinOccurs);
                    Assert.Equal(1, particle.MaxOccurs);
                    Assert.False(particle.UnboundedMaxOccurs);
                    Assert.False(particle.IsSimple());

                    {
                        // the choice particle contains 2 children
                        Assert.Equal(2, particle.ChildrenParticles.Length);

                        // the first is the group EG_BlockLevelEltsBase
                        var firstParticle = particle.ChildrenParticles[0];
                        Assert.NotNull(firstParticle);
                        Assert.Equal(ParticleType.Group, firstParticle.ParticleType);
                        Assert.Equal(0, firstParticle.MinOccurs);
                        Assert.True(firstParticle.UnboundedMaxOccurs);
                        {
                            // the group EG_BlockLevelEltsBase contains 1 child - choice particle
                            var choiceParticle = firstParticle.ChildrenParticles[0];
                            Assert.Equal(ParticleType.Choice, choiceParticle.ParticleType);
                            Assert.Equal(1, choiceParticle.MinOccurs);
                            Assert.Equal(1, choiceParticle.MaxOccurs);
                            Assert.False(choiceParticle.UnboundedMaxOccurs);
                            Assert.True(choiceParticle.IsSimple());
                            {
                                // the "altChunk" element.
                                elementParticle = choiceParticle.ChildrenParticles[0] as ElementParticle;
                                Assert.NotNull(elementParticle);
                                Assert.Equal(ParticleType.Element, elementParticle.ParticleType);
                                Assert.Equal(0, elementParticle.MinOccurs);
                                Assert.True(elementParticle.UnboundedMaxOccurs);
                                Assert.Equal(AltChunk.ElementTypeIdConst, elementParticle.ElementId);
                                Assert.Null(elementParticle.ChildrenParticles);
                            }
                        }

                        // second is a group particle
                        particle = particle.ChildrenParticles[1];
                        Assert.Equal(ParticleType.Group, particle.ParticleType);
                        Assert.Equal(0, particle.MinOccurs);
                        Assert.True(particle.UnboundedMaxOccurs);
                    }
                }

                // the last element of body is sectPr
                elementParticle = bodyData.ParticleConstraint.ChildrenParticles[1] as ElementParticle;
                Assert.NotNull(elementParticle);
                Assert.Equal(ParticleType.Element, elementParticle.ParticleType);
                Assert.Equal(0, elementParticle.MinOccurs);
                Assert.Equal(1, elementParticle.MaxOccurs);
                Assert.Equal((new SectionProperties()).ElementTypeId, elementParticle.ElementId);
                Assert.Null(elementParticle.ChildrenParticles);
                Assert.False(elementParticle.UnboundedMaxOccurs);
            }
        }
        private void TestSimpleGroup(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            Header header = new Header();
            var expected = header;
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(header).ParticleConstraint;

            // the complex type contains a <xsd:group .../> as child
            var target = particleConstraint.ParticleValidator as GroupParticleValidator;
            validationContext.Element = header;

              //<xsd:complexType name="CT_HdrFtr">
              //  <xsd:group ref="EG_BlockLevelElts" minOccurs="1" maxOccurs="unbounded" />
              //</xsd:complexType>

              //<xs:group name="EG_BlockLevelElts">
              //  <xs:choice>
              //    <xs:group ref="EG_BlockLevelEltsBase" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:group ref="EG_BlockLevelChunkElts" minOccurs="0" maxOccurs="unbounded" />
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_BlockLevelEltsBase">
              //  <xs:choice>
              //    <xs:element name="altChunk" type="CT_AltChunk" minOccurs="0" maxOccurs="unbounded"></xs:element>
              //  </xs:choice>
              //</xs:group>

              //<xsd:group name="EG_BlockLevelChunkElts">
              //  <xsd:choice>
              //    <xsd:group ref="EG_ContentBlockContent" minOccurs="0" maxOccurs="unbounded" />
              //  </xsd:choice>
              //</xsd:group>

              //<xs:group name="EG_ContentBlockContent">
              //  <xs:choice>
              //    <xs:group ref="EG_ContentBlockContentBase" minOccurs="0" maxOccurs="unbounded" />
              //    <xs:group ref="EG_RunLevelElts" minOccurs="0" maxOccurs="unbounded" />
              //  </xs:choice>
              //</xs:group>

              //<xs:group name="EG_ContentBlockContentBase">
              //  <xs:choice>
              //    <xs:element name="customXml" type="CT_CustomXmlBlock"></xs:element>
              //    <xs:element name="sdt" type="CT_SdtBlock"></xs:element>
              //    <xs:element name="p" type="CT_P" minOccurs="0" maxOccurs="unbounded"></xs:element>
              //    <xs:element name="tbl" type="CT_Tbl" minOccurs="0" maxOccurs="unbounded"></xs:element>
              //  </xs:choice>
              //</xs:group>


            // ***** good case ******
            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // Paragraph is ok
            header.Append(new Paragraph());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // Table is ok
            header.Append(new Table());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more Paragraph is ok
            header.Append(new Paragraph());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // Sdt is ok
            header.Append(new SdtBlock());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // altChunk is ok
            header.Append(new AltChunk());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // altChunk is ok
            header.Append(new AltChunk());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more Paragraph is ok
            header.Append(new Paragraph());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******
            //first is invalid
            errorChild = header.PrependChild(new Run());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":altChunk"));
            Assert.True(actual.Errors[0].Description.Contains(":tbl"));
            header.RemoveChild(errorChild);

            actual.Clear();
            //last is invalid
            errorChild = header.AppendChild(new Run());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":altChunk"));
            Assert.True(actual.Errors[0].Description.Contains(":tbl"));
            header.RemoveChild(errorChild);
        }
Ejemplo n.º 30
0
        private void TextboxConstraintTest(SdbSchemaDatas actual)
        {
              //<xsd:complexType name="CT_Textbox">
              //  <xsd:choice>
              //    <xsd:element ref="w:txbxContent" minOccurs="0" />
              //    <xsd:any namespace="##local" processContents="skip" />
              //  </xsd:choice>
              //  <xsd:attributeGroup ref="AG_Id" />
              //  <xsd:attributeGroup ref="AG_Style" />
              //  <xsd:attribute name="inset" type="xsd:string" use="optional">
              //  <xsd:attribute ref="o:singleclick">
              //</xsd:complexType>

            var constraintData = actual.GetSchemaTypeData(DocumentFormat.OpenXml.Vml.TextBox.ElementTypeIdConst);
            Assert.Equal(DocumentFormat.OpenXml.Vml.TextBox.ElementTypeIdConst, constraintData.OpenXmlTypeId);
            Assert.True(constraintData.HasAttributeConstraints);
            Assert.Equal(4, constraintData.AttributeConstraintsCount);
            Assert.Null(constraintData.SimpleTypeConstraint);
            Assert.True(constraintData.IsCompositeType);
            Assert.False(constraintData.IsSimpleContent);

            var particle = constraintData.ParticleConstraint;
            Assert.Equal(ParticleType.Choice, particle.ParticleType);
            Assert.Equal(1, particle.MinOccurs);
            Assert.Equal(1, particle.MaxOccurs);
            Assert.Equal(2, particle.ChildrenParticles.Length);
            Assert.False(particle.UnboundedMaxOccurs);
            Assert.False(particle.IsSimple());
            {
                ElementParticle elementParticle = particle.ChildrenParticles[0] as ElementParticle;
                Assert.Equal(ParticleType.Element, elementParticle.ParticleType);
                Assert.Equal(0, elementParticle.MinOccurs);
                Assert.False(elementParticle.UnboundedMaxOccurs);
                Assert.Equal(1, elementParticle.MaxOccurs);
                Assert.Null(elementParticle.ChildrenParticles);
                Assert.True(elementParticle.IsSimple());

                AnyParticle anyParticle = particle.ChildrenParticles[1] as AnyParticle;
                Assert.Equal(ParticleType.Any, anyParticle.ParticleType);
                Assert.Equal(1, anyParticle.MinOccurs);
                Assert.False(anyParticle.UnboundedMaxOccurs);
                Assert.Equal(1, anyParticle.MaxOccurs);
                Assert.Null(anyParticle.ChildrenParticles);
                Assert.True(anyParticle.IsSimple());
            }
        }
        private void TestSimpleChoice3(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            FormFieldData ffData = new FormFieldData();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(ffData).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;
            validationContext.Element = ffData;
            var expected = ffData;
            
            //<xs:complexType name="CT_FFData">
            //  <xs:choice maxOccurs="unbounded">
            //    <xs:element name="name" type="CT_FFName">
            //    <xs:element name="enabled" type="CT_OnOff">
            //    <xs:element name="calcOnExit" type="CT_OnOff">
            //    <xs:element name="entryMacro" type="CT_MacroName" minOccurs="0" maxOccurs="1">
            //    <xs:element name="exitMacro" type="CT_MacroName" minOccurs="0" maxOccurs="1">
            //    <xs:element name="helpText" type="CT_FFHelpText" minOccurs="0" maxOccurs="1">
            //    <xs:element name="statusText" type="CT_FFStatusText" minOccurs="0" maxOccurs="1">
            //    <xs:choice>
            //      <xs:element name="checkBox" type="CT_FFCheckBox">
            //      <xs:element name="ddList" type="CT_FFDDList">
            //      <xs:element name="textInput" type="CT_FFTextInput">
            //    </xs:choice>
            //  </xs:choice>
            //</xs:complexType>

            // ***** good case ******

            // empty is ok, as there are child with minOccurs="0"
            target.Validate(validationContext);
            Assert.True(actual.Valid);
  
            ffData.AppendChild(new FormFieldName());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // dup element
            ffData.AppendChild(new FormFieldName());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            ffData.RemoveAllChildren();
            ffData.AppendChild(new StatusText());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // 2 element
            ffData.AppendChild(new HelpText());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // dup element
            ffData.AppendChild(new HelpText());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more element
            ffData.AppendChild(new Enabled());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more element
            ffData.AppendChild(new CheckBox());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // more element
            ffData.AppendChild(new TextInput());
            target.Validate(validationContext);
            Assert.True(actual.Valid);
            
            // ***** error case ******
            ffData.RemoveAllChildren();
            ffData.AppendChild(new HelpText());
            ffData.AppendChild(new CheckBox());

            //first is invalid
            errorChild = ffData.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":name"));
            Assert.True(actual.Errors[0].Description.Contains(":textInput"));

            actual.Clear();
            //invalid child in middle
            ffData.RemoveChild(errorChild);
            errorChild = ffData.InsertBefore(new Paragraph(), ffData.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":name"));
            Assert.True(actual.Errors[0].Description.Contains(":textInput"));

            actual.Clear();
            //invalid child in last
            ffData.RemoveChild(errorChild);
            errorChild = ffData.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":name"));
            Assert.True(actual.Errors[0].Description.Contains(":textInput"));
        }
Ejemplo n.º 32
0
        private void AttributeConstraintTest(SdbSchemaDatas actual)
        {
              //<xsd:complexType name="CT_FileVersion">
              //  <xsd:attribute name="appName" type="xsd:string" use="optional">
              //  <xsd:attribute name="lastEdited" type="xsd:string" use="optional">
              //  <xsd:attribute name="lowestEdited" type="xsd:string" use="optional">
              //  <xsd:attribute name="rupBuild" type="xsd:string" use="optional">
              //  <xsd:attribute name="codeName" type="ST_Guid" use="optional">
              //</xsd:complexType>

            var schemaTypeData = actual.GetSchemaTypeData(DocumentFormat.OpenXml.Spreadsheet.FileVersion.ElementTypeIdConst);
            Assert.Equal(5, schemaTypeData.AttributeConstraintsCount);

            AttributeConstraint attributeConstraint;

            for (int i = 0; i < 4; i++)
            {
                attributeConstraint = schemaTypeData.AttributeConstraints[i];
                Assert.Equal(XsdAttributeUse.Optional, attributeConstraint.XsdAttributeUse);
                Assert.IsType(typeof(StringRestriction), attributeConstraint.SimpleTypeConstraint);
            }

            attributeConstraint = schemaTypeData.AttributeConstraints[4];
            Assert.Equal(XsdAttributeUse.Optional, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(TokenRestriction), attributeConstraint.SimpleTypeConstraint);

              //<xsd:complexType name="CT_LsdException">
              //  <xsd:attribute name="name" type="ST_String" use="required">
              //  <xsd:attribute name="locked" type="ST_OnOff">
              //  <xsd:attribute name="uiPriority" type="ST_DecimalNumber">
              //  <xsd:attribute name="semiHidden" type="ST_OnOff">
              //  <xsd:attribute name="unhideWhenUsed" type="ST_OnOff">
              //  <xsd:attribute name="qFormat" type="ST_OnOff">
              //</xsd:complexType>

            schemaTypeData = actual.GetSchemaTypeData(LatentStyleExceptionInfo.ElementTypeIdConst);
            Assert.Equal(6, schemaTypeData.AttributeConstraintsCount);

            attributeConstraint = schemaTypeData.AttributeConstraints[0];
            Assert.Equal(XsdAttributeUse.Required, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(StringRestriction), attributeConstraint.SimpleTypeConstraint);

            attributeConstraint = schemaTypeData.AttributeConstraints[1];
            Assert.Equal(XsdAttributeUse.None, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(BooleanValueRestriction), attributeConstraint.SimpleTypeConstraint);

            attributeConstraint = schemaTypeData.AttributeConstraints[2];
            Assert.Equal(XsdAttributeUse.None, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(Int32ValueRestriction), attributeConstraint.SimpleTypeConstraint);
            
            attributeConstraint = schemaTypeData.AttributeConstraints[3];
            Assert.Equal(XsdAttributeUse.None, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(BooleanValueRestriction), attributeConstraint.SimpleTypeConstraint);

            attributeConstraint = schemaTypeData.AttributeConstraints[4];
            Assert.Equal(XsdAttributeUse.None, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(BooleanValueRestriction), attributeConstraint.SimpleTypeConstraint);

            attributeConstraint = schemaTypeData.AttributeConstraints[5];
            Assert.Equal(XsdAttributeUse.None, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(BooleanValueRestriction), attributeConstraint.SimpleTypeConstraint);

              //<xsd:complexType name="CT_HdrFtrRef">
              //  <xsd:complexContent>
              //    <xsd:extension base="CT_Rel">
              //      <xsd:attribute name="type" type="ST_HdrFtr" use="required">
              //    </xsd:extension>
              //  </xsd:complexContent>
              //</xsd:complexType>
            
              //<xsd:complexType name="CT_Rel">
              //  <xsd:attribute ref="r:id" use="required">
              //</xsd:complexType>
        
              //<xsd:simpleType name="ST_HdrFtr">
              //  <xsd:restriction base="xsd:string">
              //    <xsd:enumeration value="even">
              //    <xsd:enumeration value="default">
              //    <xsd:enumeration value="first">
              //  </xsd:restriction>
              //</xsd:simpleType>
            schemaTypeData = actual.GetSchemaTypeData(HeaderReference.ElementTypeIdConst);
            Assert.Equal(2, schemaTypeData.AttributeConstraintsCount);

            // in generated code, @type if the first, and @r:id is the second
            attributeConstraint = schemaTypeData.AttributeConstraints[0];
            Assert.Equal(XsdAttributeUse.Required, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(EnumValueRestriction), attributeConstraint.SimpleTypeConstraint);

            attributeConstraint = schemaTypeData.AttributeConstraints[1];
            Assert.Equal(XsdAttributeUse.Required, attributeConstraint.XsdAttributeUse);
            Assert.IsType(typeof(StringRestriction), attributeConstraint.SimpleTypeConstraint);

        }
        private void TestSimpleChoice2(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            BuildSubElement bldSub = new BuildSubElement();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(bldSub).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;
            validationContext.Element = bldSub;
            var expected = bldSub;
            
              //<xsd:complexType name="CT_AnimationGraphicalObjectBuildProperties">
              //  <xsd:choice>
              //    <xsd:element name="bldDgm" type="CT_AnimationDgmBuildProperties">
              //    <xsd:element name="bldChart" type="CT_AnimationChartBuildProperties">
              //  </xsd:choice>
              //</xsd:complexType>

            // ***** good case ******
            bldSub.AppendChild(new Drawing.BuildChart());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            bldSub.RemoveAllChildren();
            bldSub.AppendChild(new Drawing.BuildDiagram());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // empty
            bldSub.RemoveAllChildren();
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_IncompleteContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":bldDgm"));
            Assert.True(actual.Errors[0].Description.Contains(":bldChart"));

            actual.Clear();
            // both element are exist
            bldSub.Append(new Drawing.BuildChart(), new Drawing.BuildDiagram());
            errorChild = bldSub.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            //first is invalid
            errorChild = bldSub.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":bldDgm"));
            Assert.True(actual.Errors[0].Description.Contains(":bldChart"));

        }
        private void TestSimpleChoice(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            FieldChar fldChar = new FieldChar();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(fldChar).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;
            validationContext.Element = fldChar;
            var expected = fldChar;

              //<xsd:complexType name="CT_FldChar">
              //  <xsd:choice>
              //    <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1">
              //    <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1">
              //    <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0">
              //  </xsd:choice>
              //</xsd:complexType>

            // ***** good case ******
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.AppendChild(new FieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new FormFieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new NumberingChange() );
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // 1st is invalid
            errorChild = fldChar.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":fldData"));
            Assert.True(actual.Errors[0].Description.Contains(":ffData"));
            Assert.True(actual.Errors[0].Description.Contains(":numberingChange"));

            actual.Clear();
            // second is invalid
            fldChar.RemoveChild(errorChild);
            errorChild = fldChar.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            
            actual.Clear();
            // dup first child
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different 
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FormFieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different 
            fldChar.RemoveAllChildren();
            fldChar.Append(new FormFieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
        }
        private void TestSimpleAll2(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            ShapeLayout shapeLayout        = new ShapeLayout();
            var         particleConstraint = sdbSchemaDatas.GetSchemaTypeData(shapeLayout).ParticleConstraint;
            var         target             = particleConstraint.ParticleValidator as AllParticleValidator;

            validationContext.Element = shapeLayout;
            var expected = shapeLayout;

            //<xsd:complexType name="CT_ShapeLayout">
            //  <xsd:all>
            //    <xsd:element name="idmap" type="CT_IdMap" minOccurs="0">
            //    <xsd:element name="regrouptable" type="CT_RegroupTable" minOccurs="0">
            //    <xsd:element name="rules" type="CT_Rules" minOccurs="0">
            //  </xsd:all>
            //  <xsd:attributeGroup ref="v:AG_Ext" />
            //</xsd:complexType>

            // ***** good case ******

            // empty is ok
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any one is ok
            shapeLayout.AppendChild(new RegroupTable());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            shapeLayout.AppendChild(new ShapeIdMap());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // any order is ok
            shapeLayout.AppendChild(new Rules());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // first is invlaid
            errorChild = shapeLayout.PrependChild(new Paragraphs());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":idmap", actual.Errors[0].Description);
            Assert.Contains(":rules", actual.Errors[0].Description);
            shapeLayout.RemoveChild(errorChild);

            actual.Clear();
            //invalid child in middle
            errorChild = shapeLayout.InsertBefore(new Paragraphs(), shapeLayout.LastChild);
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.Contains(":rules", actual.Errors[0].Description);
            shapeLayout.RemoveChild(errorChild);

            actual.Clear();
            // dup
            errorChild = shapeLayout.FirstChild;
            shapeLayout.PrependChild(new RegroupTable());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Single(actual.Errors);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_AllElement", actual.Errors[0].Id);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            shapeLayout.RemoveChild(errorChild);
        }