-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fixing MCGRIDINFO definition #2911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RussKie
merged 1 commit into
dotnet:master
from
vladimir-krestov:dev/v-vlkres/MonthCalendarNullReferenceException
Mar 24, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/Common/tests/InternalUtilitiesForTests/src/ArchitectureDetection.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace System | ||
{ | ||
public static class ArchitectureDetection | ||
{ | ||
public static bool Is32bit => IntPtr.Size == 4; | ||
public static bool Is64bit => IntPtr.Size == 8; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/System.Windows.Forms.Primitives/tests/Interop/ComCtl32/MCGRIDINFOTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
using Xunit; | ||
using static Interop.ComCtl32; | ||
|
||
namespace System.Windows.Forms.Primitives.Tests.Interop.ComCtl32 | ||
{ | ||
public class MCGRIDINFOTests : IClassFixture<ThreadExceptionFixture> | ||
{ | ||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] | ||
public unsafe void MCGRIDINFO_x32_Size() | ||
{ | ||
Assert.Equal(84, sizeof(MCGRIDINFO)); | ||
} | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] | ||
public unsafe void MCGRIDINFO_x32_Marshal_Size() | ||
{ | ||
Assert.Equal(84, Marshal.SizeOf<MCGRIDINFO>()); | ||
} | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] | ||
public unsafe void MCGRIDINFO_x32_ensure_layout() | ||
{ | ||
MCGRIDINFO sut = new MCGRIDINFO(); | ||
byte* addr = (byte*)&sut; | ||
|
||
Assert.Equal(0, (byte*)&sut.cbSize - addr); // 4, UINT | ||
Assert.Equal(4, (byte*)&sut.dwPart - addr); // 4, DWORD | ||
Assert.Equal(8, (byte*)&sut.dwFlags - addr); // 4, DWORD | ||
Assert.Equal(12, (byte*)&sut.iCalendar - addr); // 4, int | ||
Assert.Equal(16, (byte*)&sut.iRow - addr); // 4, int | ||
Assert.Equal(20, (byte*)&sut.iCol - addr); // 4, int | ||
Assert.Equal(24, (byte*)&sut.bSelected - addr); // 4, BOOL | ||
Assert.Equal(28, (byte*)&sut.stStart - addr); // 16, SYSTEMTIME | ||
Assert.Equal(44, (byte*)&sut.stEnd - addr); // 16, SYSTEMTIME | ||
Assert.Equal(60, (byte*)&sut.rc - addr); // 16, RECT | ||
Assert.Equal(76, (byte*)&sut.pszName - addr); // 4, PWSTR | ||
Assert.Equal(80, (byte*)&sut.cchName - addr); // 4, size_t | ||
} | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is32bit))] | ||
public void MCGRIDINFO_x32_Marshal_OffsetOf_IsCorrect() | ||
{ | ||
Assert.Equal(0, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.cbSize))); // 4, UINT | ||
Assert.Equal(4, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.dwPart))); // 4, DWORD | ||
Assert.Equal(8, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.dwFlags))); // 4, DWORD | ||
Assert.Equal(12, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.iCalendar))); // 4, int | ||
Assert.Equal(16, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.iRow))); // 4, int | ||
Assert.Equal(20, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.iCol))); // 4, int | ||
Assert.Equal(24, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.bSelected))); // 4, BOOL | ||
Assert.Equal(28, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.stStart))); // 16, SYSTEMTIME | ||
Assert.Equal(44, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.stEnd))); // 16, SYSTEMTIME | ||
Assert.Equal(60, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.rc))); // 16, RECT | ||
Assert.Equal(76, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.pszName))); // 8, PWSTR | ||
Assert.Equal(80, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.cchName))); // 8, size_t | ||
} | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is64bit))] | ||
public unsafe void MCGRIDINFO_x64_Size() | ||
{ | ||
Assert.Equal(96, sizeof(MCGRIDINFO)); | ||
} | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is64bit))] | ||
public void MCGRIDINFO_x64_Marshal_Size() | ||
{ | ||
Assert.Equal(96, Marshal.SizeOf<MCGRIDINFO>()); | ||
} | ||
|
||
private bool a = ArchitectureDetection.Is64bit; | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is64bit))] | ||
public unsafe void MCGRIDINFO_x64_ensure_layout() | ||
{ | ||
MCGRIDINFO sut = new MCGRIDINFO(); | ||
byte* addr = (byte*)&sut; | ||
|
||
Assert.Equal(0, (byte*)&sut.cbSize - addr); // 4, UINT | ||
Assert.Equal(4, (byte*)&sut.dwPart - addr); // 4, DWORD | ||
Assert.Equal(8, (byte*)&sut.dwFlags - addr); // 4, DWORD | ||
Assert.Equal(12, (byte*)&sut.iCalendar - addr); // 4, int | ||
Assert.Equal(16, (byte*)&sut.iRow - addr); // 4, int | ||
Assert.Equal(20, (byte*)&sut.iCol - addr); // 4, int | ||
Assert.Equal(24, (byte*)&sut.bSelected - addr); // 4, BOOL | ||
Assert.Equal(28, (byte*)&sut.stStart - addr); // 16, SYSTEMTIME | ||
Assert.Equal(44, (byte*)&sut.stEnd - addr); // 16, SYSTEMTIME | ||
Assert.Equal(60, (byte*)&sut.rc - addr); // 16, RECT | ||
// 4 bytes alignment 76 -> 80 | ||
Assert.Equal(80, (byte*)&sut.pszName - addr); // 8, PWSTR | ||
Assert.Equal(88, (byte*)&sut.cchName - addr); // 8, size_t | ||
} | ||
|
||
[ConditionalFact(typeof(ArchitectureDetection), nameof(ArchitectureDetection.Is64bit))] | ||
public void MCGRIDINFO_x64_Marshal_OffsetOf_IsCorrect() | ||
{ | ||
Assert.Equal(0, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.cbSize))); // 4, UINT | ||
Assert.Equal(4, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.dwPart))); // 4, DWORD | ||
Assert.Equal(8, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.dwFlags))); // 4, DWORD | ||
Assert.Equal(12, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.iCalendar))); // 4, int | ||
Assert.Equal(16, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.iRow))); // 4, int | ||
Assert.Equal(20, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.iCol))); // 4, int | ||
Assert.Equal(24, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.bSelected))); // 4, BOOL | ||
Assert.Equal(28, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.stStart))); // 16, SYSTEMTIME | ||
Assert.Equal(44, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.stEnd))); // 16, SYSTEMTIME | ||
Assert.Equal(60, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.rc))); // 16, RECT | ||
// 4 bytes alignment 76 -> 80 | ||
Assert.Equal(80, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.pszName))); // 8, PWSTR | ||
Assert.Equal(88, (int)Marshal.OffsetOf<MCGRIDINFO>(nameof(MCGRIDINFO.cchName))); // 8, size_t | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.