Skip to content

Commit

Permalink
feat(reply): implement ftp::reply::is_intermediate() method
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskovalchuk committed Sep 30, 2023
1 parent 5bb3de9 commit f331049
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/ftp/reply.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class reply

[[nodiscard]] bool is_negative() const;

[[nodiscard]] bool is_intermediate() const;

[[nodiscard]] std::uint16_t get_code() const;

[[nodiscard]] const std::string & get_status_string() const;
Expand Down
5 changes: 5 additions & 0 deletions src/reply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ bool reply::is_negative() const
return code_ != unspecified && code_ >= 400;
}

bool reply::is_intermediate() const
{
return code_ != unspecified && code_ >= 300 && code_ < 400;
}

std::uint16_t reply::get_code() const
{
return code_;
Expand Down
6 changes: 6 additions & 0 deletions test/reply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TEST(reply, construct)
EXPECT_EQ("", reply.get_status_string());
EXPECT_FALSE(reply.is_positive());
EXPECT_FALSE(reply.is_negative());
EXPECT_FALSE(reply.is_intermediate());
}

{
Expand All @@ -44,6 +45,7 @@ TEST(reply, construct)
EXPECT_EQ("120 Service ready in 2 minutes.", reply.get_status_string());
EXPECT_TRUE(reply.is_positive());
EXPECT_FALSE(reply.is_negative());
EXPECT_FALSE(reply.is_intermediate());
}

{
Expand All @@ -52,6 +54,7 @@ TEST(reply, construct)
EXPECT_EQ("220 FTP server is ready.", reply.get_status_string());
EXPECT_TRUE(reply.is_positive());
EXPECT_FALSE(reply.is_negative());
EXPECT_FALSE(reply.is_intermediate());
}

{
Expand All @@ -60,6 +63,7 @@ TEST(reply, construct)
EXPECT_EQ("331 Username ok, send password.", reply.get_status_string());
EXPECT_TRUE(reply.is_positive());
EXPECT_FALSE(reply.is_negative());
EXPECT_TRUE(reply.is_intermediate());
}

{
Expand All @@ -68,6 +72,7 @@ TEST(reply, construct)
EXPECT_EQ("425 Can't open data connection.", reply.get_status_string());
EXPECT_FALSE(reply.is_positive());
EXPECT_TRUE(reply.is_negative());
EXPECT_FALSE(reply.is_intermediate());
}

{
Expand All @@ -76,6 +81,7 @@ TEST(reply, construct)
EXPECT_EQ("532 Need account for storing files.", reply.get_status_string());
EXPECT_FALSE(reply.is_positive());
EXPECT_TRUE(reply.is_negative());
EXPECT_FALSE(reply.is_intermediate());
}
}

Expand Down

0 comments on commit f331049

Please sign in to comment.