Skip to content

Commit

Permalink
Merge branch 'sdf12' into ahcorde/sdf_to_usd_material_physics
Browse files Browse the repository at this point in the history
  • Loading branch information
chapulina committed Apr 25, 2022
2 parents b78bcc7 + 12e7782 commit d065641
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/sdf/Plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ namespace sdf
/// \return A reference to this plugin
public: Plugin &operator=(Plugin &&_plugin) noexcept;

/// \brief Plugin equality operator.
/// \param[in] _plugin Plugin to compare against.
/// \return True if this plugin matches the provided plugin. The name,
/// filename, and contents must all match to return true.
public: bool operator==(const Plugin &_plugin) const;

/// \brief Plugin inequality operator.
/// \param[in] _plugin Plugin to compare against.
/// \return True if this plugin does not match the provided plugin.
/// The name, filename, or contents must be different to return false.
public: bool operator!=(const Plugin &_plugin) const;

/// \brief Output stream operator for a Plugin.
/// \param[in] _out The output stream
/// \param[in] _plugin Plugin to output
Expand Down
13 changes: 13 additions & 0 deletions src/Plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,16 @@ Plugin &Plugin::operator=(Plugin &&_plugin) noexcept
this->dataPtr = std::move(_plugin.dataPtr);
return *this;
}

/////////////////////////////////////////////////
bool Plugin::operator==(const Plugin &_plugin) const
{
// Simplest thing to do is compare the string form of each plugin
return _plugin.ToElement()->ToString("") == this->ToElement()->ToString("");
}

/////////////////////////////////////////////////
bool Plugin::operator!=(const Plugin &_plugin) const
{
return !(*this == _plugin);
}
31 changes: 31 additions & 0 deletions src/Plugin_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,34 @@ TEST(DOMPlugin, InsertStringContent)
EXPECT_EQ("name", plugin5.Name());
EXPECT_TRUE(plugin5.Contents().empty());
}

/////////////////////////////////////////////////
TEST(DOMPlugin, EqualityOperators)
{
sdf::Plugin plugin("my-filename", "my-name",
"<render_engine>ogre2</render_engine>");
sdf::Plugin plugin2(plugin);
sdf::Plugin plugin3;

EXPECT_EQ(plugin, plugin2);
EXPECT_NE(plugin, plugin3);
EXPECT_NE(plugin2, plugin3);

// Test contents
plugin2.ClearContents();
EXPECT_NE(plugin, plugin2);
plugin.ClearContents();
EXPECT_EQ(plugin, plugin2);

// test name
plugin2.SetName("new-name");
EXPECT_NE(plugin, plugin2);
plugin.SetName("new-name");
EXPECT_EQ(plugin, plugin2);

// test filename
plugin2.SetFilename("new-filename");
EXPECT_NE(plugin, plugin2);
plugin.SetFilename("new-filename");
EXPECT_EQ(plugin, plugin2);
}

0 comments on commit d065641

Please sign in to comment.