public void ShouldThrowExceptionWhenGeometryIsNull() { using (IMagickImage image = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("geometry", () => { image.Evaluate(Channels.Red, null, EvaluateOperator.Set, 0.0); }); } }
public void ShouldThrowAnExceptionWhenDifferenceIsNull() { using (IMagickImage image = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("difference", () => { image.Compare(image, new CompareSettings(), null); }); } }
public void ShouldThrowExceptionWhenArgumentsIsNull() { using (IMagickImage image = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("arguments", () => { image.Evaluate(Channels.Red, EvaluateFunction.Arcsin, null); }); } }
public void ShouldThrowAnExceptionWhenImageIsNull() { using (IMagickImage image = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("image", () => { image.Compare(null); }); } }
public void ShouldThrowExceptionWhenColorIsNull() { ExceptionAssert.ThrowsArgumentNullException("color", () => { using (IMagickImage image = new MagickImage(MagickColors.White, 2, 2)) { image.FloodFill((MagickColor)null, 0, 0); } }); }
public void ShouldThrowAnExceptionWhenImageIsNullAndSettingsAreNotNull() { using (IMagickImage image = new MagickImage()) { using (IMagickImage diff = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("image", () => { image.Compare(null, new CompareSettings(), diff); }); } } }
public void ShouldThrowExceptionWhenMappingIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("mapping", () => { pixels.ToByteArray(null); }); } } }
public void ShouldThrowExceptionWhenPixelIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("pixel", () => { pixels.SetPixel((Pixel)null); }); } } }
public void ShouldThrowExceptionWhenByteArrayIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("values", () => { pixels.SetArea(10, 10, 1000, 1000, (byte[])null); }); } } }
public void ShouldThrowExceptionWhenGeometryIsNull() { using (IMagickImage image = new MagickImage(Files.RedPNG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("geometry", () => { pixels.GetArea(null); }); } } }
public void ShouldThrowAnExceptionWhenSettingsIsNull() { using (IMagickImage image = new MagickImage()) { using (IMagickImage diff = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("settings", () => { image.Compare(image, null, diff); }); } } }
public void ShouldThrowExceptionWhenGeometryIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("geometry", () => { pixels.ToShortArray(null, "RGB"); }); } } }
public void ShouldThrowExceptionWhenGeometryIsNullAndMappingIsEnum() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("geometry", () => { pixels.ToByteArray(null, PixelMapping.RGB); }); } } }
public void ShouldThrowAnExceptionWhenImageIsNullAndErrorMetricIsSpecified() { using (IMagickImage image = new MagickImage()) { using (IMagickImage diff = new MagickImage()) { ExceptionAssert.ThrowsArgumentNullException("image", () => { image.Compare(null, ErrorMetric.RootMeanSquared); }); } } }
public void ShouldThrowExceptionWhenGeometryIsSpecifiedAndMappingIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("mapping", () => { pixels.ToShortArray(new MagickGeometry(1, 2, 3, 4), null); }); } } }
public void ShouldThrowExceptionWhenByteArrayIsSpecifiedAndGeometryIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("geometry", () => { pixels.SetArea(null, new byte[] { 0 }); }); } } }
public void Test_Constructor() { PointD point = default(PointD); Assert.AreEqual(0.0, point.X); Assert.AreEqual(0.0, point.Y); point = new PointD(5); Assert.AreEqual(5.0, point.X); Assert.AreEqual(5.0, point.Y); point = new PointD(5, 10); Assert.AreEqual(5.0, point.X); Assert.AreEqual(10.0, point.Y); ExceptionAssert.ThrowsArgumentNullException("value", () => { new PointD(null); }); ExceptionAssert.ThrowsArgumentException("value", () => { new PointD(string.Empty); }); ExceptionAssert.ThrowsArgumentException("value", () => { new PointD("1.0x"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new PointD("x1.0"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new PointD("ax1.0"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new PointD("1.0xb"); }); point = new PointD("1.0x2.5"); Assert.AreEqual(1.0, point.X); Assert.AreEqual(2.5, point.Y); Assert.AreEqual("1x2.5", point.ToString()); }
public void Test_SetEncoding() { using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG)) { IptcProfile profile = image.GetIptcProfile(); TestProfileValues(profile); ExceptionAssert.ThrowsArgumentNullException("encoding", () => { profile.SetEncoding(null); }); profile.SetEncoding(Encoding.UTF8); Assert.AreEqual(Encoding.UTF8, profile.Values.First().Encoding); } }
public void Test_Execute_Variables() { MagickScript script = new MagickScript(Files.Scripts.Variables); string[] names = script.Variables.Names.ToArray(); Assert.AreEqual(4, names.Length); Assert.AreEqual("width", names[0]); Assert.AreEqual("height", names[1]); Assert.AreEqual("color", names[2]); Assert.AreEqual("fillColor", names[3]); using (IMagickImage image = new MagickImage(Files.MagickNETIconPNG)) { ExceptionAssert.ThrowsArgumentNullException("attribute", () => { script.Execute(image); }); script.Variables["width"] = "test"; ExceptionAssert.Throws <FormatException>(() => { script.Execute(image); }); script.Variables.Set("width", 100); ExceptionAssert.ThrowsArgumentNullException("attribute", () => { script.Execute(image); }); script.Variables["height"] = "100"; Assert.AreEqual("100", script.Variables.Get("height")); script.Variables["color"] = MagickColors.Yellow; script.Variables["fillColor"] = MagickColors.Red; script.Execute(image); Assert.AreEqual(100, image.Width); Assert.AreEqual(100, image.Height); ColorAssert.AreEqual(MagickColors.Yellow, image, 0, 0); ColorAssert.AreEqual(MagickColors.Yellow, image.Settings.StrokeColor); ColorAssert.AreEqual(MagickColors.Red, image.Settings.FillColor); } }
public void Test_Constructor() { ExceptionAssert.ThrowsArgumentNullException("color", () => { new MagickColor((string)null); }); ExceptionAssert.ThrowsArgumentException("color", () => { new MagickColor("FFFFFF"); }); ExceptionAssert.ThrowsArgumentException("color", () => { new MagickColor("#FFFFF"); }); ExceptionAssert.ThrowsArgumentException("color", () => { new MagickColor("#GGFFF"); }); ExceptionAssert.ThrowsArgumentException("color", () => { new MagickColor("#FGF"); }); ExceptionAssert.ThrowsArgumentException("color", () => { new MagickColor("#FFFG000000000000"); }); TestColor("#FF", Quantum.Max, Quantum.Max, Quantum.Max, false); TestColor("#F00", Quantum.Max, 0, 0, false); TestColor("#0F00", 0, Quantum.Max, 0, true); TestColor("#0000FF", 0, 0, Quantum.Max, false); TestColor("#FF00FF00", Quantum.Max, 0, Quantum.Max, true); TestColor("#0000FFFF0000", 0, Quantum.Max, 0, false); TestColor("#000080000000", 0, (QuantumType)((Quantum.Max / 2.0) + 0.5), 0, false); TestColor("#FFFf000000000000", Quantum.Max, 0, 0, true); float half = Quantum.Max * 0.5f; TestColor("gray(50%) ", half, half, half, false, 1); TestColor("rgba(100%, 0%, 0%, 0.0)", Quantum.Max, 0, 0, true); }
public void Test_Constructor() { ExceptionAssert.ThrowsArgumentNullException("fileName", () => { new MagickScript((string)null); }); ExceptionAssert.ThrowsArgumentNullException("stream", () => { new MagickScript((Stream)null); }); ExceptionAssert.Throws <DirectoryNotFoundException>(() => { new MagickScript(Files.Missing); }); }
public void Test_Image_Exceptions() { ExceptionAssert.ThrowsArgumentException("readSettings", () => { MagickReadSettings settings = CreateSettings(); settings.PixelStorage.StorageType = StorageType.Undefined; new MagickImage(Files.SnakewarePNG, settings); }); ExceptionAssert.ThrowsArgumentNullException("readSettings", () => { MagickReadSettings settings = CreateSettings(); settings.PixelStorage.Mapping = null; new MagickImage(Files.SnakewarePNG, settings); }); ExceptionAssert.ThrowsArgumentException("readSettings", () => { MagickReadSettings settings = CreateSettings(); settings.PixelStorage.Mapping = string.Empty; new MagickImage(Files.SnakewarePNG, settings); }); ExceptionAssert.ThrowsArgumentNullException("readSettings", () => { MagickReadSettings settings = CreateSettings(); settings.Width = null; new MagickImage(Files.SnakewarePNG, settings); }); ExceptionAssert.ThrowsArgumentNullException("readSettings", () => { MagickReadSettings settings = CreateSettings(); settings.Height = null; new MagickImage(Files.SnakewarePNG, settings); }); ExceptionAssert.ThrowsArgumentException("data", () => { MagickReadSettings settings = CreateSettings(); byte[] data = new byte[] { 0 }; new MagickImage(data, settings); }); }
public void Test_Constructor() { ExceptionAssert.ThrowsArgumentNullException("hash", () => { new PerceptualHash(null); }); ExceptionAssert.ThrowsArgumentException("hash", () => { new PerceptualHash(string.Empty); }); ExceptionAssert.ThrowsArgumentException("hash", () => { new PerceptualHash("a0df"); }); ExceptionAssert.ThrowsArgumentException("hash", () => { new PerceptualHash("H00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); }); }
public void Test_Path_Exceptions() { ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathArcAbs(); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new PathArcAbs(null); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathArcAbs(new PathArc[] { }); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new PathArcAbs(new PathArc[] { null }); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathArcRel(); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new PathArcRel(null); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathArcRel(new PathArc[] { }); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new PathArcRel(new PathArc[] { null }); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathLineToAbs(); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new PathLineToAbs(null); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathLineToAbs(new PointD[] { }); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathLineToRel(); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new PathLineToRel(null); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new PathLineToRel(new PointD[] { }); }); }
public void Test_Constructor() { Density density = new Density(5); Assert.AreEqual(5.0, density.X); Assert.AreEqual(5.0, density.Y); Assert.AreEqual(DensityUnit.PixelsPerInch, density.Units); density = new Density(8.5, DensityUnit.PixelsPerCentimeter); Assert.AreEqual(8.5, density.X); Assert.AreEqual(8.5, density.Y); Assert.AreEqual(DensityUnit.PixelsPerCentimeter, density.Units); density = new Density(2, 3); Assert.AreEqual(2.0, density.X); Assert.AreEqual(3.0, density.Y); Assert.AreEqual(DensityUnit.PixelsPerInch, density.Units); density = new Density(2.2, 3.3, DensityUnit.Undefined); Assert.AreEqual(2.2, density.X); Assert.AreEqual(3.3, density.Y); Assert.AreEqual(DensityUnit.Undefined, density.Units); ExceptionAssert.ThrowsArgumentNullException("value", () => { new Density(null); }); ExceptionAssert.ThrowsArgumentException("value", () => { new Density(string.Empty); }); ExceptionAssert.ThrowsArgumentException("value", () => { new Density("1.0x"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new Density("x1.0"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new Density("ax1.0"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new Density("1.0xb"); }); ExceptionAssert.ThrowsArgumentException("value", () => { new Density("1.0x6 magick"); }); density = new Density("1.0x2.5"); Assert.AreEqual(1.0, density.X); Assert.AreEqual(2.5, density.Y); Assert.AreEqual(DensityUnit.Undefined, density.Units); Assert.AreEqual("1x2.5", density.ToString()); density = new Density("2.5x1.0 cm"); Assert.AreEqual(2.5, density.X); Assert.AreEqual(1.0, density.Y); Assert.AreEqual(DensityUnit.PixelsPerCentimeter, density.Units); Assert.AreEqual("2.5x1 cm", density.ToString()); density = new Density("2.5x1.0 inch"); Assert.AreEqual(2.5, density.X); Assert.AreEqual(1.0, density.Y); Assert.AreEqual(DensityUnit.PixelsPerInch, density.Units); Assert.AreEqual("2.5x1 inch", density.ToString()); }
public void ShouldThrowExceptionWhenValueIsNull() { ExceptionAssert.ThrowsArgumentNullException("value", () => { new Density(null); }); }
public void ShouldThrowExceptionWhenValueIsNull() { ExceptionAssert.ThrowsArgumentNullException("value", () => new MagickGeometry(null)); }
public void Test_Drawables_Exceptions() { ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawableBezier(); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new DrawableBezier(null); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawableBezier(new PointD[] { }); }); ExceptionAssert.ThrowsArgumentNullException("clipPath", () => { new DrawableClipPath(null); }); ExceptionAssert.ThrowsArgumentException("clipPath", () => { new DrawableClipPath(string.Empty); }); ExceptionAssert.ThrowsArgumentNullException("offset", () => { new DrawableComposite(null, new MagickImage(Files.Builtin.Logo)); }); ExceptionAssert.ThrowsArgumentNullException("image", () => { new DrawableComposite(new MagickGeometry(), null); }); ExceptionAssert.ThrowsArgumentNullException("color", () => { new DrawableFillColor(null); }); ExceptionAssert.ThrowsArgumentNullException("family", () => { new DrawableFont(null); }); ExceptionAssert.ThrowsArgumentException("family", () => { new DrawableFont(string.Empty); }); ExceptionAssert.Throws <MagickDrawErrorException>(() => { using (IMagickImage image = new MagickImage(Files.Builtin.Wizard)) { image.Draw(new DrawableFillPatternUrl("#fail")); } }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawablePolygon(new PointD[] { new PointD(0, 0) }); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawablePolyline(new PointD[] { new PointD(0, 0), new PointD(0, 0) }); }); ExceptionAssert.ThrowsArgumentNullException("color", () => { new DrawableStrokeColor(null); }); ExceptionAssert.ThrowsArgumentNullException("value", () => { new DrawableText(0, 0, null); }); ExceptionAssert.ThrowsArgumentException("value", () => { new DrawableText(0, 0, string.Empty); }); ExceptionAssert.ThrowsArgumentNullException("encoding", () => { new DrawableTextEncoding(null); }); }
public void Test_SetValue() { using (MemoryStream memStream = new MemoryStream()) { string credit = null; for (int i = 0; i < 255; i++) { credit += i.ToString() + "."; } using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG)) { IptcProfile profile = image.GetIptcProfile(); TestProfileValues(profile); IptcValue value = profile.GetValue(IptcTag.Title); TestValue(value, "Communications"); profile.SetValue(IptcTag.Title, "Magick.NET Title"); TestValue(value, "Magick.NET Title"); value = profile.GetValue(IptcTag.Title); TestValue(value, "Magick.NET Title"); value = profile.Values.FirstOrDefault(val => val.Tag == IptcTag.ReferenceNumber); Assert.IsNull(value); profile.SetValue(IptcTag.ReferenceNumber, "Magick.NET ReferenceNümber"); value = profile.GetValue(IptcTag.ReferenceNumber); TestValue(value, "Magick.NET ReferenceNümber"); profile.SetValue(IptcTag.Credit, credit); value = profile.GetValue(IptcTag.Credit); TestValue(value, credit); // Remove the 8bim profile so we can overwrite the iptc profile. image.RemoveProfile("8bim"); image.AddProfile(profile); image.Write(memStream); memStream.Position = 0; } using (IMagickImage image = new MagickImage(memStream)) { IptcProfile profile = image.GetIptcProfile(); TestProfileValues(profile, 19); IptcValue value = profile.GetValue(IptcTag.Title); TestValue(value, "Magick.NET Title"); value = profile.GetValue(IptcTag.ReferenceNumber); TestValue(value, "Magick.NET ReferenceNümber"); value = profile.GetValue(IptcTag.Credit); TestValue(value, credit); ExceptionAssert.ThrowsArgumentNullException("encoding", () => { profile.SetValue(IptcTag.Caption, null, "Test"); }); profile.SetValue(IptcTag.Caption, "Test"); value = profile.Values.ElementAt(1); Assert.AreEqual("Test", value.Value); profile.SetValue(IptcTag.Caption, Encoding.UTF32, "Test"); Assert.AreEqual(Encoding.UTF32, value.Encoding); Assert.AreEqual("Test", value.Value); Assert.IsTrue(profile.RemoveValue(IptcTag.Caption)); Assert.IsFalse(profile.RemoveValue(IptcTag.Caption)); Assert.IsNull(profile.GetValue(IptcTag.Caption)); } } }