Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

testing constructors #98

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 13 additions & 1 deletion include/maidsafe/routing/close_nodes_change.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct CheckHoldersResult {
};

class ConnectionsChange {
protected:
public:
ConnectionsChange() = default;
ConnectionsChange(const ConnectionsChange& other) = default;
ConnectionsChange(ConnectionsChange&& other);
Expand All @@ -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_;
Expand All @@ -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 {
Expand All @@ -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;
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions src/maidsafe/routing/close_nodes_change.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -168,6 +184,14 @@ void swap(ClientNodesChange& lhs, ClientNodesChange& rhs) MAIDSAFE_NOEXCEPT {
swap(static_cast<ConnectionsChange&>(lhs), static_cast<ConnectionsChange&>(rhs));
}

bool operator==(const ClientNodesChange& lhs, const ClientNodesChange& rhs) {
return (static_cast<ConnectionsChange>(lhs) == static_cast<ConnectionsChange>(rhs));
}

bool operator!=(const ClientNodesChange& lhs, const ClientNodesChange& rhs) {
return !(lhs == rhs);
}

// ========================== non-client client close nodes change =================================

CloseNodesChange::CloseNodesChange(CloseNodesChange&& other)
Expand Down Expand Up @@ -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<ConnectionsChange>(lhs) == static_cast<ConnectionsChange>(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<ConnectionsChange&>(lhs), static_cast<ConnectionsChange&>(rhs));
Expand Down
31 changes: 31 additions & 0 deletions src/maidsafe/routing/tests/close_nodes_change_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,37 @@ TEST_F(CloseNodesChangeTest, BEH_FullSizeRoutingTable) {
}
}

TEST_F(CloseNodesChangeTest, BEH_Constructors) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a type-parameterised test rather than repeating the identical contents of the test three times.

std::vector<NodeId> 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
Expand Down