Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #26 from measurement-kit/release/0.9.2
Browse files Browse the repository at this point in the history
Release 0.9.2
  • Loading branch information
bassosimone authored Jan 8, 2019
2 parents 8806b33 + a3ce75a commit d013065
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 43 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
/mkcurl.sln
/mkmock.hpp
/rules.ninja
/unit-tests
/unit-tests.dir/
/unit-tests.vcxproj
/unit-tests.vcxproj.filters
/tests
/tests.dir/
/tests.vcxproj
/tests.vcxproj.filters
/windows-curl-*.tar.gz
/x64/
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ target_link_libraries(mkcurl-client mkcurl)

set(BUILD_TESTING "ON" CACHE BOOL "Whether to build tests")
if(${BUILD_TESTING})
add_executable(unit-tests unit-tests.cpp)
add_executable(tests tests.cpp)
if("${WIN32}")
target_compile_options(unit-tests PRIVATE /EHs) # exceptions in extern "C"
target_compile_options(tests PRIVATE /EHs) # exceptions in extern "C"
endif()
enable_testing()
add_test(NAME unit_tests COMMAND unit-tests)
add_test(NAME unit_tests COMMAND tests)
add_test(NAME external_ca COMMAND
mkcurl-client --ca-bundle-path ./ca-bundle.pem
https://www.kernel.org)
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules
Submodule Modules updated 3 files
+24 −0 CMakeLists.txt
+21 −21 MkUtils.cmake
+15 −2 README.md
71 changes: 40 additions & 31 deletions mkcurl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ Response perform(const Request &request) noexcept;

#include "mkmock.hpp"

// MKCURL_MOCK controls whether to enable mocking
#ifdef MKCURL_MOCK
#define MKCURL_HOOK MKMOCK_HOOK_ENABLED
#define MKCURL_HOOK_ALLOC MKMOCK_HOOK_ALLOC_ENABLED
#else
#define MKCURL_HOOK MKMOCK_HOOK_DISABLED
#define MKCURL_HOOK_ALLOC MKMOCK_HOOK_ALLOC_DISABLED
#endif

#ifndef MKCURL_ABORT
// MKCURL_ABORT allows to mock abort
#define MKCURL_ABORT abort
Expand Down Expand Up @@ -323,7 +332,7 @@ Response perform(const Request &req) noexcept {
mkcurl_uptr handle;
{
CURL *handlep = curl_easy_init();
MKMOCK_HOOK_ALLOC(curl_easy_init, handlep, curl_easy_cleanup);
MKCURL_HOOK_ALLOC(curl_easy_init, handlep, curl_easy_cleanup);
handle.reset(handlep);
}
Response res;
Expand All @@ -335,7 +344,7 @@ Response perform(const Request &req) noexcept {
mkcurl_slist headers; // This must have function scope
for (auto &s : req.headers) {
curl_slist *slistp = curl_slist_append(headers.p, s.c_str());
MKMOCK_HOOK_ALLOC(curl_slist_append_headers, slistp, curl_slist_free_all);
MKCURL_HOOK_ALLOC(curl_slist_append_headers, slistp, curl_slist_free_all);
if ((headers.p = slistp) == nullptr) {
res.error = CURLE_OUT_OF_MEMORY;
mkcurl_log(res.logs, "curl_slist_append() failed");
Expand All @@ -346,7 +355,7 @@ Response perform(const Request &req) noexcept {
if (!req.connect_to.empty()) {
curl_slist *slistp = curl_slist_append(
connect_to_settings.p, req.connect_to.c_str());
MKMOCK_HOOK_ALLOC(
MKCURL_HOOK_ALLOC(
curl_slist_append_connect_to, slistp, curl_slist_free_all);
if ((connect_to_settings.p = slistp) == nullptr) {
res.error = CURLE_OUT_OF_MEMORY;
Expand All @@ -355,15 +364,15 @@ Response perform(const Request &req) noexcept {
}
res.error = curl_easy_setopt(handle.get(), CURLOPT_CONNECT_TO,
connect_to_settings.p);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_CONNECT_TO, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_CONNECT_TO, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_CONNECT_TO) failed");
return res;
}
}
if (req.enable_fastopen) {
res.error = curl_easy_setopt(handle.get(), CURLOPT_TCP_FASTOPEN, 1L);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_TCP_FASTOPEN, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_TCP_FASTOPEN, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_TCP_FASTOPEN) failed");
return res;
Expand All @@ -372,7 +381,7 @@ Response perform(const Request &req) noexcept {
if (!req.ca_path.empty()) {
res.error = curl_easy_setopt(handle.get(), CURLOPT_CAINFO,
req.ca_path.c_str());
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_CAINFO, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_CAINFO, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_CAINFO) failed");
return res;
Expand All @@ -381,7 +390,7 @@ Response perform(const Request &req) noexcept {
if (req.enable_http2) {
res.error = curl_easy_setopt(handle.get(), CURLOPT_HTTP_VERSION,
CURL_HTTP_VERSION_2_0);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_HTTP_VERSION, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_HTTP_VERSION, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_HTTP_VERSION) failed");
return res;
Expand All @@ -393,7 +402,7 @@ Response perform(const Request &req) noexcept {
// with P{OS,U}T <https://curl.haxx.se/mail/lib-2017-07/0013.html>.
{
curl_slist *slistp = curl_slist_append(headers.p, "Expect:");
MKMOCK_HOOK_ALLOC(
MKCURL_HOOK_ALLOC(
curl_slist_append_Expect_header, slistp, curl_slist_free_all);
if ((headers.p = slistp) == nullptr) {
res.error = CURLE_OUT_OF_MEMORY;
Expand All @@ -403,7 +412,7 @@ Response perform(const Request &req) noexcept {
}
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_POST, 1L);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_POST, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_POST, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_POST) failed");
return res;
Expand All @@ -412,7 +421,7 @@ Response perform(const Request &req) noexcept {
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_POSTFIELDS,
req.body.c_str());
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_POSTFIELDS, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_POSTFIELDS, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_POSTFIELDS) failed");
return res;
Expand All @@ -424,23 +433,23 @@ Response perform(const Request &req) noexcept {
// using CURLOPT_POSTFIELDSIZE that takes a `long` argument.
{
bool body_size_overflow = (req.body.size() > LONG_MAX);
MKMOCK_HOOK(body_size_overflow_inject, body_size_overflow);
MKCURL_HOOK(body_size_overflow_inject, body_size_overflow);
if (body_size_overflow) {
mkcurl_log(res.logs, "Body larger than LONG_MAX");
res.error = CURLE_FILESIZE_EXCEEDED;
return res;
}
res.error = curl_easy_setopt(handle.get(), CURLOPT_POSTFIELDSIZE,
(long)req.body.size());
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_POSTFIELDSIZE, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_POSTFIELDSIZE, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(MKCURLOPT_POSTFIELDSIZE) failed");
return res;
}
}
if (req.method == "PUT") {
res.error = curl_easy_setopt(handle.get(), CURLOPT_CUSTOMREQUEST, "PUT");
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_CUSTOMREQUEST, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_CUSTOMREQUEST, res.error);
if (res.error) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_CUSTOMREQUEST) failed");
return res;
Expand All @@ -453,15 +462,15 @@ Response perform(const Request &req) noexcept {
}
if (headers.p != nullptr) {
res.error = curl_easy_setopt(handle.get(), CURLOPT_HTTPHEADER, headers.p);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_HTTPHEADER, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_HTTPHEADER, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_HTTPHEADER) failed");
return res;
}
}
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_URL, req.url.c_str());
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_URL, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_URL, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_URL) failed");
return res;
Expand All @@ -470,15 +479,15 @@ Response perform(const Request &req) noexcept {
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_WRITEFUNCTION,
mkcurl_body_cb);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_WRITEFUNCTION, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_WRITEFUNCTION, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_WRITEFUNCTION) failed");
return res;
}
}
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_WRITEDATA, &res);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_WRITEDATA, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_WRITEDATA, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_WRITEDATA) failed");
return res;
Expand All @@ -497,7 +506,7 @@ Response perform(const Request &req) noexcept {
// compiling cURL in measurement-kit/script-build-unix.
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_NOSIGNAL, 1L);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_NOSIGNAL, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_NOSIGNAL, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_NOSIGNAL) failed");
return res;
Expand All @@ -508,7 +517,7 @@ Response perform(const Request &req) noexcept {
// Implementation note: `0L` means infinite for CURLOPT_TIMEOUT.
if (req.timeout > 0 && req.timeout < LONG_MAX) t = (long)req.timeout;
res.error = curl_easy_setopt(handle.get(), CURLOPT_TIMEOUT, t);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_TIMEOUT, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_TIMEOUT, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_TIMEOUT) failed");
return res;
Expand All @@ -517,23 +526,23 @@ Response perform(const Request &req) noexcept {
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_DEBUGFUNCTION,
mkcurl_debug_cb);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_DEBUGFUNCTION, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_DEBUGFUNCTION, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_DEBUGFUNCTION) failed");
return res;
}
}
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_DEBUGDATA, &res);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_DEBUGDATA, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_DEBUGDATA, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_DEBUGDATA) failed");
return res;
}
}
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_VERBOSE, 1L);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_VERBOSE, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_VERBOSE, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_VERBOSE) failed");
return res;
Expand All @@ -542,31 +551,31 @@ Response perform(const Request &req) noexcept {
if (!req.proxy_url.empty()) {
res.error = curl_easy_setopt(handle.get(), CURLOPT_PROXY,
req.proxy_url.c_str());
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_PROXY, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_PROXY, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_PROXY) failed");
return res;
}
}
if (req.follow_redir) {
res.error = curl_easy_setopt(handle.get(), CURLOPT_FOLLOWLOCATION, 1L);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_FOLLOWLOCATION, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_FOLLOWLOCATION, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_FOLLOWLOCATION) failed");
return res;
}
}
{
res.error = curl_easy_setopt(handle.get(), CURLOPT_CERTINFO, 1L);
MKMOCK_HOOK(curl_easy_setopt_CURLOPT_CERTINFO, res.error);
MKCURL_HOOK(curl_easy_setopt_CURLOPT_CERTINFO, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_setopt(CURLOPT_CERTINFO) failed");
return res;
}
}
{
res.error = curl_easy_perform(handle.get());
MKMOCK_HOOK(curl_easy_perform, res.error);
MKCURL_HOOK(curl_easy_perform, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_perform() failed");
return res;
Expand All @@ -576,7 +585,7 @@ Response perform(const Request &req) noexcept {
long status_code = 0;
res.error = curl_easy_getinfo(
handle.get(), CURLINFO_RESPONSE_CODE, &status_code);
MKMOCK_HOOK(curl_easy_getinfo_CURLINFO_RESPONSE_CODE, res.error);
MKCURL_HOOK(curl_easy_getinfo_CURLINFO_RESPONSE_CODE, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_getinfo(CURLINFO_RESPONSE_CODE) failed");
return res;
Expand All @@ -586,7 +595,7 @@ Response perform(const Request &req) noexcept {
{
char *url = nullptr;
res.error = curl_easy_getinfo(handle.get(), CURLINFO_REDIRECT_URL, &url);
MKMOCK_HOOK(curl_easy_getinfo_CURLINFO_REDIRECT_URL, res.error);
MKCURL_HOOK(curl_easy_getinfo_CURLINFO_REDIRECT_URL, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_getinfo(CURLINFO_REDIRECT_URL) failed");
return res;
Expand All @@ -596,7 +605,7 @@ Response perform(const Request &req) noexcept {
{
curl_certinfo *certinfo = nullptr;
res.error = curl_easy_getinfo(handle.get(), CURLINFO_CERTINFO, &certinfo);
MKMOCK_HOOK(curl_easy_getinfo_CURLINFO_CERTINFO, res.error);
MKCURL_HOOK(curl_easy_getinfo_CURLINFO_CERTINFO, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_getinfo(CURLINFO_CERTINFO) failed");
return res;
Expand All @@ -619,7 +628,7 @@ Response perform(const Request &req) noexcept {
{
char *ct = nullptr;
res.error = curl_easy_getinfo(handle.get(), CURLINFO_CONTENT_TYPE, &ct);
MKMOCK_HOOK(curl_easy_getinfo_CURLINFO_CONTENT_TYPE, res.error);
MKCURL_HOOK(curl_easy_getinfo_CURLINFO_CONTENT_TYPE, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_getinfo(CURLINFO_CONTENT_TYPE) failed");
return res;
Expand All @@ -629,7 +638,7 @@ Response perform(const Request &req) noexcept {
{
long httpv = 0L;
res.error = curl_easy_getinfo(handle.get(), CURLINFO_HTTP_VERSION, &httpv);
MKMOCK_HOOK(curl_easy_getinfo_CURLINFO_HTTP_VERSION, res.error);
MKCURL_HOOK(curl_easy_getinfo_CURLINFO_HTTP_VERSION, res.error);
if (res.error != CURLE_OK) {
mkcurl_log(res.logs, "curl_easy_getinfo(CURLINFO_HTTP_VERSION) failed");
return res;
Expand Down
6 changes: 2 additions & 4 deletions unit-tests.cpp → tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ struct MkCurlAbort : public std::exception {
// MKCURL_ABORT overrides the default MKCURK_ABORT to throw MkCurlAbort.
#define MKCURL_ABORT() throw MkCurlAbort()

// By setting MKMOCK_HOOK_ENABLE and including mkmock.hpp we cause mkcurl.hpp
// to compile with mocking enabled so that we can run unit tests.
#define MKMOCK_HOOK_ENABLE
#include "mkmock.hpp"

MKMOCK_DEFINE_HOOK(curl_easy_init, CURL *);
Expand Down Expand Up @@ -64,7 +61,8 @@ MKMOCK_DEFINE_HOOK(curl_easy_getinfo_CURLINFO_HTTP_VERSION, CURLcode);
// Include mkcurl implementation
// -----------------------------

#define MKCURL_INLINE_IMPL
#define MKCURL_INLINE_IMPL // inline the implementation
#define MKCURL_MOCK // enable mocking
#include "mkcurl.hpp"

// Unit tests
Expand Down

0 comments on commit d013065

Please sign in to comment.