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>
10
11 using BoostVerb = boost::beast::http::verb;
12
TEST(BoostToHttpVerb,ValidCase)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 EXPECT_EQ(verb, httpVerb);
31 }
32 }
33
TEST(BoostToHttpVerbTest,InvalidCase)34 TEST(BoostToHttpVerbTest, InvalidCase)
35 {
36 std::optional<HttpVerb> verb = httpVerbFromBoost(BoostVerb::unknown);
37 EXPECT_FALSE(verb.has_value());
38 }
39
TEST(HttpVerbToStringTest,ValidCase)40 TEST(HttpVerbToStringTest, ValidCase)
41 {
42 std::map<HttpVerb, std::string_view> verbMap = {
43 {HttpVerb::Delete, "DELETE"}, {HttpVerb::Get, "GET"},
44 {HttpVerb::Head, "HEAD"}, {HttpVerb::Options, "OPTIONS"},
45 {HttpVerb::Patch, "PATCH"}, {HttpVerb::Post, "POST"},
46 {HttpVerb::Put, "PUT"},
47 };
48
49 for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
50 ++verbIndex)
51 {
52 HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
53 EXPECT_EQ(httpVerbToString(httpVerb), verbMap[httpVerb]);
54 }
55 }
56