<commit_before>using Uno;
using Uno.Compiler.ExportTargetInterop;
using Uno.Math;
using Uno.Testing;
using Uno.Threading;
using Fuse;
using Fuse.Controls;
using FuseTest;

namespace DrawRectsTest
{
	using DotNetNative;

	public class DrawRectsTest : TestBase
	{
		[Test]
		public void EmptyPanelIsBlack()
		{
			var p = new Panel();
			var root = TestRootPanel.CreateWithChild(p, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test a "random" pixel (center)
				fb.AssertPixel(float4(0), int2(50, 50));
			}
		}

		[Test]
		public void SolidRectangleWithMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidCachedRectangleWithMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidCachedRectangleWithMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void PanelWithBackgroundAndMarginDrawRectIsRendered()
		{
			var c = new global::UX.PanelWithBackgroundAndMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(0, 1, 0, 1));
			}
		}

		[Test]
		public void CircleWithBackgroundAndMarginDrawRectIsRendered()
		{
			var c = new global::UX.CircleWithBackgroundAndMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(60, 10, 140, 90), 1, float4(0), float4(1));
			}
		}

		[Test]
		public void FrozenPanelWithBackgroundAndMarginDrawRectIsRendered()
		{
			var c = new global::UX.FrozenPanelWithBackgroundAndMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(0, 0, 1, 1));
			}
		}

		[Test]
		public void SolidRectangleWithBlurAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithBlurAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithDesaturateAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithDesaturateAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithDropShadowAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithDropShadowAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 2, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithDuotoneAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithDuotoneAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithHalftoneAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithHalftoneAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithMaskAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithMaskAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void ViewportWithRectangleDrawRectIsRendered()
		{
			var r = new global::UX.ViewportWithRectangle();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void ImageWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.ImageWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(60, 10, 140, 90), 1, float4(1));
			}
		}

		extern(DOTNET) static class MessagePumper
		{
			public static void PumpMessages()
			{
				DotNetNative.Application.DoEvents();
			}
		}

		extern(!DOTNET) static class MessagePumper
		{
			public static void PumpMessages()
			{
				// Do nothing
			}
		}

		[Test]
		public void VideoWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.VideoWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			// Wait until the video is playing before grabbing pixels
			while (!c.IsPlaying)
			{
				root.StepFrame();
				root.TestDraw();
				MessagePumper.PumpMessages();
				Thread.Sleep(16);
			}

			// Step some more frames so the video will start playing
			for (int i = 0; i < 10; i++)
			{
				root.StepFrame();
				root.TestDraw();
				MessagePumper.PumpMessages();
				Thread.Sleep(16);
			}

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(60, 10, 140, 90), 1, float4(float3(0.92f), 1));
			}
		}

		[Test]
		public void Scale9ImageWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.Scale9ImageWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 190, 90), 1, float4(1));
			}
		}

		[Test]
		public void Scale9VideoWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.Scale9VideoWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));
<commit_msg>Ignore video-related draw rect tests on macOS<commit_after>using Uno;
using Uno.Compiler.ExportTargetInterop;
using Uno.Math;
using Uno.Testing;
using Uno.Threading;
using Fuse;
using Fuse.Controls;
using FuseTest;

namespace DrawRectsTest
{
	using DotNetNative;

	public class DrawRectsTest : TestBase
	{
		[Test]
		public void EmptyPanelIsBlack()
		{
			var p = new Panel();
			var root = TestRootPanel.CreateWithChild(p, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test a "random" pixel (center)
				fb.AssertPixel(float4(0), int2(50, 50));
			}
		}

		[Test]
		public void SolidRectangleWithMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidCachedRectangleWithMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidCachedRectangleWithMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void PanelWithBackgroundAndMarginDrawRectIsRendered()
		{
			var c = new global::UX.PanelWithBackgroundAndMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(0, 1, 0, 1));
			}
		}

		[Test]
		public void CircleWithBackgroundAndMarginDrawRectIsRendered()
		{
			var c = new global::UX.CircleWithBackgroundAndMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(60, 10, 140, 90), 1, float4(0), float4(1));
			}
		}

		[Test]
		public void FrozenPanelWithBackgroundAndMarginDrawRectIsRendered()
		{
			var c = new global::UX.FrozenPanelWithBackgroundAndMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(0, 0, 1, 1));
			}
		}

		[Test]
		public void SolidRectangleWithBlurAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithBlurAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithDesaturateAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithDesaturateAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithDropShadowAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithDropShadowAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 2, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithDuotoneAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithDuotoneAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithHalftoneAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithHalftoneAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void SolidRectangleWithMaskAndMarginDrawRectIsRendered()
		{
			var r = new global::UX.SolidRectangleWithMaskAndMargin();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void ViewportWithRectangleDrawRectIsRendered()
		{
			var r = new global::UX.ViewportWithRectangle();
			var root = TestRootPanel.CreateWithChild(r, int2(100, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 90, 90), 1, float4(1));
			}
		}

		[Test]
		public void ImageWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.ImageWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(60, 10, 140, 90), 1, float4(1));
			}
		}

		extern(DOTNET) static class MessagePumper
		{
			public static void PumpMessages()
			{
				DotNetNative.Application.DoEvents();
			}
		}

		extern(!DOTNET) static class MessagePumper
		{
			public static void PumpMessages()
			{
				// Do nothing
			}
		}

		[Test]
		[Ignore("Needs macOS message pump", "OSX")]
		public void VideoWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.VideoWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			// Wait until the video is playing before grabbing pixels
			while (!c.IsPlaying)
			{
				root.StepFrame();
				root.TestDraw();
				MessagePumper.PumpMessages();
				Thread.Sleep(16);
			}

			// Step some more frames so the video will start playing
			for (int i = 0; i < 10; i++)
			{
				root.StepFrame();
				root.TestDraw();
				MessagePumper.PumpMessages();
				Thread.Sleep(16);
			}

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(60, 10, 140, 90), 1, float4(float3(0.92f), 1));
			}
		}

		[Test]
		public void Scale9ImageWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.Scale9ImageWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

			using (var fb = root.CaptureDraw())
			{
				// Test pixel outside of element to ensure it's laid out how we expect
				fb.AssertPixel(float4(0), int2(5, 5));

				TestForDrawRects(fb, new Recti(10, 10, 190, 90), 1, float4(1));
			}
		}

		[Test]
		[Ignore("Needs macOS message pump", "OSX")]
		public void Scale9VideoWithMarginDrawRectIsRendered()
		{
			var c = new global::UX.Scale9VideoWithMargin();
			var root = TestRootPanel.CreateWithChild(c, int2(200, 100));

{'fraction_non_alphanumeric': 0.12656114752071226, 'fraction_numerical': 0.04859651292197354, 'mean_word_length': 3.6453187823090176, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6342369', 'n_tokens_mistral': 7080, 'n_tokens_neox': 5569, 'n_words': 1496}