1+ #pragma warning disable CA1416
2+
13using LiveLingo . Desktop . Platform ;
24using LiveLingo . Desktop . Platform . macOS ;
35
46namespace LiveLingo . Desktop . Tests . Platform ;
57
68public class MacNativeMethodsTests
79{
10+ private static bool SkipIfNotMac ( ) => ! OperatingSystem . IsMacOS ( ) ;
11+
812 #region MapKeyToCGKeyCode
913
1014 [ Theory ]
@@ -36,6 +40,7 @@ public class MacNativeMethodsTests
3640 [ InlineData ( "M" , 0x2E ) ]
3741 public void MapKeyToCGKeyCode_Letters ( string key , ushort expected )
3842 {
43+ if ( SkipIfNotMac ( ) ) return ;
3944 Assert . Equal ( expected , MacNativeMethods . MapKeyToCGKeyCode ( key ) ) ;
4045 }
4146
@@ -52,6 +57,7 @@ public void MapKeyToCGKeyCode_Letters(string key, ushort expected)
5257 [ InlineData ( "9" , 0x19 ) ]
5358 public void MapKeyToCGKeyCode_Digits ( string key , ushort expected )
5459 {
60+ if ( SkipIfNotMac ( ) ) return ;
5561 Assert . Equal ( expected , MacNativeMethods . MapKeyToCGKeyCode ( key ) ) ;
5662 }
5763
@@ -64,6 +70,7 @@ public void MapKeyToCGKeyCode_Digits(string key, ushort expected)
6470 [ InlineData ( "ESC" , 0x35 ) ]
6571 public void MapKeyToCGKeyCode_SpecialKeys ( string key , ushort expected )
6672 {
73+ if ( SkipIfNotMac ( ) ) return ;
6774 Assert . Equal ( expected , MacNativeMethods . MapKeyToCGKeyCode ( key ) ) ;
6875 }
6976
@@ -82,12 +89,14 @@ public void MapKeyToCGKeyCode_SpecialKeys(string key, ushort expected)
8289 [ InlineData ( "F12" , 0x6F ) ]
8390 public void MapKeyToCGKeyCode_FunctionKeys ( string key , ushort expected )
8491 {
92+ if ( SkipIfNotMac ( ) ) return ;
8593 Assert . Equal ( expected , MacNativeMethods . MapKeyToCGKeyCode ( key ) ) ;
8694 }
8795
8896 [ Fact ]
8997 public void MapKeyToCGKeyCode_CaseInsensitive ( )
9098 {
99+ if ( SkipIfNotMac ( ) ) return ;
91100 Assert . Equal ( MacNativeMethods . MapKeyToCGKeyCode ( "T" ) , MacNativeMethods . MapKeyToCGKeyCode ( "t" ) ) ;
92101 Assert . Equal ( MacNativeMethods . MapKeyToCGKeyCode ( "SPACE" ) , MacNativeMethods . MapKeyToCGKeyCode ( "space" ) ) ;
93102 }
@@ -98,6 +107,7 @@ public void MapKeyToCGKeyCode_CaseInsensitive()
98107 [ InlineData ( "F20" ) ]
99108 public void MapKeyToCGKeyCode_UnknownReturns0xFFFF ( string key )
100109 {
110+ if ( SkipIfNotMac ( ) ) return ;
101111 Assert . Equal ( ( ushort ) 0xFFFF , MacNativeMethods . MapKeyToCGKeyCode ( key ) ) ;
102112 }
103113
@@ -108,40 +118,46 @@ public void MapKeyToCGKeyCode_UnknownReturns0xFFFF(string key)
108118 [ Fact ]
109119 public void CGEventFlagsToModifiers_None ( )
110120 {
121+ if ( SkipIfNotMac ( ) ) return ;
111122 Assert . Equal ( KeyModifiers . None , MacNativeMethods . CGEventFlagsToModifiers ( 0 ) ) ;
112123 }
113124
114125 [ Fact ]
115126 public void CGEventFlagsToModifiers_Control ( )
116127 {
128+ if ( SkipIfNotMac ( ) ) return ;
117129 var mods = MacNativeMethods . CGEventFlagsToModifiers ( MacNativeMethods . kCGEventFlagMaskControl ) ;
118130 Assert . Equal ( KeyModifiers . Ctrl , mods ) ;
119131 }
120132
121133 [ Fact ]
122134 public void CGEventFlagsToModifiers_Alt ( )
123135 {
136+ if ( SkipIfNotMac ( ) ) return ;
124137 var mods = MacNativeMethods . CGEventFlagsToModifiers ( MacNativeMethods . kCGEventFlagMaskAlternate ) ;
125138 Assert . Equal ( KeyModifiers . Alt , mods ) ;
126139 }
127140
128141 [ Fact ]
129142 public void CGEventFlagsToModifiers_Shift ( )
130143 {
144+ if ( SkipIfNotMac ( ) ) return ;
131145 var mods = MacNativeMethods . CGEventFlagsToModifiers ( MacNativeMethods . kCGEventFlagMaskShift ) ;
132146 Assert . Equal ( KeyModifiers . Shift , mods ) ;
133147 }
134148
135149 [ Fact ]
136150 public void CGEventFlagsToModifiers_Command ( )
137151 {
152+ if ( SkipIfNotMac ( ) ) return ;
138153 var mods = MacNativeMethods . CGEventFlagsToModifiers ( MacNativeMethods . kCGEventFlagMaskCommand ) ;
139154 Assert . Equal ( KeyModifiers . Meta , mods ) ;
140155 }
141156
142157 [ Fact ]
143158 public void CGEventFlagsToModifiers_CtrlAlt ( )
144159 {
160+ if ( SkipIfNotMac ( ) ) return ;
145161 var flags = MacNativeMethods . kCGEventFlagMaskControl | MacNativeMethods . kCGEventFlagMaskAlternate ;
146162 var mods = MacNativeMethods . CGEventFlagsToModifiers ( flags ) ;
147163 Assert . Equal ( KeyModifiers . Ctrl | KeyModifiers . Alt , mods ) ;
@@ -150,6 +166,7 @@ public void CGEventFlagsToModifiers_CtrlAlt()
150166 [ Fact ]
151167 public void CGEventFlagsToModifiers_AllModifiers ( )
152168 {
169+ if ( SkipIfNotMac ( ) ) return ;
153170 var flags = MacNativeMethods . kCGEventFlagMaskControl
154171 | MacNativeMethods . kCGEventFlagMaskAlternate
155172 | MacNativeMethods . kCGEventFlagMaskShift
@@ -161,7 +178,7 @@ public void CGEventFlagsToModifiers_AllModifiers()
161178 [ Fact ]
162179 public void CGEventFlagsToModifiers_IgnoresUnrelatedBits ( )
163180 {
164- // CapsLock (0x10000) and NumPad (0x200000) should be ignored
181+ if ( SkipIfNotMac ( ) ) return ;
165182 ulong flags = 0x00010000 | 0x00200000 | MacNativeMethods . kCGEventFlagMaskControl ;
166183 var mods = MacNativeMethods . CGEventFlagsToModifiers ( flags ) ;
167184 Assert . Equal ( KeyModifiers . Ctrl , mods ) ;
@@ -178,6 +195,7 @@ public void CGEventFlagsToModifiers_IgnoresUnrelatedBits()
178195 public void HotkeyParser_ProducesValidMacBinding (
179196 string input , KeyModifiers expectedMods , string expectedKey , ushort expectedKeyCode )
180197 {
198+ if ( SkipIfNotMac ( ) ) return ;
181199 var binding = HotkeyParser . Parse ( "test" , input ) ;
182200 Assert . Equal ( expectedMods , binding . Modifiers ) ;
183201 Assert . Equal ( expectedKey , binding . Key ) ;
0 commit comments