aboutsummaryrefslogtreecommitdiff
path: root/libs/plugin_python/tests/runner/test_lifetime.cpp
blob: bf057d3fcec2ad715812a9106ad0692205e86bab (plain)
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);
    }
}