public void TestSvgWithUrlInStyles(string styleContent) { var constraints = new VectorImageElementConstraints(); const string ExpectedErrorType = nameof(VectorImageElementConstraints.WithoutUrlInStyles); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); TestHelpers.MakeBinaryValidationCheck <ImageWithUrlInStylesError>( string.Format(SvgTemplate, $"<circle style=\"{styleContent}\" />"), TestAction, ExpectedErrorType); TestHelpers.MakeBinaryValidationCheck <ImageWithUrlInStylesError>( string.Format(SvgTemplate, $"<g><rect style=\"{styleContent}\" /></g>"), TestAction, ExpectedErrorType); TestHelpers.MakeBinaryValidationCheck <ImageWithUrlInStylesError>( $"<svg style=\"{styleContent}\" />", TestAction, ExpectedErrorType); TestHelpers.MakeBinaryValidationCheck <ImageWithUrlInStylesError>( string.Format(SvgTemplate, $"<style>/* <![CDATA[ */{styleContent}/* ]]> */</style>"), TestAction, ExpectedErrorType); }
public void TestSvgWithBitmaps(string svgContent) { var constraints = new VectorImageElementConstraints(); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); TestHelpers.MakeBinaryValidationCheck <ImageWithBitmapsError>( string.Format(SvgTemplate, svgContent), TestAction, nameof(VectorImageElementConstraints.WithoutBitmaps)); }
public void TestSvgWithUnclosedPaths(string svgContent) { var constraints = new VectorImageElementConstraints(); const string ExpectedErrorType = nameof(VectorImageElementConstraints.PathsAreClosed); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); TestHelpers.MakeBinaryValidationCheck <ImageWithUnclosedPathsError>( string.Format(SvgTemplate, svgContent), TestAction, ExpectedErrorType); }
public void TestSvgWithGradient(string svgContent, int gradientElementsCount = 1) { var constraints = new VectorImageElementConstraints(); const string ExpectedErrorType = nameof(VectorImageElementConstraints.WithoutGradient); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); var error = TestHelpers.MakeBinaryValidationCheck <ImageWithGradientError>( string.Format(SvgTemplate, svgContent), TestAction, ExpectedErrorType); Assert.Equal(gradientElementsCount, error.GradientElements.Count); }
public void TestSvgWithClosedPaths() { var constraints = new VectorImageElementConstraints(); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); TestHelpers.MakeBinaryValidationCheck(string.Format(SvgTemplate, "<path />"), TestAction); TestHelpers.MakeBinaryValidationCheck( string.Format(SvgTemplate, "<path d=\"M 100 100 L 300 100 L 200 300 z\" fill=\"red\" stroke=\"blue\" stroke-width=\"3\" />"), TestAction); TestHelpers.MakeBinaryValidationCheck( string.Format(SvgTemplate, "<g><path d=\"M 100 100 L 300 100 L 200 300 Z \" /></g>"), TestAction); }
public static void EnsureFileContentIsValid( int templateCode, ElementDescriptorType elementDescriptorType, IElementConstraints elementConstraints, Stream inputStream, string fileName) { switch (elementDescriptorType) { case ElementDescriptorType.BitmapImage: BitmapImageValidator.ValidateBitmapImage(templateCode, (BitmapImageElementConstraints)elementConstraints, inputStream); break; case ElementDescriptorType.VectorImage: var fileFormat = DetectFileFormat(fileName); VectorImageValidator.ValidateVectorImage(templateCode, fileFormat, (VectorImageElementConstraints)elementConstraints, inputStream); break; case ElementDescriptorType.Article: ArticleValidator.ValidateArticle(templateCode, inputStream); break; case ElementDescriptorType.CompositeBitmapImage: break; case ElementDescriptorType.ScalableBitmapImage: break; case ElementDescriptorType.PlainText: case ElementDescriptorType.FormattedText: case ElementDescriptorType.FasComment: case ElementDescriptorType.Link: case ElementDescriptorType.Phone: case ElementDescriptorType.VideoLink: case ElementDescriptorType.Color: throw new NotSupportedException($"Specified element descriptor type '{elementDescriptorType}' is non-binary"); default: throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type"); } }
public void TestSvgValidationCheck() { var constraints = new VectorImageElementConstraints(); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); TestHelpers.MakeBinaryValidationCheck( "<svg><title /><style></style><metadata /><defs /></svg>", TestAction); TestHelpers.MakeBinaryValidationCheck <InvalidImageError>( "svg", TestAction, nameof(IImageElementConstraints.ValidImage)); TestHelpers.MakeBinaryValidationCheck <InvalidImageError>( string.Empty, TestAction, nameof(IImageElementConstraints.ValidImage)); }
public void TestSvgWithNonRenderedElements(string svgElementName) { var constraints = new VectorImageElementConstraints(); const string ExpectedErrorType = nameof(VectorImageElementConstraints.WithoutNonRenderedElements); void TestAction(int templateCode, Stream stream) => VectorImageValidator.ValidateVectorImage(templateCode, FileFormat.Svg, constraints, stream); TestHelpers.MakeBinaryValidationCheck <ImageWithNonRenderedElementsError>( string.Format(SvgTemplate, $"<{svgElementName} />"), TestAction, ExpectedErrorType); var error = TestHelpers.MakeBinaryValidationCheck <ImageWithNonRenderedElementsError>( string.Format(SvgTemplate, $"<g><path /><{svgElementName} /><{svgElementName} /></g>"), TestAction, ExpectedErrorType); Assert.Single(error.NonRenderedElements); Assert.Equal(svgElementName.ToLowerInvariant(), error.NonRenderedElements.First()); }
private static string EnsureFileContentIsValid( int templateCode, string fileName, ElementDescriptorType elementDescriptorType, IElementConstraints elementConstraints, Stream inputStream) { switch (elementDescriptorType) { case ElementDescriptorType.BitmapImage: return(BitmapImageValidator.ValidateBitmapImage(templateCode, (BitmapImageElementConstraints)elementConstraints, inputStream)); case ElementDescriptorType.VectorImage: { var fileFormat = DetectFileFormat(fileName); VectorImageValidator.ValidateVectorImage(templateCode, fileFormat, (VectorImageElementConstraints)elementConstraints, inputStream); return(ContentTypesMap[fileFormat]); } case ElementDescriptorType.Article: ArticleValidator.ValidateArticle(templateCode, inputStream); return(ContentTypesMap[FileFormat.Chm]); case ElementDescriptorType.PlainText: case ElementDescriptorType.FormattedText: case ElementDescriptorType.FasComment: case ElementDescriptorType.Link: case ElementDescriptorType.Phone: case ElementDescriptorType.VideoLink: case ElementDescriptorType.Color: throw new NotSupportedException($"Not binary element descriptor type {elementDescriptorType}"); default: throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type"); } }