Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 1 | #include "verb.hpp" |
| 2 | |
| 3 | #include <boost/beast/http/verb.hpp> |
| 4 | |
| 5 | #include <map> |
| 6 | #include <optional> |
| 7 | #include <string_view> |
| 8 | |
| 9 | #include <gtest/gtest.h> // IWYU pragma: keep |
| 10 | |
| 11 | using BoostVerb = boost::beast::http::verb; |
| 12 | |
| 13 | TEST(BoostToHttpVerb, ValidCase) |
| 14 | { |
| 15 | std::map<HttpVerb, BoostVerb> verbMap = { |
| 16 | {HttpVerb::Delete, BoostVerb::delete_}, |
| 17 | {HttpVerb::Get, BoostVerb::get}, |
| 18 | {HttpVerb::Head, BoostVerb::head}, |
| 19 | {HttpVerb::Options, BoostVerb::options}, |
| 20 | {HttpVerb::Patch, BoostVerb::patch}, |
| 21 | {HttpVerb::Post, BoostVerb::post}, |
| 22 | {HttpVerb::Put, BoostVerb::put}, |
| 23 | }; |
| 24 | |
| 25 | for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max); |
| 26 | ++verbIndex) |
| 27 | { |
| 28 | HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex); |
| 29 | std::optional<HttpVerb> verb = httpVerbFromBoost(verbMap[httpVerb]); |
| 30 | ASSERT_TRUE(verb.has_value()); |
| 31 | EXPECT_EQ(*verb, httpVerb); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | TEST(BoostToHttpVerbTest, InvalidCase) |
| 36 | { |
| 37 | std::optional<HttpVerb> verb = httpVerbFromBoost(BoostVerb::unknown); |
| 38 | EXPECT_FALSE(verb.has_value()); |
| 39 | } |
| 40 | |
| 41 | TEST(HttpVerbToStringTest, ValidCase) |
| 42 | { |
| 43 | std::map<HttpVerb, std::string_view> verbMap = { |
| 44 | {HttpVerb::Delete, "DELETE"}, {HttpVerb::Get, "GET"}, |
| 45 | {HttpVerb::Head, "HEAD"}, {HttpVerb::Options, "OPTIONS"}, |
| 46 | {HttpVerb::Patch, "PATCH"}, {HttpVerb::Post, "POST"}, |
| 47 | {HttpVerb::Put, "PUT"}, |
| 48 | }; |
| 49 | |
| 50 | for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max); |
| 51 | ++verbIndex) |
| 52 | { |
| 53 | HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex); |
| 54 | EXPECT_EQ(httpVerbToString(httpVerb), verbMap[httpVerb]); |
| 55 | } |
| 56 | } |