forked from commontk/PythonQt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonQtTestCleanup.cpp
More file actions
80 lines (66 loc) · 1.73 KB
/
PythonQtTestCleanup.cpp
File metadata and controls
80 lines (66 loc) · 1.73 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "PythonQtTestCleanup.h"
#include "PythonQt.h"
#include "PythonQt_QtBindings.h"
void PythonQtTestCleanup::initTestCase()
{
}
void PythonQtTestCleanup::cleanupTestCase()
{
}
void PythonQtTestCleanup::init()
{
// Initialize before each test
PythonQt::init(PythonQt::IgnoreSiteModule);
PythonQt_init_QtBindings();
_helper = new PythonQtTestCleanupHelper();
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
PythonQt::self()->addObject(main, "obj", _helper);
}
void PythonQtTestCleanup::cleanup()
{
// Finalize and cleanup after each test
if (Py_IsInitialized()) {
Py_Finalize();
}
PythonQt::cleanup();
delete _helper;
_helper = NULL;
}
void PythonQtTestCleanup::testQtEnum()
{
QVERIFY(_helper->runScript(
"import PythonQt.QtCore\n" \
"x = PythonQt.QtCore.QFile.ReadOnly\n" \
"obj.setPassed()"
));
}
void PythonQtTestCleanup::testCallQtMethodInDel()
{
QVERIFY(_helper->runScript(
"import PythonQt.QtCore\n" \
"class TimerWrapper(object):\n" \
" def __init__(self):\n" \
" self.timer = PythonQt.QtCore.QTimer()\n" \
" def __del__(self):\n" \
" self.timer.setSingleShot(True)\n" \
"x = TimerWrapper()\n" \
"obj.setPassed()\n"
));
}
void PythonQtTestCleanup::testSignalReceiverCleanup()
{
PythonQtObjectPtr main = PythonQt::self()->getMainModule();
// Test that PythonQtSignalReceiver is cleaned up properly,
// i.e. PythonQt::cleanup() doesn't segfault
main.evalScript(
"import PythonQt.QtCore\n" \
"timer = PythonQt.QtCore.QTimer(obj)\n" \
"timer.connect('destroyed()', obj.onDestroyed)\n" \
);
}
bool PythonQtTestCleanupHelper::runScript(const char* script)
{
_passed = false;
PyRun_SimpleString(script);
return _passed;
}