[System.Drawing.Common] Relax IconTests.CorrectColorDepthExtracted test (dotnet/coref...
authorFilip Navara <filip.navara@gmail.com>
Thu, 3 Oct 2019 01:19:22 +0000 (03:19 +0200)
committerStephen Toub <stoub@microsoft.com>
Thu, 3 Oct 2019 01:19:22 +0000 (21:19 -0400)
* [System.Drawing.Common] Relax IconTests.CorrectColorDepthExtracted to work on newer libgdiplus on Unix

* Address PR comment

Commit migrated from https://github.com/dotnet/corefx/commit/a50e056c5a62fb6dfe2e9475be47b93d33661700

src/libraries/System.Drawing.Common/tests/IconTests.cs

index 6263f93..40489ae 100644 (file)
@@ -861,8 +861,23 @@ namespace System.Drawing.Tests
                         switch (expectedBitDepth)
                         {
                             case 32:
-                                Assert.Equal(0x879EE532u, (uint)bitmap.GetPixel(0, 0).ToArgb());
-                                Assert.Equal(0x661CD8B7u, (uint)bitmap.GetPixel(0, 31).ToArgb());
+                                if (!PlatformDetection.IsWindows)
+                                {
+                                    // libgdiplus on Unix doesn't natively support ARGB32 format. It
+                                    // uses the Cairo library which represents the bitmaps as PARGB32
+                                    // with individual channels premultiplied with the alpha channel.
+                                    // When converting back and forth it results in slight loss of
+                                    // precision so allow both original and rounded values here.
+                                    uint color = (uint)bitmap.GetPixel(0, 0).ToArgb();
+                                    Assert.True(color == 0x879EE532u || color == 0x879EE431u, color.ToString("x"));
+                                    color = (uint)bitmap.GetPixel(0, 31).ToArgb();
+                                    Assert.True(color == 0x661CD8B7u || color == 0x661BD7B6u, color.ToString("x"));
+                                }
+                                else
+                                {
+                                    Assert.Equal(0x879EE532u, (uint)bitmap.GetPixel(0, 0).ToArgb());
+                                    Assert.Equal(0x661CD8B7u, (uint)bitmap.GetPixel(0, 31).ToArgb());
+                                }
                                 break;
                             case 16:
                             case 8: