From 674787e662b01a5427454e8ac926a2ef52b3c99a Mon Sep 17 00:00:00 2001 From: moadeli Date: Tue, 27 Jan 2015 16:40:22 +0000 Subject: [PATCH 1/4] testing constructors --- include/maidsafe/routing/close_nodes_change.h | 14 +++++++- src/maidsafe/routing/close_nodes_change.cc | 33 +++++++++++++++++++ .../routing/tests/close_nodes_change_test.cc | 31 +++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) 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..b2168f65 100644 --- a/src/maidsafe/routing/tests/close_nodes_change_test.cc +++ b/src/maidsafe/routing/tests/close_nodes_change_test.cc @@ -385,6 +385,37 @@ TEST_F(CloseNodesChangeTest, BEH_FullSizeRoutingTable) { } } +TEST_F(CloseNodesChangeTest, 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(CloseNodesChange(kNodeId_, old_ids, new_ids)); + auto copy(close_nodes_change); + auto copy2(std::move(copy)); + EXPECT_EQ(close_nodes_change, copy2); + EXPECT_NE(copy, copy2); + } + { + auto client_nodes_change(ClientNodesChange(kNodeId_, old_ids, new_ids)); + auto copy(client_nodes_change); + auto copy2(std::move(copy)); + EXPECT_EQ(client_nodes_change, copy2); + EXPECT_NE(copy, copy2); + } + { + auto connections_change(ConnectionsChange(kNodeId_, old_ids, new_ids)); + auto copy(connections_change); + auto copy2(std::move(copy)); + EXPECT_EQ(connections_change, copy2); + EXPECT_NE(copy, copy2); + } +} + } // namespace test } // namespace routing From 7f4e5f840a5c560cb93cc3bc6fcf644feb6f38f6 Mon Sep 17 00:00:00 2001 From: moadeli Date: Fri, 30 Jan 2015 11:19:29 +0000 Subject: [PATCH 2/4] replace tests with parameterized ones --- .../routing/tests/close_nodes_change_test.cc | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/maidsafe/routing/tests/close_nodes_change_test.cc b/src/maidsafe/routing/tests/close_nodes_change_test.cc index b2168f65..05ddb62d 100644 --- a/src/maidsafe/routing/tests/close_nodes_change_test.cc +++ b/src/maidsafe/routing/tests/close_nodes_change_test.cc @@ -385,36 +385,32 @@ TEST_F(CloseNodesChangeTest, BEH_FullSizeRoutingTable) { } } -TEST_F(CloseNodesChangeTest, BEH_Constructors) { - std::vector old_ids, new_ids; +template +class ConnectionChangesTest : public testing::Test { + public: + ConnectionChangesTest() { + std::vector old_ids, new_ids; - for (auto index(Parameters::closest_nodes_size); index != 0; --index) - old_ids.push_back(NodeId(RandomString(NodeId::kSize))); + 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(CloseNodesChange(kNodeId_, old_ids, new_ids)); + new_ids = old_ids; + old_ids.erase(old_ids.begin()); + auto close_nodes_change(ConnectionType(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); } - { - auto client_nodes_change(ClientNodesChange(kNodeId_, old_ids, new_ids)); - auto copy(client_nodes_change); - auto copy2(std::move(copy)); - EXPECT_EQ(client_nodes_change, copy2); - EXPECT_NE(copy, copy2); - } - { - auto connections_change(ConnectionsChange(kNodeId_, old_ids, new_ids)); - auto copy(connections_change); - auto copy2(std::move(copy)); - EXPECT_EQ(connections_change, copy2); - EXPECT_NE(copy, copy2); - } -} +}; + +TYPED_TEST_CASE_P(ConnectionChangesTest); + +TYPED_TEST_P(ConnectionChangesTest, BEH_BEH_Constructors) {} + +REGISTER_TYPED_TEST_CASE_P(ConnectionChangesTest, BEH_BEH_Constructors); +typedef testing::Types ConnectionTypes; +INSTANTIATE_TYPED_TEST_CASE_P(AccountTransfer, ConnectionChangesTest, ConnectionTypes); } // namespace test From d243ba79af4ce0d4c14c4c1cb116a732dfca9e85 Mon Sep 17 00:00:00 2001 From: moadeli Date: Fri, 30 Jan 2015 11:21:56 +0000 Subject: [PATCH 3/4] uses using --- src/maidsafe/routing/tests/close_nodes_change_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/maidsafe/routing/tests/close_nodes_change_test.cc b/src/maidsafe/routing/tests/close_nodes_change_test.cc index 05ddb62d..e0558cc8 100644 --- a/src/maidsafe/routing/tests/close_nodes_change_test.cc +++ b/src/maidsafe/routing/tests/close_nodes_change_test.cc @@ -409,7 +409,7 @@ TYPED_TEST_CASE_P(ConnectionChangesTest); TYPED_TEST_P(ConnectionChangesTest, BEH_BEH_Constructors) {} REGISTER_TYPED_TEST_CASE_P(ConnectionChangesTest, BEH_BEH_Constructors); -typedef testing::Types ConnectionTypes; +using ConnectionTypes = testing::Types; INSTANTIATE_TYPED_TEST_CASE_P(AccountTransfer, ConnectionChangesTest, ConnectionTypes); } // namespace test From f79411fe084a15dfdb90ac495680e373d70ad5ed Mon Sep 17 00:00:00 2001 From: moadeli Date: Mon, 2 Feb 2015 12:13:03 +0000 Subject: [PATCH 4/4] changes connenction constructors Parameterised tests to typed ones. --- .../routing/tests/close_nodes_change_test.cc | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/maidsafe/routing/tests/close_nodes_change_test.cc b/src/maidsafe/routing/tests/close_nodes_change_test.cc index e0558cc8..143fe49b 100644 --- a/src/maidsafe/routing/tests/close_nodes_change_test.cc +++ b/src/maidsafe/routing/tests/close_nodes_change_test.cc @@ -386,31 +386,25 @@ TEST_F(CloseNodesChangeTest, BEH_FullSizeRoutingTable) { } template -class ConnectionChangesTest : public testing::Test { - public: - ConnectionChangesTest() { - 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(ConnectionType(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); - } -}; +class ConnectionChangesTest : public testing::Test {}; -TYPED_TEST_CASE_P(ConnectionChangesTest); +using ConnectionTypes = testing::Types; +TYPED_TEST_CASE(ConnectionChangesTest, ConnectionTypes); -TYPED_TEST_P(ConnectionChangesTest, BEH_BEH_Constructors) {} +TYPED_TEST(ConnectionChangesTest, BEH_Constructors) { + std::vector old_ids, new_ids; -REGISTER_TYPED_TEST_CASE_P(ConnectionChangesTest, BEH_BEH_Constructors); -using ConnectionTypes = testing::Types; -INSTANTIATE_TYPED_TEST_CASE_P(AccountTransfer, ConnectionChangesTest, ConnectionTypes); + 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