Skip to content

Commit

Permalink
UserJson test
Browse files Browse the repository at this point in the history
  • Loading branch information
afiskon committed Oct 27, 2017
1 parent 036b138 commit 006e581
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ class User {
};


bool operator==(const User& d1, const User& d2);
bool operator!=(const User& d1, const User& d2);
std::ostream& operator<<(std::ostream& os, const User& user);
11 changes: 11 additions & 0 deletions src/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ User& User::setBirthday(Date birthday) {
return *this;
}

bool operator==(const User& u1, const User& u2) {
return (u1.getId() == u2.getId()) &&
(u1.getName() == u2.getName()) &&
(u1.getPhone() == u2.getPhone()) &&
(u1.getBirthday() == u2.getBirthday());
}

bool operator!=(const User& u1, const User& u2) {
return !(u1 == u2);
}

std::ostream& operator<<(std::ostream& os, const User& user) {
os << "User(id = " << user.getId() << ", name = " << user.getName() << ", phone = " << user.getPhone()
<< ", birthday = " << user.getBirthday() << ")";
Expand Down
7 changes: 7 additions & 0 deletions tests/TestSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ TEST_F(TestSerialization, DateJson) {
ASSERT_EQ(d1, d2);
}

TEST_F(TestSerialization, UserJson) {
User u1(123, "Alex", 7916123456, Date(1988, 8, 5));
rapidjson::Document json = u1.toJSON();
User u2 = User::fromJSON(json);
ASSERT_EQ(u1, u2);
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit 006e581

Please sign in to comment.