Skip to content

Commit

Permalink
Replacing time_t with std::chrono::seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Aug 18, 2024
1 parent 42d2804 commit 5772153
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions test/get_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <chrono>
#include <gtest/gtest.h>

#include <memory>
Expand Down Expand Up @@ -113,8 +114,8 @@ TEST(CookiesTests, BasicCookiesTest) {
cpr::Cookies res_cookies{response.cookies};
std::string expected_text{"Basic Cookies"};
cpr::Cookies expectedCookies{
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
};
EXPECT_EQ(expected_text, response.text);
EXPECT_EQ(url, response.url);
Expand All @@ -138,8 +139,8 @@ TEST(CookiesTests, EmptyCookieTest) {
cpr::Cookies res_cookies{response.cookies};
std::string expected_text{"Empty Cookies"};
cpr::Cookies expectedCookies{
{"SID", "", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"lang", "", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"SID", "", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
{"lang", "", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
};
EXPECT_EQ(url, response.url);
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
Expand All @@ -160,8 +161,8 @@ TEST(CookiesTests, EmptyCookieTest) {
TEST(CookiesTests, ClientSetCookiesTest) {
Url url{server->GetBaseUrl() + "/cookies_reflect.html"};
Cookies cookies{
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
};
Response response = cpr::Get(url, cookies);
std::string expected_text{"SID=31d4d96e407aad42; lang=en-US;"};
Expand All @@ -175,8 +176,8 @@ TEST(CookiesTests, ClientSetCookiesTest) {
TEST(CookiesTests, UnencodedCookiesTest) {
Url url{server->GetBaseUrl() + "/cookies_reflect.html"};
Cookies cookies{
{"SID", "31d4d %$ 96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"SID", "31d4d %$ 96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
};
cookies.encode = false;
Response response = cpr::Get(url, cookies);
Expand Down
4 changes: 2 additions & 2 deletions test/head_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ TEST(HeadTests, CookieHeadTest) {
Url url{server->GetBaseUrl() + "/basic_cookies.html"};
Response response = cpr::Head(url);
cpr::Cookies expectedCookies{
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
};
cpr::Cookies res_cookies{response.cookies};
EXPECT_EQ(std::string{}, response.text);
Expand Down
4 changes: 2 additions & 2 deletions test/session_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,8 @@ TEST(CookiesTests, BasicCookiesTest) {
Cookies res_cookies{response.cookies};
std::string expected_text{"Basic Cookies"};
cpr::Cookies expectedCookies{
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::from_time_t(3905119080)},
{"SID", "31d4d96e407aad42", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
{"lang", "en-US", "127.0.0.1", false, "/", true, std::chrono::system_clock::time_point{} + std::chrono::seconds(3905119080)},
};
EXPECT_EQ(std::string{"text/html"}, response.header["content-type"]);
EXPECT_EQ(200, response.status_code);
Expand Down

0 comments on commit 5772153

Please sign in to comment.