The image tests here are limited to loading and integration tests, not visual tests, which
you can find in DeltaEngine.Rendering2D.Tests.SpriteTests.
View code on GitHub
Inheritance Hierarchy
DeltaEngine.Platforms TestWithMocksOrVisually
DeltaEngine.Graphics.Tests ImageTests
Namespace: DeltaEngine.Graphics.Tests
Assembly: DeltaEngine.Graphics.Tests (in DeltaEngine.Graphics.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax
The ImageTests type exposes the following members.
Constructors
Name | Description | |
---|---|---|
ImageTests | Initializes a new instance of the ImageTests class |
Methods
Name | Description | |
---|---|---|
AdvanceTimeAndUpdateEntities | (Inherited from TestWithMocksOrVisually.) | |
BlendModes | ||
CreatingTwoImagesWithTheSameDataAlwaysResultsInDifferentImages | ||
DrawCustomImageFromBytes | ||
DrawCustomImageFromColorClickToChangeIt | ||
DrawCustomImageHalfRedHalfGold |
From http://forum.deltaengine.net/yaf_postsm6203_Dynamic-textures---v--0-9-8-2.aspx#post6203
View code on GitHub | |
DrawCustomImageHalfTransparent | ||
DrawDefaultTexture | ||
DrawOpaqueImageWithVertexColors | ||
FillCustomImageWitDifferentSizeThanImageCausesException | ||
InitializeResolver | (Inherited from TestWithMocksOrVisually.) | |
LoadExistingImage | ||
RegisterMock T | (Inherited from TestWithMocksOrVisually.) | |
Resolve T | (Inherited from TestWithMocksOrVisually.) | |
RunAfterFirstFrame | (Inherited from TestWithMocksOrVisually.) | |
RunTestAndDisposeResolverWhenDone | (Inherited from TestWithMocksOrVisually.) | |
ShouldThrowIfImageNotLoadedWithDebuggerAttached |
Properties
Name | Description | |
---|---|---|
IsMockResolver | (Inherited from TestWithMocksOrVisually.) |
Examples
[Test, ApproveFirstFrameScreenshot] public void DrawOpaqueImageWithVertexColors() { Resolve<Window>().BackgroundColor = Color.CornflowerBlue; new ColoredSprite(ContentLoader.Load<Image>("DeltaEngineLogoOpaque")); RunAfterFirstFrame( () => Assert.AreEqual(4, Resolve<Drawing>().NumberOfDynamicVerticesDrawnThisFrame)); }
[Test, CloseAfterFirstFrame] public void LoadExistingImage() { var image = ContentLoader.Load<Image>("DeltaEngineLogoOpaque"); Assert.AreEqual("DeltaEngineLogoOpaque", image.Name); Assert.IsFalse(image.IsDisposed); Assert.AreEqual(new Size(128, 128), image.PixelSize); }
[Test, CloseAfterFirstFrame] public void ShouldThrowIfImageNotLoadedWithDebuggerAttached() { //ncrunch: no coverage start if (Debugger.IsAttached) Assert.Throws<ContentLoader.ContentNotFound>( () => ContentLoader.Load<Image>("UnavailableImage")); //ncrunch: no coverage end }
[Test, ApproveFirstFrameScreenshot] public void DrawDefaultTexture() { Resolve<Window>().BackgroundColor = Color.CornflowerBlue; new ColoredSprite(ContentLoader.Load<Image>("UnavailableImage")); RunAfterFirstFrame( () => Assert.AreEqual(4, Resolve<Drawing>().NumberOfDynamicVerticesDrawnThisFrame)); }
[Test, ApproveFirstFrameScreenshot] public void DrawCustomImageFromColorClickToChangeIt() { var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(8, 8))); customImage.Fill(Color.Purple); new SolidSprite(customImage); new Command(Command.Click, () => customImage.Fill(Color.GetRandomColor())); }
[Test, ApproveFirstFrameScreenshot] public void DrawCustomImageFromBytes() { var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(8, 8))); var bytes = new byte[8 * 8 * 4]; var color = Color.Purple; for (int i = 0; i < 8 * 8; i++) { bytes[i * 4] = color.R; bytes[i * 4 + 1] = color.G; bytes[i * 4 + 2] = color.B; } customImage.FillRgbaData(bytes); new SolidSprite(customImage); }
/// <summary> /// From http://forum.deltaengine.net/yaf_postsm6203_Dynamic-textures---v--0-9-8-2.aspx#post6203 /// </summary> [Test, ApproveFirstFrameScreenshot] public void DrawCustomImageHalfRedHalfGold() { var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(64, 64))); var colors = new Color[64 * 64]; for (int i = 0; i < colors.Length; i++) colors[i] = i < colors.Length / 2 ? Color.Red : Color.Gold; customImage.Fill(colors); new SolidSprite(customImage); }
[Test, ApproveFirstFrameScreenshot] public void DrawCustomImageHalfTransparent() { Resolve<Window>().BackgroundColor = Color.Yellow; var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(64, 64))); customImage.Fill(new Color(0, 0, 0, 0.5f)); customImage.BlendMode = BlendMode.Normal; new SolidSprite(customImage); }
[Test, CloseAfterFirstFrame] public void FillCustomImageWitDifferentSizeThanImageCausesException() { var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(8, 9))); var colors = new Color[8 * 8]; Assert.Throws<Image.InvalidNumberOfColors>(() => customImage.Fill(colors)); var byteArray = new byte[8 * 8]; Assert.Throws<Image.InvalidNumberOfBytes>(() => customImage.FillRgbaData(byteArray)); var goodByteArray = new byte[8 * 9 * 4]; customImage.FillRgbaData(goodByteArray); }
[Test, CloseAfterFirstFrame] public void CreatingTwoImagesWithTheSameDataAlwaysResultsInDifferentImages() { var data1 = new ImageCreationData(new Size(4, 4)); var data2 = new ImageCreationData(new Size(4, 4)); Assert.AreNotEqual(data1, data2); var image1 = ContentLoader.Create<Image>(data1); var image2 = ContentLoader.Create<Image>(data2); Assert.AreEqual(image1.PixelSize, image2.PixelSize); Assert.AreEqual(image1.BlendMode, image2.BlendMode); Assert.AreNotEqual(image1, image2); }
[Test, ApproveFirstFrameScreenshot] public void BlendModes() { new DrawableEntity().OnDraw<RenderBlendModes>(); }
See Also