1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
32c9efc3cSEd Tanous #include "verb.hpp"
42c9efc3cSEd Tanous
52c9efc3cSEd Tanous #include <boost/beast/http/verb.hpp>
62c9efc3cSEd Tanous
72c9efc3cSEd Tanous #include <map>
82c9efc3cSEd Tanous #include <optional>
92c9efc3cSEd Tanous #include <string_view>
102c9efc3cSEd Tanous
11478b7adfSEd Tanous #include <gtest/gtest.h>
122c9efc3cSEd Tanous
132c9efc3cSEd Tanous using BoostVerb = boost::beast::http::verb;
142c9efc3cSEd Tanous
TEST(BoostToHttpVerb,ValidCase)152c9efc3cSEd Tanous TEST(BoostToHttpVerb, ValidCase)
162c9efc3cSEd Tanous {
172c9efc3cSEd Tanous std::map<HttpVerb, BoostVerb> verbMap = {
182c9efc3cSEd Tanous {HttpVerb::Delete, BoostVerb::delete_},
192c9efc3cSEd Tanous {HttpVerb::Get, BoostVerb::get},
202c9efc3cSEd Tanous {HttpVerb::Head, BoostVerb::head},
212c9efc3cSEd Tanous {HttpVerb::Options, BoostVerb::options},
222c9efc3cSEd Tanous {HttpVerb::Patch, BoostVerb::patch},
232c9efc3cSEd Tanous {HttpVerb::Post, BoostVerb::post},
242c9efc3cSEd Tanous {HttpVerb::Put, BoostVerb::put},
252c9efc3cSEd Tanous };
262c9efc3cSEd Tanous
272c9efc3cSEd Tanous for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
282c9efc3cSEd Tanous ++verbIndex)
292c9efc3cSEd Tanous {
302c9efc3cSEd Tanous HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
312c9efc3cSEd Tanous std::optional<HttpVerb> verb = httpVerbFromBoost(verbMap[httpVerb]);
32e01d0c36SEd Tanous EXPECT_EQ(verb, httpVerb);
332c9efc3cSEd Tanous }
342c9efc3cSEd Tanous }
352c9efc3cSEd Tanous
TEST(BoostToHttpVerbTest,InvalidCase)362c9efc3cSEd Tanous TEST(BoostToHttpVerbTest, InvalidCase)
372c9efc3cSEd Tanous {
382c9efc3cSEd Tanous std::optional<HttpVerb> verb = httpVerbFromBoost(BoostVerb::unknown);
392c9efc3cSEd Tanous EXPECT_FALSE(verb.has_value());
402c9efc3cSEd Tanous }
412c9efc3cSEd Tanous
TEST(HttpVerbToStringTest,ValidCase)422c9efc3cSEd Tanous TEST(HttpVerbToStringTest, ValidCase)
432c9efc3cSEd Tanous {
442c9efc3cSEd Tanous std::map<HttpVerb, std::string_view> verbMap = {
452c9efc3cSEd Tanous {HttpVerb::Delete, "DELETE"}, {HttpVerb::Get, "GET"},
462c9efc3cSEd Tanous {HttpVerb::Head, "HEAD"}, {HttpVerb::Options, "OPTIONS"},
472c9efc3cSEd Tanous {HttpVerb::Patch, "PATCH"}, {HttpVerb::Post, "POST"},
482c9efc3cSEd Tanous {HttpVerb::Put, "PUT"},
492c9efc3cSEd Tanous };
502c9efc3cSEd Tanous
512c9efc3cSEd Tanous for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
522c9efc3cSEd Tanous ++verbIndex)
532c9efc3cSEd Tanous {
542c9efc3cSEd Tanous HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
552c9efc3cSEd Tanous EXPECT_EQ(httpVerbToString(httpVerb), verbMap[httpVerb]);
562c9efc3cSEd Tanous }
572c9efc3cSEd Tanous }
58