Increase warning level and enable warning as error (#28)

This commit is contained in:
Brennan 2020-04-14 13:05:15 -07:00 коммит произвёл GitHub
Родитель 81d33af509
Коммит 7a72b7a295
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
29 изменённых файлов: 179 добавлений и 116 удалений

Просмотреть файл

@ -8,6 +8,9 @@ project (signalrclient)
include(CTest)
set(WERROR true CACHE BOOL "Enable warnings as errors.")
set(WALL true CACHE BOOL "Enable all warnings.")
if(NOT WIN32)
set(EXTRA_FLAGS "-std=c++11 -fPIC -DNO_SIGNALRCLIENT_EXPORTS")
else()

Просмотреть файл

@ -36,6 +36,15 @@ namespace signalr
http_response() {}
http_response(http_response&& rhs) noexcept : status_code(rhs.status_code), content(std::move(rhs.content)) {}
http_response(int code, const std::string& content) : status_code(code), content(content) {}
http_response(const http_response& rhs) : status_code(rhs.status_code), content(rhs.content) {}
http_response& operator=(const http_response& rhs)
{
status_code = rhs.status_code;
content = rhs.content;
return *this;
}
http_response& operator=(http_response&& rhs) noexcept
{

Просмотреть файл

@ -13,5 +13,7 @@ namespace signalr
public:
// NOTE: the caller does not enforce thread safety of this call
SIGNALRCLIENT_API virtual void write(const std::string &entry) = 0;
virtual ~log_writer() {}
};
}

Просмотреть файл

@ -5,8 +5,11 @@
#pragma once
#ifdef USE_CPPRESTSDK
#include "cpprest/http_client.h"
#include "cpprest/ws_client.h"
#pragma warning (push)
#pragma warning (disable : 5204 4355 4625 4626 4868)
#include <cpprest/http_client.h>
#include <cpprest/ws_client.h>
#pragma warning (pop)
#endif
#include "_exports.h"

Просмотреть файл

@ -180,8 +180,22 @@ namespace signalr
double number;
std::map<std::string, value> map;
// constructor of types in union are not implicitly called
// this is expected as we only construct a single type in the union once we know
// what that type is when constructing the signalr_value type.
#pragma warning (push)
#pragma warning (disable: 4582)
storage() {}
#pragma warning (pop)
storage(const storage&) = delete;
storage& operator=(const storage&) = delete;
// destructor is not implicitly called
#pragma warning (push)
#pragma warning (disable: 4583)
~storage() {}
#pragma warning (pop)
};
storage mStorage;

Просмотреть файл

