-
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 #586 from microsoft/fix585
Add interop helpers to BOOLEAN
- Loading branch information
Showing
8 changed files
with
196 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
partial struct BOOL | ||
{ | ||
internal unsafe BOOL(bool value) => this.Value = *(sbyte*)&value; | ||
public static unsafe implicit operator bool(BOOL value) | ||
{ | ||
sbyte v = checked((sbyte)value.Value); | ||
return *(bool*)&v; | ||
} | ||
|
||
public static implicit operator BOOL(bool value) => new BOOL(value); | ||
} |
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,11 @@ | ||
partial struct BOOLEAN | ||
{ | ||
internal unsafe BOOLEAN(bool value) => this.Value = *(byte*)&value; | ||
public static unsafe implicit operator bool(BOOLEAN value) | ||
{ | ||
byte v = checked((byte)value.Value); | ||
return *(bool*)&v; | ||
} | ||
|
||
public static implicit operator BOOLEAN(bool value) => new BOOLEAN(value); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Windows.Win32.Foundation; | ||
|
||
public class BoolTests | ||
{ | ||
[Fact] | ||
public void Bool() | ||
{ | ||
BOOL b = true; | ||
bool b2 = b; | ||
Assert.True(b); | ||
Assert.True(b2); | ||
|
||
Assert.False(default(BOOL)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(3)] | ||
[InlineData(-1)] | ||
public void NotLossyConversionBetweenBoolAndBOOL(int ordinal) | ||
{ | ||
BOOL nativeBool = new BOOL(ordinal); | ||
bool managedBool = nativeBool; | ||
BOOL roundtrippedNativeBool = managedBool; | ||
Assert.Equal(nativeBool, roundtrippedNativeBool); | ||
} | ||
|
||
[Theory] | ||
[InlineData(3)] | ||
[InlineData(-1)] | ||
public void NotLossyConversionBetweenBoolAndBOOL_Ctors(int ordinal) | ||
{ | ||
BOOL nativeBool = new BOOL(ordinal); | ||
bool managedBool = nativeBool; | ||
BOOL roundtrippedNativeBool = new BOOL(managedBool); | ||
Assert.Equal(nativeBool, roundtrippedNativeBool); | ||
} | ||
|
||
[Fact] | ||
public void BOOLEqualsComparesExactValue() | ||
{ | ||
BOOL b1 = new BOOL(1); | ||
BOOL b2 = new BOOL(2); | ||
Assert.Equal(b1, b1); | ||
Assert.NotEqual(b1, b2); | ||
} | ||
|
||
[Fact] | ||
public void BOOL_OverridesEqualityOperator() | ||
{ | ||
var @true = new BOOL(true); | ||
var @false = new BOOL(false); | ||
Assert.True(@true == new BOOL(true)); | ||
Assert.False(@true != new BOOL(true)); | ||
Assert.True(@true != @false); | ||
Assert.False(@true == @false); | ||
} | ||
} |
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,60 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Windows.Win32.Foundation; | ||
|
||
public class BooleanTests | ||
{ | ||
[Fact] | ||
public void Boolean() | ||
{ | ||
BOOLEAN b = true; | ||
bool b2 = b; | ||
Assert.True(b); | ||
Assert.True(b2); | ||
|
||
Assert.False(default(BOOLEAN)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(3)] | ||
[InlineData(0xff)] | ||
public void NotLossyConversionBetweenBoolAndBOOLEAN(byte ordinal) | ||
{ | ||
BOOLEAN nativeBool = new BOOLEAN(ordinal); | ||
bool managedBool = nativeBool; | ||
BOOLEAN roundtrippedNativeBool = managedBool; | ||
Assert.Equal(nativeBool, roundtrippedNativeBool); | ||
} | ||
|
||
[Theory] | ||
[InlineData(3)] | ||
[InlineData(0xff)] | ||
public void NotLossyConversionBetweenBoolAndBOOLEAN_Ctors(byte ordinal) | ||
{ | ||
BOOLEAN nativeBool = new BOOLEAN(ordinal); | ||
bool managedBool = nativeBool; | ||
BOOLEAN roundtrippedNativeBool = new BOOLEAN(managedBool); | ||
Assert.Equal(nativeBool, roundtrippedNativeBool); | ||
} | ||
|
||
[Fact] | ||
public void BOOLEANEqualsComparesExactValue() | ||
{ | ||
BOOLEAN b1 = new BOOLEAN(1); | ||
BOOLEAN b2 = new BOOLEAN(2); | ||
Assert.Equal(b1, b1); | ||
Assert.NotEqual(b1, b2); | ||
} | ||
|
||
[Fact] | ||
public void BOOLEAN_OverridesEqualityOperator() | ||
{ | ||
var @true = new BOOLEAN(true); | ||
var @false = new BOOLEAN(false); | ||
Assert.True(@true == new BOOLEAN(true)); | ||
Assert.False(@true != new BOOLEAN(true)); | ||
Assert.True(@true != @false); | ||
Assert.False(@true == @false); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
BOOL | ||
BOOLEAN | ||
CHAR | ||
CreateCursor | ||
CreateFile | ||
|
Oops, something went wrong.