2022-05-02 18:56:44 +02:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#include "MockOrganizer.h"
|
|
|
|
|
#include "pythonrunner.h"
|
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
TEST(Lifetime, Plugins)
|
|
|
|
|
{
|
2023-07-10 21:57:59 +02:00
|
|
|
const auto plugins_folder = std::filesystem::path(std::getenv("PLUGIN_DIR"));
|
2022-05-02 18:56:44 +02:00
|
|
|
|
2022-05-06 17:40:11 +02:00
|
|
|
auto runner = mo2::python::createPythonRunner();
|
2022-05-02 18:56:44 +02:00
|
|
|
runner->initialize();
|
|
|
|
|
|
|
|
|
|
{
|
2023-07-10 21:57:59 +02:00
|
|
|
const auto objects =
|
|
|
|
|
runner->load("dummy_iplugin", plugins_folder / "dummy-iplugin.py");
|
2022-05-02 18:56:44 +02:00
|
|
|
|
|
|
|
|
// we found one plugin
|
2023-07-10 21:57:59 +02:00
|
|
|
ASSERT_EQ(objects.size(), 1);
|
2022-05-02 18:56:44 +02:00
|
|
|
|
|
|
|
|
// check that deleting the object actually destroys it
|
|
|
|
|
bool destroyed = false;
|
2023-07-10 21:57:59 +02:00
|
|
|
QObject::connect(objects[0][0], &QObject::destroyed, [&destroyed]() {
|
2022-05-02 18:56:44 +02:00
|
|
|
destroyed = true;
|
|
|
|
|
});
|
2023-07-10 21:57:59 +02:00
|
|
|
delete objects[0][0];
|
2022-05-02 18:56:44 +02:00
|
|
|
EXPECT_EQ(destroyed, true);
|
2023-07-10 21:57:59 +02:00
|
|
|
|
|
|
|
|
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();
|
2023-07-10 21:57:59 +02:00
|
|
|
const auto objects =
|
|
|
|
|
runner->load("dummy_iplugin", plugins_folder / "dummy-iplugin.py");
|
2022-05-02 18:56:44 +02:00
|
|
|
|
|
|
|
|
// we found one plugin
|
2023-07-10 21:57:59 +02:00
|
|
|
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;
|
2023-07-10 21:57:59 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|