@ -31,6 +31,40 @@ include_directories(
add_library (signalrclient SHARED ${SOURCES})
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(WERROR)
target_compile_options(signalrclient PRIVATE /WX)
endif()
if(WALL)
target_compile_options(signalrclient PRIVATE /Wall)
endif()
target_compile_options(signalrclient PRIVATE
/wd4820 # padding added after data member
/wd4514 # unreferenced inline function removed
/wd5045 # compiler will insert Spectre mitigation if /Qspectre switch is added
/wd4464 # relative include paths
/wd4711 # function 'x' selected for automatic inline expansion
/wd4710 # function not inlined
/experimental:external /external:anglebrackets /external:templates- /external:W0
/GR- # disable run-time type information
/guard:cf # enable control-flow guard
/EHa # enable C++ EH (w/ SEH exceptions)
)
else()
if(WERROR)
target_compile_options(signalrclient PRIVATE -Werror)
endif()
if(WALL)
target_compile_options(signalrclient PRIVATE -Wall)
endif()
# GCC on OSX has a bug with exceptions and no-rtti that can cause crashes
if(NOT APPLE)
target_compile_options(signalrclient PRIVATE -fno-rtti)
endif()
target_compile_options(signalrclient PRIVATE -Wextra -Wpedantic -Wno-unknown-pragmas)
endif()
if(NOT USE_CPPRESTSDK)
target_link_libraries(signalrclient)
else()

Просмотреть файл

@ -24,6 +24,9 @@ namespace signalr
{
}
cancellation_token(const cancellation_token&) = delete;
cancellation_token& operator=(const cancellation_token&) = delete;
void cancel()
{
std::lock_guard<std::mutex> lock(m_lock);

Просмотреть файл

@ -21,7 +21,7 @@ namespace signalr
return false;
}
for (int i = 0; i < s1.size(); ++i)
for (unsigned i = 0; i < s1.size(); ++i)
{
if (std::toupper(s1[i]) != std::toupper(s2[i]))
{
@ -41,7 +41,7 @@ namespace signalr
std::hash<size_t> hasher;
for (const auto& c : s)
{
hash ^= hasher(std::toupper(c)) + (hash << 5) + (hash >> 2);
hash ^= hasher(static_cast<size_t>(std::toupper(c))) + (hash << 5) + (hash >> 2);
}
return hash;

Просмотреть файл

@ -4,13 +4,19 @@
#pragma once
#pragma warning (push)
#pragma warning (disable : 5204 4355)
#include <future>
#pragma warning (pop)
namespace signalr
{
class completion_event_impl : public std::enable_shared_from_this<completion_event_impl>
{
public:
completion_event_impl(const completion_event_impl&) = delete;
completion_event_impl& operator=(const completion_event_impl&) = delete;
static std::shared_ptr<completion_event_impl> create()
{
return std::shared_ptr<completion_event_impl>(new completion_event_impl());

Просмотреть файл

@ -13,7 +13,6 @@
#include "signalrclient/signalr_exception.h"
#include "default_http_client.h"
#include "case_insensitive_comparison_utils.h"
#include "make_unique.h"
#include "completion_event.h"
#include <assert.h>
#include "signalrclient/websocket_client.h"
@ -21,13 +20,6 @@
namespace signalr
{
// unnamed namespace makes it invisble outside this translation unit
namespace
{
// this is a workaround for a compiler bug where mutable lambdas won't sometimes compile
static void log(const logger& logger, trace_level level, const std::string& entry);
}
std::shared_ptr<connection_impl> connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr<log_writer>& log_writer)
{
return connection_impl::create(url, trace_level, log_writer, nullptr, nullptr);
@ -259,8 +251,7 @@ namespace signalr
}
catch (const std::exception& e)
{
auto canceled = dynamic_cast<const canceled_exception*>(&e);
if (canceled)
if (token->is_canceled())
{
connection->m_logger.log(trace_level::info,
"starting the connection has been canceled.");

Просмотреть файл

@ -7,7 +7,10 @@
#ifdef USE_CPPRESTSDK
#include "default_http_client.h"
#include <thread>
#include "cpprest/http_client.h"
#pragma warning (push)
#pragma warning (disable : 5204 4355 4625 4626 4868)
#include <cpprest/http_client.h>
#pragma warning (pop)
namespace signalr
{

Просмотреть файл

@ -52,6 +52,7 @@ namespace signalr
{
try
{
task.get();
callback(nullptr);
}
catch (...)

Просмотреть файл

@ -6,7 +6,10 @@
#ifdef USE_CPPRESTSDK
#include "cpprest/ws_client.h"
#pragma warning (push)
#pragma warning (disable : 5204 4355 4625 4626 4868)
#include <cpprest/ws_client.h>
#pragma warning (pop)
#include "signalrclient/signalr_client_config.h"
#include "signalrclient/websocket_client.h"

Просмотреть файл

@ -7,7 +7,6 @@
#include "signalrclient/hub_exception.h"
#include "trace_log_writer.h"
#include "signalrclient/signalr_exception.h"
#include "make_unique.h"
#include "json_hub_protocol.h"
#include "message_type.h"
#include "handshake_protocol.h"
@ -40,7 +39,7 @@ namespace signalr
: m_connection(connection_impl::create(url, trace_level, log_writer,
http_client, websocket_factory)), m_logger(log_writer, trace_level),
m_callback_manager(signalr::value(std::map<std::string, signalr::value> { { std::string("error"), std::string("connection went out of scope before invocation result was received") } })),
m_disconnected([]() noexcept {}), m_handshakeReceived(false), m_protocol(std::make_shared<json_hub_protocol>())
m_handshakeReceived(false), m_disconnected([]() noexcept {}), m_protocol(std::make_shared<json_hub_protocol>())
{}
void hub_connection_impl::initialize()

Просмотреть файл

@ -7,7 +7,6 @@
#include "message_type.h"
#include "json_helpers.h"
#include "signalrclient/signalr_exception.h"
#include "json/json.h"
namespace signalr
{
@ -84,6 +83,6 @@ namespace signalr
break;
}
return std::move(value);
return value;
}
}

Просмотреть файл

@ -71,6 +71,10 @@ namespace signalr
return "error";
case signalr::trace_level::info:
return "info";
case signalr::trace_level::none:
return "none";
case signalr::trace_level::all:
return "all";
default:
assert(false);
return "(unknown)";

Просмотреть файл

@ -1,19 +0,0 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#pragma once
#if defined (__GNUC__)
#include <memory>
namespace std
{
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
#endif

Просмотреть файл

@ -4,10 +4,6 @@
#include "stdafx.h"
#include "signalrclient/signalr_client_config.h"
#ifdef USE_CPPRESTSDK
#include "cpprest/http_client.h"
#include "cpprest/ws_client.h"
#endif
namespace signalr
{

Просмотреть файл

@ -51,6 +51,7 @@ namespace signalr
case value_type::map:
new (&mStorage.map) std::map<std::string, value>();
break;
case value_type::null:
default:
break;
}
@ -121,6 +122,7 @@ namespace signalr
case value_type::map:
new (&mStorage.map) std::map<std::string, value>(rhs.mStorage.map);
break;
case value_type::null:
default:
break;
}
@ -146,6 +148,7 @@ namespace signalr
case value_type::map:
new (&mStorage.map) std::map<std::string, signalr::value>(std::move(rhs.mStorage.map));
break;
case value_type::null:
default:
break;
}
@ -169,6 +172,9 @@ namespace signalr
case value_type::map:
mStorage.map.~map();
break;
case value_type::null:
case value_type::float64:
case value_type::boolean:
default:
break;
}
@ -196,6 +202,7 @@ namespace signalr
case value_type::map:
new (&mStorage.map) std::map<std::string, value>(rhs.mStorage.map);
break;
case value_type::null:
default:
break;
}
@ -225,6 +232,7 @@ namespace signalr
case value_type::map:
new (&mStorage.map) std::map<std::string, value>(std::move(rhs.mStorage.map));
break;
case value_type::null:
default:
break;
}

Просмотреть файл

@ -8,11 +8,7 @@
// prevents from defining min/max macros that conflict with std::min()/std::max() functions
#define NOMINMAX
#include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

Просмотреть файл

@ -4,7 +4,6 @@
#include "stdafx.h"
#include "transport_factory.h"
#include "default_websocket_client.h"
#include "websocket_transport.h"
#include "signalrclient/websocket_client.h"

Просмотреть файл

@ -7,7 +7,11 @@
#include "logger.h"
#include "signalrclient/signalr_exception.h"
#include "base_uri.h"
#pragma warning (push)
#pragma warning (disable : 5204 4355)
#include <future>
#pragma warning (pop)
namespace signalr
{
@ -20,9 +24,9 @@ namespace signalr
websocket_transport::websocket_transport(const std::function<std::shared_ptr<websocket_client>(const signalr_client_config&)>& websocket_client_factory,
const signalr_client_config& signalr_client_config, const logger& logger)
: transport(logger), m_websocket_client_factory(websocket_client_factory), m_close_callback([](std::exception_ptr) {}),
m_process_response_callback([](std::string, std::exception_ptr) {}), m_receive_loop_cts(std::make_shared<cancellation_token>()),
m_signalr_client_config(signalr_client_config)
: transport(logger), m_websocket_client_factory(websocket_client_factory), m_process_response_callback([](std::string, std::exception_ptr) {}),
m_close_callback([](std::exception_ptr) {}), m_signalr_client_config(signalr_client_config),
m_receive_loop_cts(std::make_shared<cancellation_token>())
{
// we use this cts to check if the receive loop is running so it should be
// initially canceled to indicate that the receive loop is not running

Просмотреть файл

@ -107,10 +107,10 @@ TEST(connection_impl_start, connection_state_is_connected_when_connection_establ
TEST(connection_impl_start, connection_state_is_disconnected_when_connection_cannot_be_established)
{
auto http_client = std::make_unique<test_http_client>([](const std::string&, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string&, http_request)
{
return http_response{ 404, "" };
});
}));
auto connection =
connection_impl::create(create_uri(), trace_level::none, std::make_shared<memory_log_writer>(),
@ -234,10 +234,10 @@ TEST(connection_impl_start, start_logs_exceptions)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string&, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string&, http_request)
{
return http_response{ 404, "" };
});
}));
auto connection =
connection_impl::create(create_uri(), trace_level::errors, writer,
@ -266,10 +266,10 @@ TEST(connection_impl_start, start_logs_exceptions)
TEST(connection_impl_start, start_propagates_exceptions_from_negotiate)
{
auto http_client = std::make_unique<test_http_client>([](const std::string&, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string&, http_request)
{
return http_response{ 404, "" };
});
}));
auto connection =
connection_impl::create(create_uri(), trace_level::none, std::make_shared<memory_log_writer>(),
@ -374,10 +374,10 @@ TEST(connection_impl_start, start_fails_if_negotiate_request_fails)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string&, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string&, http_request)
{
return http_response{ 400, "" };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -406,7 +406,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_has_error)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
auto response_body =
url.find("/negotiate") != std::string::npos
@ -414,7 +414,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_has_error)
: "";
return http_response{ 200, response_body };
});
}));
auto connect_mre = manual_reset_event<void>();
auto websocket_client = std::make_shared<test_websocket_client>();
@ -451,7 +451,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_does_not_have_webs
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
auto response_body =
url.find("/negotiate") != std::string::npos
@ -459,7 +459,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_does_not_have_webs
: "";
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -488,7 +488,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_does_not_have_tran
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
auto response_body =
url.find("/negotiate") != std::string::npos
@ -496,7 +496,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_does_not_have_tran
: "";
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -525,7 +525,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_is_invalid)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
auto response_body =
url.find("/negotiate") != std::string::npos
@ -533,7 +533,7 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_is_invalid)
: "";
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -559,7 +559,7 @@ TEST(connection_impl_start, negotiate_follows_redirect)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -576,7 +576,7 @@ TEST(connection_impl_start, negotiate_follows_redirect)
}
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -607,7 +607,7 @@ TEST(connection_impl_start, negotiate_redirect_uses_accessToken)
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
std::string accessToken;
auto http_client = std::make_unique<test_http_client>([&accessToken](const std::string& url, http_request request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([&accessToken](const std::string& url, http_request request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -625,7 +625,7 @@ TEST(connection_impl_start, negotiate_redirect_uses_accessToken)
accessToken = request.headers["Authorization"];
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -656,7 +656,7 @@ TEST(connection_impl_start, negotiate_fails_after_too_many_redirects)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -666,7 +666,7 @@ TEST(connection_impl_start, negotiate_fails_after_too_many_redirects)
}
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -695,7 +695,7 @@ TEST(connection_impl_start, negotiate_fails_if_ProtocolVersion_in_response)
{
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -704,7 +704,7 @@ TEST(connection_impl_start, negotiate_fails_if_ProtocolVersion_in_response)
}
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -733,7 +733,7 @@ TEST(connection_impl_start, negotiate_redirect_does_not_overwrite_url)
std::shared_ptr<log_writer> writer(std::make_shared<memory_log_writer>());
int redirectCount = 0;
auto http_client = std::make_unique<test_http_client>([&redirectCount](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([&redirectCount](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -751,7 +751,7 @@ TEST(connection_impl_start, negotiate_redirect_does_not_overwrite_url)
}
return http_response{ 200, response_body };
});
}));
auto websocket_client = std::make_shared<test_websocket_client>();
@ -794,7 +794,7 @@ TEST(connection_impl_start, negotiate_redirect_uses_own_query_string)
callback(std::make_exception_ptr(std::runtime_error("connecting failed")));
});
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -811,7 +811,7 @@ TEST(connection_impl_start, negotiate_redirect_uses_own_query_string)
}
return http_response{ 200, response_body };
});
}));
auto connection = connection_impl::create(create_uri("a=b&c=d"), trace_level::errors, writer, std::move(http_client),
[websocket_client](const signalr_client_config&) { return websocket_client; });
@ -848,7 +848,7 @@ TEST(connection_impl_start, negotiate_with_negotiateVersion_uses_connectionToken
callback(std::make_exception_ptr(std::runtime_error("connecting failed")));
});
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -859,7 +859,7 @@ TEST(connection_impl_start, negotiate_with_negotiateVersion_uses_connectionToken
}
return http_response{ 200, response_body };
});
}));
auto connection = connection_impl::create(create_uri(), trace_level::errors, writer, std::move(http_client),
[websocket_client](const signalr_client_config&) { return websocket_client; });
@ -889,12 +889,12 @@ TEST(connection_impl_start, correct_connection_id_returned_with_negotiateVersion
auto websocket_client = create_test_websocket_client(
/* send function */ [](const std::string&, std::function<void(std::exception_ptr)> callback) { callback(std::make_exception_ptr(std::runtime_error("should not be invoked"))); },
/* connect function */[](const std::string& url, std::function<void(std::exception_ptr)> callback)
/* connect function */[](const std::string&, std::function<void(std::exception_ptr)> callback)
{
callback(nullptr);
});
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
std::string response_body = "";
if (url.find("/negotiate") != std::string::npos)
@ -905,7 +905,7 @@ TEST(connection_impl_start, correct_connection_id_returned_with_negotiateVersion
}
return http_response{ 200, response_body };
});
}));
auto connection = connection_impl::create(create_uri(), trace_level::errors, writer, std::move(http_client),
[websocket_client](const signalr_client_config&) { return websocket_client; });
@ -1448,7 +1448,7 @@ TEST(connection_impl_stop, stop_cancels_ongoing_start_request)
{
auto disconnect_completed_event = std::make_shared<cancellation_token>();
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
auto response_body =
url.find("/negotiate") != std::string::npos
@ -1457,9 +1457,10 @@ TEST(connection_impl_stop, stop_cancels_ongoing_start_request)
: "";
return http_response{ 200, response_body };
});
}));
auto wait_for_start_mre = manual_reset_event<void>();
auto close_complete = manual_reset_event<void>();
auto websocket_client = create_test_websocket_client(
[](const std::string&, std::function<void(std::exception_ptr)> callback) { callback(std::make_exception_ptr(std::exception())); },
@ -1467,6 +1468,9 @@ TEST(connection_impl_stop, stop_cancels_ongoing_start_request)
wait_for_start_mre.set();
disconnect_completed_event->wait();
callback(nullptr);
}, [&close_complete](std::function<void(std::exception_ptr)> callback) {
callback(nullptr);
close_complete.set();
});
auto writer = std::shared_ptr<log_writer>{ std::make_shared<memory_log_writer>() };
@ -1496,22 +1500,24 @@ TEST(connection_impl_stop, stop_cancels_ongoing_start_request)
}
ASSERT_EQ(connection_state::disconnected, connection->get_connection_state());
close_complete.get();
auto log_entries = std::dynamic_pointer_cast<memory_log_writer>(writer)->get_log_entries();
ASSERT_EQ(6U, log_entries.size()) << dump_vector(log_entries);
ASSERT_EQ(7U, log_entries.size()) << dump_vector(log_entries);
ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0]));
ASSERT_EQ("[info ] [websocket transport] connecting to: ws://stop_cancels_ongoing_start_request/?id=f7707523-307d-4cba-9abf-3eef701241e8\n", remove_date_from_log_entry(log_entries[1]));
ASSERT_EQ("[info ] stopping connection\n", remove_date_from_log_entry(log_entries[2]));
ASSERT_EQ("[info ] acquired lock in shutdown()\n", remove_date_from_log_entry(log_entries[3]));
ASSERT_EQ("[info ] starting the connection has been canceled.\n", remove_date_from_log_entry(log_entries[4]));
ASSERT_EQ("[state change] connecting -> disconnected\n", remove_date_from_log_entry(log_entries[5]));
ASSERT_EQ("[info ] Stopping was ignored because the connection is already in the disconnected state.\n", remove_date_from_log_entry(log_entries[6]));
}
// Test races with start and stop
TEST(connection_impl_stop, DISABLED_ongoing_start_request_canceled_if_connection_stopped_before_init_message_received)
{
auto stop_mre = manual_reset_event<void>();
auto http_client = std::make_unique<test_http_client>([&stop_mre](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([&stop_mre](const std::string& url, http_request)
{
stop_mre.get();
@ -1522,7 +1528,7 @@ TEST(connection_impl_stop, DISABLED_ongoing_start_request_canceled_if_connection
: "";
return http_response{ 200, response_body };
});
}));
auto websocket_client = create_test_websocket_client();
@ -1671,7 +1677,7 @@ TEST(connection_impl_config, custom_headers_set_in_requests)
{
auto writer = std::shared_ptr<log_writer>{ std::make_shared<memory_log_writer>() };
auto http_client = std::make_unique<test_http_client>([](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([](const std::string& url, http_request)
{
auto response_body =
url.find("/negotiate") != std::string::npos
@ -1688,7 +1694,7 @@ TEST(connection_impl_config, custom_headers_set_in_requests)
};*/
return http_response{ 200, response_body };
});
}));
auto websocket_client = create_test_websocket_client();
@ -1844,7 +1850,7 @@ TEST(connection_id, connection_id_reset_when_starting_connection)
auto websocket_client = create_test_websocket_client();
auto http_client = std::make_unique<test_http_client>([&fail_http_requests](const std::string& url, http_request)
auto http_client = std::unique_ptr<test_http_client>(new test_http_client([&fail_http_requests](const std::string& url, http_request)
{
if (!fail_http_requests) {
auto response_body =
@ -1857,7 +1863,7 @@ TEST(connection_id, connection_id_reset_when_starting_connection)
}
return http_response{ 500, "" };
});
}));
auto connection =
connection_impl::create(create_uri(), trace_level::none, std::make_shared<memory_log_writer>(),

Просмотреть файл

@ -1315,7 +1315,6 @@ TEST(on, cannot_register_handler_if_connection_not_in_disconnected_state)
{
try
{
int number = 0;
auto websocket_client = create_test_websocket_client();
auto hub_connection = create_hub_connection(websocket_client);

Просмотреть файл

@ -24,7 +24,7 @@ TEST(negotiate, request_created_with_correct_url)
auto mre = manual_reset_event<void>();
negotiate::negotiate(http_client, "http://fake/signalr", signalr_client_config(),
[&mre](signalr::negotiation_response&& response, std::exception_ptr exception)
[&mre](signalr::negotiation_response&&, std::exception_ptr exception)
{
mre.set();
});

Просмотреть файл

@ -11,5 +11,4 @@
#include "gtest/gtest.h"
#include "../../src/signalrclient/cancellation_token.h"
#include "../../src/signalrclient/make_unique.h"
#include <thread>

Просмотреть файл

@ -19,7 +19,7 @@ std::string remove_date_from_log_entry(const std::string &log_entry)
std::unique_ptr<http_client> create_test_http_client()
{
return std::make_unique<test_http_client>([](const std::string & url, http_request request)
return std::unique_ptr<test_http_client>(new test_http_client([](const std::string & url, http_request request)
{
auto response_body =
url.find_first_of("/negotiate") != 0
@ -28,7 +28,7 @@ std::unique_ptr<http_client> create_test_http_client()
: "";
return http_response{ 200, response_body };
});
}));
}
std::string create_uri()

Просмотреть файл

@ -38,7 +38,7 @@ namespace signalr
/// </summary>
inline bool is_unreserved(int c)
{
return utility::is_alnum((char)c) || c == '-' || c == '.' || c == '_' || c == '~';
return utility::is_alnum((unsigned char)c) || c == '-' || c == '.' || c == '_' || c == '~';
}
/// <summary>
@ -93,7 +93,7 @@ namespace signalr
/// </summary>
inline bool is_scheme_character(int c)
{
return utility::is_alnum((char)c) || c == '+' || c == '-' || c == '.';
return utility::is_alnum((unsigned char)c) || c == '+' || c == '-' || c == '.';
}
/// <summary>
@ -732,13 +732,13 @@ namespace signalr
}
else if (equals_index == 0)
{
std::string value(key_value_pair.begin() + equals_index + 1, key_value_pair.end());
std::string value(key_value_pair.begin() + (int64_t)equals_index + 1, key_value_pair.end());
results[std::string{}] = value;
}
else
{
std::string key(key_value_pair.begin(), key_value_pair.begin() + equals_index);
std::string value(key_value_pair.begin() + equals_index + 1, key_value_pair.end());
std::string key(key_value_pair.begin(), key_value_pair.begin() + (int64_t)equals_index);
std::string value(key_value_pair.begin() + (int64_t)equals_index + 1, key_value_pair.end());
results[key] = value;
}
}

Просмотреть файл

@ -69,7 +69,8 @@ license you like.
// //////////////////////////////////////////////////////////////////////
#pragma warning( push, 0 )
#pragma warning( disable: 4702 )
@ -5380,7 +5381,7 @@ JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM& sout, Value const& root) {
// End of content of file: src/lib_json/json_writer.cpp
// //////////////////////////////////////////////////////////////////////
#pragma warning ( pop )