Skip to content

Commit

Permalink
C#: Add pointer cast test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasvajk committed Sep 23, 2020
1 parent d652b95 commit 2868d5b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions csharp/ql/test/library-tests/conversion/pointer/Pointer.cs
@@ -0,0 +1,28 @@
using System;

class C
{
unsafe static void M1(int[] arr)
{
fixed (int* i1 = arr)
{
}

fixed (int* i2 = &arr[0])
{
int* i3 = i2;
i3 = i3 + 1;
*i2 = *i2 + 1;
void* v2 = i2;
}

int* i4 = null;

int number = 1024;
byte* p = (byte*)&number;

var s = "some string";
fixed (char* c1 = s)
{ }
}
}
11 changes: 11 additions & 0 deletions csharp/ql/test/library-tests/conversion/pointer/Pointer.expected
@@ -0,0 +1,11 @@
| Pointer.cs:7:21:7:28 | Pointer.cs:7:21:7:28 | Int32* | Int32[] | access to parameter arr |
| Pointer.cs:11:21:11:32 | Pointer.cs:11:21:11:32 | Int32* | Int32* | &... |
| Pointer.cs:13:18:13:24 | Pointer.cs:13:18:13:24 | Int32* | Int32* | access to local variable i2 |
| Pointer.cs:14:13:14:23 | Pointer.cs:14:13:14:23 | Int32* | Int32* | ... + ... |
| Pointer.cs:15:13:15:25 | Pointer.cs:15:13:15:25 | Int32 | Int32 | ... + ... |
| Pointer.cs:16:19:16:25 | Pointer.cs:16:19:16:25 | Void* | Void* | (...) ... |
| Pointer.cs:19:14:19:22 | Pointer.cs:19:14:19:22 | Int32* | null | null |
| Pointer.cs:21:13:21:25 | Pointer.cs:21:13:21:25 | Int32 | Int32 | 1024 |
| Pointer.cs:22:15:22:32 | Pointer.cs:22:15:22:32 | Byte* | Byte* | (...) ... |
| Pointer.cs:24:13:24:29 | Pointer.cs:24:13:24:29 | String | String | "some string" |
| Pointer.cs:25:22:25:27 | Pointer.cs:25:22:25:27 | Char* | String | access to local variable s |
5 changes: 5 additions & 0 deletions csharp/ql/test/library-tests/conversion/pointer/Pointer.ql
@@ -0,0 +1,5 @@
import csharp

from Assignment a
select a.getLocation(), a.getLValue().getType().toString(), a.getRValue().getType().toString(),
a.getRValue().toString()

0 comments on commit 2868d5b

Please sign in to comment.