FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/src/embed_tests/TestTypeManager.cs at master · sdpython/pythonnet · GitHub
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
sdpython
pythonnet
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestTypeManager.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (58 loc) · 2.41 KB
Breadcrumbs
pythonnet
/
src
/
embed_tests
/
TestTypeManager.cs
Copy path
File metadata and controls
65 lines (58 loc) · 2.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using
NUnit
.
Framework
;
using
Python
.
Runtime
;
using
Python
.
Runtime
.
Platform
;
using
System
.
Runtime
.
InteropServices
;
namespace
Python
.
EmbeddingTest
{
class
TestTypeManager
{
[
SetUp
]
public
static
void
Init
(
)
{
Runtime
.
Runtime
.
Initialize
(
)
;
}
[
TearDown
]
public
static
void
Fini
(
)
{
Runtime
.
Runtime
.
Shutdown
(
)
;
}
[
Test
]
public
static
void
TestNativeCode
(
)
{
Assert
.
That
(
(
)
=>
{
var
_
=
NativeCodePageHelper
.
NativeCode
.
Active
;
}
,
Throws
.
Nothing
)
;
Assert
.
That
(
NativeCodePageHelper
.
NativeCode
.
Active
.
Code
.
Length
,
Is
.
GreaterThan
(
0
)
)
;
}
[
Test
]
public
static
void
TestMemoryMapping
(
)
{
Assert
.
That
(
(
)
=>
{
var
_
=
NativeCodePageHelper
.
CreateMemoryMapper
(
)
;
}
,
Throws
.
Nothing
)
;
var
mapper
=
NativeCodePageHelper
.
CreateMemoryMapper
(
)
;
// Allocate a read-write page.
int
len
=
12
;
var
page
=
mapper
.
MapWriteable
(
len
)
;
Assert
.
That
(
(
)
=>
{
Marshal
.
WriteInt64
(
page
,
17
)
;
}
,
Throws
.
Nothing
)
;
Assert
.
That
(
Marshal
.
ReadInt64
(
page
)
,
Is
.
EqualTo
(
17
)
)
;
// Mark it read-execute. We can still read, haven't changed any values.
mapper
.
SetReadExec
(
page
,
len
)
;
Assert
.
That
(
Marshal
.
ReadInt64
(
page
)
,
Is
.
EqualTo
(
17
)
)
;
// Test that we can't write to the protected page.
//
// We can't actually test access protection under Microsoft
// versions of .NET, because AccessViolationException is assumed to
// mean we're in a corrupted state:
// https://stackoverflow.com/questions/3469368/how-to-handle-accessviolationexception
//
// We can test under Mono but it throws NRE instead of AccessViolationException.
//
// We can't use compiler flags because we compile with MONO_LINUX
// while running on the Microsoft .NET Core during continuous
// integration tests.
/* if (System.Type.GetType ("Mono.Runtime") != null)
{
// Mono throws NRE instead of AccessViolationException for some reason.
Assert.That(() => { Marshal.WriteInt64(page, 73); }, Throws.TypeOf<System.NullReferenceException>());
Assert.That(Marshal.ReadInt64(page), Is.EqualTo(17));
} */
}
}
}
Back
|
FazBrowse Home
|
New Git URL