From b2896149c39967dd9d1ee79357bdc53537cfabd7 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Wed, 31 Jan 2024 15:25:47 -0800 Subject: Rename FileBody to HttpBody Now that our custom body type does things more than files, it makes sense to rename it. This commit renames the header itself, then all instances of the class. Tested: Basic GET requests succeed. Change-Id: If4361ac8992fc7c268f48a336707f96e68d3576c Signed-off-by: Ed Tanous --- test/http/http_body_test.cpp | 128 ++++++++++++++++++++++++++++++++++++++ test/http/http_file_body_test.cpp | 128 -------------------------------------- test/http/http_response_test.cpp | 17 ++--- 3 files changed, 137 insertions(+), 136 deletions(-) create mode 100644 test/http/http_body_test.cpp delete mode 100644 test/http/http_file_body_test.cpp (limited to 'test') diff --git a/test/http/http_body_test.cpp b/test/http/http_body_test.cpp new file mode 100644 index 0000000000..6367cf9409 --- /dev/null +++ b/test/http/http_body_test.cpp @@ -0,0 +1,128 @@ +#include "file_test_utilities.hpp" +#include "http_body.hpp" + +#include + +#include +#include +#include + +#include +#include + +using ::testing::ElementsAre; + +namespace bmcweb +{ +namespace +{ + +TEST(HttpHttpBodyValueType, MoveString) +{ + HttpBody::value_type value("teststring"); + // Move constructor + HttpBody::value_type value2(std::move(value)); + EXPECT_EQ(value2.encodingType, EncodingType::Raw); + EXPECT_EQ(value2.str(), "teststring"); + EXPECT_EQ(value2.payloadSize(), 10); +} + +TEST(HttpHttpBodyValueType, MoveOperatorString) +{ + HttpBody::value_type value; + value.str() = "teststring"; + // Move constructor + HttpBody::value_type value2 = std::move(value); + EXPECT_EQ(value2.encodingType, EncodingType::Raw); + EXPECT_EQ(value2.str(), "teststring"); + EXPECT_EQ(value2.payloadSize(), 10); +} + +TEST(HttpHttpBodyValueType, copysignl) +{ + HttpBody::value_type value; + value.str() = "teststring"; + // Move constructor + HttpBody::value_type value2(value); + EXPECT_EQ(value2.encodingType, EncodingType::Raw); + EXPECT_EQ(value2.str(), "teststring"); + EXPECT_EQ(value2.payloadSize(), 10); +} + +TEST(HttpHttpBodyValueType, CopyOperatorString) +{ + HttpBody::value_type value; + value.str() = "teststring"; + // Move constructor + HttpBody::value_type value2 = value; + EXPECT_EQ(value2.encodingType, EncodingType::Raw); + EXPECT_EQ(value2.str(), "teststring"); + EXPECT_EQ(value2.payloadSize(), 10); +} + +TEST(HttpHttpBodyValueType, MoveFile) +{ + HttpBody::value_type value(EncodingType::Base64); + std::string filepath = makeFile("teststring"); + boost::system::error_code ec; + value.open(filepath.c_str(), boost::beast::file_mode::read, ec); + ASSERT_FALSE(ec); + // Move constructor + HttpBody::value_type value2(std::move(value)); + std::array buffer{}; + size_t out = value2.file().read(buffer.data(), buffer.size(), ec); + ASSERT_FALSE(ec); + EXPECT_EQ(value2.encodingType, EncodingType::Base64); + + EXPECT_THAT(std::span(buffer.data(), out), + ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', 'g')); + + EXPECT_THAT(buffer, ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', + 'g', '\0')); + + EXPECT_EQ(value2.payloadSize(), 16); +} + +TEST(HttpHttpBodyValueType, MoveOperatorFile) +{ + HttpBody::value_type value(EncodingType::Base64); + std::string filepath = makeFile("teststring"); + boost::system::error_code ec; + value.open(filepath.c_str(), boost::beast::file_mode::read, ec); + ASSERT_FALSE(ec); + // Move constructor + HttpBody::value_type value2 = std::move(value); + std::array buffer{}; + size_t out = value2.file().read(buffer.data(), buffer.size(), ec); + ASSERT_FALSE(ec); + EXPECT_EQ(value2.encodingType, EncodingType::Base64); + + EXPECT_THAT(std::span(buffer.data(), out), + ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', 'g')); + EXPECT_THAT(buffer, ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', + 'g', '\0')); + + EXPECT_EQ(value2.payloadSize(), 16); +} + +TEST(HttpBodyValueType, SetFd) +{ + HttpBody::value_type value(EncodingType::Base64); + std::string filepath = makeFile("teststring"); + + boost::system::error_code ec; + value.setFd(fileno(fopen(filepath.c_str(), "r")), ec); + ASSERT_FALSE(ec); + + std::array buffer{}; + + size_t out = value.file().read(buffer.data(), buffer.size(), ec); + ASSERT_FALSE(ec); + + EXPECT_THAT(std::span(buffer.data(), out), + ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', 'g')); + EXPECT_EQ(value.payloadSize(), 16); +} + +} // namespace +} // namespace bmcweb diff --git a/test/http/http_file_body_test.cpp b/test/http/http_file_body_test.cpp deleted file mode 100644 index 4eaa93bac2..0000000000 --- a/test/http/http_file_body_test.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "file_test_utilities.hpp" -#include "http_file_body.hpp" - -#include - -#include -#include -#include - -#include -#include - -using ::testing::ElementsAre; - -namespace bmcweb -{ -namespace -{ - -TEST(HttpFileBodyValueType, MoveString) -{ - FileBody::value_type value("teststring"); - // Move constructor - FileBody::value_type value2(std::move(value)); - EXPECT_EQ(value2.encodingType, EncodingType::Raw); - EXPECT_EQ(value2.str(), "teststring"); - EXPECT_EQ(value2.payloadSize(), 10); -} - -TEST(HttpFileBodyValueType, MoveOperatorString) -{ - FileBody::value_type value; - value.str() = "teststring"; - // Move constructor - FileBody::value_type value2 = std::move(value); - EXPECT_EQ(value2.encodingType, EncodingType::Raw); - EXPECT_EQ(value2.str(), "teststring"); - EXPECT_EQ(value2.payloadSize(), 10); -} - -TEST(HttpFileBodyValueType, copysignl) -{ - FileBody::value_type value; - value.str() = "teststring"; - // Move constructor - FileBody::value_type value2(value); - EXPECT_EQ(value2.encodingType, EncodingType::Raw); - EXPECT_EQ(value2.str(), "teststring"); - EXPECT_EQ(value2.payloadSize(), 10); -} - -TEST(HttpFileBodyValueType, CopyOperatorString) -{ - FileBody::value_type value; - value.str() = "teststring"; - // Move constructor - FileBody::value_type value2 = value; - EXPECT_EQ(value2.encodingType, EncodingType::Raw); - EXPECT_EQ(value2.str(), "teststring"); - EXPECT_EQ(value2.payloadSize(), 10); -} - -TEST(HttpFileBodyValueType, MoveFile) -{ - FileBody::value_type value(EncodingType::Base64); - std::string filepath = makeFile("teststring"); - boost::system::error_code ec; - value.open(filepath.c_str(), boost::beast::file_mode::read, ec); - ASSERT_FALSE(ec); - // Move constructor - FileBody::value_type value2(std::move(value)); - std::array buffer{}; - size_t out = value2.file().read(buffer.data(), buffer.size(), ec); - ASSERT_FALSE(ec); - EXPECT_EQ(value2.encodingType, EncodingType::Base64); - - EXPECT_THAT(std::span(buffer.data(), out), - ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', 'g')); - - EXPECT_THAT(buffer, ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', - 'g', '\0')); - - EXPECT_EQ(value2.payloadSize(), 16); -} - -TEST(HttpFileBodyValueType, MoveOperatorFile) -{ - FileBody::value_type value(EncodingType::Base64); - std::string filepath = makeFile("teststring"); - boost::system::error_code ec; - value.open(filepath.c_str(), boost::beast::file_mode::read, ec); - ASSERT_FALSE(ec); - // Move constructor - FileBody::value_type value2 = std::move(value); - std::array buffer{}; - size_t out = value2.file().read(buffer.data(), buffer.size(), ec); - ASSERT_FALSE(ec); - EXPECT_EQ(value2.encodingType, EncodingType::Base64); - - EXPECT_THAT(std::span(buffer.data(), out), - ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', 'g')); - EXPECT_THAT(buffer, ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', - 'g', '\0')); - - EXPECT_EQ(value2.payloadSize(), 16); -} - -TEST(HttpFileBodyValueType, SetFd) -{ - FileBody::value_type value(EncodingType::Base64); - std::string filepath = makeFile("teststring"); - - boost::system::error_code ec; - value.setFd(fileno(fopen(filepath.c_str(), "r")), ec); - ASSERT_FALSE(ec); - - std::array buffer{}; - - size_t out = value.file().read(buffer.data(), buffer.size(), ec); - ASSERT_FALSE(ec); - - EXPECT_THAT(std::span(buffer.data(), out), - ElementsAre('t', 'e', 's', 't', 's', 't', 'r', 'i', 'n', 'g')); - EXPECT_EQ(value.payloadSize(), 16); -} - -} // namespace -} // namespace bmcweb diff --git a/test/http/http_response_test.cpp b/test/http/http_response_test.cpp index c5bfbdca99..457cd7a924 100644 --- a/test/http/http_response_test.cpp +++ b/test/http/http_response_test.cpp @@ -2,6 +2,7 @@ #include "boost/beast/core/flat_buffer.hpp" #include "boost/beast/http/serializer.hpp" #include "file_test_utilities.hpp" +#include "http/http_body.hpp" #include "http/http_response.hpp" #include @@ -24,11 +25,11 @@ void verifyHeaders(crow::Response& res) EXPECT_EQ(res.result(), boost::beast::http::status::ok); } -std::string getData(boost::beast::http::response& m) +std::string getData(boost::beast::http::response& m) { std::string ret; - boost::beast::http::response_serializer sr{m}; + boost::beast::http::response_serializer sr{m}; sr.split(true); auto reader = [&sr, &ret](const boost::system::error_code& ec2, @@ -73,7 +74,7 @@ TEST(HttpResponse, StringBody) EXPECT_EQ(*res.body(), bodyvalue); verifyHeaders(res); } -TEST(HttpResponse, FileBody) +TEST(HttpResponse, HttpBody) { crow::Response res; addHeaders(res); @@ -83,7 +84,7 @@ TEST(HttpResponse, FileBody) verifyHeaders(res); std::filesystem::remove(path); } -TEST(HttpResponse, FileBodyWithFd) +TEST(HttpResponse, HttpBodyWithFd) { crow::Response res; addHeaders(res); @@ -95,7 +96,7 @@ TEST(HttpResponse, FileBodyWithFd) std::filesystem::remove(path); } -TEST(HttpResponse, Base64FileBodyWithFd) +TEST(HttpResponse, Base64HttpBodyWithFd) { crow::Response res; addHeaders(res); @@ -145,7 +146,7 @@ TEST(HttpResponse, StringBodyWriterLarge) testFileData(res, data); } -TEST(HttpResponse, Base64FileBodyWriter) +TEST(HttpResponse, Base64HttpBodyWriter) { crow::Response res; std::string data = "sample text"; @@ -157,7 +158,7 @@ TEST(HttpResponse, Base64FileBodyWriter) std::filesystem::remove(path); } -TEST(HttpResponse, Base64FileBodyWriterLarge) +TEST(HttpResponse, Base64HttpBodyWriterLarge) { crow::Response res; std::string data = generateBigdata(); @@ -174,7 +175,7 @@ TEST(HttpResponse, Base64FileBodyWriterLarge) std::filesystem::remove(path); } -TEST(HttpResponse, FileBodyWriterLarge) +TEST(HttpResponse, HttpBodyWriterLarge) { crow::Response res; std::string data = generateBigdata(); -- cgit v1.2.3