Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.4 KiB
C++
Raw Permalink Normal View History

2022-05-02 18:56:44 +02:00
#include "gtest/gtest.h"
#include "MockOrganizer.h"
#include "pythonrunner.h"
#include <QCoreApplication>
TEST(Lifetime, Plugins)
{
const auto plugins_folder = std::filesystem::path(std::getenv("PLUGIN_DIR"));
2022-05-02 18:56:44 +02:00
auto runner = mo2::python::createPythonRunner();
2022-05-02 18:56:44 +02:00
runner->initialize();
{
const auto objects =
runner->load("dummy_iplugin", plugins_folder / "dummy-iplugin.py");
2022-05-02 18:56:44 +02:00
// we found one plugin
ASSERT_EQ(objects.size(), 1);
2022-05-02 18:56:44 +02:00
// check that deleting the object actually destroys it
bool destroyed = false;
QObject::connect(objects[0][0], &QObject::destroyed, [&destroyed]() {
2022-05-02 18:56:44 +02:00
destroyed = true;
});
delete objects[0][0];
2022-05-02 18:56:44 +02:00
EXPECT_EQ(destroyed, true);
runner->unload("dummy_iplugin", plugins_folder / "dummy-iplugin.py");
2022-05-02 18:56:44 +02:00
}
// same things but with a parent
{
QObject* dummy_parent = new QObject();
const auto objects =
runner->load("dummy_iplugin", plugins_folder / "dummy-iplugin.py");
2022-05-02 18:56:44 +02:00
// we found one plugin
ASSERT_EQ(objects.size(), 1);
objects[0][0]->setParent(dummy_parent);
2022-05-02 18:56:44 +02:00
// check that deleting the object actually destroys it
bool destroyed = false;
QObject::connect(objects[0][0], &QObject::destroyed, [&destroyed]() {
2022-05-02 18:56:44 +02:00
destroyed = true;
});
delete dummy_parent;
EXPECT_EQ(destroyed, true);
}
}