Winforms: Test failure ListView_Handle_GetTextBackColor_Success in 32 bit

Created on 28 May 2020  路  7Comments  路  Source: dotnet/winforms

.NET Core Version:
github master

Have you experienced this same bug with .NET Framework?:
n/a

Problem description:
ListView_Handle_GetTextBackColor_Success fails in VS when running the 32 bit test runner, don't know why it doesn't fail in CI, I thought it used both 32 bit and 64 bit test runner?

System.OverflowException: 'Arithmetic operation resulted in an overflow.'
This exception was originally thrown at this call stack:
    System.IntPtr.explicit operator System.IntPtr(long)
    System.Windows.Forms.Tests.ListViewTests.ListView_Handle_GetTextBackColor_Success() in ListViewTests.cs

I think (IntPtr)0xFFFFFFFF is invalid in 32 bit

Expected behavior:

  • CI should recognize the test failure without the fix
  • Test gets fixed

Minimal repro:
Execute the test in VS with 32 bit test runner checked

infra test-bug

Most helpful comment

Taking a peek. I'll use some Learning Day time to learn about your WOW64 issues :)

All 7 comments

@RussKie PR for test fix is trivial but I'd like to know whats wrong with CI, is it by design that this doesn't run tests in 32 bit?

@MattGal is this something you could help us with?

As @weltkante pointed our tests may not be running as true 32-bit processes.
image

I'm guessing 32-bit SDK needs to be installed, but I'm not sure how to do that in the CI.

Taking a peek. I'll use some Learning Day time to learn about your WOW64 issues :)

Actually this is less obvious to fix than I thought, the quickest solution I can come up with is ugly: Environment.Is64BitProcess ? (IntPtr)0xFFFFFFFF : (IntPtr)(-1) because 0xFFFFFFFF is no valid 32 bit IntPtr but -1 is sign extended and differs from the expected value in 64 bit.

Technically this would call for an UIntPtr so maybe you can get the right constant with enough casts.

I'm seeing if this'd work:

diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs
index 7106fffd2..a29df340b 100644
--- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs
+++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ListViewTests.cs
@@ -1620,7 +1620,7 @@ namespace System.Windows.Forms.Tests
         {
             using var control = new ListView();
             Assert.NotEqual(IntPtr.Zero, control.Handle);
-            Assert.Equal((IntPtr)0xFFFFFFFF, User32.SendMessageW(control.Handle, (User32.WM)LVM.GETTEXTBKCOLOR));
+            Assert.Equal(IntPtr.MaxValue, User32.SendMessageW(control.Handle, (User32.WM)LVM.GETTEXTBKCOLOR));
         }

Doesn't work as is:

    System.Windows.Forms.Tests.ListViewTests.ListView_Handle_GetTextBackColor_Success [FAIL]
      Assert.Equal() Failure
      Expected: 9223372036854775807
      Actual:   4294967295

I guess we'd need to use the ugly version

Thank you @weltkante, I had a few goes at it, but ultimately converged to your suggestion

Was this page helpful?
0 / 5 - 0 ratings