8000 Add unit tests for (U)IntPtr conversions · pythonnet/pythonnet@1c21526 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c21526

Browse files
committed
Add unit tests for (U)IntPtr conversions
1 parent d484797 commit 1c21526

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/testing/conversiontest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Python.Test
22
{
3+
using System;
34
using System.Collections.Generic;
45

56
/// <summary>
@@ -26,6 +27,8 @@ public ConversionTest()
2627
public ulong UInt64Field = 0;
2728
public float SingleField = 0.0F;
2829
public double DoubleField = 0.0;
30+
public IntPtr IntPtrField = IntPtr.Zero;
31+
public UIntPtr UIntPtrField = UIntPtr.Zero;
2932
public decimal DecimalField = 0;
3033
public string StringField;
3134
public ShortEnum EnumField;
@@ -42,7 +45,7 @@ public ConversionTest()
4245

4346
}
4447

45-
48+
4649

4750
public interface ISpam
4851
{
@@ -63,7 +66,7 @@ public string GetValue()
6366
return value;
6467
}
6568
}
66-
69+
6770
public class UnicodeString
6871
{
6972
public string value = "안녕";

tests/test_conversion.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_bool_conversion():
2525

2626
with pytest.raises(TypeError):
2727
ob.BooleanField = 1
28-
28+
2929
with pytest.raises(TypeError):
3030
ob.BooleanField = 0
3131

@@ -679,3 +679,20 @@ def test_iconvertible_conversion():
679679
assert 1024 == change_type(1024, System.Int32)
680680
assert 1024 == change_type(1024, System.Int64)
681681
assert 1024 == change_type(1024, System.Int16)
682+
683+
def test_intptr_conversion():
684+
from System import IntPtr, UIntPtr, Int64
685+
686+
ob = ConversionTest()
687+
688+
assert ob.IntPtrField == IntPtr.Zero
689+
assert ob.UIntPtrField == UIntPtr.Zero
690+
691+
ob.IntPtrField = IntPtr(-1)
692+
assert ob.IntPtrField == IntPtr(-1)
693+
694+
ob.IntPtrField = IntPtr(Int64(1024))
695+
assert ob.IntPtrField == IntPtr(1024)
696+
697+
ob.UIntPtrField = ob.IntPtrField
698+
assert ob.UIntPtrField == UIntPtr(1024)

0 commit comments

Comments
 (0)
0