-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #923 from microsoft/fix913
Recognize `MemorySizeAttribute` in metadata to improve friendly overloads
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
38 changes: 38 additions & 0 deletions
38
test/Microsoft.Windows.CsWin32.Tests/FriendlyOverloadTests.cs
This file contains 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,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
public class FriendlyOverloadTests : GeneratorTestBase | ||
{ | ||
public FriendlyOverloadTests(ITestOutputHelper logger) | ||
: base(logger) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public void WriteFile() | ||
{ | ||
const string name = "WriteFile"; | ||
this.Generate(name); | ||
Assert.Contains(this.FindGeneratedMethod(name), m => m.ParameterList.Parameters.Count == 4); | ||
} | ||
|
||
[Fact] | ||
public void SHGetFileInfo() | ||
{ | ||
// This method uses MemorySize but for determining the size of a struct that another parameter points to. | ||
// We cannot know the size of that, since it may be a v1 struct, a v2 struct, etc. | ||
// So assert that no overload has fewer parameters. | ||
const string name = "SHGetFileInfo"; | ||
this.Generate(name); | ||
Assert.All(this.FindGeneratedMethod(name), m => Assert.Equal(5, m.ParameterList.Parameters.Count)); | ||
} | ||
|
||
private void Generate(string name) | ||
{ | ||
this.compilation = this.compilation.WithOptions(this.compilation.Options.WithPlatform(Platform.X64)); | ||
this.generator = this.CreateGenerator(); | ||
Assert.True(this.generator.TryGenerate(name, CancellationToken.None)); | ||
this.CollectGeneratedCode(this.generator); | ||
this.AssertNoDiagnostics(); | ||
} | ||
} |