From b3a467678dc5bebdc2970be211b2b8338ae73ad6 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 26 Aug 2023 23:59:04 -0600 Subject: [PATCH] Add tests for `sf::Http` This class hides a lot of its logic in the private section of the classes and uses friends to access them so there is little accessible in the public interface for testing. --- include/SFML/Network/Http.hpp | 2 +- src/SFML/Network/Http.cpp | 4 --- test/Network/Http.test.cpp | 48 ++++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/include/SFML/Network/Http.hpp b/include/SFML/Network/Http.hpp index fff7619d..df22fe98 100644 --- a/include/SFML/Network/Http.hpp +++ b/include/SFML/Network/Http.hpp @@ -338,7 +338,7 @@ public: /// \brief Default constructor /// //////////////////////////////////////////////////////////// - Http(); + Http() = default; //////////////////////////////////////////////////////////// /// \brief Construct the HTTP client with the target host diff --git a/src/SFML/Network/Http.cpp b/src/SFML/Network/Http.cpp index f9ee0d54..3e9e705d 100644 --- a/src/SFML/Network/Http.cpp +++ b/src/SFML/Network/Http.cpp @@ -286,10 +286,6 @@ void Http::Response::parseFields(std::istream& in) } -//////////////////////////////////////////////////////////// -Http::Http() = default; - - //////////////////////////////////////////////////////////// Http::Http(const std::string& host, unsigned short port) { diff --git a/test/Network/Http.test.cpp b/test/Network/Http.test.cpp index 71e8cc65..bc362af3 100644 --- a/test/Network/Http.test.cpp +++ b/test/Network/Http.test.cpp @@ -1,8 +1,48 @@ #include +#include + #include -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); -static_assert(!std::is_nothrow_move_constructible_v); -static_assert(!std::is_nothrow_move_assignable_v); +TEST_CASE("[Network] sf::Http") +{ + SECTION("Type traits") + { + STATIC_CHECK(!std::is_copy_constructible_v); + STATIC_CHECK(!std::is_copy_assignable_v); + STATIC_CHECK(!std::is_nothrow_move_constructible_v); + STATIC_CHECK(!std::is_nothrow_move_assignable_v); + } + + SECTION("Request") + { + SECTION("Type traits") + { + STATIC_CHECK(std::is_copy_constructible_v); + STATIC_CHECK(std::is_copy_assignable_v); + STATIC_CHECK(std::is_move_constructible_v); + STATIC_CHECK(std::is_nothrow_move_assignable_v); + } + } + + SECTION("Response") + { + SECTION("Type traits") + { + STATIC_CHECK(std::is_copy_constructible_v); + STATIC_CHECK(std::is_copy_assignable_v); + STATIC_CHECK(std::is_move_constructible_v); + STATIC_CHECK(std::is_nothrow_move_assignable_v); + } + + SECTION("Construction") + { + const sf::Http::Response response; + CHECK(response.getField("").empty()); + CHECK(response.getStatus() == sf::Http::Response::Status::ConnectionFailed); + CHECK(response.getMajorHttpVersion() == 0); + CHECK(response.getMinorHttpVersion() == 0); + CHECK(response.getBody().empty()); + } + } +}