Skip to content

Commit

Permalink
Add PATCH callback tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whoshuu committed Oct 28, 2015
1 parent 2c3adbb commit 8b4284d
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions test/callback_tests.cpp
Expand Up @@ -620,6 +620,109 @@ TEST(CallbackOptionsTests, CallbackOptionsFunctionTextReferenceTest) {
EXPECT_EQ(expected_text, future.get());
}

TEST(CallbackPatchTests, CallbackPatchLambdaStatusTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto status_code = 0;
auto future = cpr::PatchCallback([&status_code] (Response r) {
status_code = r.status_code;
return r.status_code;
}, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(status_code, future.get());
}

TEST(CallbackPatchTests, CallbackPatchLambdaTextTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto expected_text = std::string{};
auto future = cpr::PatchCallback([&expected_text] (Response r) {
expected_text = r.text;
return r.text;
}, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(expected_text, future.get());
}

TEST(CallbackPatchTests, CallbackPatchLambdaStatusReferenceTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto status_code = 0;
auto future = cpr::PatchCallback([&status_code] (const Response& r) {
status_code = r.status_code;
return r.status_code;
}, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(status_code, future.get());
}

TEST(CallbackPatchTests, CallbackPatchLambdaTextReferenceTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto expected_text = std::string{};
auto future = cpr::PatchCallback([&expected_text] (const Response& r) {
expected_text = r.text;
return r.text;
}, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(expected_text, future.get());
}

TEST(CallbackPatchTests, CallbackPatchFunctionStatusTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto status_code = 0;
auto callback = std::function<int(Response)>(std::bind(status_callback, std::ref(status_code),
std::placeholders::_1));
auto future = cpr::PatchCallback(callback, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(status_code, future.get());
}

TEST(CallbackPatchTests, CallbackPatchFunctionTextTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto expected_text = std::string{};
auto callback = std::function<std::string(Response)>(std::bind(text_callback,
std::ref(expected_text),
std::placeholders::_1));
auto future = cpr::PatchCallback(callback, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(expected_text, future.get());
}

TEST(CallbackPatchTests, CallbackPatchFunctionStatusReferenceTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto status_code = 0;
auto callback = std::function<int(Response)>(std::bind(status_callback_ref,
std::ref(status_code),
std::placeholders::_1));
auto future = cpr::PatchCallback(callback, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(status_code, future.get());
}

TEST(CallbackPatchTests, CallbackPatchFunctionTextReferenceTest) {
auto url = Url{base + "/url_post.html"};
auto payload = Payload{{"x", "5"}};
auto expected_text = std::string{};
auto callback = std::function<std::string(Response)>(std::bind(text_callback_ref,
std::ref(expected_text),
std::placeholders::_1));
auto future = cpr::PatchCallback(callback, url, payload);
std::this_thread::sleep_for(sleep_time);
EXPECT_EQ(future.wait_for(zero), std::future_status::ready);
EXPECT_EQ(expected_text, future.get());
}

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
::testing::AddGlobalTestEnvironment(server);
Expand Down

0 comments on commit 8b4284d

Please sign in to comment.