This repository was archived by the owner on Jul 22, 2023. It is now read-only.
forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestRuntime.cs
More file actions
51 lines (43 loc) · 1.71 KB
/
TestRuntime.cs
File metadata and controls
51 lines (43 loc) · 1.71 KB
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
using System;
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestRuntime
{
[Test]
public static void Py_IsInitializedValue()
{
Runtime.Runtime.Py_Finalize(); // In case another test left it on.
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
Runtime.Runtime.Py_Initialize();
Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized());
Runtime.Runtime.Py_Finalize();
Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized());
}
[Test]
public static void RefCountTest()
{
Runtime.Runtime.Py_Initialize();
IntPtr op = Runtime.Runtime.PyUnicode_FromString("FooBar");
// New object RefCount should be one
Assert.AreEqual(1, Runtime.Runtime.Refcount(op));
// Checking refcount didn't change refcount
Assert.AreEqual(1, Runtime.Runtime.Refcount(op));
// New reference doesn't increase refcount
IntPtr p = op;
Assert.AreEqual(1, Runtime.Runtime.Refcount(p));
// Py_IncRef/Py_DecRef increase and decrease RefCount
Runtime.Runtime.Py_IncRef(op);
Assert.AreEqual(2, Runtime.Runtime.Refcount(op));
Runtime.Runtime.Py_DecRef(op);
Assert.AreEqual(1, Runtime.Runtime.Refcount(op));
// XIncref/XDecref increase and decrease RefCount
Runtime.Runtime.XIncref(op);
Assert.AreEqual(2, Runtime.Runtime.Refcount(op));
Runtime.Runtime.XDecref(op);
Assert.AreEqual(1, Runtime.Runtime.Refcount(op));
Runtime.Runtime.Py_Finalize();
}
}
}