Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash if a plugin has invalid QML #315

Merged
merged 1 commit into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ bool Application::LoadPlugin(const std::string &_filename,
else
plugin->Load(_pluginElem);

if (nullptr == plugin->CardItem())
return false;

// Store plugin in queue to be added to the window
this->dataPtr->pluginsToAdd.push(plugin);

Expand Down
8 changes: 8 additions & 0 deletions src/Application_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ TEST(ApplicationTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(LoadPlugin))

EXPECT_FALSE(app.LoadPlugin("TestNotRegisteredPlugin"));
}

// Plugin with invalid QML
{
Application app(g_argc, g_argv);
app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");

EXPECT_FALSE(app.LoadPlugin("TestInvalidQmlPlugin"));
}
}

//////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions test/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ link_directories(

set (plugins
TestBadInheritancePlugin
TestInvalidQmlPlugin
TestNotRegisteredPlugin
TestPlugin
)
Expand Down
38 changes: 38 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <ignition/plugin/Register.hh>

#include "TestInvalidQmlPlugin.hh"

using namespace ignition;
using namespace gui;

/////////////////////////////////////////////////
TestInvalidQmlPlugin::TestInvalidQmlPlugin()
: Plugin()
{
}

/////////////////////////////////////////////////
TestInvalidQmlPlugin::~TestInvalidQmlPlugin()
{
}

// Register this plugin
IGNITION_ADD_PLUGIN(ignition::gui::TestInvalidQmlPlugin,
ignition::gui::Plugin)
40 changes: 40 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef IGNITION_GUI_TEST_MALFORMEDPLUGIN_HH_
#define IGNITION_GUI_TEST_MALFORMEDPLUGIN_HH_

#include <ignition/gui/Plugin.hh>

namespace ignition
{
namespace gui
{
class TestInvalidQmlPlugin : public Plugin
{
Q_OBJECT

/// \brief Constructor
public: TestInvalidQmlPlugin();

/// \brief Destructor
public: virtual ~TestInvalidQmlPlugin();
};
}
}

#endif
21 changes: 21 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import QtQuick 2.9

Rectangle {
banana: fail
}
5 changes: 5 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="TestInvalidQmlPlugin/">
<file>TestInvalidQmlPlugin.qml</file>
</qresource>
</RCC>