Skip to content

Commit

Permalink
Updating plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
  • Loading branch information
mjcarroll committed Dec 7, 2023
1 parent 47c92c2 commit 861f355
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 114 deletions.
2 changes: 1 addition & 1 deletion include/gz/gui/qml/GzCardSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Dialog {
ColorDialog {
id: colorDialog
title: "Please choose a color"
options: [ColorDialog.ShowAlphaChannel]
options: ColorDialog.ShowAlphaChannel
onAccepted: {
content.color = colorDialog.color
bgColor.color = colorDialog.color
Expand Down
3 changes: 3 additions & 0 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ Application::~Application()
}
this->dataPtr->dialogs.clear();

this->dataPtr->engine->clearComponentCache();
this->dataPtr->engine->clearSingletons();

delete this->dataPtr->engine;

std::queue<std::shared_ptr<Plugin>> empty;
Expand Down
175 changes: 71 additions & 104 deletions src/Application_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <stdlib.h>
#include <gtest/gtest.h>
#include <chrono>
#include <gz/common/Console.hh>
#include <gz/utils/ExtraTestMacros.hh>

Expand All @@ -35,16 +36,23 @@ char* g_argv[] =
using namespace gz;
using namespace gui;

// See https://github.com/gazebosim/gz-gui/issues/75
//////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor))
class ApplicationTest: public ::testing::Test
{
common::Console::SetVerbosity(4);
protected:
void SetUp() override
{
common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
ASSERT_EQ(nullptr, App());
}
};

// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
ASSERT_EQ(nullptr, App());

// See https://github.com/gazebosim/gz-gui/issues/75
//////////////////////////////////////////////////
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor))
{
// One app construct - destruct
{
Application app(g_argc, g_argv);
Expand All @@ -63,36 +71,27 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Constructor))
}

//////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadPlugin))
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadPlugin))
{
gz::common::Console::SetVerbosity(4);

// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

EXPECT_TRUE(app.LoadPlugin("Publisher"));
}
//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadNonexistantPlugin))
{
gz::common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

EXPECT_FALSE(app.LoadPlugin("_doesnt_exist"));
EXPECT_FALSE(app.RemovePlugin("_doesnt_exist"));
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadProgrammaticPlugin))
{
gz::common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

std::string pluginName;
Expand All @@ -117,11 +116,8 @@ TEST(ApplicationTest,
}

//////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadEnvPlugin))
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadEnvPlugin))
{
gz::common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

setenv("TEST_ENV_VAR",
Expand All @@ -131,51 +127,38 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadEnvPlugin))
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadBadInheritancePlugin))
{
gz::common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");
EXPECT_FALSE(app.LoadPlugin("TestBadInheritancePlugin"));
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadNotRegisteredPlugin))
{
gz::common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");
EXPECT_FALSE(app.LoadPlugin("TestNotRegisteredPlugin"));
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadInvalidQmlPlugin))
{
gz::common::Console::SetVerbosity(4);
// No Qt app
ASSERT_EQ(nullptr, qGuiApp);
Application app(g_argc, g_argv);

app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");
EXPECT_FALSE(app.LoadPlugin("TestInvalidQmlPlugin"));
}

//////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig))
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig))
{
common::Console::SetVerbosity(4);

ASSERT_EQ(nullptr, qGuiApp);

// Empty string
{
Application app(g_argc, g_argv);
Expand Down Expand Up @@ -220,12 +203,8 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadConfig))
}

