Skip to content

Commit 8d35d64

Browse files
committed
Add test cases to cover constant variables, different integer types, and non-literal integer expressions
1 parent 8ac6d65 commit 8d35d64

File tree

1 file changed

+49
-21
lines changed
  • tests/ClangSharp.PInvokeGenerator.UnitTests

1 file changed

+49
-21
lines changed

tests/ClangSharp.PInvokeGenerator.UnitTests/CTest.cs

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -283,39 +283,67 @@ public static partial class Methods
283283
[Test]
284284
public Task UnsignedIntBitshiftTest()
285285
{
286-
var inputContents = @"#define LEFT 1 << 1U
287-
#define RIGHT 1 >> 1U
288-
#define INT 1 << 1
289-
#define LONG 1 << 1L
290-
#define LONGLONG 1 << 1LL
291-
#define ULONG 1 << 1UL
292-
#define ULONGLONG 1 << 1ULL
286+
var inputContents = @"
287+
const int Signed = 1;
288+
const unsigned int Unsigned = 1U;
289+
290+
const int ShiftSigned = 1 << Signed;
291+
const int ShiftUnsigned = 1 << Unsigned;
292+
293+
const int CInt = 1 << 1;
294+
const int CUint = 1 << 1U;
295+
296+
#define Left 1 << 1U
297+
#define Right 1 >> 1U
298+
#define Int 1 << 1
299+
#define Long 1 << 1L
300+
#define LongLong 1 << 1LL
301+
#define ULong 1 << 1UL
302+
#define ULongLong 1 << 1ULL
293303
";
294304

295305
var expectedOutputContents = @"namespace ClangSharp.Test
296306
{
297307
public static partial class Methods
298308
{
299-
[NativeTypeName(""#define LEFT 1 << 1U"")]
300-
public const int LEFT = 1 << (int)(1U);
309+
[NativeTypeName(""const int"")]
310+
public const int Signed = 1;
301311
302-
[NativeTypeName(""#define RIGHT 1 >> 1U"")]
303-
public const int RIGHT = 1 >> (int)(1U);
312+
[NativeTypeName(""const unsigned int"")]
313+
public const uint Unsigned = 1U;
304314
305-
[NativeTypeName(""#define INT 1 << 1"")]
306-
public const int INT = 1 << 1;
315+
[NativeTypeName(""const int"")]
316+
public const int ShiftSigned = 1 << Signed;
307317
308-
[NativeTypeName(""#define LONG 1 << 1L"")]
309-
public const int LONG = 1 << (int)(1);
318+
[NativeTypeName(""const int"")]
319+
public const int ShiftUnsigned = 1 << (int)(Unsigned);
310320
311-
[NativeTypeName(""#define LONGLONG 1 << 1LL"")]
312-
public const int LONGLONG = 1 << (int)(1L);
321+
[NativeTypeName(""const int"")]
322+
public const int CInt = 1 << 1;
313323
314-
[NativeTypeName(""#define ULONG 1 << 1UL"")]
315-
public const int ULONG = 1 << (int)(1U);
324+
[NativeTypeName(""const int"")]
325+
public const int CUint = 1 << (int)(1U);
316326
317-
[NativeTypeName(""#define ULONGLONG 1 << 1ULL"")]
318-
public const int ULONGLONG = 1 << (int)(1UL);
327+
[NativeTypeName(""#define Left 1 << 1U"")]
328+
public const int Left = 1 << (int)(1U);
329+
330+
[NativeTypeName(""#define Right 1 >> 1U"")]
331+
public const int Right = 1 >> (int)(1U);
332+
333+
[NativeTypeName(""#define Int 1 << 1"")]
334+
public const int Int = 1 << 1;
335+
336+
[NativeTypeName(""#define Long 1 << 1L"")]
337+
public const int Long = 1 << (int)(1);
338+
339+
[NativeTypeName(""#define LongLong 1 << 1LL"")]
340+
public const int LongLong = 1 << (int)(1L);
341+
342+
[NativeTypeName(""#define ULong 1 << 1UL"")]
343+
public const int ULong = 1 << (int)(1U);
344+
345+
[NativeTypeName(""#define ULongLong 1 << 1ULL"")]
346+
public const int ULongLong = 1 << (int)(1UL);
319347
}
320348
}
321349
";

0 commit comments

Comments
 (0)