Skip to content

Commit a79de0d

Browse files
Added test case
1 parent 87e655d commit a79de0d

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<MauiFont Include="Resources\Fonts\**" />
6767
<MauiFont Remove="Resources\Fonts\Dokdo-Regular.ttf" />
6868
<EmbeddedResource Include="Resources\Fonts\Dokdo-Regular.ttf" />
69+
<EmbeddedResource Include="Resources\Images\royals.png" />
6970
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
7071
</ItemGroup>
7172

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Reflection;
2+
using IImage = Microsoft.Maui.Graphics.IImage;
3+
using Microsoft.Maui.Graphics.Platform;
4+
5+
namespace Maui.Controls.Sample.Issues;
6+
7+
8+
[Issue(IssueTracker.Github, 19642, "NullReferenceException when using ImagePaint on Mac/iOS", PlatformAffected.iOS | PlatformAffected.macOS)]
9+
public class Issue19642 : TestContentPage
10+
{
11+
Issue19642_ImagePaintDrawable _drawable;
12+
VerticalStackLayout rootLayout;
13+
Label _descriptionLabel;
14+
15+
protected override void Init()
16+
{
17+
rootLayout = new VerticalStackLayout();
18+
GraphicsView graphicsView = new GraphicsView() { HeightRequest = 500, WidthRequest = 400 };
19+
_drawable = new Issue19642_ImagePaintDrawable();
20+
_descriptionLabel = new Label() { AutomationId = "TestLabel", Text = "The image should be displayed and should not be inverted. If the image is inverted or not displayed, the test has failed." };
21+
22+
graphicsView.Drawable = _drawable;
23+
rootLayout.Add(graphicsView);
24+
rootLayout.Add(_descriptionLabel);
25+
Content = rootLayout;
26+
}
27+
}
28+
29+
internal class Issue19642_ImagePaintDrawable : IDrawable
30+
{
31+
public void Draw(ICanvas canvas, RectF dirtyRect)
32+
{
33+
IImage image;
34+
var assembly = GetType().GetTypeInfo().Assembly;
35+
using (var stream = assembly.GetManifestResourceStream("Controls.TestCases.HostApp.Resources.Images.royals.png"))
36+
{
37+
image = PlatformImage.FromStream(stream);
38+
}
39+
40+
if (image is not null)
41+
{
42+
canvas.SetFillImage(image.Downsize(100));
43+
canvas.FillRectangle(0, 0, 240, 300);
44+
}
45+
}
46+
}
84 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#if TEST_FAILS_ON_MACCATALYST || TEST_FAILS_ON_IOS //Issue link - https://github.com/dotnet/maui/issues/19642
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue19642 : _IssuesUITest
9+
{
10+
public Issue19642(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "NullReferenceException when using ImagePaint on Mac/iOS";
15+
16+
[Test]
17+
[Category(UITestCategories.GraphicsView)]
18+
public void ImagePaintShouldBeDrawn()
19+
{
20+
App.WaitForElement("TestLabel");
21+
VerifyScreenshot();
22+
}
23+
}
24+
#endif

0 commit comments

Comments
 (0)