diff --git a/include/maidsafe/routing/close_nodes_change.h b/include/maidsafe/routing/close_nodes_change.h index 454c01a4..d2678519 100644 --- a/include/maidsafe/routing/close_nodes_change.h +++ b/include/maidsafe/routing/close_nodes_change.h @@ -49,7 +49,7 @@ struct CheckHoldersResult { }; class ConnectionsChange { - protected: + public: ConnectionsChange() = default; ConnectionsChange(const ConnectionsChange& other) = default; ConnectionsChange(ConnectionsChange&& other); @@ -68,6 +68,7 @@ class ConnectionsChange { std::string Print() const; friend void swap(ConnectionsChange& lhs, ConnectionsChange& rhs) MAIDSAFE_NOEXCEPT; + friend bool operator==(const ConnectionsChange& lhs, const ConnectionsChange& rhs); protected: NodeId node_id_; @@ -87,6 +88,7 @@ class ClientNodesChange : public ConnectionsChange { std::string ReportConnection() const; friend void swap(ClientNodesChange& lhs, ClientNodesChange& rhs) MAIDSAFE_NOEXCEPT; + friend bool operator==(const ClientNodesChange& lhs, const ClientNodesChange& rhs); }; class CloseNodesChange : public ConnectionsChange { @@ -104,6 +106,8 @@ class CloseNodesChange : public ConnectionsChange { std::string ReportConnection() const; friend void swap(CloseNodesChange& lhs, CloseNodesChange& rhs) MAIDSAFE_NOEXCEPT; + friend bool operator==(const CloseNodesChange& lhs, const CloseNodesChange& rhs); + friend class RoutingTable; friend class test::CloseNodesChangeTest_BEH_CheckHolders_Test; friend class test::SingleCloseNodesChangeTest_BEH_ChoosePmidNode_Test; @@ -116,6 +120,14 @@ void swap(ConnectionsChange& lhs, ConnectionsChange& rhs) MAIDSAFE_NOEXCEPT; void swap(ClientNodesChange& lhs, ClientNodesChange& rhs) MAIDSAFE_NOEXCEPT; void swap(CloseNodesChange& lhs, CloseNodesChange& rhs) MAIDSAFE_NOEXCEPT; +bool operator==(const ConnectionsChange& lhs, const ConnectionsChange& rhs); +bool operator==(const ClientNodesChange& lhs, const ClientNodesChange& rhs); +bool operator==(const CloseNodesChange& lhs, const CloseNodesChange& rhs); +bool operator!=(const ConnectionsChange& lhs, const ConnectionsChange& rhs); +bool operator!=(const ClientNodesChange& lhs, const ClientNodesChange& rhs); +bool operator!=(const CloseNodesChange& lhs, const CloseNodesChange& rhs); + + } // namespace routing } // namespace maidsafe diff --git a/src/maidsafe/routing/close_nodes_change.cc b/src/maidsafe/routing/close_nodes_change.cc index bc76df5d..365dc399 100644 --- a/src/maidsafe/routing/close_nodes_change.cc +++ b/src/maidsafe/routing/close_nodes_change.cc @@ -122,6 +122,22 @@ void swap(ConnectionsChange& lhs, ConnectionsChange& rhs) MAIDSAFE_NOEXCEPT { swap(lhs.new_close_nodes_, rhs.new_close_nodes_); } +bool operator==(const ConnectionsChange& lhs, const ConnectionsChange& rhs) { + return lhs.node_id_ == rhs.node_id_ && + lhs.new_close_nodes_.size() == rhs.new_close_nodes_.size() && + lhs.old_close_nodes_.size() == rhs.old_close_nodes_.size() && + lhs.new_node_ == rhs.new_node_ && + lhs.lost_node_ == rhs.lost_node_ && + std::equal(lhs.old_close_nodes_.begin(), lhs.old_close_nodes_.end(), + rhs.old_close_nodes_.begin()) && + std::equal(lhs.new_close_nodes_.begin(), lhs.new_close_nodes_.end(), + rhs.new_close_nodes_.begin()); +} + +bool operator!=(const ConnectionsChange& lhs, const ConnectionsChange& rhs) { + return !(lhs == rhs); +} + // ============================== client node change ========================================= ClientNodesChange::ClientNodesChange(ClientNodesChange&& other) @@ -168,6 +184,14 @@ void swap(ClientNodesChange& lhs, ClientNodesChange& rhs) MAIDSAFE_NOEXCEPT { swap(static_cast(lhs), static_cast(rhs)); } +bool operator==(const ClientNodesChange& lhs, const ClientNodesChange& rhs) { + return (static_cast(lhs) == static_cast(rhs)); +} + +bool operator!=(const ClientNodesChange& lhs, const ClientNodesChange& rhs) { + return !(lhs == rhs); +} + // ========================== non-client client close nodes change ================================= CloseNodesChange::CloseNodesChange(CloseNodesChange&& other) @@ -321,6 +345,15 @@ std::string CloseNodesChange::ReportConnection() const { return stringstream.str(); } +bool operator==(const CloseNodesChange& lhs, const CloseNodesChange& rhs) { + return lhs.radius_ == rhs.radius_ && + (static_cast(lhs) == static_cast(rhs)); +} + +bool operator!=(const CloseNodesChange& lhs, const CloseNodesChange& rhs) { + return !(lhs == rhs); +} + void swap(CloseNodesChange& lhs, CloseNodesChange& rhs) MAIDSAFE_NOEXCEPT { using std::swap; swap(static_cast(lhs), static_cast(rhs)); diff --git a/src/maidsafe/routing/tests/close_nodes_change_test.cc b/src/maidsafe/routing/tests/close_nodes_change_test.cc index 5219575e..143fe49b 100644 --- a/src/maidsafe/routing/tests/close_nodes_change_test.cc +++ b/src/maidsafe/routing/tests/close_nodes_change_test.cc @@ -385,6 +385,27 @@ TEST_F(CloseNodesChangeTest, BEH_FullSizeRoutingTable) { } } +template +class ConnectionChangesTest : public testing::Test {}; + +using ConnectionTypes = testing::Types; +TYPED_TEST_CASE(ConnectionChangesTest, ConnectionTypes); + +TYPED_TEST(ConnectionChangesTest, BEH_Constructors) { + std::vector old_ids, new_ids; + + for (auto index(Parameters::closest_nodes_size); index != 0; --index) + old_ids.push_back(NodeId(RandomString(NodeId::kSize))); + + new_ids = old_ids; + old_ids.erase(old_ids.begin()); + auto close_nodes_change(TypeParam(NodeId(RandomString(NodeId::kSize)), old_ids, new_ids)); + auto copy(close_nodes_change); + auto copy2(std::move(copy)); + EXPECT_EQ(close_nodes_change, copy2); + EXPECT_NE(copy, copy2); +} + } // namespace test } // namespace routing