-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_lifetime.cpp
47 lines (37 loc) · 1.27 KB
/
test_lifetime.cpp
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
#include "gtest/gtest.h"
#include "MockOrganizer.h"
#include "pythonrunner.h"
#include <QCoreApplication>
TEST(Lifetime, Plugins)
{
const auto plugins_folder = QString(std::getenv("PLUGIN_DIR"));
auto runner = mo2::python::createPythonRunner();
runner->initialize();
{
const auto objects = runner->load(plugins_folder + "/dummy-iplugin.py");
// we found one plugin
EXPECT_EQ(objects.size(), 1);
// check that deleting the object actually destroys it
bool destroyed = false;
QObject::connect(objects[0], &QObject::destroyed, [&destroyed]() {
destroyed = true;
});
delete objects[0];
EXPECT_EQ(destroyed, true);
}
// same things but with a parent
{
QObject* dummy_parent = new QObject();
const auto objects = runner->load(plugins_folder + "/dummy-iplugin.py");
// we found one plugin
EXPECT_EQ(objects.size(), 1);
objects[0]->setParent(dummy_parent);
// check that deleting the object actually destroys it
bool destroyed = false;
QObject::connect(objects[0], &QObject::destroyed, [&destroyed]() {
destroyed = true;
});
delete dummy_parent;
EXPECT_EQ(destroyed, true);
}
}