Nan Zhou | 93b443d | 2022-06-21 17:46:51 +0000 | [diff] [blame] | 1 | #include "http_utility.hpp" |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 2 | |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 3 | #include <gtest/gtest.h> // IWYU pragma: keep |
| 4 | |
| 5 | // IWYU pragma: no_include <gtest/gtest-message.h> |
| 6 | // IWYU pragma: no_include <gtest/gtest-test-part.h> |
| 7 | // IWYU pragma: no_include "gtest/gtest_pred_impl.h" |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 8 | |
Nan Zhou | ad3edd4 | 2022-06-21 17:46:44 +0000 | [diff] [blame] | 9 | namespace http_helpers |
| 10 | { |
| 11 | namespace |
| 12 | { |
| 13 | |
Nan Zhou | a02b586 | 2022-06-21 17:46:56 +0000 | [diff] [blame] | 14 | TEST(RequestPrefersHtml, ContainsHtmlReturnsTrue) |
| 15 | { |
| 16 | EXPECT_TRUE(requestPrefersHtml("text/html, application/json")); |
| 17 | } |
| 18 | |
| 19 | TEST(RequestPrefersHtml, NoHtmlReturnsFalse) |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 20 | { |
Nan Zhou | ad3edd4 | 2022-06-21 17:46:44 +0000 | [diff] [blame] | 21 | EXPECT_FALSE(requestPrefersHtml("*/*, application/octet-stream")); |
Nan Zhou | ad3edd4 | 2022-06-21 17:46:44 +0000 | [diff] [blame] | 22 | EXPECT_FALSE(requestPrefersHtml("application/json")); |
Nan Zhou | a02b586 | 2022-06-21 17:46:56 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | TEST(IsOctetAccepted, ContainsOctetReturnsTrue) |
| 26 | { |
| 27 | EXPECT_TRUE(isOctetAccepted("*/*, application/octet-stream")); |
| 28 | } |
| 29 | |
Gunnar Mills | a3526fe | 2022-02-02 21:56:44 +0000 | [diff] [blame] | 30 | TEST(IsOctetAccepted, ContainsAnyMimeTypeReturnsTrue) |
| 31 | { |
| 32 | EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*")); |
| 33 | } |
| 34 | |
| 35 | TEST(IsOctetAccepted, ContainsQFactorWeightingReturnsTrue) |
| 36 | { |
| 37 | EXPECT_TRUE(http_helpers::isOctetAccepted("text/html, */*;q=0.8")); |
| 38 | } |
| 39 | |
Nan Zhou | a02b586 | 2022-06-21 17:46:56 +0000 | [diff] [blame] | 40 | TEST(IsOctetAccepted, NoOctetReturnsFalse) |
| 41 | { |
| 42 | EXPECT_FALSE(isOctetAccepted("text/html, application/json")); |
Nan Zhou | ad3edd4 | 2022-06-21 17:46:44 +0000 | [diff] [blame] | 43 | EXPECT_FALSE(isOctetAccepted("application/json")); |
George Liu | 647b3cd | 2021-07-05 12:43:56 +0800 | [diff] [blame] | 44 | } |
Nan Zhou | ad3edd4 | 2022-06-21 17:46:44 +0000 | [diff] [blame] | 45 | |
| 46 | } // namespace |
Gunnar Mills | a3526fe | 2022-02-02 21:56:44 +0000 | [diff] [blame] | 47 | } // namespace http_helpers |