//////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig))
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig))
{
common::Console::SetVerbosity(4);

ASSERT_EQ(nullptr, qGuiApp);

// Test config file
{
Application app(g_argc, g_argv);
Expand All @@ -245,34 +224,30 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadDefaultConfig))
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindowSimple))
{
common::Console::SetVerbosity(4);
ASSERT_EQ(nullptr, qGuiApp);

// No plugins
Application app(g_argc, g_argv);

auto wins = app.allWindows();
ASSERT_EQ(wins.size(), 1);

// Close window after some time
QTimer::singleShot(300, wins[0], [&wins](){
wins[0]->close();
});
QObject::connect(&app, &QGuiApplication::applicationStateChanged,
[&wins](auto /*state*/){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
wins[0]->close();
});

// Show window
app.exec();
gz::gui::Application::exec();
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindowPlugin))
{
common::Console::SetVerbosity(4);
ASSERT_EQ(nullptr, qGuiApp);

Application app(g_argc, g_argv);

EXPECT_TRUE(app.LoadPlugin("Publisher"));
Expand All @@ -285,25 +260,19 @@ TEST(ApplicationTest,
EXPECT_EQ(1, plugins.count());

QObject::connect(&app, &QGuiApplication::applicationStateChanged,
[&win](auto state){
std::cout << "State Changed, starting timer" << std::endl;
QTimer::singleShot(100, [&win](){
win->QuickWindow()->close();
});
});
[&win](auto /*state*/){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
win->QuickWindow()->close();
});

// Show window
app.exec();
app.quit();
gz::gui::Application::exec();
}

//////////////////////////////////////////////////
TEST(ApplicationTest,
TEST_F(ApplicationTest,
GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(InitializeMainWindowConfig))
{
common::Console::SetVerbosity(4);
ASSERT_EQ(nullptr, qGuiApp);

// Test config
auto testBuildPath = std::string(PROJECT_BINARY_PATH) + "/lib/";
auto testSourcePath = std::string(PROJECT_SOURCE_PATH) + "/test/";
Expand All @@ -325,21 +294,19 @@ TEST(ApplicationTest,
EXPECT_EQ(1, plugins.count());

// Close window after some time
QTimer::singleShot(1000, win, [&win](){
win->QuickWindow()->close();
});
QObject::connect(&app, &QGuiApplication::applicationStateChanged,
[&win](auto /*state*/){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
win->QuickWindow()->close();
});

// Show window
app.exec();
gz::gui::Application::exec();
}

//////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))
{
common::Console::SetVerbosity(4);

ASSERT_EQ(nullptr, qGuiApp);

// Single dialog
{
Application app(g_argc, g_argv, WindowType::kDialog);
Expand All @@ -354,21 +321,23 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))

// Close dialog after some time
auto closed = false;
QTimer::singleShot(300, &app, [&] {
auto ds = app.allWindows();

// The main dialog - some systems return more, not sure why
ASSERT_GE(ds.size(), 1);

EXPECT_TRUE(qobject_cast<QQuickWindow *>(ds[0]));

// Close
ds[0]->close();
closed = true;
// Close window after some time
QObject::connect(&app, &QGuiApplication::applicationStateChanged,
[&closed](auto /*state*/){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
auto ds = gz::gui::Application::allWindows();

// The main diaog - some systems return more, not sure why
ASSERT_GE(ds.size(), 1);
EXPECT_TRUE(qobject_cast<QQuickWindow *>(ds[0]));
// Close
ds[0]->close();
closed = true;
});

// Exec dialog
app.exec();
// Show window
gz::gui::Application::exec();

// Make sure timer was triggered
EXPECT_TRUE(closed);
Expand All @@ -389,32 +358,30 @@ TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Dialog))

// Close dialogs after some time
auto closed = false;
QTimer::singleShot(300, &app, [&] {
auto ds = app.allWindows();
QObject::connect(&app, &QGuiApplication::applicationStateChanged,
[&closed](auto /*state*/){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
auto ds = gz::gui::Application::allWindows();

// 2 dialog - some systems return more, not sure why
EXPECT_GE(ds.size(), 2);
// 2 dialog - some systems return more, not sure why
ASSERT_GE(ds.size(), 2);

for (auto dialog : ds)
dialog->close();
closed = true;
});
for (auto *dialog : ds)
dialog->close();
closed = true;
});

// Exec dialog
app.exec();
gz::gui::Application::exec();

// Make sure timer was triggered
EXPECT_TRUE(closed);
}
}

/////////////////////////////////////////////////
TEST(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(messageHandler))
TEST_F(ApplicationTest, GZ_UTILS_TEST_ENABLED_ONLY_ON_LINUX(messageHandler))
{
common::Console::SetVerbosity(4);

ASSERT_EQ(nullptr, qGuiApp);

Application app(g_argc, g_argv);

// \todo Verify output, see commmon::Console_TEST for example
Expand Down
Loading

0 comments on commit 861f355

Please sign in to comment.