-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNativeStringEncodingTests.cs
More file actions
44 lines (37 loc) · 1003 Bytes
/
NativeStringEncodingTests.cs
File metadata and controls
44 lines (37 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Runtime.InteropServices;
using CSharpDB.Native;
namespace CSharpDB.Tests;
public sealed class NativeStringEncodingTests
{
[Fact]
public void StringCache_ReturnsUtf8Pointers()
{
IntPtr resultHandle = new(1234);
const string value = "naïve café";
try
{
IntPtr ptr = StringCache.GetOrAdd(resultHandle, 0, value);
Assert.Equal(value, Marshal.PtrToStringUTF8(ptr));
}
finally
{
StringCache.Remove(resultHandle);
}
}
[Fact]
public void ErrorState_ReturnsUtf8Pointers()
{
const string message = "naïve café";
try
{
ErrorState.Set(new InvalidOperationException(message));
IntPtr ptr = ErrorState.GetMessagePtr();
Assert.NotEqual(IntPtr.Zero, ptr);
Assert.Equal(message, Marshal.PtrToStringUTF8(ptr));
}
finally
{
ErrorState.Clear();
}
}
}