diff --git a/src/Plugin.cc b/src/Plugin.cc index b6c58d292..d95c87229 100644 --- a/src/Plugin.cc +++ b/src/Plugin.cc @@ -289,9 +289,11 @@ std::string Plugin::ConfigStr() auto pluginElem = doc.FirstChildElement("plugin"); if (!pluginElem) { + // LCOV_EXCL_START ignerr << "Missing element, not updating config string." << std::endl; return this->configStr; + // LCOV_EXCL_STOP } // @@ -360,8 +362,10 @@ std::string Plugin::ConfigStr() tinyxml2::XMLPrinter printer; if (!pluginElem->Accept(&printer)) { + // LCOV_EXCL_START ignwarn << "There was an error parsing the plugin element for " << "[" << this->title << "]." << std::endl; + // LCOV_EXCL_STOP } else { diff --git a/src/Plugin_TEST.cc b/src/Plugin_TEST.cc index 532171f97..4f8d94cca 100644 --- a/src/Plugin_TEST.cc +++ b/src/Plugin_TEST.cc @@ -15,6 +15,7 @@ * */ +#include #include #include @@ -134,3 +135,189 @@ TEST(PluginTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(Getters)) ASSERT_NE(nullptr, plugin->CardItem()); ASSERT_NE(nullptr, plugin->Context()); } + +///////////////////////////////////////////////// +TEST(PluginTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(ConfigStr)) +{ + ignition::common::Console::SetVerbosity(4); + + Application app(g_argc, g_argv); + app.AddPluginPath( + common::joinPaths(std::string(PROJECT_BINARY_PATH), "lib")); + + // Load normal plugin + const char *pluginStr = + "" + " " + " World stats" + " true" + " true" + " 200" + " 300" + " 2" + " floating" + " " + " " + " " + " " + " " + ""; + + std::unordered_map pluginProps; + std::unordered_map pluginTypes; + pluginProps["showTitleBar"] = "true"; + pluginProps["resizable"] = "true"; + pluginProps["height"] = "200"; + pluginProps["width"] = "300"; + pluginProps["z"] = "2"; + pluginProps["state"] = "floating"; + + pluginTypes["showTitleBar"] = "bool"; + pluginTypes["resizable"] = "bool"; + pluginTypes["height"] = "double"; + pluginTypes["width"] = "double"; + pluginTypes["z"] = "double"; + pluginTypes["state"] = "string"; + + tinyxml2::XMLDocument pluginDoc; + pluginDoc.Parse(pluginStr); + EXPECT_TRUE(app.LoadPlugin("WorldStats", + pluginDoc.FirstChildElement("plugin"))); + + // Create main window + auto win = app.findChild(); + ASSERT_NE(nullptr, win); + + // Check plugin count + EXPECT_EQ(1, win->findChildren().size()); + + // Get the output for ConfigStr() + std::string configStr; + tinyxml2::XMLDocument configDoc; + auto plugin = win->findChildren()[0]; + configStr = plugin->ConfigStr(); + configDoc.Parse(configStr.c_str()); + + // + auto pluginElem = configDoc.FirstChildElement("plugin"); + ASSERT_NE(nullptr, pluginElem); + + // + auto ignGuiElem = pluginElem->FirstChildElement("ignition-gui"); + ASSERT_NE(nullptr, ignGuiElem); + + // Iterate properties + for (auto propElem = ignGuiElem->FirstChildElement("property"); + propElem != nullptr;) + { + // If property in map, mark it as "Verified" + if (pluginProps.find(propElem->Attribute("key")) != pluginProps.end()) + { + // check if the type is correct + EXPECT_EQ(propElem->Attribute("type"), + pluginTypes[propElem->Attribute("key")]) << propElem->Attribute("key"); + + // check if the value is correct + EXPECT_EQ(propElem->GetText(), pluginProps[propElem->Attribute("key")]) + << propElem->Attribute("key"); + pluginProps[propElem->Attribute("key")] = "Verified"; + } + auto nextProp = propElem->NextSiblingElement("property"); + propElem = nextProp; + } + + // Verify all inputs properties are checked + for (auto itr = pluginProps.begin(); itr != pluginProps.end(); itr++) + { + EXPECT_EQ(itr->second, "Verified") << "Did not find property: " + << itr->first; + } + +} + +///////////////////////////////////////////////// +TEST(PluginTest, IGN_UTILS_TEST_DISABLED_ON_WIN32(ConfigStrInputNoPlugin)) +{ + ignition::common::Console::SetVerbosity(4); + + Application app(g_argc, g_argv); + app.AddPluginPath( + common::joinPaths(std::string(PROJECT_BINARY_PATH), "lib")); + + // Load normal plugin + const char *pluginStr = ""; + + tinyxml2::XMLDocument pluginDoc; + pluginDoc.Parse(pluginStr); + EXPECT_TRUE(app.LoadPlugin("WorldStats", + pluginDoc.FirstChildElement("plugin"))); + + // Create main window + auto win = app.findChild(); + ASSERT_NE(nullptr, win); + + // Check plugin count + EXPECT_EQ(1, win->findChildren().size()); + + // Get the output for ConfigStr() + std::string configStr; + tinyxml2::XMLDocument configDoc; + auto plugin = win->findChildren()[0]; + configStr = plugin->ConfigStr(); + configDoc.Parse(configStr.c_str()); + + // ConfigStr() creates a plugin with default value when input doesn't + // contain a tag. + // We select a few to verify. + std::unordered_map pluginProps; + std::unordered_map pluginTypes; + pluginProps["showTitleBar"] = "true"; + pluginProps["resizable"] = "true"; + pluginProps["cardMinimumWidth"] = "290"; + pluginProps["cardMinimumHeight"] = "110"; + pluginProps["z"] = "0"; + pluginProps["state"] = "docked"; + + pluginTypes["showTitleBar"] = "bool"; + pluginTypes["resizable"] = "bool"; + pluginTypes["cardMinimumWidth"] = "int"; + pluginTypes["cardMinimumHeight"] = "int"; + pluginTypes["z"] = "double"; + pluginTypes["state"] = "string"; + + // + auto pluginElem = configDoc.FirstChildElement("plugin"); + ASSERT_NE(nullptr, pluginElem); + + // + auto ignGuiElem = pluginElem->FirstChildElement("ignition-gui"); + ASSERT_NE(nullptr, ignGuiElem); + + // Iterate properties + for (auto propElem = ignGuiElem->FirstChildElement("property"); + propElem != nullptr;) + { + // If property in map, mark it as "Verified" + if (pluginProps.find(propElem->Attribute("key")) != pluginProps.end()) + { + // check if the type is correct + EXPECT_EQ(propElem->Attribute("type"), + pluginTypes[propElem->Attribute("key")]) << propElem->Attribute("key"); + + // check if the value is correct + EXPECT_EQ(propElem->GetText(), pluginProps[propElem->Attribute("key")]) + << propElem->Attribute("key"); + pluginProps[propElem->Attribute("key")] = "Verified"; + } + auto nextProp = propElem->NextSiblingElement("property"); + propElem = nextProp; + } + + // Verify all selected inputs properties are checked + for (auto itr = pluginProps.begin(); itr != pluginProps.end(); itr++) + { + EXPECT_EQ(itr->second, "Verified") << "Did not find property: " + << itr->first; + } +} +