diff --git a/src/SignalR/clients/cpp/include/signalrclient/connection.h b/src/SignalR/clients/cpp/include/signalrclient/connection.h index 396876c9a783..c5f48cd3c3ff 100644 --- a/src/SignalR/clients/cpp/include/signalrclient/connection.h +++ b/src/SignalR/clients/cpp/include/signalrclient/connection.h @@ -19,9 +19,9 @@ namespace signalr class connection { public: - typedef std::function message_received_handler; + typedef std::function message_received_handler; - SIGNALRCLIENT_API explicit connection(const utility::string_t& url, trace_level trace_level = trace_level::all, std::shared_ptr log_writer = nullptr); + SIGNALRCLIENT_API explicit connection(const std::string& url, trace_level trace_level = trace_level::all, std::shared_ptr log_writer = nullptr); SIGNALRCLIENT_API ~connection(); @@ -31,7 +31,7 @@ namespace signalr SIGNALRCLIENT_API pplx::task __cdecl start(); - SIGNALRCLIENT_API pplx::task __cdecl send(const utility::string_t& data); + SIGNALRCLIENT_API pplx::task __cdecl send(const std::string& data); SIGNALRCLIENT_API void __cdecl set_message_received(const message_received_handler& message_received_callback); SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function& disconnected_callback); @@ -41,7 +41,7 @@ namespace signalr SIGNALRCLIENT_API pplx::task __cdecl stop(); SIGNALRCLIENT_API connection_state __cdecl get_connection_state() const noexcept; - SIGNALRCLIENT_API utility::string_t __cdecl get_connection_id() const; + SIGNALRCLIENT_API std::string __cdecl get_connection_id() const; private: // The recommended smart pointer to use when doing pImpl is the `std::unique_ptr`. However diff --git a/src/SignalR/clients/cpp/include/signalrclient/hub_connection.h b/src/SignalR/clients/cpp/include/signalrclient/hub_connection.h index 36adb7c6bdeb..4eea630f3398 100644 --- a/src/SignalR/clients/cpp/include/signalrclient/hub_connection.h +++ b/src/SignalR/clients/cpp/include/signalrclient/hub_connection.h @@ -22,7 +22,7 @@ namespace signalr public: typedef std::function method_invoked_handler; - SIGNALRCLIENT_API explicit hub_connection(const utility::string_t& url, trace_level trace_level = trace_level::all, + SIGNALRCLIENT_API explicit hub_connection(const std::string& url, trace_level trace_level = trace_level::all, std::shared_ptr log_writer = nullptr); SIGNALRCLIENT_API ~hub_connection(); @@ -35,17 +35,17 @@ namespace signalr SIGNALRCLIENT_API pplx::task __cdecl stop(); SIGNALRCLIENT_API connection_state __cdecl get_connection_state() const; - SIGNALRCLIENT_API utility::string_t __cdecl get_connection_id() const; + SIGNALRCLIENT_API std::string __cdecl get_connection_id() const; SIGNALRCLIENT_API void __cdecl set_disconnected(const std::function& disconnected_callback); SIGNALRCLIENT_API void __cdecl set_client_config(const signalr_client_config& config); - SIGNALRCLIENT_API void __cdecl on(const utility::string_t& event_name, const method_invoked_handler& handler); + SIGNALRCLIENT_API void __cdecl on(const std::string& event_name, const method_invoked_handler& handler); - SIGNALRCLIENT_API pplx::task invoke(const utility::string_t& method_name, const web::json::value& arguments = web::json::value::array()); + SIGNALRCLIENT_API pplx::task invoke(const std::string& method_name, const web::json::value& arguments = web::json::value::array()); - SIGNALRCLIENT_API pplx::task send(const utility::string_t& method_name, const web::json::value& arguments = web::json::value::array()); + SIGNALRCLIENT_API pplx::task send(const std::string& method_name, const web::json::value& arguments = web::json::value::array()); private: std::shared_ptr m_pImpl; diff --git a/src/SignalR/clients/cpp/include/signalrclient/hub_exception.h b/src/SignalR/clients/cpp/include/signalrclient/hub_exception.h index c0d38af48f31..0c653acc2a49 100644 --- a/src/SignalR/clients/cpp/include/signalrclient/hub_exception.h +++ b/src/SignalR/clients/cpp/include/signalrclient/hub_exception.h @@ -5,14 +5,13 @@ #include #include "signalr_exception.h" -#include "cpprest/details/basic_types.h" namespace signalr { class hub_exception : public signalr_exception { public: - hub_exception(const utility::string_t &what) + hub_exception(const std::string &what) : signalr_exception(what) {} }; diff --git a/src/SignalR/clients/cpp/include/signalrclient/log_writer.h b/src/SignalR/clients/cpp/include/signalrclient/log_writer.h index 19049ec0b1a1..89dc3815c4f1 100644 --- a/src/SignalR/clients/cpp/include/signalrclient/log_writer.h +++ b/src/SignalR/clients/cpp/include/signalrclient/log_writer.h @@ -3,14 +3,12 @@ #pragma once -#include "cpprest/details/basic_types.h" - namespace signalr { class log_writer { public: // NOTE: the caller does not enforce thread safety of this call - virtual void __cdecl write(const utility::string_t &entry) = 0; + virtual void __cdecl write(const std::string &entry) = 0; }; -} \ No newline at end of file +} diff --git a/src/SignalR/clients/cpp/include/signalrclient/signalr_exception.h b/src/SignalR/clients/cpp/include/signalrclient/signalr_exception.h index c7b48725b081..e475ff4ee982 100644 --- a/src/SignalR/clients/cpp/include/signalrclient/signalr_exception.h +++ b/src/SignalR/clients/cpp/include/signalrclient/signalr_exception.h @@ -4,16 +4,14 @@ #pragma once #include -#include "cpprest/details/basic_types.h" -#include "cpprest/asyncrt_utils.h" namespace signalr { class signalr_exception : public std::runtime_error { public: - explicit signalr_exception(const utility::string_t &what) - : runtime_error(utility::conversions::to_utf8string(what)) + explicit signalr_exception(const std::string &what) + : runtime_error(what) {} }; } diff --git a/src/SignalR/clients/cpp/include/signalrclient/web_exception.h b/src/SignalR/clients/cpp/include/signalrclient/web_exception.h index 1d841d07ea43..f8d4c9a520ad 100644 --- a/src/SignalR/clients/cpp/include/signalrclient/web_exception.h +++ b/src/SignalR/clients/cpp/include/signalrclient/web_exception.h @@ -4,16 +4,14 @@ #pragma once #include -#include "cpprest/details/basic_types.h" -#include "cpprest/asyncrt_utils.h" namespace signalr { class web_exception : public std::runtime_error { public: - web_exception(const utility::string_t &what, unsigned short status_code) - : runtime_error(utility::conversions::to_utf8string(what)), m_status_code(status_code) + web_exception(const std::string &what, unsigned short status_code) + : runtime_error(what), m_status_code(status_code) {} unsigned short status_code() const noexcept diff --git a/src/SignalR/clients/cpp/samples/HubConnectionSample/HubConnectionSample.cpp b/src/SignalR/clients/cpp/samples/HubConnectionSample/HubConnectionSample.cpp index 5f03987aa309..c67e9f1a2543 100644 --- a/src/SignalR/clients/cpp/samples/HubConnectionSample/HubConnectionSample.cpp +++ b/src/SignalR/clients/cpp/samples/HubConnectionSample/HubConnectionSample.cpp @@ -11,20 +11,20 @@ class logger : public signalr::log_writer { // Inherited via log_writer - virtual void __cdecl write(const utility::string_t & entry) override + virtual void __cdecl write(const std::string & entry) override { //std::cout << utility::conversions::to_utf8string(entry) << std::endl; } }; -void send_message(signalr::hub_connection& connection, const utility::string_t& name, const utility::string_t& message) +void send_message(signalr::hub_connection& connection, const std::string& name, const std::string& message) { web::json::value args{}; - args[0] = web::json::value::string(name); - args[1] = web::json::value(message); + args[0] = web::json::value::string(utility::conversions::to_string_t(name)); + args[1] = web::json::value(utility::conversions::to_string_t(message)); // if you get an internal compiler error uncomment the lambda below or install VS Update 4 - connection.invoke(U("Invoke"), args/*, [](const web::json::value&){}*/) + connection.invoke("Invoke", args/*, [](const web::json::value&){}*/) .then([](pplx::task invoke_task) // fire and forget but we need to observe exceptions { try @@ -39,10 +39,10 @@ void send_message(signalr::hub_connection& connection, const utility::string_t& }); } -void chat(const utility::string_t& name) +void chat(const std::string& name) { - signalr::hub_connection connection(U("http://localhost:5000/default"), signalr::trace_level::all, std::make_shared()); - connection.on(U("Send"), [](const web::json::value& m) + signalr::hub_connection connection("http://localhost:5000/default", signalr::trace_level::all, std::make_shared()); + connection.on("Send", [](const web::json::value& m) { ucout << std::endl << m.at(0).as_string() << /*U(" wrote:") << m.at(1).as_string() <<*/ std::endl << U("Enter your message: "); }); @@ -53,10 +53,10 @@ void chat(const utility::string_t& name) ucout << U("Enter your message:"); for (;;) { - utility::string_t message; - std::getline(ucin, message); + std::string message; + std::getline(std::cin, message); - if (message == U(":q")) + if (message == ":q") { break; } @@ -85,8 +85,8 @@ void chat(const utility::string_t& name) int main() { ucout << U("Enter your name: "); - utility::string_t name; - std::getline(ucin, name); + std::string name; + std::getline(std::cin, name); chat(name); diff --git a/src/SignalR/clients/cpp/src/signalrclient/callback_manager.cpp b/src/SignalR/clients/cpp/src/signalrclient/callback_manager.cpp index 24d83b4a628a..31f6806c5410 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/callback_manager.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/callback_manager.cpp @@ -18,7 +18,7 @@ namespace signalr } // note: callback must not throw except for the `on_progress` callback which will never be invoked from the dtor - utility::string_t callback_manager::register_callback(const std::function& callback) + std::string callback_manager::register_callback(const std::function& callback) { auto callback_id = get_callback_id(); @@ -33,7 +33,7 @@ namespace signalr // invokes a callback and stops tracking it if remove callback set to true - bool callback_manager::invoke_callback(const utility::string_t& callback_id, const web::json::value& arguments, bool remove_callback) + bool callback_manager::invoke_callback(const std::string& callback_id, const web::json::value& arguments, bool remove_callback) { std::function callback; @@ -58,7 +58,7 @@ namespace signalr return true; } - bool callback_manager::remove_callback(const utility::string_t& callback_id) + bool callback_manager::remove_callback(const std::string& callback_id) { { std::lock_guard lock(m_map_lock); @@ -81,10 +81,10 @@ namespace signalr } } - utility::string_t callback_manager::get_callback_id() + std::string callback_manager::get_callback_id() { const auto callback_id = m_id++; - utility::stringstream_t ss; + std::stringstream ss; ss << callback_id; return ss.str(); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/callback_manager.h b/src/SignalR/clients/cpp/src/signalrclient/callback_manager.h index 4bbea0825418..ae1bb877bbf1 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/callback_manager.h +++ b/src/SignalR/clients/cpp/src/signalrclient/callback_manager.h @@ -20,17 +20,17 @@ namespace signalr callback_manager(const callback_manager&) = delete; callback_manager& operator=(const callback_manager&) = delete; - utility::string_t register_callback(const std::function& callback); - bool invoke_callback(const utility::string_t& callback_id, const web::json::value& arguments, bool remove_callback); - bool remove_callback(const utility::string_t& callback_id); + std::string register_callback(const std::function& callback); + bool invoke_callback(const std::string& callback_id, const web::json::value& arguments, bool remove_callback); + bool remove_callback(const std::string& callback_id); void clear(const web::json::value& arguments); private: std::atomic m_id { 0 }; - std::unordered_map> m_callbacks; + std::unordered_map> m_callbacks; std::mutex m_map_lock; const web::json::value m_dtor_clear_arguments; - utility::string_t get_callback_id(); + std::string get_callback_id(); }; } diff --git a/src/SignalR/clients/cpp/src/signalrclient/case_insensitive_comparison_utils.h b/src/SignalR/clients/cpp/src/signalrclient/case_insensitive_comparison_utils.h index 0b5d42f157b2..a5b3f2eb3131 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/case_insensitive_comparison_utils.h +++ b/src/SignalR/clients/cpp/src/signalrclient/case_insensitive_comparison_utils.h @@ -12,9 +12,9 @@ namespace signalr // Note: These functions are not pretending to be all-purpose helpers for case insensitive string comparison. Rather // we use them to compare hub and hub method names which are expected to be almost exclusively ASCII and this is the // simplest thing that would work without having to take dependencies on third party libraries. - struct case_insensitive_equals : std::binary_function + struct case_insensitive_equals : std::binary_function { - bool operator()(const utility::string_t& s1, const utility::string_t& s2) const + bool operator()(const std::string& s1, const std::string& s2) const { if (s1.length() != s2.length()) { @@ -33,9 +33,9 @@ namespace signalr } }; - struct case_insensitive_hash : std::unary_function + struct case_insensitive_hash : std::unary_function { - std::size_t operator()(const utility::string_t& s) const noexcept + std::size_t operator()(const std::string& s) const noexcept { size_t hash = 0; std::hash hasher; diff --git a/src/SignalR/clients/cpp/src/signalrclient/connection.cpp b/src/SignalR/clients/cpp/src/signalrclient/connection.cpp index 3e524151bfcf..0b7bfb8f3c19 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/connection.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/connection.cpp @@ -8,7 +8,7 @@ namespace signalr { - connection::connection(const utility::string_t& url, trace_level trace_level, std::shared_ptr log_writer) + connection::connection(const std::string& url, trace_level trace_level, std::shared_ptr log_writer) : m_pImpl(connection_impl::create(url, trace_level, std::move(log_writer))) {} @@ -21,7 +21,7 @@ namespace signalr return m_pImpl->start(); } - pplx::task connection::send(const utility::string_t& data) + pplx::task connection::send(const std::string& data) { return m_pImpl->send(data); } @@ -51,7 +51,7 @@ namespace signalr return m_pImpl->get_connection_state(); } - utility::string_t connection::get_connection_id() const + std::string connection::get_connection_id() const { return m_pImpl->get_connection_id(); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp b/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp index 2eb04a626ce2..0195d7d1728a 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/connection_impl.cpp @@ -18,26 +18,26 @@ namespace signalr 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 utility::string_t& entry); + static void log(const logger& logger, trace_level level, const std::string& entry); } - std::shared_ptr connection_impl::create(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer) + std::shared_ptr connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer) { return connection_impl::create(url, trace_level, log_writer, std::make_unique(), std::make_unique()); } - std::shared_ptr connection_impl::create(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer, + std::shared_ptr connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory) { return std::shared_ptr(new connection_impl(url, trace_level, log_writer ? log_writer : std::make_shared(), std::move(web_request_factory), std::move(transport_factory))); } - connection_impl::connection_impl(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer, + connection_impl::connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory) : m_base_url(url), m_connection_state(connection_state::disconnected), m_logger(log_writer, trace_level), m_transport(nullptr), m_web_request_factory(std::move(web_request_factory)), m_transport_factory(std::move(transport_factory)), - m_message_received([](const utility::string_t&) noexcept {}), m_disconnected([]() noexcept {}) + m_message_received([](const std::string&) noexcept {}), m_disconnected([]() noexcept {}) { } connection_impl::~connection_impl() @@ -72,7 +72,7 @@ namespace signalr if (!change_state(connection_state::disconnected, connection_state::connecting)) { return pplx::task_from_exception( - signalr_exception(_XPLATSTR("cannot start a connection that is not in the disconnected state"))); + signalr_exception("cannot start a connection that is not in the disconnected state")); } // there should not be any active transport at this point @@ -80,17 +80,17 @@ namespace signalr m_disconnect_cts = pplx::cancellation_token_source(); m_start_completed_event.reset(); - m_connection_id = _XPLATSTR(""); + m_connection_id = ""; } return start_negotiate(m_base_url, 0); } - pplx::task connection_impl::start_negotiate(const utility::string_t& url, int redirect_count) + pplx::task connection_impl::start_negotiate(const std::string& url, int redirect_count) { if (redirect_count >= MAX_NEGOTIATE_REDIRECTS) { - return pplx::task_from_exception(signalr_exception(_XPLATSTR("Negotiate redirection limit exceeded."))); + return pplx::task_from_exception(signalr_exception("Negotiate redirection limit exceeded.")); } pplx::task_completion_event start_tce; @@ -103,7 +103,7 @@ namespace signalr auto connection = weak_connection.lock(); if (!connection) { - return pplx::task_from_exception(_XPLATSTR("connection no longer exists")); + return pplx::task_from_exception("connection no longer exists"); } return request_sender::negotiate(*connection->m_web_request_factory, url, connection->m_signalr_client_config); }, m_disconnect_cts.get_token()) @@ -112,7 +112,7 @@ namespace signalr auto connection = weak_connection.lock(); if (!connection) { - return pplx::task_from_exception(_XPLATSTR("connection no longer exists")); + return pplx::task_from_exception("connection no longer exists"); } if (!negotiation_response.error.empty()) @@ -125,7 +125,7 @@ namespace signalr if (!negotiation_response.accessToken.empty()) { auto headers = connection->m_signalr_client_config.get_http_headers(); - headers[_XPLATSTR("Authorization")] = _XPLATSTR("Bearer ") + negotiation_response.accessToken; + headers[_XPLATSTR("Authorization")] = utility::conversions::to_string_t("Bearer " + negotiation_response.accessToken); connection->m_signalr_client_config.set_http_headers(headers); } return connection->start_negotiate(negotiation_response.url, redirect_count + 1); @@ -138,7 +138,7 @@ namespace signalr bool foundWebsockets = false; for (auto availableTransport : negotiation_response.availableTransports) { - if (availableTransport.transport == _XPLATSTR("WebSockets")) + if (availableTransport.transport == "WebSockets") { foundWebsockets = true; break; @@ -147,7 +147,7 @@ namespace signalr if (!foundWebsockets) { - return pplx::task_from_exception(signalr_exception(_XPLATSTR("The server does not support WebSockets which is currently the only transport supported by this client."))); + return pplx::task_from_exception(signalr_exception("The server does not support WebSockets which is currently the only transport supported by this client.")); } // TODO: use transfer format @@ -158,14 +158,14 @@ namespace signalr auto connection = weak_connection.lock(); if (!connection) { - return pplx::task_from_exception(_XPLATSTR("connection no longer exists")); + return pplx::task_from_exception("connection no longer exists"); } connection->m_transport = transport; if (!connection->change_state(connection_state::connecting, connection_state::connected)) { connection->m_logger.log(trace_level::errors, - utility::string_t(_XPLATSTR("internal error - transition from an unexpected state. expected state: connecting, actual state: ")) + std::string("internal error - transition from an unexpected state. expected state: connecting, actual state: ") .append(translate_connection_state(connection->get_connection_state()))); _ASSERTE(false); @@ -193,13 +193,13 @@ namespace signalr if (task_canceled_exception) { connection->m_logger.log(trace_level::info, - _XPLATSTR("starting the connection has been canceled.")); + "starting the connection has been canceled."); } else { connection->m_logger.log(trace_level::errors, - utility::string_t(_XPLATSTR("connection could not be started due to: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("connection could not be started due to: ") + .append(e.what())); } connection->m_transport = nullptr; @@ -214,7 +214,7 @@ namespace signalr return pplx::create_task(start_tce); } - pplx::task> connection_impl::start_transport(const utility::string_t& url) + pplx::task> connection_impl::start_transport(const std::string& url) { auto connection = shared_from_this(); @@ -225,7 +225,7 @@ namespace signalr const auto& logger = m_logger; auto process_response_callback = - [weak_connection, disconnect_cts, logger](const utility::string_t& response) mutable + [weak_connection, disconnect_cts, logger](const std::string& response) mutable { // When a connection is stopped we don't wait for its transport to stop. As a result if the same connection // is immediately re-started the old transport can still invoke this callback. To prevent this we capture @@ -234,7 +234,7 @@ namespace signalr if (disconnect_cts.get_token().is_canceled()) { logger.log(trace_level::info, - utility::string_t{ _XPLATSTR("ignoring stray message received after connection was restarted. message: " }) + std::string{ "ignoring stray message received after connection was restarted. message: " } .append(response)); return; } @@ -257,8 +257,8 @@ namespace signalr if (disconnect_cts.get_token().is_canceled()) { logger.log(trace_level::info, - utility::string_t{ _XPLATSTR("ignoring stray error received after connection was restarted. error: " }) - .append(utility::conversions::to_string_t(e.what()))); + std::string{ "ignoring stray error received after connection was restarted. error: " } + .append(e.what())); return; } @@ -286,7 +286,7 @@ namespace signalr } else { - connect_request_tce.set_exception(signalr_exception(_XPLATSTR("transport timed out when trying to connect"))); + connect_request_tce.set_exception(signalr_exception("transport timed out when trying to connect")); } }); @@ -294,10 +294,10 @@ namespace signalr .then([transport](){ return pplx::task_from_result(transport); }); } - pplx::task connection_impl::send_connect_request(const std::shared_ptr& transport, const utility::string_t& url, const pplx::task_completion_event& connect_request_tce) + pplx::task connection_impl::send_connect_request(const std::shared_ptr& transport, const std::string& url, const pplx::task_completion_event& connect_request_tce) { auto logger = m_logger; - auto query_string = _XPLATSTR("id=" + m_connection_id); + auto query_string = "id=" + m_connection_id; auto connect_url = url_builder::build_connect(url, transport->get_transport_type(), query_string); transport->connect(connect_url) @@ -312,8 +312,8 @@ namespace signalr { logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("transport could not connect due to: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("transport could not connect due to: ") + .append(e.what())); connect_request_tce.set_exception(std::current_exception()); } @@ -322,15 +322,15 @@ namespace signalr return pplx::create_task(connect_request_tce); } - void connection_impl::process_response(const utility::string_t& response) + void connection_impl::process_response(const std::string& response) { m_logger.log(trace_level::messages, - utility::string_t(_XPLATSTR("processing message: ")).append(response)); + std::string("processing message: ").append(response)); invoke_message_received(response); } - void connection_impl::invoke_message_received(const utility::string_t& message) + void connection_impl::invoke_message_received(const std::string& message) { try { @@ -340,16 +340,16 @@ namespace signalr { m_logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("message_received callback threw an exception: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("message_received callback threw an exception: ") + .append(e.what())); } catch (...) { - m_logger.log(trace_level::errors, _XPLATSTR("message_received callback threw an unknown exception")); + m_logger.log(trace_level::errors, "message_received callback threw an unknown exception"); } } - pplx::task connection_impl::send(const utility::string_t& data) + pplx::task connection_impl::send(const std::string& data) { // To prevent an (unlikely) condition where the transport is nulled out after we checked the connection_state // and before sending data we store the pointer in the local variable. In this case `send()` will throw but @@ -360,13 +360,13 @@ namespace signalr if (connection_state != signalr::connection_state::connected || !transport) { return pplx::task_from_exception(signalr_exception( - utility::string_t(_XPLATSTR("cannot send data when the connection is not in the connected state. current connection state: ")) + std::string("cannot send data when the connection is not in the connected state. current connection state: ") .append(translate_connection_state(connection_state)))); } auto logger = m_logger; - logger.log(trace_level::info, utility::string_t(_XPLATSTR("sending data: ")).append(data)); + logger.log(trace_level::info, std::string("sending data: ").append(data)); return transport->send(data) .then([logger](pplx::task send_task) @@ -379,8 +379,8 @@ namespace signalr { logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("error sending data: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("error sending data: ") + .append(e.what())); throw; } @@ -389,7 +389,7 @@ namespace signalr pplx::task connection_impl::stop() { - m_logger.log(trace_level::info, _XPLATSTR("stopping connection")); + m_logger.log(trace_level::info, "stopping connection"); auto connection = shared_from_this(); return shutdown() @@ -415,14 +415,14 @@ namespace signalr { connection->m_logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("disconnected callback threw an exception: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("disconnected callback threw an exception: ") + .append(e.what())); } catch (...) { connection->m_logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("disconnected callback threw an unknown exception"))); + std::string("disconnected callback threw an unknown exception")); } }); } @@ -432,7 +432,7 @@ namespace signalr { { std::lock_guard lock(m_stop_lock); - m_logger.log(trace_level::info, _XPLATSTR("acquired lock in shutdown()")); + m_logger.log(trace_level::info, "acquired lock in shutdown()"); const auto current_state = get_connection_state(); if (current_state == connection_state::disconnected) @@ -456,7 +456,7 @@ namespace signalr while (m_start_completed_event.wait(60000) != 0) { m_logger.log(trace_level::errors, - _XPLATSTR("internal error - stopping the connection is still waiting for the start operation to finish which should have already finished or timed out")); + "internal error - stopping the connection is still waiting for the start operation to finish which should have already finished or timed out"); } // at this point we are either in the connected or disconnected state. If we are in the disconnected state @@ -479,41 +479,41 @@ namespace signalr return m_connection_state.load(); } - utility::string_t connection_impl::get_connection_id() const noexcept + std::string connection_impl::get_connection_id() const noexcept { if (m_connection_state.load() == connection_state::connecting) { - return _XPLATSTR(""); + return ""; } return m_connection_id; } - void connection_impl::set_message_received(const std::function& message_received) + void connection_impl::set_message_received(const std::function& message_received) { - ensure_disconnected(_XPLATSTR("cannot set the callback when the connection is not in the disconnected state. ")); + ensure_disconnected("cannot set the callback when the connection is not in the disconnected state. "); m_message_received = message_received; } void connection_impl::set_client_config(const signalr_client_config& config) { - ensure_disconnected(_XPLATSTR("cannot set client config when the connection is not in the disconnected state. ")); + ensure_disconnected("cannot set client config when the connection is not in the disconnected state. "); m_signalr_client_config = config; } void connection_impl::set_disconnected(const std::function& disconnected) { - ensure_disconnected(_XPLATSTR("cannot set the disconnected callback when the connection is not in the disconnected state. ")); + ensure_disconnected("cannot set the disconnected callback when the connection is not in the disconnected state. "); m_disconnected = disconnected; } - void connection_impl::ensure_disconnected(const utility::string_t& error_message) const + void connection_impl::ensure_disconnected(const std::string& error_message) const { const auto state = get_connection_state(); if (state != connection_state::disconnected) { throw signalr_exception( - error_message + _XPLATSTR("current connection state: ") + translate_connection_state(state)); + error_message + "current connection state: " + translate_connection_state(state)); } } @@ -544,7 +544,7 @@ namespace signalr m_logger.log( trace_level::state_changes, translate_connection_state(old_state) - .append(_XPLATSTR(" -> ")) + .append(" -> ") .append(translate_connection_state(new_state))); // Words of wisdom (if we decide to add a state_changed callback and invoke it from here): @@ -553,21 +553,21 @@ namespace signalr // stopped while / after transitioning into the connecting state." } - utility::string_t connection_impl::translate_connection_state(connection_state state) + std::string connection_impl::translate_connection_state(connection_state state) { switch (state) { case connection_state::connecting: - return _XPLATSTR("connecting"); + return "connecting"; case connection_state::connected: - return _XPLATSTR("connected"); + return "connected"; case connection_state::disconnecting: - return _XPLATSTR("disconnecting"); + return "disconnecting"; case connection_state::disconnected: - return _XPLATSTR("disconnected"); + return "disconnected"; default: _ASSERTE(false); - return _XPLATSTR("(unknown)"); + return "(unknown)"; } } } diff --git a/src/SignalR/clients/cpp/src/signalrclient/connection_impl.h b/src/SignalR/clients/cpp/src/signalrclient/connection_impl.h index d5af038460e5..cd712e59217d 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/connection_impl.h +++ b/src/SignalR/clients/cpp/src/signalrclient/connection_impl.h @@ -25,9 +25,9 @@ namespace signalr class connection_impl : public std::enable_shared_from_this { public: - static std::shared_ptr create(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer); + static std::shared_ptr create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer); - static std::shared_ptr create(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer, + static std::shared_ptr create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory); connection_impl(const connection_impl&) = delete; @@ -37,51 +37,51 @@ namespace signalr ~connection_impl(); pplx::task start(); - pplx::task send(const utility::string_t &data); + pplx::task send(const std::string &data); pplx::task stop(); connection_state get_connection_state() const noexcept; - utility::string_t get_connection_id() const noexcept; + std::string get_connection_id() const noexcept; - void set_message_received(const std::function& message_received); + void set_message_received(const std::function& message_received); void set_disconnected(const std::function& disconnected); void set_client_config(const signalr_client_config& config); private: - utility::string_t m_base_url; + std::string m_base_url; std::atomic m_connection_state; logger m_logger; std::shared_ptr m_transport; std::unique_ptr m_web_request_factory; std::unique_ptr m_transport_factory; - std::function m_message_received; + std::function m_message_received; std::function m_disconnected; signalr_client_config m_signalr_client_config; pplx::cancellation_token_source m_disconnect_cts; std::mutex m_stop_lock; event m_start_completed_event; - utility::string_t m_connection_id; + std::string m_connection_id; - connection_impl(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer, + connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory); - pplx::task> start_transport(const utility::string_t& url); + pplx::task> start_transport(const std::string& url); pplx::task send_connect_request(const std::shared_ptr& transport, - const utility::string_t& url, const pplx::task_completion_event& connect_request_tce); - pplx::task start_negotiate(const utility::string_t& url, int redirect_count); + const std::string& url, const pplx::task_completion_event& connect_request_tce); + pplx::task start_negotiate(const std::string& url, int redirect_count); - void process_response(const utility::string_t& response); + void process_response(const std::string& response); pplx::task shutdown(); bool change_state(connection_state old_state, connection_state new_state); connection_state change_state(connection_state new_state); void handle_connection_state_change(connection_state old_state, connection_state new_state); - void invoke_message_received(const utility::string_t& message); + void invoke_message_received(const std::string& message); - static utility::string_t translate_connection_state(connection_state state); - void ensure_disconnected(const utility::string_t& error_message) const; + static std::string translate_connection_state(connection_state state); + void ensure_disconnected(const std::string& error_message) const; }; } diff --git a/src/SignalR/clients/cpp/src/signalrclient/constants.h b/src/SignalR/clients/cpp/src/signalrclient/constants.h index 0e43d1c3c015..80098b24c88a 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/constants.h +++ b/src/SignalR/clients/cpp/src/signalrclient/constants.h @@ -3,6 +3,6 @@ #pragma once -#define SIGNALR_VERSION _XPLATSTR("0.1.0-alpha0") -#define USER_AGENT _XPLATSTR("SignalR.Client.Cpp/") SIGNALR_VERSION +#define SIGNALR_VERSION "0.1.0-alpha0" +#define USER_AGENT "SignalR.Client.Cpp/" SIGNALR_VERSION #define MAX_NEGOTIATE_REDIRECTS 100 diff --git a/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.cpp b/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.cpp index ea5aa995d164..2bf07b93f9f9 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.cpp @@ -21,15 +21,15 @@ namespace signalr : m_underlying_client(create_client_config(signalr_client_config)) { } - pplx::task default_websocket_client::connect(const web::uri &url) + pplx::task default_websocket_client::connect(const std::string& url) { - return m_underlying_client.connect(url); + return m_underlying_client.connect(utility::conversions::to_string_t(url)); } - pplx::task default_websocket_client::send(const utility::string_t &message) + pplx::task default_websocket_client::send(const std::string &message) { web::websockets::client::websocket_outgoing_message msg; - msg.set_utf8_message(utility::conversions::to_utf8string(message)); + msg.set_utf8_message(message); return m_underlying_client.send(msg); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h b/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h index f4805c77b554..a1c2c346f65e 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h +++ b/src/SignalR/clients/cpp/src/signalrclient/default_websocket_client.h @@ -14,9 +14,9 @@ namespace signalr public: explicit default_websocket_client(const signalr_client_config& signalr_client_config = signalr_client_config{}) noexcept; - pplx::task connect(const web::uri &url) override; + pplx::task connect(const std::string& url) override; - pplx::task send(const utility::string_t &message) override; + pplx::task send(const std::string& message) override; pplx::task receive() override; diff --git a/src/SignalR/clients/cpp/src/signalrclient/http_sender.cpp b/src/SignalR/clients/cpp/src/signalrclient/http_sender.cpp index 9a2fb8941e80..4c3cc67d2aff 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/http_sender.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/http_sender.cpp @@ -10,11 +10,11 @@ namespace signalr { namespace http_sender { - pplx::task get(web_request_factory& request_factory, const utility::string_t& url, + pplx::task get(web_request_factory& request_factory, const std::string& url, const signalr_client_config& signalr_client_config) { auto request = request_factory.create_web_request(url); - request->set_method(web::http::methods::GET); + request->set_method(utility::conversions::to_utf8string(web::http::methods::GET)); request->set_user_agent(USER_AGENT); request->set_client_config(signalr_client_config); @@ -23,8 +23,8 @@ namespace signalr { if (response.status_code != 200) { - utility::ostringstream_t oss; - oss << _XPLATSTR("web exception - ") << response.status_code << _XPLATSTR(" ") << response.reason_phrase; + std::stringstream oss; + oss << "web exception - " << response.status_code << " " << response.reason_phrase; throw web_exception(oss.str(), response.status_code); } @@ -32,11 +32,11 @@ namespace signalr }); } - pplx::task post(web_request_factory& request_factory, const utility::string_t& url, + pplx::task post(web_request_factory& request_factory, const std::string& url, const signalr_client_config& signalr_client_config) { auto request = request_factory.create_web_request(url); - request->set_method(web::http::methods::POST); + request->set_method(utility::conversions::to_utf8string(web::http::methods::POST)); request->set_user_agent(USER_AGENT); request->set_client_config(signalr_client_config); @@ -45,8 +45,8 @@ namespace signalr { if (response.status_code != 200) { - utility::ostringstream_t oss; - oss << _XPLATSTR("web exception - ") << response.status_code << _XPLATSTR(" ") << response.reason_phrase; + std::stringstream oss; + oss << "web exception - " << response.status_code << " " << response.reason_phrase; throw web_exception(oss.str(), response.status_code); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/http_sender.h b/src/SignalR/clients/cpp/src/signalrclient/http_sender.h index c8ab364566a6..9c6c97298ef3 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/http_sender.h +++ b/src/SignalR/clients/cpp/src/signalrclient/http_sender.h @@ -4,7 +4,6 @@ #pragma once #include "pplx/pplxtasks.h" -#include "cpprest/details/basic_types.h" #include "signalrclient/signalr_client_config.h" #include "web_request_factory.h" @@ -12,10 +11,10 @@ namespace signalr { namespace http_sender { - pplx::task get(web_request_factory& request_factory, const utility::string_t& url, + pplx::task get(web_request_factory& request_factory, const std::string& url, const signalr_client_config& client_config = signalr_client_config{}); - pplx::task post(web_request_factory& request_factory, const utility::string_t& url, + pplx::task post(web_request_factory& request_factory, const std::string& url, const signalr_client_config& client_config = signalr_client_config{}); } } diff --git a/src/SignalR/clients/cpp/src/signalrclient/hub_connection.cpp b/src/SignalR/clients/cpp/src/signalrclient/hub_connection.cpp index a9884a8e369a..3dee3cdbb006 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/hub_connection.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/hub_connection.cpp @@ -8,7 +8,7 @@ namespace signalr { - hub_connection::hub_connection(const utility::string_t& url, + hub_connection::hub_connection(const std::string& url, trace_level trace_level, std::shared_ptr log_writer) : m_pImpl(hub_connection_impl::create(url, trace_level, std::move(log_writer))) {} @@ -27,31 +27,31 @@ namespace signalr return m_pImpl->stop(); } - void hub_connection::on(const utility::string_t& event_name, const method_invoked_handler& handler) + void hub_connection::on(const std::string& event_name, const method_invoked_handler& handler) { if (!m_pImpl) { - throw signalr_exception(_XPLATSTR("on() cannot be called on uninitialized hub_connection instance")); + throw signalr_exception("on() cannot be called on uninitialized hub_connection instance"); } return m_pImpl->on(event_name, handler); } - pplx::task hub_connection::invoke(const utility::string_t& method_name, const web::json::value& arguments) + pplx::task hub_connection::invoke(const std::string& method_name, const web::json::value& arguments) { if (!m_pImpl) { - throw signalr_exception(_XPLATSTR("invoke() cannot be called on uninitialized hub_connection instance")); + throw signalr_exception("invoke() cannot be called on uninitialized hub_connection instance"); } return m_pImpl->invoke(method_name, arguments); } - pplx::task hub_connection::send(const utility::string_t& method_name, const web::json::value& arguments) + pplx::task hub_connection::send(const std::string& method_name, const web::json::value& arguments) { if (!m_pImpl) { - throw signalr_exception(_XPLATSTR("send() cannot be called on uninitialized hub_connection instance")); + throw signalr_exception("send() cannot be called on uninitialized hub_connection instance"); } return m_pImpl->send(method_name, arguments); @@ -62,7 +62,7 @@ namespace signalr return m_pImpl->get_connection_state(); } - utility::string_t hub_connection::get_connection_id() const + std::string hub_connection::get_connection_id() const { return m_pImpl->get_connection_id(); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp b/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp index 985b62d78706..260794a3eb65 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.cpp @@ -20,14 +20,14 @@ namespace signalr const std::function& set_exception); } - std::shared_ptr hub_connection_impl::create(const utility::string_t& url, trace_level trace_level, + std::shared_ptr hub_connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer) { return hub_connection_impl::create(url, trace_level, log_writer, std::make_unique(), std::make_unique()); } - std::shared_ptr hub_connection_impl::create(const utility::string_t& url, trace_level trace_level, + std::shared_ptr hub_connection_impl::create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory) { @@ -39,7 +39,7 @@ namespace signalr return connection; } - hub_connection_impl::hub_connection_impl(const utility::string_t& url, trace_level trace_level, + hub_connection_impl::hub_connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory) : m_connection(connection_impl::create(url, trace_level, log_writer, @@ -55,7 +55,7 @@ namespace signalr // weak_ptr prevents a circular dependency leading to memory leak and other problems auto weak_hub_connection = std::weak_ptr(this_hub_connection); - m_connection->set_message_received([weak_hub_connection](const utility::string_t& message) + m_connection->set_message_received([weak_hub_connection](const std::string& message) { auto connection = weak_hub_connection.lock(); if (connection) @@ -69,13 +69,13 @@ namespace signalr auto connection = weak_hub_connection.lock(); if (connection) { - connection->m_handshakeTask.set_exception(signalr_exception(_XPLATSTR("connection closed while handshake was in progress."))); + connection->m_handshakeTask.set_exception(signalr_exception("connection closed while handshake was in progress.")); connection->m_disconnected(); } }); } - void hub_connection_impl::on(const utility::string_t& event_name, const std::function& handler) + void hub_connection_impl::on(const std::string& event_name, const std::function& handler) { if (event_name.length() == 0) { @@ -86,16 +86,16 @@ namespace signalr auto connection = weak_connection.lock(); if (connection && connection->get_connection_state() != connection_state::disconnected) { - throw signalr_exception(_XPLATSTR("can't register a handler if the connection is in a disconnected state")); + throw signalr_exception("can't register a handler if the connection is in a disconnected state"); } if (m_subscriptions.find(event_name) != m_subscriptions.end()) { throw signalr_exception( - _XPLATSTR("an action for this event has already been registered. event name: ") + event_name); + "an action for this event has already been registered. event name: " + event_name); } - m_subscriptions.insert(std::pair> {event_name, handler}); + m_subscriptions.insert(std::pair> {event_name, handler}); } pplx::task hub_connection_impl::start() @@ -103,7 +103,7 @@ namespace signalr if (m_connection->get_connection_state() != connection_state::disconnected) { throw signalr_exception( - _XPLATSTR("the connection can only be started if it is in the disconnected state")); + "the connection can only be started if it is in the disconnected state"); } m_connection->set_client_config(m_signalr_client_config); @@ -118,16 +118,16 @@ namespace signalr if (!connection) { // The connection has been destructed - return pplx::task_from_exception(signalr_exception(_XPLATSTR("the hub connection has been deconstructed"))); + return pplx::task_from_exception(signalr_exception("the hub connection has been deconstructed")); } - return connection->m_connection->send(_XPLATSTR("{\"protocol\":\"json\",\"version\":1}\x1e")) + return connection->m_connection->send("{\"protocol\":\"json\",\"version\":1}\x1e") .then([weak_connection](pplx::task previous_task) { auto connection = weak_connection.lock(); if (!connection) { // The connection has been destructed - return pplx::task_from_exception(signalr_exception(_XPLATSTR("the hub connection has been deconstructed"))); + return pplx::task_from_exception(signalr_exception("the hub connection has been deconstructed")); } previous_task.get(); return pplx::task(connection->m_handshakeTask); @@ -172,20 +172,20 @@ namespace signalr Close, }; - void hub_connection_impl::process_message(const utility::string_t& response) + void hub_connection_impl::process_message(const std::string& response) { try { auto pos = response.find('\x1e'); std::size_t lastPos = 0; - while (pos != utility::string_t::npos) + while (pos != std::string::npos) { auto message = response.substr(lastPos, pos - lastPos); - const auto result = web::json::value::parse(message); + const auto result = web::json::value::parse(utility::conversions::to_string_t(message)); if (!result.is_object()) { - m_logger.log(trace_level::info, utility::string_t(_XPLATSTR("unexpected response received from the server: ")) + m_logger.log(trace_level::info, std::string("unexpected response received from the server: ") .append(message)); return; @@ -195,17 +195,17 @@ namespace signalr { if (result.has_field(_XPLATSTR("error"))) { - auto error = result.at(_XPLATSTR("error")).as_string(); - m_logger.log(trace_level::errors, utility::string_t(_XPLATSTR("handshake error: ")) + auto error = utility::conversions::to_utf8string(result.at(_XPLATSTR("error")).as_string()); + m_logger.log(trace_level::errors, std::string("handshake error: ") .append(error)); - m_handshakeTask.set_exception(signalr_exception(utility::string_t(_XPLATSTR("Received an error during handshake: ")).append(error))); + m_handshakeTask.set_exception(signalr_exception(std::string("Received an error during handshake: ").append(error))); return; } else { if (result.has_field(_XPLATSTR("type"))) { - m_handshakeTask.set_exception(signalr_exception(utility::string_t(_XPLATSTR("Received unexpected message while waiting for the handshake response.")))); + m_handshakeTask.set_exception(signalr_exception(std::string("Received unexpected message while waiting for the handshake response."))); } m_handshakeReceived = true; m_handshakeTask.set(); @@ -218,7 +218,7 @@ namespace signalr { case MessageType::Invocation: { - auto method = result.at(_XPLATSTR("target")).as_string(); + auto method = utility::conversions::to_utf8string(result.at(_XPLATSTR("target")).as_string()); auto event = m_subscriptions.find(method); if (event != m_subscriptions.end()) { @@ -258,26 +258,26 @@ namespace signalr } catch (const std::exception &e) { - m_logger.log(trace_level::errors, utility::string_t(_XPLATSTR("error occured when parsing response: ")) - .append(utility::conversions::to_string_t(e.what())) - .append(_XPLATSTR(". response: ")) + m_logger.log(trace_level::errors, std::string("error occured when parsing response: ") + .append(e.what()) + .append(". response: ") .append(response)); } } bool hub_connection_impl::invoke_callback(const web::json::value& message) { - auto id = message.at(_XPLATSTR("invocationId")).as_string(); + auto id = utility::conversions::to_utf8string(message.at(_XPLATSTR("invocationId")).as_string()); if (!m_callback_manager.invoke_callback(id, message, true)) { - m_logger.log(trace_level::info, utility::string_t(_XPLATSTR("no callback found for id: ")).append(id)); + m_logger.log(trace_level::info, std::string("no callback found for id: ").append(id)); return false; } return true; } - pplx::task hub_connection_impl::invoke(const utility::string_t& method_name, const json::value& arguments) + pplx::task hub_connection_impl::invoke(const std::string& method_name, const json::value& arguments) { _ASSERTE(arguments.is_array()); @@ -293,29 +293,29 @@ namespace signalr return pplx::create_task(tce); } - pplx::task hub_connection_impl::send(const utility::string_t& method_name, const json::value& arguments) + pplx::task hub_connection_impl::send(const std::string& method_name, const json::value& arguments) { _ASSERTE(arguments.is_array()); pplx::task_completion_event tce; - invoke_hub_method(method_name, arguments, _XPLATSTR(""), + invoke_hub_method(method_name, arguments, "", [tce]() { tce.set(); }, [tce](const std::exception_ptr e){ tce.set_exception(e); }); return pplx::create_task(tce); } - void hub_connection_impl::invoke_hub_method(const utility::string_t& method_name, const json::value& arguments, - const utility::string_t& callback_id, std::function set_completion, std::function set_exception) + void hub_connection_impl::invoke_hub_method(const std::string& method_name, const json::value& arguments, + const std::string& callback_id, std::function set_completion, std::function set_exception) { json::value request; request[_XPLATSTR("type")] = json::value::value(1); if (!callback_id.empty()) { - request[_XPLATSTR("invocationId")] = json::value::string(callback_id); + request[_XPLATSTR("invocationId")] = json::value::string(utility::conversions::to_string_t(callback_id)); } - request[_XPLATSTR("target")] = json::value::string(method_name); + request[_XPLATSTR("target")] = json::value::string(utility::conversions::to_string_t(method_name)); request[_XPLATSTR("arguments")] = arguments; auto this_hub_connection = shared_from_this(); @@ -323,7 +323,7 @@ namespace signalr // weak_ptr prevents a circular dependency leading to memory leak and other problems auto weak_hub_connection = std::weak_ptr(this_hub_connection); - m_connection->send(request.serialize() + _XPLATSTR('\x1e')) + m_connection->send(utility::conversions::to_utf8string(request.serialize() + _XPLATSTR('\x1e'))) .then([set_completion, set_exception, weak_hub_connection, callback_id](pplx::task send_task) { try @@ -352,7 +352,7 @@ namespace signalr return m_connection->get_connection_state(); } - utility::string_t hub_connection_impl::get_connection_id() const + std::string hub_connection_impl::get_connection_id() const { return m_connection->get_connection_id(); } @@ -385,7 +385,7 @@ namespace signalr { set_exception( std::make_exception_ptr( - hub_exception(message.at(_XPLATSTR("error")).serialize()))); + hub_exception(utility::conversions::to_utf8string(message.at(_XPLATSTR("error")).serialize())))); } set_result(json::value::null()); diff --git a/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.h b/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.h index 3423d03af1c3..1548c2c4980a 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.h +++ b/src/SignalR/clients/cpp/src/signalrclient/hub_connection_impl.h @@ -4,7 +4,6 @@ #pragma once #include -#include "cpprest/details/basic_types.h" #include "connection_impl.h" #include "callback_manager.h" #include "case_insensitive_comparison_utils.h" @@ -21,38 +20,38 @@ namespace signalr class hub_connection_impl : public std::enable_shared_from_this { public: - static std::shared_ptr create(const utility::string_t& url, trace_level trace_level, + static std::shared_ptr create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer); - static std::shared_ptr create(const utility::string_t& url, trace_level trace_level, + static std::shared_ptr create(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory); hub_connection_impl(const hub_connection_impl&) = delete; hub_connection_impl& operator=(const hub_connection_impl&) = delete; - void on(const utility::string_t& event_name, const std::function& handler); + void on(const std::string& event_name, const std::function& handler); - pplx::task invoke(const utility::string_t& method_name, const json::value& arguments); - pplx::task send(const utility::string_t& method_name, const json::value& arguments); + pplx::task invoke(const std::string& method_name, const json::value& arguments); + pplx::task send(const std::string& method_name, const json::value& arguments); pplx::task start(); pplx::task stop(); connection_state get_connection_state() const noexcept; - utility::string_t get_connection_id() const; + std::string get_connection_id() const; void set_client_config(const signalr_client_config& config); void set_disconnected(const std::function& disconnected); private: - hub_connection_impl(const utility::string_t& url, trace_level trace_level, const std::shared_ptr& log_writer, + hub_connection_impl(const std::string& url, trace_level trace_level, const std::shared_ptr& log_writer, std::unique_ptr web_request_factory, std::unique_ptr transport_factory); std::shared_ptr m_connection; logger m_logger; callback_manager m_callback_manager; - std::unordered_map, case_insensitive_hash, case_insensitive_equals> m_subscriptions; + std::unordered_map, case_insensitive_hash, case_insensitive_equals> m_subscriptions; bool m_handshakeReceived; pplx::task_completion_event m_handshakeTask; std::function m_disconnected; @@ -60,9 +59,9 @@ namespace signalr void initialize(); - void process_message(const utility::string_t& message); + void process_message(const std::string& message); - void invoke_hub_method(const utility::string_t& method_name, const json::value& arguments, const utility::string_t& callback_id, + void invoke_hub_method(const std::string& method_name, const json::value& arguments, const std::string& callback_id, std::function set_completion, std::function set_exception); bool invoke_callback(const web::json::value& message); }; diff --git a/src/SignalR/clients/cpp/src/signalrclient/logger.cpp b/src/SignalR/clients/cpp/src/signalrclient/logger.cpp index a6e0883b939e..c1226bff43a8 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/logger.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/logger.cpp @@ -12,46 +12,46 @@ namespace signalr : m_log_writer(log_writer), m_trace_level(trace_level) { } - void logger::log(trace_level level, const utility::string_t& entry) const + void logger::log(trace_level level, const std::string& entry) const { if ((level & m_trace_level) != trace_level::none) { try { - utility::ostringstream_t os; - os << utility::datetime::utc_now().to_string(utility::datetime::date_format::ISO_8601) << _XPLATSTR(" [") + std::stringstream os; + os << utility::conversions::to_utf8string(utility::datetime::utc_now().to_string(utility::datetime::date_format::ISO_8601)) << " [" << std::left << std::setw(12) << translate_trace_level(level) << "] "<< entry << std::endl; m_log_writer->write(os.str()); } catch (const std::exception &e) { - ucerr << _XPLATSTR("error occurred when logging: ") << utility::conversions::to_string_t(e.what()) - << std::endl << _XPLATSTR(" entry: ") << entry << std::endl; + std::cerr << "error occurred when logging: " << e.what() + << std::endl << " entry: " << entry << std::endl; } catch (...) { - ucerr << _XPLATSTR("unknown error occurred when logging") << std::endl << _XPLATSTR(" entry: ") << entry << std::endl; + std::cerr << "unknown error occurred when logging" << std::endl << " entry: " << entry << std::endl; } } } - utility::string_t logger::translate_trace_level(trace_level trace_level) + std::string logger::translate_trace_level(trace_level trace_level) { switch (trace_level) { case signalr::trace_level::messages: - return _XPLATSTR("message"); + return "message"; case signalr::trace_level::state_changes: - return _XPLATSTR("state change"); + return "state change"; case signalr::trace_level::events: - return _XPLATSTR("event"); + return "event"; case signalr::trace_level::errors: - return _XPLATSTR("error"); + return "error"; case signalr::trace_level::info: - return _XPLATSTR("info"); + return "info"; default: _ASSERTE(false); - return _XPLATSTR("(unknown)"); + return "(unknown)"; } } } diff --git a/src/SignalR/clients/cpp/src/signalrclient/logger.h b/src/SignalR/clients/cpp/src/signalrclient/logger.h index 40b0c07a024d..4bec153d44c1 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/logger.h +++ b/src/SignalR/clients/cpp/src/signalrclient/logger.h @@ -14,12 +14,12 @@ namespace signalr public: logger(const std::shared_ptr& log_writer, trace_level trace_level) noexcept; - void log(trace_level level, const utility::string_t& entry) const; + void log(trace_level level, const std::string& entry) const; private: std::shared_ptr m_log_writer; trace_level m_trace_level; - static utility::string_t translate_trace_level(trace_level trace_level); + static std::string translate_trace_level(trace_level trace_level); }; } diff --git a/src/SignalR/clients/cpp/src/signalrclient/negotiation_response.h b/src/SignalR/clients/cpp/src/signalrclient/negotiation_response.h index 3772d4d06b94..56fa8f7bd4ca 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/negotiation_response.h +++ b/src/SignalR/clients/cpp/src/signalrclient/negotiation_response.h @@ -3,22 +3,20 @@ #pragma once -#include "cpprest/details/basic_types.h" - namespace signalr { struct available_transport { - utility::string_t transport; - std::vector transfer_formats; + std::string transport; + std::vector transfer_formats; }; struct negotiation_response { - utility::string_t connectionId; + std::string connectionId; std::vector availableTransports; - utility::string_t url; - utility::string_t accessToken; - utility::string_t error; + std::string url; + std::string accessToken; + std::string error; }; } diff --git a/src/SignalR/clients/cpp/src/signalrclient/request_sender.cpp b/src/SignalR/clients/cpp/src/signalrclient/request_sender.cpp index 0c4f7d5323c2..b3d2e99d3914 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/request_sender.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/request_sender.cpp @@ -11,27 +11,27 @@ namespace signalr { namespace request_sender { - pplx::task negotiate(web_request_factory& request_factory, const utility::string_t& base_url, + pplx::task negotiate(web_request_factory& request_factory, const std::string& base_url, const signalr_client_config& signalr_client_config) { auto negotiate_url = url_builder::build_negotiate(base_url); return http_sender::post(request_factory, negotiate_url, signalr_client_config) - .then([](utility::string_t body) + .then([](std::string body) { - auto negotiation_response_json = web::json::value::parse(body); + auto negotiation_response_json = web::json::value::parse(utility::conversions::to_string_t(body)); negotiation_response response; if (negotiation_response_json.has_field(_XPLATSTR("error"))) { - response.error = negotiation_response_json[_XPLATSTR("error")].as_string(); + response.error = utility::conversions::to_utf8string(negotiation_response_json[_XPLATSTR("error")].as_string()); return std::move(response); } if (negotiation_response_json.has_field(_XPLATSTR("connectionId"))) { - response.connectionId = negotiation_response_json[_XPLATSTR("connectionId")].as_string(); + response.connectionId = utility::conversions::to_utf8string(negotiation_response_json[_XPLATSTR("connectionId")].as_string()); } if (negotiation_response_json.has_field(_XPLATSTR("availableTransports"))) @@ -39,11 +39,11 @@ namespace signalr for (auto transportData : negotiation_response_json[_XPLATSTR("availableTransports")].as_array()) { available_transport transport; - transport.transport = transportData[_XPLATSTR("transport")].as_string(); + transport.transport = utility::conversions::to_utf8string(transportData[_XPLATSTR("transport")].as_string()); for (auto format : transportData[_XPLATSTR("transferFormats")].as_array()) { - transport.transfer_formats.push_back(format.as_string()); + transport.transfer_formats.push_back(utility::conversions::to_utf8string(format.as_string())); } response.availableTransports.push_back(transport); @@ -52,17 +52,17 @@ namespace signalr if (negotiation_response_json.has_field(_XPLATSTR("url"))) { - response.url = negotiation_response_json[_XPLATSTR("url")].as_string(); + response.url = utility::conversions::to_utf8string(negotiation_response_json[_XPLATSTR("url")].as_string()); if (negotiation_response_json.has_field(_XPLATSTR("accessToken"))) { - response.accessToken = negotiation_response_json[_XPLATSTR("accessToken")].as_string(); + response.accessToken = utility::conversions::to_utf8string(negotiation_response_json[_XPLATSTR("accessToken")].as_string()); } } if (negotiation_response_json.has_field(_XPLATSTR("ProtocolVersion"))) { - throw signalr_exception(_XPLATSTR("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.")); + throw signalr_exception("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details."); } return std::move(response); diff --git a/src/SignalR/clients/cpp/src/signalrclient/request_sender.h b/src/SignalR/clients/cpp/src/signalrclient/request_sender.h index 80419ec0b70f..73becd3eb06d 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/request_sender.h +++ b/src/SignalR/clients/cpp/src/signalrclient/request_sender.h @@ -3,7 +3,6 @@ #pragma once -#include "cpprest/base_uri.h" #include "signalrclient/signalr_client_config.h" #include "signalrclient/transport_type.h" #include "web_request_factory.h" @@ -14,7 +13,7 @@ namespace signalr { namespace request_sender { - pplx::task negotiate(web_request_factory& request_factory, const utility::string_t& base_url, + pplx::task negotiate(web_request_factory& request_factory, const std::string& base_url, const signalr_client_config& signalr_client_config = signalr::signalr_client_config{}); } } diff --git a/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.cpp b/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.cpp index 642ce6b936d4..466c79324ed3 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.cpp @@ -6,11 +6,11 @@ namespace signalr { - void trace_log_writer::write(const utility::string_t &entry) + void trace_log_writer::write(const std::string &entry) { #ifdef _WIN32 // OutputDebugString is thread safe - OutputDebugString(entry.c_str()); + OutputDebugStringA(entry.c_str()); #else // Note: there is no data race for standard output streams in C++ 11 but the results // might be garbled when the method is called concurrently from multiple threads diff --git a/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.h b/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.h index e5894bfe1c4d..f944fa1e70df 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.h +++ b/src/SignalR/clients/cpp/src/signalrclient/trace_log_writer.h @@ -10,6 +10,6 @@ namespace signalr class trace_log_writer : public log_writer { public: - void __cdecl write(const utility::string_t &entry) override; + void __cdecl write(const std::string &entry) override; }; } \ No newline at end of file diff --git a/src/SignalR/clients/cpp/src/signalrclient/transport.cpp b/src/SignalR/clients/cpp/src/signalrclient/transport.cpp index a3304f70cd71..89de95eeaea0 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/transport.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/transport.cpp @@ -7,7 +7,7 @@ namespace signalr { - transport::transport(const logger& logger, const std::function& process_response_callback, + transport::transport(const logger& logger, const std::function& process_response_callback, std::function error_callback) : m_logger(logger), m_process_response_callback(process_response_callback), m_error_callback(error_callback) {} @@ -17,7 +17,7 @@ namespace signalr transport::~transport() { } - void transport::process_response(const utility::string_t &message) + void transport::process_response(const std::string &message) { m_process_response_callback(message); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/transport.h b/src/SignalR/clients/cpp/src/signalrclient/transport.h index f1eea73d027c..3316b2af03c1 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/transport.h +++ b/src/SignalR/clients/cpp/src/signalrclient/transport.h @@ -4,7 +4,6 @@ #pragma once #include "pplx/pplxtasks.h" -#include "cpprest/base_uri.h" #include "signalrclient/transport_type.h" #include "logger.h" @@ -13,9 +12,9 @@ namespace signalr class transport { public: - virtual pplx::task connect(const utility::string_t &url) = 0; + virtual pplx::task connect(const std::string &url) = 0; - virtual pplx::task send(const utility::string_t &data) = 0; + virtual pplx::task send(const std::string &data) = 0; virtual pplx::task disconnect() = 0; @@ -24,16 +23,16 @@ namespace signalr virtual ~transport(); protected: - transport(const logger& logger, const std::function& process_response_callback, + transport(const logger& logger, const std::function& process_response_callback, std::function error_callback); - void process_response(const utility::string_t &message); + void process_response(const std::string &message); void error(const std::exception &e); logger m_logger; private: - std::function m_process_response_callback; + std::function m_process_response_callback; std::function m_error_callback; }; diff --git a/src/SignalR/clients/cpp/src/signalrclient/transport_factory.cpp b/src/SignalR/clients/cpp/src/signalrclient/transport_factory.cpp index c3c5e0fb9c8c..125b5b3bacc9 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/transport_factory.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/transport_factory.cpp @@ -9,7 +9,7 @@ namespace signalr { std::shared_ptr transport_factory::create_transport(transport_type transport_type, const logger& logger, const signalr_client_config& signalr_client_config, - std::function process_response_callback, + std::function process_response_callback, std::function error_callback) { if (transport_type == signalr::transport_type::websockets) diff --git a/src/SignalR/clients/cpp/src/signalrclient/transport_factory.h b/src/SignalR/clients/cpp/src/signalrclient/transport_factory.h index 835401f90d5c..a6c80df4c31a 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/transport_factory.h +++ b/src/SignalR/clients/cpp/src/signalrclient/transport_factory.h @@ -15,7 +15,7 @@ namespace signalr public: virtual std::shared_ptr create_transport(transport_type transport_type, const logger& logger, const signalr_client_config& signalr_client_config, - std::function process_response_callback, + std::function process_response_callback, std::function error_callback); virtual ~transport_factory(); diff --git a/src/SignalR/clients/cpp/src/signalrclient/url_builder.cpp b/src/SignalR/clients/cpp/src/signalrclient/url_builder.cpp index e26b14f8ba06..66a1512f910c 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/url_builder.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/url_builder.cpp @@ -15,44 +15,44 @@ namespace signalr { if (builder.scheme() == _XPLATSTR("https")) { - builder.set_scheme(utility::string_t(_XPLATSTR("wss"))); + builder.set_scheme(utility::conversions::to_string_t("wss")); } else { - builder.set_scheme(utility::string_t(_XPLATSTR("ws"))); + builder.set_scheme(utility::conversions::to_string_t("ws")); } } return builder; } - web::uri_builder build_uri(const web::uri& base_url, const utility::string_t& command, const utility::string_t& query_string) + web::uri_builder build_uri(const std::string& base_url, const std::string& command, const std::string& query_string) { - web::uri_builder builder(base_url); - builder.append_path(command); - return builder.append_query(query_string); + web::uri_builder builder(utility::conversions::to_string_t(base_url)); + builder.append_path(utility::conversions::to_string_t(command)); + return builder.append_query(utility::conversions::to_string_t(query_string)); } - web::uri_builder build_uri(const web::uri& base_url, const utility::string_t& command) + web::uri_builder build_uri(const std::string& base_url, const std::string& command) { - web::uri_builder builder(base_url); - return builder.append_path(command); + web::uri_builder builder(utility::conversions::to_string_t(base_url)); + return builder.append_path(utility::conversions::to_string_t(command)); } - utility::string_t build_negotiate(const utility::string_t& base_url) + std::string build_negotiate(const std::string& base_url) { - return build_uri(base_url, _XPLATSTR("negotiate")).to_string(); + return utility::conversions::to_utf8string(build_uri(base_url, "negotiate").to_string()); } - utility::string_t build_connect(const utility::string_t& base_url, transport_type transport, const utility::string_t& query_string) + std::string build_connect(const std::string& base_url, transport_type transport, const std::string& query_string) { - auto builder = build_uri(base_url, _XPLATSTR(""), query_string); - return convert_to_websocket_url(builder, transport).to_string(); + auto builder = build_uri(base_url, "", query_string); + return utility::conversions::to_utf8string(convert_to_websocket_url(builder, transport).to_string()); } - utility::string_t build_start(const utility::string_t& base_url, const utility::string_t &query_string) + std::string build_start(const std::string& base_url, const std::string &query_string) { - return build_uri(base_url, _XPLATSTR(""), query_string).to_string(); + return utility::conversions::to_utf8string(build_uri(base_url, "", query_string).to_string()); } } } diff --git a/src/SignalR/clients/cpp/src/signalrclient/url_builder.h b/src/SignalR/clients/cpp/src/signalrclient/url_builder.h index bdc27e8a7948..f165e67ca51e 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/url_builder.h +++ b/src/SignalR/clients/cpp/src/signalrclient/url_builder.h @@ -10,8 +10,8 @@ namespace signalr { namespace url_builder { - utility::string_t build_negotiate(const utility::string_t& base_url); - utility::string_t build_connect(const utility::string_t& base_url, transport_type transport, const utility::string_t& query_string); - utility::string_t build_start(const utility::string_t& base_url, const utility::string_t& query_string); + std::string build_negotiate(const std::string& base_url); + std::string build_connect(const std::string& base_url, transport_type transport, const std::string& query_string); + std::string build_start(const std::string& base_url, const std::string& query_string); } } diff --git a/src/SignalR/clients/cpp/src/signalrclient/web_request.cpp b/src/SignalR/clients/cpp/src/signalrclient/web_request.cpp index 5d22027eec26..abe468563842 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/web_request.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/web_request.cpp @@ -7,16 +7,16 @@ namespace signalr { - web_request::web_request(const utility::string_t& url) + web_request::web_request(const std::string& url) : m_url(url) { } - void web_request::set_method(const utility::string_t &method) + void web_request::set_method(const std::string &method) { - m_request.set_method(method); + m_request.set_method(utility::conversions::to_string_t(method)); } - void web_request::set_user_agent(const utility::string_t &user_agent_string) + void web_request::set_user_agent(const std::string &user_agent_string) { m_user_agent_string = user_agent_string; } @@ -28,12 +28,12 @@ namespace signalr pplx::task web_request::get_response() { - web::http::client::http_client client(m_url, m_signalr_client_config.get_http_client_config()); + web::http::client::http_client client(utility::conversions::to_string_t(m_url), m_signalr_client_config.get_http_client_config()); m_request.headers() = m_signalr_client_config.get_http_headers(); if (!m_user_agent_string.empty()) { - m_request.headers()[_XPLATSTR("User-Agent")] = m_user_agent_string; + m_request.headers()[_XPLATSTR("User-Agent")] = utility::conversions::to_string_t(m_user_agent_string); } return client.request(m_request) @@ -42,8 +42,11 @@ namespace signalr return web_response { response.status_code(), - response.reason_phrase(), - response.extract_string() + utility::conversions::to_utf8string(response.reason_phrase()), + response.extract_string().then([](const utility::string_t& body) + { + return utility::conversions::to_utf8string(body); + }) }; }); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/web_request.h b/src/SignalR/clients/cpp/src/signalrclient/web_request.h index 0e114586972c..4f02397c8d0b 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/web_request.h +++ b/src/SignalR/clients/cpp/src/signalrclient/web_request.h @@ -11,10 +11,10 @@ namespace signalr class web_request { public: - explicit web_request(const utility::string_t& url); + explicit web_request(const std::string& url); - virtual void set_method(const utility::string_t &method); - virtual void set_user_agent(const utility::string_t &user_agent_string); + virtual void set_method(const std::string &method); + virtual void set_user_agent(const std::string &user_agent_string); virtual void set_client_config(const signalr_client_config& signalr_client_config); virtual pplx::task get_response(); @@ -24,9 +24,9 @@ namespace signalr virtual ~web_request(); private: - const utility::string_t m_url; + const std::string m_url; web::http::http_request m_request; - utility::string_t m_user_agent_string; + std::string m_user_agent_string; signalr_client_config m_signalr_client_config; }; } diff --git a/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.cpp b/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.cpp index cd1a50249775..234507cc6038 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.cpp @@ -7,7 +7,7 @@ namespace signalr { - std::unique_ptr web_request_factory::create_web_request(const utility::string_t& url) + std::unique_ptr web_request_factory::create_web_request(const std::string& url) { return std::make_unique(url); } diff --git a/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.h b/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.h index 1d7d03630dbe..fe0e5542e7d0 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.h +++ b/src/SignalR/clients/cpp/src/signalrclient/web_request_factory.h @@ -3,7 +3,6 @@ #pragma once -#include "cpprest/base_uri.h" #include "web_request.h" namespace signalr @@ -11,7 +10,7 @@ namespace signalr class web_request_factory { public: - virtual std::unique_ptr create_web_request(const utility::string_t& url); + virtual std::unique_ptr create_web_request(const std::string& url); virtual ~web_request_factory(); }; diff --git a/src/SignalR/clients/cpp/src/signalrclient/web_response.h b/src/SignalR/clients/cpp/src/signalrclient/web_response.h index d89cf991ca85..2ea3b235a7e5 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/web_response.h +++ b/src/SignalR/clients/cpp/src/signalrclient/web_response.h @@ -4,14 +4,13 @@ #pragma once #include "pplx/pplxtasks.h" -#include "cpprest/details/basic_types.h" namespace signalr { struct web_response { unsigned short status_code; - utility::string_t reason_phrase; - pplx::task body; + std::string reason_phrase; + pplx::task body; }; -} \ No newline at end of file +} diff --git a/src/SignalR/clients/cpp/src/signalrclient/websocket_client.h b/src/SignalR/clients/cpp/src/signalrclient/websocket_client.h index 870d409ec35f..9be26a27e8c3 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/websocket_client.h +++ b/src/SignalR/clients/cpp/src/signalrclient/websocket_client.h @@ -4,16 +4,15 @@ #pragma once #include "pplx/pplxtasks.h" -#include "cpprest/base_uri.h" namespace signalr { class websocket_client { public: - virtual pplx::task connect(const web::uri &url) = 0; + virtual pplx::task connect(const std::string& url) = 0; - virtual pplx::task send(const utility::string_t &message) = 0; + virtual pplx::task send(const std::string& message) = 0; virtual pplx::task receive() = 0; @@ -21,4 +20,4 @@ namespace signalr virtual ~websocket_client() {}; }; -} \ No newline at end of file +} diff --git a/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.cpp b/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.cpp index b573a9e29098..96812decc931 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.cpp +++ b/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.cpp @@ -9,7 +9,7 @@ namespace signalr { std::shared_ptr websocket_transport::create(const std::function()>& websocket_client_factory, - const logger& logger, const std::function& process_response_callback, + const logger& logger, const std::function& process_response_callback, std::function error_callback) { return std::shared_ptr( @@ -17,7 +17,7 @@ namespace signalr } websocket_transport::websocket_transport(const std::function()>& websocket_client_factory, - const logger& logger, const std::function& process_response_callback, + const logger& logger, const std::function& process_response_callback, std::function error_callback) : transport(logger, process_response_callback, error_callback), m_websocket_client_factory(websocket_client_factory) { @@ -41,9 +41,9 @@ namespace signalr return transport_type::websockets; } - pplx::task websocket_transport::connect(const utility::string_t& url) + pplx::task websocket_transport::connect(const std::string& url) { - web::uri uri(url); + web::uri uri(utility::conversions::to_string_t(url)); _ASSERTE(uri.scheme() == _XPLATSTR("ws") || uri.scheme() == _XPLATSTR("wss")); { @@ -51,11 +51,11 @@ namespace signalr if (!m_receive_loop_cts.get_token().is_canceled()) { - throw signalr_exception(_XPLATSTR("transport already connected")); + throw signalr_exception("transport already connected"); } m_logger.log(trace_level::info, - utility::string_t(_XPLATSTR("[websocket transport] connecting to: ")) + std::string("[websocket transport] connecting to: ") .append(url)); auto websocket_client = m_websocket_client_factory(); @@ -83,8 +83,8 @@ namespace signalr { transport->m_logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("[websocket transport] exception when connecting to the server: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("[websocket transport] exception when connecting to the server: ") + .append(e.what())); receive_loop_cts.cancel(); connect_tce.set_exception(std::current_exception()); @@ -97,7 +97,7 @@ namespace signalr } } - pplx::task websocket_transport::send(const utility::string_t &data) + pplx::task websocket_transport::send(const std::string &data) { // send will return a faulted task if client has disconnected return safe_get_websocket_client()->send(data); @@ -133,8 +133,8 @@ namespace signalr { logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("[websocket transport] exception when closing websocket: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("[websocket transport] exception when closing websocket: ") + .append(e.what())); } }); } @@ -165,7 +165,7 @@ namespace signalr auto transport = weak_transport.lock(); if (transport) { - transport->process_response(utility::conversions::to_string_t(message)); + transport->process_response(message); if (!cts.get_token().is_canceled()) { @@ -186,7 +186,7 @@ namespace signalr cts.cancel(); logger.log(trace_level::info, - utility::string_t(_XPLATSTR("[websocket transport] receive task canceled."))); + std::string("[websocket transport] receive task canceled.")); } catch (const std::exception& e) { @@ -194,8 +194,8 @@ namespace signalr logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("[websocket transport] error receiving response from websocket: ")) - .append(utility::conversions::to_string_t(e.what()))); + std::string("[websocket transport] error receiving response from websocket: ") + .append(e.what())); websocket_client->close() .then([](pplx::task task) @@ -216,7 +216,7 @@ namespace signalr logger.log( trace_level::errors, - utility::string_t(_XPLATSTR("[websocket transport] unknown error occurred when receiving response from websocket"))); + std::string("[websocket transport] unknown error occurred when receiving response from websocket")); websocket_client->close() .then([](pplx::task task) @@ -228,7 +228,7 @@ namespace signalr auto transport = weak_transport.lock(); if (transport) { - transport->error(signalr_exception(_XPLATSTR("unknown error"))); + transport->error(signalr_exception("unknown error")); } } }); diff --git a/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.h b/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.h index 38b97b667898..6176bcc35843 100644 --- a/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.h +++ b/src/SignalR/clients/cpp/src/signalrclient/websocket_transport.h @@ -16,7 +16,7 @@ namespace signalr { public: static std::shared_ptr create(const std::function()>& websocket_client_factory, - const logger& logger, const std::function& process_response_callback, + const logger& logger, const std::function& process_response_callback, std::function error_callback); ~websocket_transport(); @@ -25,9 +25,9 @@ namespace signalr websocket_transport& operator=(const websocket_transport&) = delete; - pplx::task connect(const utility::string_t& url) override; + pplx::task connect(const std::string& url) override; - pplx::task send(const utility::string_t &data) override; + pplx::task send(const std::string &data) override; pplx::task disconnect() override; @@ -35,7 +35,7 @@ namespace signalr private: websocket_transport(const std::function()>& websocket_client_factory, - const logger& logger, const std::function& process_response_callback, + const logger& logger, const std::function& process_response_callback, std::function error_callback); std::function()> m_websocket_client_factory; diff --git a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/connection_tests.cpp b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/connection_tests.cpp index 144b983e706d..6e9fc8b99270 100644 --- a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/connection_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/connection_tests.cpp @@ -10,11 +10,11 @@ #include "connection.h" #include "hub_connection.h" -extern utility::string_t url; +extern std::string url; TEST(connection_tests, connection_status_start_stop) { - auto conn = std::make_shared(url + U("raw-connection")); + auto conn = std::make_shared(url + "raw-connection"); conn->start().get(); ASSERT_EQ(conn->get_connection_state(), signalr::connection_state::connected); @@ -28,11 +28,11 @@ TEST(connection_tests, connection_status_start_stop) TEST(connection_tests, send_message) { - auto conn = std::make_shared(url + U("raw-connection")); - auto message = std::make_shared(); + auto conn = std::make_shared(url + "raw-connection"); + auto message = std::make_shared(); auto received_event = std::make_shared(); - conn->set_message_received([message, received_event](const utility::string_t& payload) + conn->set_message_received([message, received_event](const std::string& payload) { *message = payload; received_event->set(); @@ -43,22 +43,22 @@ TEST(connection_tests, send_message) web::json::value obj; obj[U("type")] = web::json::value::number(0); obj[U("value")] = web::json::value::string(U("test")); - return conn->send(obj.serialize()); + return conn->send(utility::conversions::to_utf8string(obj.serialize())); }).get(); ASSERT_FALSE(received_event->wait(2000)); - ASSERT_EQ(*message, U("{\"data\":\"test\",\"type\":0}")); + ASSERT_EQ(*message, "{\"data\":\"test\",\"type\":0}"); } TEST(connection_tests, send_message_after_connection_restart) { - auto conn = std::make_shared(url + U("raw-connection")); - auto message = std::make_shared(); + auto conn = std::make_shared(url + "raw-connection"); + auto message = std::make_shared(); auto received_event = std::make_shared(); - conn->set_message_received([message, received_event](const utility::string_t& payload) + conn->set_message_received([message, received_event](const std::string& payload) { *message = payload; received_event->set(); @@ -73,29 +73,29 @@ TEST(connection_tests, send_message_after_connection_restart) web::json::value obj; obj[U("type")] = web::json::value::number(0); obj[U("value")] = web::json::value::string(U("test")); - return conn->send(obj.serialize()); + return conn->send(utility::conversions::to_utf8string(obj.serialize())); }).get(); ASSERT_FALSE(received_event->wait(2000)); - ASSERT_EQ(*message, U("{\"data\":\"test\",\"type\":0}")); + ASSERT_EQ(*message, "{\"data\":\"test\",\"type\":0}"); } TEST(connection_tests, connection_id_start_stop) { - auto conn = std::make_shared(url + U("raw-connection")); + auto conn = std::make_shared(url + "raw-connection"); - ASSERT_EQ(U(""), conn->get_connection_id()); + ASSERT_EQ("", conn->get_connection_id()); conn->start().get(); auto connection_id = conn->get_connection_id(); - ASSERT_NE(connection_id, U("")); + ASSERT_NE(connection_id, ""); conn->stop().get(); ASSERT_EQ(conn->get_connection_id(), connection_id); conn->start().get(); - ASSERT_NE(conn->get_connection_id(), U("")); + ASSERT_NE(conn->get_connection_id(), ""); ASSERT_NE(conn->get_connection_id(), connection_id); } diff --git a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/hub_connection_tests.cpp b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/hub_connection_tests.cpp index b7e76250b506..f434895febf0 100644 --- a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/hub_connection_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/hub_connection_tests.cpp @@ -11,7 +11,7 @@ #include "hub_connection.h" #include "signalr_exception.h" -extern utility::string_t url; +extern std::string url; TEST(hub_connection_tests, connection_status_start_stop_start) { @@ -30,13 +30,13 @@ TEST(hub_connection_tests, connection_status_start_stop_start) TEST(hub_connection_tests, send_message) { - auto hub_conn = std::make_shared(url + U("custom"), signalr::trace_level::all, nullptr); - auto message = std::make_shared(); + auto hub_conn = std::make_shared(url + "custom", signalr::trace_level::all, nullptr); + auto message = std::make_shared(); auto received_event = std::make_shared(); - hub_conn->on(U("sendString"), [message, received_event](const web::json::value& arguments) + hub_conn->on("sendString", [message, received_event](const web::json::value& arguments) { - *message = arguments.serialize(); + *message = utility::conversions::to_utf8string(arguments.serialize()); received_event->set(); }); @@ -45,13 +45,13 @@ TEST(hub_connection_tests, send_message) web::json::value obj{}; obj[0] = web::json::value(U("test")); - return hub_conn->send(U("invokeWithString"), obj); + return hub_conn->send("invokeWithString", obj); }).get(); ASSERT_FALSE(received_event->wait(2000)); - ASSERT_EQ(*message, U("[\"Send: test\"]")); + ASSERT_EQ(*message, "[\"Send: test\"]"); } TEST(hub_connection_tests, send_message_return) @@ -63,7 +63,7 @@ TEST(hub_connection_tests, send_message_return) web::json::value obj{}; obj[0] = web::json::value(U("test")); - return hub_conn->invoke(U("returnString"), obj); + return hub_conn->invoke("returnString", obj); }).get(); @@ -73,12 +73,12 @@ TEST(hub_connection_tests, send_message_return) TEST(hub_connection_tests, send_message_after_connection_restart) { auto hub_conn = std::make_shared(url); - auto message = std::make_shared(); + auto message = std::make_shared(); auto received_event = std::make_shared(); - hub_conn->on(U("sendString"), [message, received_event](const web::json::value& arguments) + hub_conn->on("sendString", [message, received_event](const web::json::value& arguments) { - *message = arguments.serialize(); + *message = utility::conversions::to_utf8string(arguments.serialize()); received_event->set(); }); @@ -91,47 +91,47 @@ TEST(hub_connection_tests, send_message_after_connection_restart) web::json::value obj{}; obj[0] = web::json::value(U("test")); - return hub_conn->send(U("invokeWithString"), obj); + return hub_conn->send("invokeWithString", obj); }).get(); ASSERT_FALSE(received_event->wait(2000)); - ASSERT_EQ(*message, U("[\"Send: test\"]")); + ASSERT_EQ(*message, "[\"Send: test\"]"); } TEST(hub_connection_tests, send_message_empty_param) { auto hub_conn = std::make_shared(url); - auto message = std::make_shared(); + auto message = std::make_shared(); auto received_event = std::make_shared(); - hub_conn->on(U("sendString"), [message, received_event](const web::json::value& arguments) + hub_conn->on("sendString", [message, received_event](const web::json::value& arguments) { - *message = arguments.serialize(); + *message = utility::conversions::to_utf8string(arguments.serialize()); received_event->set(); }); hub_conn->start().then([&hub_conn]() { - return hub_conn->invoke(U("invokeWithEmptyParam")); + return hub_conn->invoke("invokeWithEmptyParam"); }).get(); ASSERT_FALSE(received_event->wait(2000)); - ASSERT_EQ(*message, U("[\"Send\"]")); + ASSERT_EQ(*message, "[\"Send\"]"); } TEST(hub_connection_tests, send_message_primitive_params) { auto hub_conn = std::make_shared(url); - auto message = std::make_shared(); + auto message = std::make_shared(); auto received_event = std::make_shared(); - hub_conn->on(U("sendPrimitiveParams"), [message, received_event](const web::json::value& arguments) + hub_conn->on("sendPrimitiveParams", [message, received_event](const web::json::value& arguments) { - *message = arguments.serialize(); + *message = utility::conversions::to_utf8string(arguments.serialize()); received_event->set(); }); @@ -143,7 +143,7 @@ TEST(hub_connection_tests, send_message_primitive_params) obj[2] = web::json::value(8.999999999); obj[3] = web::json::value(true); obj[4] = web::json::value('a'); - return hub_conn->send(U("invokeWithPrimitiveParams"), obj); + return hub_conn->send("invokeWithPrimitiveParams", obj); }).get(); @@ -156,18 +156,18 @@ TEST(hub_connection_tests, send_message_primitive_params) obj[3] = web::json::value(true); obj[4] = web::json::value::string(U("a")); - ASSERT_EQ(*message, obj.serialize()); + ASSERT_EQ(*message, utility::conversions::to_utf8string(obj.serialize())); } TEST(hub_connection_tests, send_message_complex_type) { auto hub_conn = std::make_shared(url); - auto message = std::make_shared(); + auto message = std::make_shared(); auto received_event = std::make_shared(); - hub_conn->on(U("sendComplexType"), [message, received_event](const web::json::value& arguments) + hub_conn->on("sendComplexType", [message, received_event](const web::json::value& arguments) { - *message = arguments.serialize(); + *message = utility::conversions::to_utf8string(arguments.serialize()); received_event->set(); }); @@ -183,13 +183,13 @@ TEST(hub_connection_tests, send_message_complex_type) person[U("age")] = web::json::value::number(15); obj[0] = person; - return hub_conn->send(U("invokeWithComplexType"), obj); + return hub_conn->send("invokeWithComplexType", obj); }).get(); ASSERT_FALSE(received_event->wait(2000)); - ASSERT_EQ(*message, U("[{\"Address\":{\"Street\":\"main st\",\"Zip\":\"98052\"},\"Age\":15,\"Name\":\"test\"}]")); + ASSERT_EQ(*message, "[{\"Address\":{\"Street\":\"main st\",\"Zip\":\"98052\"},\"Age\":15,\"Name\":\"test\"}]"); } TEST(hub_connection_tests, send_message_complex_type_return) @@ -208,7 +208,7 @@ TEST(hub_connection_tests, send_message_complex_type_return) person[U("age")] = web::json::value::number(15); obj[0] = person; - return hub_conn->invoke(U("returnComplexType"), obj); + return hub_conn->invoke("returnComplexType", obj); }).get(); @@ -220,19 +220,19 @@ TEST(hub_connection_tests, connection_id_start_stop_start) auto hub_conn = std::make_shared(url); auto weak_hub_conn = std::weak_ptr(hub_conn); - utility::string_t connection_id; + std::string connection_id; - ASSERT_EQ(U(""), hub_conn->get_connection_id()); + ASSERT_EQ(u8"", hub_conn->get_connection_id()); hub_conn->start().get(); connection_id = hub_conn->get_connection_id(); - ASSERT_NE(connection_id, U("")); + ASSERT_NE(connection_id, u8""); hub_conn->stop().get(); ASSERT_EQ(hub_conn->get_connection_id(), connection_id); hub_conn->start().get(); - ASSERT_NE(hub_conn->get_connection_id(), U("")); + ASSERT_NE(hub_conn->get_connection_id(), u8""); ASSERT_NE(hub_conn->get_connection_id(), connection_id); connection_id = hub_conn->get_connection_id(); diff --git a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/signalrclient-e2e-tests.cpp b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/signalrclient-e2e-tests.cpp index 1872795984cd..0cd4043ed60c 100644 --- a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/signalrclient-e2e-tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/signalrclient-e2e-tests.cpp @@ -5,15 +5,11 @@ #include #include "test_utils.h" -#if defined(_WIN32) -int wmain(int argc, wchar_t* argv[]) -#else int main(int argc, char* argv[]) -#endif { get_url(argc, argv); ::testing::InitGoogleTest(&argc, argv); RUN_ALL_TESTS(); return 0; -} \ No newline at end of file +} diff --git a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.cpp b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.cpp index 91ff846e6f05..8a8da25339d3 100644 --- a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.cpp +++ b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.cpp @@ -9,17 +9,17 @@ #include "cpprest/asyncrt_utils.h" #include -utility::string_t url; +std::string url; -void get_url(int argc, utility::char_t* argv[]) +void get_url(int argc, char* argv[]) { - url = U("http://localhost:42524/"); + url = "http://localhost:42524/"; for (int i = 0; i < argc; ++i) { - utility::string_t str = argv[i]; + std::string str = argv[i]; - auto pos = str.find(U("url=")); + auto pos = str.find("url="); if (pos != std::string::npos) { url = str.substr(pos + 4); diff --git a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.h b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.h index 3bd47159bd3e..41d72ced843e 100644 --- a/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.h +++ b/src/SignalR/clients/cpp/test/signalrclient-e2e-tests/test_utils.h @@ -4,6 +4,5 @@ #pragma once #include "stdafx.h" -#include "cpprest/details/basic_types.h" -void get_url(int argc, utility::char_t* argv[]); +void get_url(int argc, char* argv[]); diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/callback_manager_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/callback_manager_tests.cpp index a1e7f4f908de..1e0afedde459 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/callback_manager_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/callback_manager_tests.cpp @@ -20,18 +20,18 @@ TEST(callback_manager_invoke_callback, invoke_callback_invokes_and_removes_callb { callback_manager callback_mgr{ json::value::object() }; - utility::string_t callback_argument{_XPLATSTR("")}; + std::string callback_argument{ "" }; auto callback_id = callback_mgr.register_callback( [&callback_argument](const json::value& argument) { - callback_argument = argument.serialize(); + callback_argument = utility::conversions::to_utf8string(argument.serialize()); }); auto callback_found = callback_mgr.invoke_callback(callback_id, json::value::number(42), true); ASSERT_TRUE(callback_found); - ASSERT_EQ(_XPLATSTR("42"), callback_argument); + ASSERT_EQ("42", callback_argument); ASSERT_FALSE(callback_mgr.remove_callback(callback_id)); } @@ -39,25 +39,25 @@ TEST(callback_manager_invoke_callback, invoke_callback_invokes_and_does_not_remo { callback_manager callback_mgr{ json::value::object() }; - utility::string_t callback_argument{ _XPLATSTR("") }; + std::string callback_argument{ "" }; auto callback_id = callback_mgr.register_callback( [&callback_argument](const json::value& argument) { - callback_argument = argument.serialize(); + callback_argument = utility::conversions::to_utf8string(argument.serialize()); }); auto callback_found = callback_mgr.invoke_callback(callback_id, json::value::number(42), false); ASSERT_TRUE(callback_found); - ASSERT_EQ(_XPLATSTR("42"), callback_argument); + ASSERT_EQ("42", callback_argument); ASSERT_TRUE(callback_mgr.remove_callback(callback_id)); } TEST(callback_manager_ivoke_callback, invoke_callback_returns_false_for_invalid_callback_id) { callback_manager callback_mgr{ json::value::object() }; - auto callback_found = callback_mgr.invoke_callback(_XPLATSTR("42"), json::value::object(), true); + auto callback_found = callback_mgr.invoke_callback("42", json::value::object(), true); ASSERT_FALSE(callback_found); } @@ -84,7 +84,7 @@ TEST(callback_manager_remove, remove_removes_callback_and_returns_true_for_valid TEST(callback_manager_remove, remove_returns_false_for_invalid_callback_id) { callback_manager callback_mgr{ json::value::object() }; - ASSERT_FALSE(callback_mgr.remove_callback(_XPLATSTR("42"))); + ASSERT_FALSE(callback_mgr.remove_callback("42")); } TEST(callback_manager_clear, clear_invokes_all_callbacks) diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/case_insensitive_comparison_utils_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/case_insensitive_comparison_utils_tests.cpp index 55f8436cf18e..0b94f476553f 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/case_insensitive_comparison_utils_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/case_insensitive_comparison_utils_tests.cpp @@ -10,21 +10,21 @@ TEST(case_insensitive_equals_functor, basic_comparison_tests) { case_insensitive_equals case_insensitive_compare; - ASSERT_TRUE(case_insensitive_compare(_XPLATSTR(""), _XPLATSTR(""))); - ASSERT_TRUE(case_insensitive_compare(_XPLATSTR("abc"), _XPLATSTR("ABC"))); - ASSERT_TRUE(case_insensitive_compare(_XPLATSTR("abc123!@"), _XPLATSTR("ABC123!@"))); + ASSERT_TRUE(case_insensitive_compare("", "")); + ASSERT_TRUE(case_insensitive_compare("abc", "ABC")); + ASSERT_TRUE(case_insensitive_compare("abc123!@", "ABC123!@")); - ASSERT_FALSE(case_insensitive_compare(_XPLATSTR("abc"), _XPLATSTR("ABCD"))); - ASSERT_FALSE(case_insensitive_compare(_XPLATSTR("abce"), _XPLATSTR("ABCD"))); + ASSERT_FALSE(case_insensitive_compare("abc", "ABCD")); + ASSERT_FALSE(case_insensitive_compare("abce", "ABCD")); } TEST(case_insensitive_hash_functor, basic_hash_tests) { case_insensitive_hash case_insensitive_hasher; - ASSERT_EQ(0U, case_insensitive_hasher(_XPLATSTR(""))); + ASSERT_EQ(0U, case_insensitive_hasher("")); - ASSERT_EQ(case_insensitive_hasher(_XPLATSTR("abc")), case_insensitive_hasher(_XPLATSTR("ABC"))); - ASSERT_EQ(case_insensitive_hasher(_XPLATSTR("abc123!@")), case_insensitive_hasher(_XPLATSTR("ABC123!@"))); - ASSERT_NE(case_insensitive_hasher(_XPLATSTR("abcd")), case_insensitive_hasher(_XPLATSTR("ABC"))); -} \ No newline at end of file + ASSERT_EQ(case_insensitive_hasher("abc"), case_insensitive_hasher("ABC")); + ASSERT_EQ(case_insensitive_hasher("abc123!@"), case_insensitive_hasher("ABC123!@")); + ASSERT_NE(case_insensitive_hasher("abcd"), case_insensitive_hasher("ABC")); +} diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/connection_impl_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/connection_impl_tests.cpp index cb9282ad404a..e95a78f66a7c 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/connection_impl_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/connection_impl_tests.cpp @@ -56,8 +56,8 @@ TEST(connection_impl_start, connection_state_is_connecting_when_connection_is_be auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* send function */ [](const utility::string_t){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */[](const web::uri&) + /* send function */ [](const std::string){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */[](const std::string&) { return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); @@ -92,9 +92,9 @@ 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 web_request_factory = std::make_unique([](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([](const std::string&) -> std::unique_ptr { - return std::unique_ptr(new web_request_stub((unsigned short)404, _XPLATSTR("Bad request"), _XPLATSTR(""))); + return std::unique_ptr(new web_request_stub((unsigned short)404, "Bad request", "")); }); auto connection = @@ -118,7 +118,7 @@ TEST(connection_impl_start, throws_for_invalid_uri) auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }); - auto connection = connection_impl::create(_XPLATSTR(":1\t ä bad_uri&a=b"), trace_level::errors, writer, create_test_web_request_factory(), std::make_unique(websocket_client)); + auto connection = connection_impl::create(":1\t ä bad_uri&a=b", trace_level::errors, writer, create_test_web_request_factory(), std::make_unique(websocket_client)); try { @@ -136,18 +136,18 @@ TEST(connection_impl_start, throws_for_invalid_uri) TEST(connection_impl_start, start_sets_id_query_string) { std::shared_ptr writer(std::make_shared()); - utility::string_t query_string; + std::string query_string; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* send function */ [](const utility::string_t) { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */[&query_string](const web::uri& url) + /* send function */ [](const std::string&) { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */[&query_string](const std::string& url) { - query_string = url.query(); - return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); + query_string = utility::conversions::to_utf8string(url.substr(url.find('?') + 1)); + return pplx::task_from_exception(web::websockets::client::websocket_exception("connecting failed")); }); - auto connection = connection_impl::create(create_uri(_XPLATSTR("")), trace_level::errors, writer, create_test_web_request_factory(), std::make_unique(websocket_client)); + auto connection = connection_impl::create(create_uri(""), trace_level::errors, writer, create_test_web_request_factory(), std::make_unique(websocket_client)); try { @@ -157,24 +157,24 @@ TEST(connection_impl_start, start_sets_id_query_string) { } - ASSERT_EQ(_XPLATSTR("id=f7707523-307d-4cba-9abf-3eef701241e8"), query_string); + ASSERT_EQ("id=f7707523-307d-4cba-9abf-3eef701241e8", query_string); } TEST(connection_impl_start, start_appends_id_query_string) { std::shared_ptr writer(std::make_shared()); - utility::string_t query_string; + std::string query_string; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* send function */ [](const utility::string_t) { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */[&query_string](const web::uri& url) + /* send function */ [](const std::string) { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */[&query_string](const std::string& url) { - query_string = url.query(); + query_string = utility::conversions::to_utf8string(url.substr(url.find('?') + 1)); return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); - auto connection = connection_impl::create(create_uri(_XPLATSTR("a=b&c=d")), trace_level::errors, writer, create_test_web_request_factory(), std::make_unique(websocket_client)); + auto connection = connection_impl::create(create_uri("a=b&c=d"), trace_level::errors, writer, create_test_web_request_factory(), std::make_unique(websocket_client)); try { @@ -184,16 +184,16 @@ TEST(connection_impl_start, start_appends_id_query_string) { } - ASSERT_EQ(_XPLATSTR("a=b&c=d&id=f7707523-307d-4cba-9abf-3eef701241e8"), query_string); + ASSERT_EQ("a=b&c=d&id=f7707523-307d-4cba-9abf-3eef701241e8", query_string); } TEST(connection_impl_start, start_logs_exceptions) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([](const std::string&) -> std::unique_ptr { - return std::unique_ptr(new web_request_stub((unsigned short)404, _XPLATSTR("Bad request"), _XPLATSTR(""))); + return std::unique_ptr(new web_request_stub((unsigned short)404, "Bad request", "")); }); auto connection = @@ -211,15 +211,15 @@ TEST(connection_impl_start, start_logs_exceptions) ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[error ] connection could not be started due to: web exception - 404 Bad request\n"), entry); + ASSERT_EQ("[error ] connection could not be started due to: web exception - 404 Bad request\n", entry); } TEST(connection_impl_start, start_propagates_exceptions_from_negotiate) { - auto web_request_factory = std::make_unique([](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([](const std::string&) -> std::unique_ptr { - return std::unique_ptr(new web_request_stub((unsigned short)404, _XPLATSTR("Bad request"), _XPLATSTR(""))); + return std::unique_ptr(new web_request_stub((unsigned short)404, "Bad request", "")); }); auto connection = @@ -243,8 +243,8 @@ TEST(connection_impl_start, start_fails_if_transport_connect_throws) auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* send function */ [](const utility::string_t){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */[](const web::uri&) + /* send function */ [](const std::string){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */[](const std::string&) { return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); @@ -265,7 +265,7 @@ TEST(connection_impl_start, start_fails_if_transport_connect_throws) ASSERT_TRUE(log_entries.size() > 1); auto entry = remove_date_from_log_entry(log_entries[1]); - ASSERT_EQ(_XPLATSTR("[error ] transport could not connect due to: connecting failed\n"), entry); + ASSERT_EQ("[error ] transport could not connect due to: connecting failed\n", entry); } #if defined(_WIN32) // https://github.com/aspnet/SignalR-Client-Cpp/issues/131 @@ -275,7 +275,7 @@ TEST(connection_impl_send, send_fails_if_transport_fails_when_receiving_messages std::shared_ptr writer(std::make_shared()); auto websocket_client = create_test_websocket_client([]() { return pplx::task_from_result(std::string("")); }, - /* send function */ [](const utility::string_t &) + /* send function */ [](const std::string &) { return pplx::task_from_exception(std::runtime_error("send error")); }); @@ -286,19 +286,19 @@ TEST(connection_impl_send, send_fails_if_transport_fails_when_receiving_messages try { - connection->send(_XPLATSTR("message")).get(); + connection->send("message").get(); ASSERT_TRUE(false); // exception not thrown } catch (const std::exception &e) { - ASSERT_EQ(_XPLATSTR("send error"), utility::conversions::to_string_t(e.what())); + ASSERT_STREQ("send error", e.what()); } auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_TRUE(log_entries.size() == 1) << dump_vector(log_entries); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[error ] error sending data: send error\n"), entry) << dump_vector(log_entries); + ASSERT_EQ("[error ] error sending data: send error\n", entry) << dump_vector(log_entries); } #endif @@ -307,9 +307,9 @@ TEST(connection_impl_start, start_fails_if_negotiate_request_fails) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri&) + auto web_request_factory = std::make_unique([](const std::string&) { - return std::unique_ptr(new web_request_stub((unsigned short)400, _XPLATSTR("Bad Request"))); + return std::unique_ptr(new web_request_stub((unsigned short)400, "Bad Request")); }); auto websocket_client = std::make_shared(); @@ -337,19 +337,19 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_has_error) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{ \"error\": \"bad negotiate\" }") - : _XPLATSTR(""); + url.find("/negotiate") != std::string::npos + ? "{ \"error\": \"bad negotiate\" }" + : ""; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); pplx::task_completion_event tce; auto websocket_client = std::make_shared(); - websocket_client->set_connect_function([tce](const web::uri&) mutable + websocket_client->set_connect_function([tce](const std::string&) mutable { return pplx::task(tce); }); @@ -373,19 +373,19 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_does_not_have_webs { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{ \"availableTransports\": [ { \"transport\": \"ServerSentEvents\", \"transferFormats\": [ \"Text\" ] } ] }") - : _XPLATSTR(""); + url.find("/negotiate") != std::string::npos + ? "{ \"availableTransports\": [ { \"transport\": \"ServerSentEvents\", \"transferFormats\": [ \"Text\" ] } ] }" + : ""; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); pplx::task_completion_event tce; auto websocket_client = std::make_shared(); - websocket_client->set_connect_function([tce](const web::uri&) mutable + websocket_client->set_connect_function([tce](const std::string&) mutable { return pplx::task(tce); }); @@ -409,19 +409,19 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_does_not_have_tran { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{ \"availableTransports\": [ ] }") - : _XPLATSTR(""); + url.find("/negotiate") != std::string::npos + ? "{ \"availableTransports\": [ ] }" + : ""; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); pplx::task_completion_event tce; auto websocket_client = std::make_shared(); - websocket_client->set_connect_function([tce](const web::uri&) mutable + websocket_client->set_connect_function([tce](const std::string&) mutable { return pplx::task(tce); }); @@ -445,19 +445,19 @@ TEST(connection_impl_start, start_fails_if_negotiate_response_is_invalid) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{ \"availableTransports\": [ ") - : _XPLATSTR(""); + url.find("/negotiate") != std::string::npos + ? "{ \"availableTransports\": [ " + : ""; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); pplx::task_completion_event tce; auto websocket_client = std::make_shared(); - websocket_client->set_connect_function([tce](const web::uri&) mutable + websocket_client->set_connect_function([tce](const std::string&) mutable { return pplx::task(tce); }); @@ -481,31 +481,31 @@ TEST(connection_impl_start, negotiate_follows_redirect) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { - utility::string_t response_body = _XPLATSTR(""); - if (url.path() == _XPLATSTR("/negotiate")) + std::string response_body = ""; + if (url.find("/negotiate") != std::string::npos) { - if (url.host() == _XPLATSTR("redirected")) + if (url.find("redirected") != std::string::npos) { - response_body = _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"); + response_body = "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"; } else { - response_body = _XPLATSTR("{ \"url\": \"http://redirected\" }"); + response_body = "{ \"url\": \"http://redirected\" }"; } } - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); auto websocket_client = std::make_shared(); - utility::string_t connectUrl; - websocket_client->set_connect_function([&connectUrl](const web::uri& url) + std::string connectUrl; + websocket_client->set_connect_function([&connectUrl](const std::string& url) { - connectUrl = url.to_string(); + connectUrl = url; return pplx::task_from_result(); }); @@ -515,44 +515,44 @@ TEST(connection_impl_start, negotiate_follows_redirect) connection->start().get(); - ASSERT_EQ(_XPLATSTR("ws://redirected/?id=f7707523-307d-4cba-9abf-3eef701241e8"), connectUrl); + ASSERT_EQ("ws://redirected/?id=f7707523-307d-4cba-9abf-3eef701241e8", connectUrl); } TEST(connection_impl_start, negotiate_redirect_uses_accessToken) { std::shared_ptr writer(std::make_shared()); - utility::string_t accessToken; + std::string accessToken; - auto web_request_factory = std::make_unique([&accessToken](const web::uri & url) + auto web_request_factory = std::make_unique([&accessToken](const std::string& url) { - utility::string_t response_body = _XPLATSTR(""); - if (url.path() == _XPLATSTR("/negotiate")) + std::string response_body = ""; + if (url.find("/negotiate") != std::string::npos) { - if (url.host() == _XPLATSTR("redirected")) + if (url.find("redirected") != std::string::npos) { - response_body = _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"); + response_body = "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"; } else { - response_body = _XPLATSTR("{ \"url\": \"http://redirected\", \"accessToken\": \"secret\" }"); + response_body = "{ \"url\": \"http://redirected\", \"accessToken\": \"secret\" }"; } } - auto request = new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body); + auto request = new web_request_stub((unsigned short)200, "OK", response_body); request->on_get_response = [&accessToken](web_request_stub& stub) { - accessToken = stub.m_signalr_client_config.get_http_headers()[_XPLATSTR("Authorization")]; + accessToken = utility::conversions::to_utf8string(stub.m_signalr_client_config.get_http_headers()[_XPLATSTR("Authorization")]); }; return std::unique_ptr(request); }); auto websocket_client = std::make_shared(); - utility::string_t connectUrl; - websocket_client->set_connect_function([&connectUrl](const web::uri& url) + std::string connectUrl; + websocket_client->set_connect_function([&connectUrl](const std::string& url) { - connectUrl = url.to_string(); + connectUrl = url; return pplx::task_from_result(); }); @@ -562,24 +562,24 @@ TEST(connection_impl_start, negotiate_redirect_uses_accessToken) connection->start().get(); - ASSERT_EQ(_XPLATSTR("ws://redirected/?id=f7707523-307d-4cba-9abf-3eef701241e8"), connectUrl); - ASSERT_EQ(_XPLATSTR("Bearer secret"), accessToken); + ASSERT_EQ("ws://redirected/?id=f7707523-307d-4cba-9abf-3eef701241e8", connectUrl); + ASSERT_EQ("Bearer secret", accessToken); } TEST(connection_impl_start, negotiate_fails_after_too_many_redirects) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { - utility::string_t response_body = _XPLATSTR(""); - if (url.path() == _XPLATSTR("/negotiate")) + std::string response_body = ""; + if (url.find("/negotiate") != std::string::npos) { // infinite redirect - response_body = _XPLATSTR("{ \"url\": \"http://redirected\" }"); + response_body = "{ \"url\": \"http://redirected\" }"; } - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); auto websocket_client = std::make_shared(); @@ -602,15 +602,15 @@ TEST(connection_impl_start, negotiate_fails_if_ProtocolVersion_in_response) { std::shared_ptr writer(std::make_shared()); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { - utility::string_t response_body = _XPLATSTR(""); - if (url.path() == _XPLATSTR("/negotiate")) + std::string response_body = ""; + if (url.find("/negotiate") != std::string::npos) { - response_body = _XPLATSTR("{\"ProtocolVersion\" : \"\" }"); + response_body = "{\"ProtocolVersion\" : \"\" }"; } - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); auto websocket_client = std::make_shared(); @@ -634,24 +634,24 @@ TEST(connection_impl_start, negotiate_redirect_does_not_overwrite_url) std::shared_ptr writer(std::make_shared()); int redirectCount = 0; - auto web_request_factory = std::make_unique([&redirectCount](const web::uri & url) + auto web_request_factory = std::make_unique([&redirectCount](const std::string& url) { - utility::string_t response_body = _XPLATSTR(""); - if (url.path() == _XPLATSTR("/negotiate")) + std::string response_body = ""; + if (url.find("/negotiate") != std::string::npos) { - if (url.host() == _XPLATSTR("redirected")) + if (url.find("redirected") != std::string::npos) { - response_body = _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"); + response_body = "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"; } else { - response_body = _XPLATSTR("{ \"url\": \"http://redirected\" }"); + response_body = "{ \"url\": \"http://redirected\" }"; redirectCount++; } } - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); auto websocket_client = std::make_shared(); @@ -670,37 +670,37 @@ TEST(connection_impl_start, negotiate_redirect_does_not_overwrite_url) TEST(connection_impl_start, negotiate_redirect_uses_own_query_string) { std::shared_ptr writer(std::make_shared()); - utility::string_t query_string; + std::string query_string; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* send function */ [](const utility::string_t) { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */[&query_string](const web::uri& url) + /* send function */ [](const std::string) { return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */[&query_string](const std::string& url) { - query_string = url.query(); + query_string = url.substr(url.find('?') + 1); return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); - auto web_request_factory = std::make_unique([](const web::uri & url) + auto web_request_factory = std::make_unique([](const std::string& url) { - utility::string_t response_body = _XPLATSTR(""); - if (url.path() == _XPLATSTR("/negotiate")) + std::string response_body = ""; + if (url.find("/negotiate") != std::string::npos) { - if (url.host() == _XPLATSTR("redirected")) + if (url.find("redirected") != std::string::npos) { - response_body = _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"); + response_body = "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }"; } else { - response_body = _XPLATSTR("{ \"url\": \"http://redirected?customQuery=1\" }"); + response_body = "{ \"url\": \"http://redirected?customQuery=1\" }"; } } - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); - auto connection = connection_impl::create(create_uri(_XPLATSTR("a=b&c=d")), trace_level::errors, writer, std::move(web_request_factory), std::make_unique(websocket_client)); + auto connection = connection_impl::create(create_uri("a=b&c=d"), trace_level::errors, writer, std::move(web_request_factory), std::make_unique(websocket_client)); try { @@ -710,7 +710,7 @@ TEST(connection_impl_start, negotiate_redirect_uses_own_query_string) { } - ASSERT_EQ(_XPLATSTR("customQuery=1&id=f7707523-307d-4cba-9abf-3eef701241e8"), query_string); + ASSERT_EQ("customQuery=1&id=f7707523-307d-4cba-9abf-3eef701241e8", query_string); } TEST(connection_impl_start, start_fails_if_connect_request_times_out) @@ -721,7 +721,7 @@ TEST(connection_impl_start, start_fails_if_connect_request_times_out) pplx::task_completion_event tce; auto websocket_client = std::make_shared(); - websocket_client->set_connect_function([tce](const web::uri&) mutable + websocket_client->set_connect_function([tce](const std::string&) mutable { return pplx::task(tce); }); @@ -761,16 +761,16 @@ TEST(connection_impl_process_response, process_response_logs_messages) ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[message ] processing message: { }\n"), entry); + ASSERT_EQ("[message ] processing message: { }\n", entry); } TEST(connection_impl_send, message_sent) { - utility::string_t actual_message; + std::string actual_message; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }, - /* send function */ [&actual_message](const utility::string_t& message) + /* send function */ [&actual_message](const std::string& message) { actual_message = message; return pplx::task_from_result(); @@ -778,7 +778,7 @@ TEST(connection_impl_send, message_sent) auto connection = create_connection(websocket_client); - const utility::string_t message{ _XPLATSTR("Test message") }; + const std::string message{ "Test message" }; connection->start() .then([connection, message]() @@ -796,7 +796,7 @@ TEST(connection_impl_send, send_throws_if_connection_not_connected) try { - connection->send(_XPLATSTR("whatever")).get(); + connection->send("whatever").get(); ASSERT_TRUE(false); // exception expected but not thrown } catch (const signalr_exception &e) @@ -813,7 +813,7 @@ TEST(connection_impl_send, exceptions_from_send_logged_and_propagated) { return pplx::task_from_result(std::string("{}")); }, - /* send function */ [](const utility::string_t&) + /* send function */ [](const std::string&) { return pplx::task_from_exception(std::runtime_error("error")); }); @@ -825,7 +825,7 @@ TEST(connection_impl_send, exceptions_from_send_logged_and_propagated) connection->start() .then([connection]() { - return connection->send(_XPLATSTR("Test message")); + return connection->send("Test message"); }).get(); ASSERT_TRUE(false); // exception expected but not thrown @@ -839,7 +839,7 @@ TEST(connection_impl_send, exceptions_from_send_logged_and_propagated) ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[error ] error sending data: error\n"), entry); + ASSERT_EQ("[error ] error sending data: error\n", entry); } TEST(connection_impl_set_message_received, callback_invoked_when_message_received) @@ -862,17 +862,17 @@ TEST(connection_impl_set_message_received, callback_invoked_when_message_receive auto connection = create_connection(websocket_client); - auto message = std::make_shared(); + auto message = std::make_shared(); auto message_received_event = std::make_shared(); - connection->set_message_received([message, message_received_event](const utility::string_t &m) + connection->set_message_received([message, message_received_event](const std::string &m) { - if (m == _XPLATSTR("Test")) + if (m == "Test") { *message = m; } - if (m == _XPLATSTR("release")) + if (m == "release") { message_received_event->set(); } @@ -882,7 +882,7 @@ TEST(connection_impl_set_message_received, callback_invoked_when_message_receive ASSERT_FALSE(message_received_event->wait(5000)); - ASSERT_EQ(_XPLATSTR("Test"), *message); + ASSERT_EQ("Test", *message); } TEST(connection_impl_set_message_received, exception_from_callback_caught_and_logged) @@ -907,14 +907,14 @@ TEST(connection_impl_set_message_received, exception_from_callback_caught_and_lo auto connection = create_connection(websocket_client, writer, trace_level::errors); auto message_received_event = std::make_shared(); - connection->set_message_received([message_received_event](const utility::string_t &m) + connection->set_message_received([message_received_event](const std::string &m) { - if (m == _XPLATSTR("throw")) + if (m == "throw") { throw std::runtime_error("oops"); } - if (m == _XPLATSTR("release")) + if (m == "release") { message_received_event->set(); } @@ -928,7 +928,7 @@ TEST(connection_impl_set_message_received, exception_from_callback_caught_and_lo ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[error ] message_received callback threw an exception: oops\n"), entry); + ASSERT_EQ("[error ] message_received callback threw an exception: oops\n", entry); } TEST(connection_impl_set_message_received, non_std_exception_from_callback_caught_and_logged) @@ -953,14 +953,14 @@ TEST(connection_impl_set_message_received, non_std_exception_from_callback_caugh auto connection = create_connection(websocket_client, writer, trace_level::errors); auto message_received_event = std::make_shared(); - connection->set_message_received([message_received_event](const utility::string_t &m) + connection->set_message_received([message_received_event](const std::string &m) { - if (m == _XPLATSTR("throw")) + if (m == "throw") { throw 42; } - if (m == _XPLATSTR("release")) + if (m == "release") { message_received_event->set(); } @@ -974,7 +974,7 @@ TEST(connection_impl_set_message_received, non_std_exception_from_callback_caugh ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[error ] message_received callback threw an unknown exception\n"), entry); + ASSERT_EQ("[error ] message_received callback threw an unknown exception\n", entry); } void can_be_set_only_in_disconnected_state(std::function callback, const char* expected_exception_message) @@ -999,7 +999,7 @@ void can_be_set_only_in_disconnected_state(std::functionset_message_received([](const utility::string_t&){}); }, + [](connection_impl* connection) { connection->set_message_received([](const std::string&){}); }, "cannot set the callback when the connection is not in the disconnected state. current connection state: connected"); } @@ -1020,8 +1020,8 @@ TEST(connection_impl_stop, stopping_disconnected_connection_is_no_op) auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(2U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[info ] stopping connection\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[info ] acquired lock in shutdown()\n"), remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[info ] stopping connection\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[info ] acquired lock in shutdown()\n", remove_date_from_log_entry(log_entries[1])); } TEST(connection_impl_stop, stopping_disconnecting_connection_returns_cancelled_task) @@ -1031,8 +1031,8 @@ TEST(connection_impl_stop, stopping_disconnecting_connection_returns_cancelled_t auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }, - /* send function */ [](const utility::string_t){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */ [&close_event](const web::uri&) { return pplx::task_from_result(); }, + /* send function */ [](const std::string){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */ [&close_event](const std::string&) { return pplx::task_from_result(); }, /* close function */ [&close_event]() { return pplx::create_task([&close_event]() @@ -1061,10 +1061,10 @@ TEST(connection_impl_stop, stopping_disconnecting_connection_returns_cancelled_t auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(4U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> connected\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[state change] connected -> disconnecting\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[state change] disconnecting -> disconnected\n"), remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[state change] connecting -> connected\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[state change] connected -> disconnecting\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[state change] disconnecting -> disconnected\n", remove_date_from_log_entry(log_entries[3])); } TEST(connection_impl_stop, can_start_and_stop_connection) @@ -1083,10 +1083,10 @@ TEST(connection_impl_stop, can_start_and_stop_connection) auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(4U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> connected\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[state change] connected -> disconnecting\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[state change] disconnecting -> disconnected\n"), remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[state change] connecting -> connected\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[state change] connected -> disconnecting\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[state change] disconnecting -> disconnected\n", remove_date_from_log_entry(log_entries[3])); } TEST(connection_impl_stop, can_start_and_stop_connection_multiple_times) @@ -1121,14 +1121,14 @@ TEST(connection_impl_stop, can_start_and_stop_connection_multiple_times) auto log_entries = memory_writer->get_log_entries(); ASSERT_EQ(8U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> connected\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[state change] connected -> disconnecting\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[state change] disconnecting -> disconnected\n"), remove_date_from_log_entry(log_entries[3])); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[4])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> connected\n"), remove_date_from_log_entry(log_entries[5])); - ASSERT_EQ(_XPLATSTR("[state change] connected -> disconnecting\n"), remove_date_from_log_entry(log_entries[6])); - ASSERT_EQ(_XPLATSTR("[state change] disconnecting -> disconnected\n"), remove_date_from_log_entry(log_entries[7])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[state change] connecting -> connected\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[state change] connected -> disconnecting\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[state change] disconnecting -> disconnected\n", remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[4])); + ASSERT_EQ("[state change] connecting -> connected\n", remove_date_from_log_entry(log_entries[5])); + ASSERT_EQ("[state change] connected -> disconnecting\n", remove_date_from_log_entry(log_entries[6])); + ASSERT_EQ("[state change] disconnecting -> disconnected\n", remove_date_from_log_entry(log_entries[7])); } TEST(connection_impl_stop, dtor_stops_the_connection) @@ -1159,10 +1159,10 @@ TEST(connection_impl_stop, dtor_stops_the_connection) auto log_entries = memory_writer->get_log_entries(); ASSERT_EQ(4U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> connected\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[state change] connected -> disconnecting\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[state change] disconnecting -> disconnected\n"), remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[state change] connecting -> connected\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[state change] connected -> disconnecting\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[state change] disconnecting -> disconnected\n", remove_date_from_log_entry(log_entries[3])); } TEST(connection_impl_stop, stop_cancels_ongoing_start_request) @@ -1198,24 +1198,24 @@ TEST(connection_impl_stop, stop_cancels_ongoing_start_request) auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(5U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[info ] stopping connection\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[info ] acquired lock in shutdown()\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[info ] starting the connection has been canceled.\n"), remove_date_from_log_entry(log_entries[3])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> disconnected\n"), remove_date_from_log_entry(log_entries[4])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[info ] stopping connection\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[info ] acquired lock in shutdown()\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[info ] starting the connection has been canceled.\n", remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] connecting -> disconnected\n", remove_date_from_log_entry(log_entries[4])); } TEST(connection_impl_stop, ongoing_start_request_canceled_if_connection_stopped_before_init_message_received) { - auto web_request_factory = std::make_unique([](const web::uri& url) + auto web_request_factory = std::make_unique([](const std::string& url) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{ \"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }") - : _XPLATSTR(""); + url.find("/negotiate") != std::string::npos + ? "{ \"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }" + : ""; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); auto websocket_client = create_test_websocket_client(/*receive function*/ []() @@ -1243,11 +1243,11 @@ TEST(connection_impl_stop, ongoing_start_request_canceled_if_connection_stopped_ auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(5U, log_entries.size()) << dump_vector(log_entries); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[info ] stopping connection\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[info ] acquired lock in shutdown()\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[info ] starting the connection has been canceled.\n"), remove_date_from_log_entry(log_entries[3])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> disconnected\n"), remove_date_from_log_entry(log_entries[4])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[info ] stopping connection\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[info ] acquired lock in shutdown()\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[info ] starting the connection has been canceled.\n", remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] connecting -> disconnected\n", remove_date_from_log_entry(log_entries[4])); } TEST(connection_impl_stop, stop_invokes_disconnected_callback) @@ -1298,7 +1298,7 @@ TEST(connection_impl_stop, std_exception_for_disconnected_callback_caught_and_lo auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(1U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[error ] disconnected callback threw an exception: exception from disconnected\n"), remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[error ] disconnected callback threw an exception: exception from disconnected\n", remove_date_from_log_entry(log_entries[0])); } TEST(connection_impl_stop, exception_for_disconnected_callback_caught_and_logged) @@ -1331,22 +1331,22 @@ TEST(connection_impl_stop, exception_for_disconnected_callback_caught_and_logged auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_EQ(1U, log_entries.size()); - ASSERT_EQ(_XPLATSTR("[error ] disconnected callback threw an unknown exception\n"), remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[error ] disconnected callback threw an unknown exception\n", remove_date_from_log_entry(log_entries[0])); } TEST(connection_impl_config, custom_headers_set_in_requests) { auto writer = std::shared_ptr{std::make_shared()}; - auto web_request_factory = std::make_unique([](const web::uri& url) + auto web_request_factory = std::make_unique([](const std::string& url) { - auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }") - : _XPLATSTR(""); + auto response_body = + url.find("/negotiate") != std::string::npos + ? "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }" + : ""; - auto request = new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body); + auto request = new web_request_stub((unsigned short)200, "OK", response_body); request->on_get_response = [](web_request_stub& request) { auto http_headers = request.m_signalr_client_config.get_http_headers(); @@ -1402,7 +1402,7 @@ TEST(connection_impl_change_state, change_state_logs) ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), entry); + ASSERT_EQ("[state change] disconnected -> connecting\n", entry); } TEST(connection_id, connection_id_is_set_if_start_fails_but_negotiate_request_succeeds) @@ -1411,8 +1411,8 @@ TEST(connection_id, connection_id_is_set_if_start_fails_but_negotiate_request_su auto websocket_client = create_test_websocket_client( /* receive function */ [](){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* send function */ [](const utility::string_t){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, - /* connect function */[](const web::uri&) + /* send function */ [](const std::string){ return pplx::task_from_exception(std::runtime_error("should not be invoked")); }, + /* connect function */[](const std::string&) { return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); @@ -1433,9 +1433,9 @@ TEST(connection_id, connection_id_is_set_if_start_fails_but_negotiate_request_su } }); - ASSERT_EQ(_XPLATSTR(""), connection->get_connection_id()); + ASSERT_EQ("", connection->get_connection_id()); start_task.get(); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), connection->get_connection_id()); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", connection->get_connection_id()); } TEST(connection_id, can_get_connection_id_when_connection_in_connected_state) @@ -1446,7 +1446,7 @@ TEST(connection_id, can_get_connection_id_when_connection_in_connected_state) /* receive function */ [](){ return pplx::task_from_result(std::string("{ }\x1e")); }); auto connection = create_connection(websocket_client, writer, trace_level::state_changes); - utility::string_t connection_id; + std::string connection_id; connection->start() .then([connection, &connection_id]() mutable { @@ -1454,7 +1454,7 @@ TEST(connection_id, can_get_connection_id_when_connection_in_connected_state) return connection->stop(); }).get(); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), connection_id); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", connection_id); } TEST(connection_id, can_get_connection_id_after_connection_has_stopped) @@ -1471,7 +1471,7 @@ TEST(connection_id, can_get_connection_id_after_connection_has_stopped) return connection->stop(); }).get(); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), connection->get_connection_id()); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", connection->get_connection_id()); } TEST(connection_id, connection_id_reset_when_starting_connection) @@ -1483,19 +1483,19 @@ TEST(connection_id, connection_id_reset_when_starting_connection) auto websocket_client = create_test_websocket_client( /* receive function */ [](){ return pplx::task_from_result(std::string("{ }\x1e")); }); - auto web_request_factory = std::make_unique([&fail_http_requests](const web::uri &url) -> std::unique_ptr + auto web_request_factory = std::make_unique([&fail_http_requests](const std::string &url) -> std::unique_ptr { if (!fail_http_requests) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }") - : _XPLATSTR(""); + url.find("/negotiate") != std::string::npos + ? "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }" + : ""; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); } - return std::unique_ptr(new web_request_stub((unsigned short)500, _XPLATSTR("Internal Server Error"), _XPLATSTR(""))); + return std::unique_ptr(new web_request_stub((unsigned short)500, "Internal Server Error", "")); }); auto connection = @@ -1508,7 +1508,7 @@ TEST(connection_id, connection_id_reset_when_starting_connection) return connection->stop(); }).get(); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), connection->get_connection_id()); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", connection->get_connection_id()); fail_http_requests = true; @@ -1526,5 +1526,5 @@ TEST(connection_id, connection_id_reset_when_starting_connection) } }).get(); - ASSERT_EQ(_XPLATSTR(""), connection->get_connection_id()); + ASSERT_EQ("", connection->get_connection_id()); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/http_sender_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/http_sender_tests.cpp index 32419b51149d..683687f0dc63 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/http_sender_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/http_sender_tests.cpp @@ -11,67 +11,67 @@ TEST(http_sender_get_response, request_sent_using_get_method) { - utility::string_t response_body{ _XPLATSTR("response body") }; + std::string response_body{ "response body" }; - auto web_request_factory = std::make_unique([response_body](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([response_body](const std::string &) -> std::unique_ptr { - auto request = new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body); - request->on_get_response = [](web_request_stub& request) { ASSERT_EQ(_XPLATSTR("GET"), request.m_method); }; + auto request = new web_request_stub((unsigned short)200, "OK", response_body); + request->on_get_response = [](web_request_stub& request) { ASSERT_EQ("GET", request.m_method); }; return std::unique_ptr(request); }); - ASSERT_EQ(response_body, http_sender::get(*web_request_factory, _XPLATSTR("url")).get()); + ASSERT_EQ(response_body, http_sender::get(*web_request_factory, "url").get()); } TEST(http_sender_get_response, exception_thrown_if_status_code_not_200) { - utility::string_t response_phrase(_XPLATSTR("Custom Not Found")); + std::string response_phrase("Custom Not Found"); - auto web_request_factory = std::make_unique([response_phrase](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([response_phrase](const std::string &) -> std::unique_ptr { return std::unique_ptr(new web_request_stub((unsigned short)404, response_phrase)); }); try { - http_sender::get(*web_request_factory, _XPLATSTR("url")).get(); + http_sender::get(*web_request_factory, "url").get(); ASSERT_TRUE(false); // exception not thrown } catch (const web_exception &e) { ASSERT_EQ( - _XPLATSTR("web exception - 404 ") + response_phrase, - utility::conversions::to_string_t(e.what())); + "web exception - 404 " + response_phrase, + e.what()); ASSERT_EQ(404, e.status_code()); } } TEST(http_sender_get_response, user_agent_set) { - utility::string_t response_body{ _XPLATSTR("response body") }; + std::string response_body{ "response body" }; - auto web_request_factory = std::make_unique([response_body](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([response_body](const std::string &) -> std::unique_ptr { - auto request = new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body); + auto request = new web_request_stub((unsigned short)200, "OK", response_body); request->on_get_response = [](web_request_stub& request) { - ASSERT_EQ(_XPLATSTR("SignalR.Client.Cpp/0.1.0-alpha0"), request.m_user_agent_string); + ASSERT_EQ("SignalR.Client.Cpp/0.1.0-alpha0", request.m_user_agent_string); }; return std::unique_ptr(request); }); - ASSERT_EQ(response_body, http_sender::get(*web_request_factory, _XPLATSTR("url")).get()); + ASSERT_EQ(response_body, http_sender::get(*web_request_factory, "url").get()); } TEST(http_sender_get_response, headers_set) { - utility::string_t response_body{ _XPLATSTR("response body") }; + std::string response_body{ "response body" }; - auto web_request_factory = std::make_unique([response_body](const web::uri &) -> std::unique_ptr + auto web_request_factory = std::make_unique([response_body](const std::string &) -> std::unique_ptr { - auto request = new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body); + auto request = new web_request_stub((unsigned short)200, "OK", response_body); request->on_get_response = [](web_request_stub& request) { auto http_headers = request.m_signalr_client_config.get_http_headers(); @@ -88,5 +88,5 @@ TEST(http_sender_get_response, headers_set) signalr_client_config.set_http_headers(http_headers); // ensures that web_request.get_response() was invoked - ASSERT_EQ(response_body, http_sender::get(*web_request_factory, _XPLATSTR("url"), signalr_client_config).get()); + ASSERT_EQ(response_body, http_sender::get(*web_request_factory, "url", signalr_client_config).get()); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/hub_connection_impl_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/hub_connection_impl_tests.cpp index b4afe6e6e074..20b1436da568 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/hub_connection_impl_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/hub_connection_impl_tests.cpp @@ -22,15 +22,15 @@ std::shared_ptr create_hub_connection(std::shared_ptr([&requested_url](const web::uri &url) + std::string requested_url; + auto web_request_factory = std::make_unique([&requested_url](const std::string& url) { requested_url = url; - return std::unique_ptr(new web_request_stub((unsigned short)404, _XPLATSTR("Bad request"), _XPLATSTR(""))); + return std::unique_ptr(new web_request_stub((unsigned short)404, "Bad request", "")); }); auto hub_connection = hub_connection_impl::create(base_url, trace_level::none, @@ -43,7 +43,7 @@ TEST(url, negotiate_appended_to_url) } catch (const std::exception&) {} - ASSERT_EQ(web::uri(_XPLATSTR("http://fakeuri/negotiate")), requested_url); + ASSERT_EQ("http://fakeuri/negotiate", requested_url); } } @@ -60,15 +60,15 @@ TEST(start, start_starts_connection) TEST(start, start_sends_handshake) { - auto message = std::make_shared(); + auto message = std::make_shared(); auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }, - /* send function */ [message](const utility::string_t& msg) { *message = msg; return pplx::task_from_result(); }); + /* send function */ [message](const std::string& msg) { *message = msg; return pplx::task_from_result(); }); auto hub_connection = create_hub_connection(websocket_client); hub_connection->start().get(); - ASSERT_EQ(_XPLATSTR("{\"protocol\":\"json\",\"version\":1}\x1e"), *message); + ASSERT_EQ("{\"protocol\":\"json\",\"version\":1}\x1e", *message); ASSERT_EQ(connection_state::connected, hub_connection->get_connection_state()); } @@ -120,7 +120,7 @@ TEST(start, start_fails_if_stop_called_before_handshake_response) pplx::task_completion_event tceWaitForSend; auto websocket_client = create_test_websocket_client( /* receive function */ [tce]() { return pplx::task(tce); }, - /* send function */ [tceWaitForSend](const utility::string_t &) + /* send function */ [tceWaitForSend](const std::string &) { tceWaitForSend.set(); return pplx::task_from_result(); @@ -195,10 +195,10 @@ TEST(stop, connection_stopped_when_going_out_of_scope) auto log_entries = memory_writer->get_log_entries(); ASSERT_EQ(4U, log_entries.size()) << dump_vector(log_entries); - ASSERT_EQ(_XPLATSTR("[state change] disconnected -> connecting\n"), remove_date_from_log_entry(log_entries[0])); - ASSERT_EQ(_XPLATSTR("[state change] connecting -> connected\n"), remove_date_from_log_entry(log_entries[1])); - ASSERT_EQ(_XPLATSTR("[state change] connected -> disconnecting\n"), remove_date_from_log_entry(log_entries[2])); - ASSERT_EQ(_XPLATSTR("[state change] disconnecting -> disconnected\n"), remove_date_from_log_entry(log_entries[3])); + ASSERT_EQ("[state change] disconnected -> connecting\n", remove_date_from_log_entry(log_entries[0])); + ASSERT_EQ("[state change] connecting -> connected\n", remove_date_from_log_entry(log_entries[1])); + ASSERT_EQ("[state change] connected -> disconnecting\n", remove_date_from_log_entry(log_entries[2])); + ASSERT_EQ("[state change] disconnecting -> disconnected\n", remove_date_from_log_entry(log_entries[3])); } TEST(stop, stop_cancels_pending_callbacks) @@ -223,7 +223,7 @@ TEST(stop, stop_cancels_pending_callbacks) auto hub_connection = create_hub_connection(websocket_client); hub_connection->start().get(); - auto t = hub_connection->invoke(_XPLATSTR("method"), json::value::array()); + auto t = hub_connection->invoke("method", json::value::array()); hub_connection->stop(); try @@ -262,7 +262,7 @@ TEST(stop, pending_callbacks_finished_if_hub_connections_goes_out_of_scope) { auto hub_connection = create_hub_connection(websocket_client); hub_connection->start().get(); - t = hub_connection->invoke(_XPLATSTR("method"), json::value::array()); + t = hub_connection->invoke("method", json::value::array()); } try @@ -295,28 +295,28 @@ TEST(hub_invocation, hub_connection_invokes_users_code_on_hub_invocations) auto hub_connection = create_hub_connection(websocket_client); - auto payload = std::make_shared(); + auto payload = std::make_shared(); auto on_broadcast_event = std::make_shared(); - hub_connection->on(_XPLATSTR("broadCAST"), [on_broadcast_event, payload](const json::value& message) + hub_connection->on("broadCAST", [on_broadcast_event, payload](const json::value& message) { - *payload = message.serialize(); + *payload = utility::conversions::to_utf8string(message.serialize()); on_broadcast_event->set(); }); hub_connection->start().get(); ASSERT_FALSE(on_broadcast_event->wait(5000)); - ASSERT_EQ(_XPLATSTR("[\"message\",1]"), *payload); + ASSERT_EQ("[\"message\",1]", *payload); } TEST(send, creates_correct_payload) { - utility::string_t payload; + std::string payload; bool handshakeReceived = false; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }, - /* send function */[&payload, &handshakeReceived](const utility::string_t& m) + /* send function */[&payload, &handshakeReceived](const std::string& m) { if (handshakeReceived) { @@ -330,9 +330,9 @@ TEST(send, creates_correct_payload) auto hub_connection = create_hub_connection(websocket_client); hub_connection->start().get(); - hub_connection->send(_XPLATSTR("method"), json::value::array()).get(); + hub_connection->send("method", json::value::array()).get(); - ASSERT_EQ(_XPLATSTR("{\"arguments\":[],\"target\":\"method\",\"type\":1}\x1e"), payload); + ASSERT_EQ("{\"arguments\":[],\"target\":\"method\",\"type\":1}\x1e", payload); } TEST(send, does_not_wait_for_server_response) @@ -363,18 +363,18 @@ TEST(send, does_not_wait_for_server_response) hub_connection->start().get(); // wont block waiting for server response - hub_connection->send(_XPLATSTR("method"), json::value::array()).get(); + hub_connection->send("method", json::value::array()).get(); waitForSend.set(); } TEST(invoke, creates_correct_payload) { - utility::string_t payload; + std::string payload; bool handshakeReceived = false; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }, - /* send function */[&payload, &handshakeReceived](const utility::string_t& m) + /* send function */[&payload, &handshakeReceived](const std::string& m) { if (handshakeReceived) { @@ -390,14 +390,14 @@ TEST(invoke, creates_correct_payload) try { - hub_connection->invoke(_XPLATSTR("method"), json::value::array()).get(); + hub_connection->invoke("method", json::value::array()).get(); } catch (...) { // the invoke is not setup to succeed because it's not needed in this test } - ASSERT_EQ(_XPLATSTR("{\"arguments\":[],\"invocationId\":\"0\",\"target\":\"method\",\"type\":1}\x1e"), payload); + ASSERT_EQ("{\"arguments\":[],\"invocationId\":\"0\",\"target\":\"method\",\"type\":1}\x1e", payload); } TEST(invoke, callback_not_called_if_send_throws) @@ -405,7 +405,7 @@ TEST(invoke, callback_not_called_if_send_throws) bool handshakeReceived = false; auto websocket_client = create_test_websocket_client( /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }, - /* send function */[handshakeReceived](const utility::string_t&) mutable + /* send function */[handshakeReceived](const std::string&) mutable { if (handshakeReceived) { @@ -420,7 +420,7 @@ TEST(invoke, callback_not_called_if_send_throws) try { - hub_connection->invoke(_XPLATSTR("method"), json::value::array()).get(); + hub_connection->invoke("method", json::value::array()).get(); ASSERT_TRUE(false); // exception expected but not thrown } catch (const std::runtime_error& e) @@ -462,7 +462,7 @@ TEST(invoke, invoke_returns_value_returned_from_the_server) auto result = hub_connection->start() .then([hub_connection, callback_registered_event]() { - auto t = hub_connection->invoke(_XPLATSTR("method"), json::value::array()); + auto t = hub_connection->invoke("method", json::value::array()); callback_registered_event->set(); return t; }).get(); @@ -500,7 +500,7 @@ TEST(invoke, invoke_propagates_errors_from_server_as_hub_exceptions) hub_connection->start() .then([hub_connection, callback_registered_event]() { - auto t = hub_connection->invoke(_XPLATSTR("method"), json::value::array()); + auto t = hub_connection->invoke("method", json::value::array()); callback_registered_event->set(); return t; }).get(); @@ -541,7 +541,7 @@ TEST(invoke, unblocks_task_when_server_completes_call) hub_connection->start() .then([hub_connection, callback_registered_event]() { - auto t = hub_connection->invoke(_XPLATSTR("method"), json::value::array()); + auto t = hub_connection->invoke("method", json::value::array()); callback_registered_event->set(); return t; }).get(); @@ -577,7 +577,7 @@ TEST(receive, logs_if_callback_for_given_id_not_found) return pplx::task_from_result(responses[call_number]); }, - [handshake_sent](const utility::string_t&) + [handshake_sent](const std::string&) { handshake_sent->set(); return pplx::task_from_result(); @@ -593,7 +593,7 @@ TEST(receive, logs_if_callback_for_given_id_not_found) ASSERT_TRUE(log_entries.size() > 1); auto entry = remove_date_from_log_entry(log_entries[2]); - ASSERT_EQ(_XPLATSTR("[info ] no callback found for id: 0\n"), entry) << dump_vector(log_entries); + ASSERT_EQ("[info ] no callback found for id: 0\n", entry) << dump_vector(log_entries); } TEST(invoke_void, invoke_creates_runtime_error) @@ -626,7 +626,7 @@ TEST(invoke_void, invoke_creates_runtime_error) hub_connection->start() .then([hub_connection, callback_registered_event]() { - auto t = hub_connection->invoke(_XPLATSTR("method"), json::value::array()); + auto t = hub_connection->invoke("method", json::value::array()); callback_registered_event->set(); return t; }).get(); @@ -646,14 +646,14 @@ TEST(connection_id, can_get_connection_id) /* receive function */ []() { return pplx::task_from_result(std::string("{ }\x1e")); }); auto hub_connection = create_hub_connection(websocket_client); - ASSERT_EQ(_XPLATSTR(""), hub_connection->get_connection_id()); + ASSERT_EQ("", hub_connection->get_connection_id()); hub_connection->start().get(); auto connection_id = hub_connection->get_connection_id(); hub_connection->stop().get(); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), connection_id); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), hub_connection->get_connection_id()); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", connection_id); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", hub_connection->get_connection_id()); } TEST(on, event_name_must_not_be_empty_string) @@ -661,7 +661,7 @@ TEST(on, event_name_must_not_be_empty_string) auto hub_connection = create_hub_connection(); try { - hub_connection->on(_XPLATSTR(""), [](const json::value&) {}); + hub_connection->on("", [](const json::value&) {}); ASSERT_TRUE(false); // exception expected but not thrown } @@ -674,11 +674,11 @@ TEST(on, event_name_must_not_be_empty_string) TEST(on, cannot_register_multiple_handlers_for_event) { auto hub_connection = create_hub_connection(); - hub_connection->on(_XPLATSTR("ping"), [](const json::value&) {}); + hub_connection->on("ping", [](const json::value&) {}); try { - hub_connection->on(_XPLATSTR("ping"), [](const json::value&) {}); + hub_connection->on("ping", [](const json::value&) {}); ASSERT_TRUE(false); // exception expected but not thrown } catch (const signalr_exception& e) @@ -697,7 +697,7 @@ TEST(on, cannot_register_handler_if_connection_not_in_disconnected_state) hub_connection->start().get(); - hub_connection->on(_XPLATSTR("myfunc"), [](const web::json::value&) {}); + hub_connection->on("myfunc", [](const web::json::value&) {}); ASSERT_TRUE(false); // exception expected but not thrown } @@ -713,7 +713,7 @@ TEST(invoke, invoke_throws_when_the_underlying_connection_is_not_valid) try { - hub_connection->invoke(_XPLATSTR("method"), json::value::array()).get(); + hub_connection->invoke("method", json::value::array()).get(); ASSERT_TRUE(true); // exception expected but not thrown } catch (const signalr_exception& e) @@ -728,7 +728,7 @@ TEST(invoke, send_throws_when_the_underlying_connection_is_not_valid) try { - hub_connection->invoke(_XPLATSTR("method"), json::value::array()).get(); + hub_connection->invoke("method", json::value::array()).get(); ASSERT_TRUE(true); // exception expected but not thrown } catch (const signalr_exception& e) diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/hub_exception_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/hub_exception_tests.cpp index c269d47190d1..c7952066bd86 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/hub_exception_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/hub_exception_tests.cpp @@ -8,7 +8,7 @@ using namespace signalr; TEST(hub_exception_initialization, hub_exception_initialized_correctly) { - auto e = hub_exception{ _XPLATSTR("error") }; + auto e = hub_exception{ "error" }; ASSERT_STREQ("error", e.what()); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/logger_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/logger_tests.cpp index 7b27750978d1..d3f5760ab454 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/logger_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/logger_tests.cpp @@ -14,7 +14,7 @@ TEST(logger_write, entry_added_if_trace_level_set) std::shared_ptr writer(std::make_shared()); logger l(writer, trace_level::messages); - l.log(trace_level::messages, _XPLATSTR("message")); + l.log(trace_level::messages, "message"); auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); @@ -26,7 +26,7 @@ TEST(logger_write, entry_not_added_if_trace_level_not_set) std::shared_ptr writer(std::make_shared()); logger l(writer, trace_level::messages); - l.log(trace_level::events, _XPLATSTR("event")); + l.log(trace_level::events, "event"); auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); @@ -38,11 +38,11 @@ TEST(logger_write, entries_added_for_combined_trace_level) std::shared_ptr writer(std::make_shared()); logger l(writer, trace_level::messages | trace_level::state_changes | trace_level::events | trace_level::errors | trace_level::info); - l.log(trace_level::messages, _XPLATSTR("message")); - l.log(trace_level::events, _XPLATSTR("event")); - l.log(trace_level::state_changes, _XPLATSTR("state_change")); - l.log(trace_level::errors, _XPLATSTR("error")); - l.log(trace_level::info, _XPLATSTR("info")); + l.log(trace_level::messages, "message"); + l.log(trace_level::events, "event"); + l.log(trace_level::state_changes, "state_change"); + l.log(trace_level::errors, "error"); + l.log(trace_level::info, "info"); auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); @@ -54,16 +54,16 @@ TEST(logger_write, entries_formatted_correctly) std::shared_ptr writer(std::make_shared()); logger l(writer, trace_level::all); - l.log(trace_level::messages, _XPLATSTR("message")); + l.log(trace_level::messages, "message"); auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_FALSE(log_entries.empty()); auto entry = log_entries[0]; - auto date_str = entry.substr(0, entry.find_first_of(_XPLATSTR("Z")) + 1); - auto date = utility::datetime::from_string(date_str, utility::datetime::ISO_8601); - ASSERT_EQ(date_str, date.to_string(utility::datetime::ISO_8601)); + auto date_str = entry.substr(0, entry.find_first_of("Z") + 1); + auto date = utility::datetime::from_string(utility::conversions::to_string_t(date_str), utility::datetime::ISO_8601); + ASSERT_EQ(date_str, utility::conversions::to_utf8string(date.to_string(utility::datetime::ISO_8601))); - ASSERT_EQ(_XPLATSTR("[message ] message\n"), remove_date_from_log_entry(entry)); -} \ No newline at end of file + ASSERT_EQ("[message ] message\n", remove_date_from_log_entry(entry)); +} diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.cpp index dad3999d5958..e8a2ff29f58e 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.cpp @@ -4,13 +4,13 @@ #include "stdafx.h" #include "memory_log_writer.h" -void memory_log_writer::write(const utility::string_t& entry) +void memory_log_writer::write(const std::string& entry) { std::lock_guard lock(m_entries_lock); m_log_entries.push_back(entry); } -std::vector memory_log_writer::get_log_entries() +std::vector memory_log_writer::get_log_entries() { std::lock_guard lock(m_entries_lock); return m_log_entries; diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.h b/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.h index 4af60f9c526d..e98882d7da80 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.h +++ b/src/SignalR/clients/cpp/test/signalrclienttests/memory_log_writer.h @@ -12,10 +12,10 @@ using namespace signalr; class memory_log_writer : public log_writer { public: - void __cdecl write(const utility::string_t &entry) override; - std::vector get_log_entries(); + void __cdecl write(const std::string &entry) override; + std::vector get_log_entries(); private: - std::vector m_log_entries; + std::vector m_log_entries; std::mutex m_entries_lock; }; \ No newline at end of file diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/request_sender_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/request_sender_tests.cpp index d1dbc09efc2a..d332848f7729 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/request_sender_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/request_sender_tests.cpp @@ -13,41 +13,41 @@ using namespace signalr; TEST(request_sender_negotiate, request_created_with_correct_url) { - utility::string_t requested_url; - auto request_factory = test_web_request_factory([&requested_url](const utility::string_t& url) -> std::unique_ptr + std::string requested_url; + auto request_factory = test_web_request_factory([&requested_url](const std::string& url) -> std::unique_ptr { - utility::string_t response_body( - _XPLATSTR("{ \"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [] }")); + std::string response_body( + "{ \"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [] }"); requested_url = url; - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); - request_sender::negotiate(request_factory, _XPLATSTR("http://fake/signalr")).get(); + request_sender::negotiate(request_factory, "http://fake/signalr").get(); - ASSERT_EQ(_XPLATSTR("http://fake/signalr/negotiate"), requested_url); + ASSERT_EQ("http://fake/signalr/negotiate", requested_url); } TEST(request_sender_negotiate, negotiation_request_sent_and_response_serialized) { - auto request_factory = test_web_request_factory([](const utility::string_t&) -> std::unique_ptr + auto request_factory = test_web_request_factory([](const std::string&) -> std::unique_ptr { - utility::string_t response_body( - _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] },") - _XPLATSTR("{ \"transport\": \"ServerSentEvents\", \"transferFormats\": [ \"Text\" ] } ] }")); + std::string response_body( + "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] }," + "{ \"transport\": \"ServerSentEvents\", \"transferFormats\": [ \"Text\" ] } ] }"); - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); - auto response = request_sender::negotiate(request_factory, _XPLATSTR("http://fake/signalr")).get(); + auto response = request_sender::negotiate(request_factory, "http://fake/signalr").get(); - ASSERT_EQ(_XPLATSTR("f7707523-307d-4cba-9abf-3eef701241e8"), response.connectionId); + ASSERT_EQ("f7707523-307d-4cba-9abf-3eef701241e8", response.connectionId); ASSERT_EQ(2u, response.availableTransports.size()); ASSERT_EQ(2u, response.availableTransports[0].transfer_formats.size()); - ASSERT_EQ(_XPLATSTR("Text"), response.availableTransports[0].transfer_formats[0]); - ASSERT_EQ(_XPLATSTR("Binary"), response.availableTransports[0].transfer_formats[1]); + ASSERT_EQ("Text", response.availableTransports[0].transfer_formats[0]); + ASSERT_EQ("Binary", response.availableTransports[0].transfer_formats[1]); ASSERT_EQ(1u, response.availableTransports[1].transfer_formats.size()); - ASSERT_EQ(_XPLATSTR("Text"), response.availableTransports[1].transfer_formats[0]); + ASSERT_EQ("Text", response.availableTransports[1].transfer_formats[0]); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.cpp index cddd6a5a440a..1d4e3cbe00c5 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.cpp @@ -10,7 +10,7 @@ test_transport_factory::test_transport_factory(const std::shared_ptr test_transport_factory::create_transport(transport_type transport_type, const logger& logger, - const signalr_client_config&, std::function process_message_callback, + const signalr_client_config&, std::function process_message_callback, std::function error_callback) { if (transport_type == signalr::transport_type::websockets) diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.h b/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.h index a557e5e7879c..2f7f6c9a81ad 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.h +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_transport_factory.h @@ -15,7 +15,7 @@ class test_transport_factory : public transport_factory std::shared_ptr create_transport(transport_type transport_type, const logger& logger, const signalr_client_config& signalr_client_config, - std::function process_message_callback, + std::function process_message_callback, std::function error_callback) override; private: diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.cpp index 100ba7d0b7e8..39f4b0fb0224 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.cpp @@ -8,18 +8,18 @@ using namespace signalr; -utility::string_t remove_date_from_log_entry(const utility::string_t &log_entry) +std::string remove_date_from_log_entry(const std::string &log_entry) { // dates are ISO 8601 (e.g. `2014-11-13T06:05:29.452066Z`) - auto date_end_index = log_entry.find_first_of(_XPLATSTR("Z")) + 1; + auto date_end_index = log_entry.find_first_of("Z") + 1; // date is followed by a whitespace hence +1 return log_entry.substr(date_end_index + 1); } std::shared_ptr create_test_websocket_client(std::function()> receive_function, - std::function(const utility::string_t &msg)> send_function, - std::function(const web::uri &url)> connect_function, + std::function(const std::string& msg)> send_function, + std::function(const std::string& url)> connect_function, std::function()> close_function) { auto websocket_client = std::make_shared(); @@ -33,61 +33,59 @@ std::shared_ptr create_test_websocket_client(std::function create_test_web_request_factory() { - return std::make_unique([](const web::uri& url) + return std::make_unique([](const std::string& url) { auto response_body = - url.path() == _XPLATSTR("/negotiate") - ? _XPLATSTR("{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", ") - _XPLATSTR("\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }") - : url.path() == _XPLATSTR("/start") || url.path() == _XPLATSTR("/signalr/start") - ? _XPLATSTR("{\"Response\":\"started\" }") - : _XPLATSTR(""); - - return std::unique_ptr(new web_request_stub((unsigned short)200, _XPLATSTR("OK"), response_body)); + url.find_first_of("/negotiate") != 0 + ? "{\"connectionId\" : \"f7707523-307d-4cba-9abf-3eef701241e8\", " + "\"availableTransports\" : [ { \"transport\": \"WebSockets\", \"transferFormats\": [ \"Text\", \"Binary\" ] } ] }" + : ""; + + return std::unique_ptr(new web_request_stub((unsigned short)200, "OK", response_body)); }); } -utility::string_t create_uri() +std::string create_uri() { auto unit_test = ::testing::UnitTest::GetInstance(); // unit test will be null if this function is not called in a test _ASSERTE(unit_test); - return utility::string_t(_XPLATSTR("http://")) - .append(utility::conversions::to_string_t(unit_test->current_test_info()->name())); + return std::string("http://") + .append(unit_test->current_test_info()->name()); } -utility::string_t create_uri(const utility::string_t& query_string) +std::string create_uri(const std::string& query_string) { auto unit_test = ::testing::UnitTest::GetInstance(); // unit test will be null if this function is not called in a test _ASSERTE(unit_test); - return utility::string_t(_XPLATSTR("http://")) - .append(utility::conversions::to_string_t(unit_test->current_test_info()->name())) - .append(_XPLATSTR("?" + query_string)); + return std::string("http://") + .append(unit_test->current_test_info()->name()) + .append("?" + query_string); } -std::vector filter_vector(const std::vector& source, const utility::string_t& string) +std::vector filter_vector(const std::vector& source, const std::string& string) { - std::vector filtered_entries; - std::copy_if(source.begin(), source.end(), std::back_inserter(filtered_entries), [&string](const utility::string_t &e) + std::vector filtered_entries; + std::copy_if(source.begin(), source.end(), std::back_inserter(filtered_entries), [&string](const std::string &e) { - return e.find(string) != utility::string_t::npos; + return e.find(string) != std::string::npos; }); return filtered_entries; } -utility::string_t dump_vector(const std::vector& source) +std::string dump_vector(const std::vector& source) { - utility::stringstream_t ss; - ss << _XPLATSTR("Number of entries: ") << source.size() << std::endl; + std::stringstream ss; + ss << "Number of entries: " << source.size() << std::endl; for (const auto& e : source) { ss << e; - if (e.back() != _XPLATSTR('\n')) + if (e.back() != '\n') { ss << std::endl; } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.h b/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.h index 3e474702bf75..4e007c657884 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.h +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_utils.h @@ -7,16 +7,16 @@ #include "websocket_client.h" #include "web_request_factory.h" -utility::string_t remove_date_from_log_entry(const utility::string_t &log_entry); +std::string remove_date_from_log_entry(const std::string &log_entry); std::shared_ptr create_test_websocket_client( std::function()> receive_function = [](){ return pplx::task_from_result(""); }, - std::function(const utility::string_t &msg)> send_function = [](const utility::string_t msg){ return pplx::task_from_result(); }, - std::function(const web::uri &url)> connect_function = [](const web::uri &){ return pplx::task_from_result(); }, + std::function(const std::string& msg)> send_function = [](const std::string&){ return pplx::task_from_result(); }, + std::function(const std::string& url)> connect_function = [](const std::string&){ return pplx::task_from_result(); }, std::function()> close_function = [](){ return pplx::task_from_result(); }); std::unique_ptr create_test_web_request_factory(); -utility::string_t create_uri(); -utility::string_t create_uri(const utility::string_t& query_string); -std::vector filter_vector(const std::vector& source, const utility::string_t& string); -utility::string_t dump_vector(const std::vector& source); +std::string create_uri(); +std::string create_uri(const std::string& query_string); +std::vector filter_vector(const std::vector& source, const std::string& string); +std::string dump_vector(const std::vector& source); diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.cpp index 6009aa9d48a0..e1b0d785b385 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.cpp @@ -6,11 +6,11 @@ using namespace signalr; -test_web_request_factory::test_web_request_factory(std::function(const utility::string_t& url)> create_web_request_fn) +test_web_request_factory::test_web_request_factory(std::function(const std::string& url)> create_web_request_fn) : m_create_web_request_fn(create_web_request_fn) { } -std::unique_ptr test_web_request_factory::create_web_request(const utility::string_t& url) +std::unique_ptr test_web_request_factory::create_web_request(const std::string& url) { return m_create_web_request_fn(url); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.h b/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.h index 3801651271d8..d96ab5286ca2 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.h +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_web_request_factory.h @@ -11,10 +11,10 @@ using namespace signalr; class test_web_request_factory : public web_request_factory { public: - explicit test_web_request_factory(std::function(const utility::string_t& url)> create_web_request_fn); + explicit test_web_request_factory(std::function(const std::string& url)> create_web_request_fn); - virtual std::unique_ptr create_web_request(const utility::string_t& url) override; + virtual std::unique_ptr create_web_request(const std::string& url) override; private: - std::function(const utility::string_t& url)> m_create_web_request_fn; + std::function(const std::string& url)> m_create_web_request_fn; }; diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.cpp index 533054561b01..fbf2e8ef9334 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.cpp @@ -5,19 +5,19 @@ #include "test_websocket_client.h" test_websocket_client::test_websocket_client() - : m_connect_function([](const web::uri &){ return pplx::task_from_result(); }), - m_send_function ([](const utility::string_t msg){ return pplx::task_from_result(); }), + : m_connect_function([](const std::string&){ return pplx::task_from_result(); }), + m_send_function ([](const std::string msg){ return pplx::task_from_result(); }), m_receive_function([](){ return pplx::task_from_result(""); }), m_close_function([](){ return pplx::task_from_result(); }) { } -pplx::task test_websocket_client::connect(const web::uri &url) +pplx::task test_websocket_client::connect(const std::string& url) { return m_connect_function(url); } -pplx::task test_websocket_client::send(const utility::string_t &msg) +pplx::task test_websocket_client::send(const std::string &msg) { return m_send_function(msg); } @@ -32,12 +32,12 @@ pplx::task test_websocket_client::close() return m_close_function(); } -void test_websocket_client::set_connect_function(std::function(const web::uri &url)> connect_function) +void test_websocket_client::set_connect_function(std::function(const std::string& url)> connect_function) { m_connect_function = connect_function; } -void test_websocket_client::set_send_function(std::function(const utility::string_t &msg)> send_function) +void test_websocket_client::set_send_function(std::function(const std::string& msg)> send_function) { m_send_function = send_function; } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.h b/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.h index 1d339acc9283..bea66aded20d 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.h +++ b/src/SignalR/clients/cpp/test/signalrclienttests/test_websocket_client.h @@ -13,28 +13,28 @@ class test_websocket_client : public websocket_client public: test_websocket_client(); - pplx::task connect(const web::uri &url) override; + pplx::task connect(const std::string& url) override; - pplx::task send(const utility::string_t& msg) override; + pplx::task send(const std::string& msg) override; pplx::task receive() override; pplx::task close() override; - void set_connect_function(std::function(const web::uri &url)> connect_function); + void set_connect_function(std::function(const std::string& url)> connect_function); - void set_send_function(std::function(const utility::string_t& msg)> send_function); + void set_send_function(std::function(const std::string& msg)> send_function); void set_receive_function(std::function()> receive_function); void set_close_function(std::function()> close_function); private: - std::function(const web::uri &url)> m_connect_function; + std::function(const std::string& url)> m_connect_function; - std::function(const utility::string_t&)> m_send_function; + std::function(const std::string&)> m_send_function; std::function()> m_receive_function; std::function()> m_close_function; -}; \ No newline at end of file +}; diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/url_builder_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/url_builder_tests.cpp index 8d6682520889..6e4d04cc252f 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/url_builder_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/url_builder_tests.cpp @@ -9,20 +9,20 @@ using namespace signalr; TEST(url_builder_negotiate, url_correct_if_query_string_empty) { ASSERT_EQ( - _XPLATSTR("http://fake/negotiate"), - url_builder::build_negotiate(_XPLATSTR("http://fake/"))); + "http://fake/negotiate", + url_builder::build_negotiate("http://fake/")); } TEST(url_builder_negotiate, url_correct_if_query_string_not_empty) { ASSERT_EQ( - _XPLATSTR("http://fake/negotiate?q1=1&q2=2"), - url_builder::build_negotiate(_XPLATSTR("http://fake/?q1=1&q2=2"))); + "http://fake/negotiate?q1=1&q2=2", + url_builder::build_negotiate("http://fake/?q1=1&q2=2")); } TEST(url_builder_connect_webSockets, url_correct_if_query_string_not_empty) { ASSERT_EQ( - _XPLATSTR("ws://fake/?q1=1&q2=2"), - url_builder::build_connect(_XPLATSTR("http://fake/"), transport_type::websockets, _XPLATSTR("q1=1&q2=2"))); + "ws://fake/?q1=1&q2=2", + url_builder::build_connect("http://fake/", transport_type::websockets, "q1=1&q2=2")); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.cpp index 7b4b20744f88..a2633b6ec6d8 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.cpp @@ -4,16 +4,16 @@ #include "stdafx.h" #include "web_request_stub.h" -web_request_stub::web_request_stub(unsigned short status_code, const utility::string_t& reason_phrase, const utility::string_t& response_body) - : web_request(_XPLATSTR("")), m_status_code(status_code), m_reason_phrase(reason_phrase), m_response_body(response_body) +web_request_stub::web_request_stub(unsigned short status_code, const std::string& reason_phrase, const std::string& response_body) + : web_request(""), m_status_code(status_code), m_reason_phrase(reason_phrase), m_response_body(response_body) { } -void web_request_stub::set_method(const utility::string_t &method) +void web_request_stub::set_method(const std::string &method) { m_method = method; } -void web_request_stub::set_user_agent(const utility::string_t &user_agent_string) +void web_request_stub::set_user_agent(const std::string &user_agent_string) { m_user_agent_string = user_agent_string; } @@ -28,5 +28,5 @@ pplx::task web_request_stub::get_response() on_get_response(*this); return pplx::task_from_result( - web_response{ m_status_code, m_reason_phrase, pplx::task_from_result(m_response_body) }); + web_response{ m_status_code, m_reason_phrase, pplx::task_from_result(m_response_body) }); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.h b/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.h index f15c550e37e1..23c37be88fef 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.h +++ b/src/SignalR/clients/cpp/test/signalrclienttests/web_request_stub.h @@ -11,17 +11,17 @@ using namespace signalr; struct web_request_stub : public web_request { unsigned short m_status_code; - utility::string_t m_reason_phrase; - utility::string_t m_response_body; - utility::string_t m_method; - utility::string_t m_user_agent_string; + std::string m_reason_phrase; + std::string m_response_body; + std::string m_method; + std::string m_user_agent_string; signalr_client_config m_signalr_client_config; std::function on_get_response = [](web_request_stub&){}; - web_request_stub(unsigned short status_code, const utility::string_t& reason_phrase, const utility::string_t& response_body = _XPLATSTR("")); + web_request_stub(unsigned short status_code, const std::string& reason_phrase, const std::string& response_body = ""); - virtual void set_method(const utility::string_t &method) override; - virtual void set_user_agent(const utility::string_t &user_agent_string) override; + virtual void set_method(const std::string &method) override; + virtual void set_user_agent(const std::string &user_agent_string) override; virtual void set_client_config(const signalr_client_config& client_config) override; virtual pplx::task get_response() override; diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/web_request_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/web_request_tests.cpp index 6932e67efc0a..d7e789b04d6d 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/web_request_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/web_request_tests.cpp @@ -10,35 +10,35 @@ using namespace signalr; TEST(web_request_get_response, DISABLED_sends_request_receives_response) { - utility::string_t url(_XPLATSTR("http://localhost:56000/web_request_test")); + std::string url("http://localhost:56000/web_request_test"); auto request_received = false; - utility::string_t user_agent_string; + std::string user_agent_string; - http::experimental::listener::http_listener listener(url); + http::experimental::listener::http_listener listener(utility::conversions::to_string_t(url)); listener.support(http::methods::GET, [&request_received, &user_agent_string](http::http_request request) { request_received = true; - user_agent_string = request.headers()[_XPLATSTR("User-Agent")]; - request.reply(http::status_codes::OK, _XPLATSTR("response")); + user_agent_string = utility::conversions::to_utf8string(request.headers()[_XPLATSTR("User-Agent")]); + request.reply(http::status_codes::OK, "response"); }); listener.open() .then([&url]() { web_request request(url); - request.set_method(http::methods::GET); - request.set_user_agent(_XPLATSTR("007")); + request.set_method(utility::conversions::to_utf8string(http::methods::GET)); + request.set_user_agent("007"); request.get_response() .then([](web_response response) { ASSERT_EQ((unsigned short)200, response.status_code); - ASSERT_EQ(_XPLATSTR("OK"), response.reason_phrase); - ASSERT_EQ(_XPLATSTR("response"), response.body.get()); + ASSERT_EQ("OK", response.reason_phrase); + ASSERT_EQ("response", response.body.get()); }).wait(); }).wait(); listener.close(); ASSERT_TRUE(request_received); - ASSERT_EQ(_XPLATSTR("007"), user_agent_string); + ASSERT_EQ("007", user_agent_string); } diff --git a/src/SignalR/clients/cpp/test/signalrclienttests/websocket_transport_tests.cpp b/src/SignalR/clients/cpp/test/signalrclienttests/websocket_transport_tests.cpp index f0842767466e..2c620a0ee1d0 100644 --- a/src/SignalR/clients/cpp/test/signalrclienttests/websocket_transport_tests.cpp +++ b/src/SignalR/clients/cpp/test/signalrclienttests/websocket_transport_tests.cpp @@ -16,7 +16,7 @@ TEST(websocket_transport_connect, connect_connects_and_starts_receive_loop) auto receive_called = std::make_shared(); auto client = std::make_shared(); - client->set_connect_function([&connect_called](const web::uri &) -> pplx::task + client->set_connect_function([&connect_called](const std::string&) -> pplx::task { connect_called = true; return pplx::task_from_result(); @@ -31,9 +31,9 @@ TEST(websocket_transport_connect, connect_connects_and_starts_receive_loop) std::shared_ptr writer(std::make_shared()); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(writer, trace_level::info), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org/connect?param=42")).get(); + ws_transport->connect("ws://fakeuri.org/connect?param=42").get(); ASSERT_TRUE(connect_called); ASSERT_FALSE(receive_called->wait(5000)); @@ -42,23 +42,23 @@ TEST(websocket_transport_connect, connect_connects_and_starts_receive_loop) ASSERT_FALSE(log_entries.empty()); auto entry = remove_date_from_log_entry(log_entries[0]); - ASSERT_EQ(_XPLATSTR("[info ] [websocket transport] connecting to: ws://fakeuri.org/connect?param=42\n"), entry); + ASSERT_EQ("[info ] [websocket transport] connecting to: ws://fakeuri.org/connect?param=42\n", entry); } TEST(websocket_transport_connect, connect_propagates_exceptions) { auto client = std::make_shared(); - client->set_connect_function([](const web::uri &)->pplx::task + client->set_connect_function([](const std::string&)->pplx::task { return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); try { - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); ASSERT_TRUE(false); // exception not thrown } catch (const std::exception &e) @@ -70,18 +70,18 @@ TEST(websocket_transport_connect, connect_propagates_exceptions) TEST(websocket_transport_connect, connect_logs_exceptions) { auto client = std::make_shared(); - client->set_connect_function([](const web::uri &) -> pplx::task + client->set_connect_function([](const std::string&) -> pplx::task { return pplx::task_from_exception(web::websockets::client::websocket_exception(_XPLATSTR("connecting failed"))); }); std::shared_ptr writer(std::make_shared()); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(writer, trace_level::errors), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); try { - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).wait(); + ws_transport->connect("ws://fakeuri.org").wait(); } catch (...) { } @@ -93,7 +93,7 @@ TEST(websocket_transport_connect, connect_logs_exceptions) auto entry = remove_date_from_log_entry(log_entries[0]); ASSERT_EQ( - _XPLATSTR("[error ] [websocket transport] exception when connecting to the server: connecting failed\n"), + "[error ] [websocket transport] exception when connecting to the server: connecting failed\n", entry); } @@ -101,13 +101,13 @@ TEST(websocket_transport_connect, cannot_call_connect_on_already_connected_trans { auto client = std::make_shared(); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).wait(); + ws_transport->connect("ws://fakeuri.org").wait(); try { - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).wait(); + ws_transport->connect("ws://fakeuri.org").wait(); ASSERT_TRUE(false); // exception not thrown } catch (const std::exception &e) @@ -120,11 +120,11 @@ TEST(websocket_transport_connect, can_connect_after_disconnecting) { auto client = std::make_shared(); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); ws_transport->disconnect().get(); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); // shouldn't throw or crash } @@ -134,17 +134,17 @@ TEST(websocket_transport_send, send_creates_and_sends_websocket_messages) auto client = std::make_shared(); - client->set_send_function([&send_called](const utility::string_t&) -> pplx::task + client->set_send_function([&send_called](const std::string&) -> pplx::task { send_called = true; return pplx::task_from_result(); }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://url")) - .then([ws_transport](){ return ws_transport->send(_XPLATSTR("ABC")); }) + ws_transport->connect("ws://url") + .then([ws_transport](){ return ws_transport->send("ABC"); }) .wait(); ASSERT_TRUE(send_called); @@ -163,9 +163,9 @@ TEST(websocket_transport_disconnect, disconnect_closes_websocket) }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://url")) + ws_transport->connect("ws://url") .then([ws_transport]() { return ws_transport->disconnect(); @@ -186,9 +186,9 @@ TEST(websocket_transport_disconnect, disconnect_does_not_throw) }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://url")) + ws_transport->connect("ws://url") .then([ws_transport]() { return ws_transport->disconnect(); @@ -208,9 +208,9 @@ TEST(websocket_transport_disconnect, disconnect_logs_exceptions) std::shared_ptr writer(std::make_shared()); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(writer, trace_level::errors), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://url")) + ws_transport->connect("ws://url") .then([ws_transport]() { return ws_transport->disconnect(); @@ -223,10 +223,10 @@ TEST(websocket_transport_disconnect, disconnect_logs_exceptions) // disconnect cancels the receive loop by setting the cancellation token source to cancelled which results in writing // to the log. Exceptions from close are also logged but this happens on a different thread. As a result the order // of messages in the log is not deterministic and therefore we just use the "contains" idiom to find the message. - ASSERT_NE(std::find_if(log_entries.begin(), log_entries.end(), [](const utility::string_t& entry) + ASSERT_NE(std::find_if(log_entries.begin(), log_entries.end(), [](const std::string& entry) { return remove_date_from_log_entry(entry) == - _XPLATSTR("[error ] [websocket transport] exception when closing websocket: connection closing failed\n"); + "[error ] [websocket transport] exception when closing websocket: connection closing failed\n"; }), log_entries.end()); } @@ -258,15 +258,15 @@ TEST(websocket_transport_disconnect, receive_not_called_after_disconnect) }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); pplx::create_task(receive_task_started_tce).get(); ws_transport->disconnect().get(); receive_task_tce = pplx::task_completion_event(); receive_task_started_tce = pplx::task_completion_event(); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); pplx::create_task(receive_task_started_tce).get(); ws_transport->disconnect().get(); @@ -286,7 +286,7 @@ TEST(websocket_transport_disconnect, disconnect_is_no_op_if_transport_not_starte }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); ws_transport->disconnect().get(); @@ -308,9 +308,9 @@ TEST(websocket_transport_disconnect, exceptions_from_outstanding_receive_task_ob }); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); ws_transport->disconnect().get(); // at this point the cancellation token that closes the receive loop is set to cancelled so @@ -319,13 +319,13 @@ TEST(websocket_transport_disconnect, exceptions_from_outstanding_receive_task_ob } template -void receive_loop_logs_exception_runner(const T& e, const utility::string_t& expected_message, trace_level trace_level); +void receive_loop_logs_exception_runner(const T& e, const std::string& expected_message, trace_level trace_level); TEST(websocket_transport_receive_loop, receive_loop_logs_websocket_exceptions) { receive_loop_logs_exception_runner( web::websockets::client::websocket_exception(_XPLATSTR("receive failed")), - _XPLATSTR("[error ] [websocket transport] error receiving response from websocket: receive failed\n"), + "[error ] [websocket transport] error receiving response from websocket: receive failed\n", trace_level::errors); } @@ -333,7 +333,7 @@ TEST(websocket_transport_receive_loop, receive_loop_logs_if_receive_task_cancele { receive_loop_logs_exception_runner( pplx::task_canceled("canceled"), - _XPLATSTR("[info ] [websocket transport] receive task canceled.\n"), + "[info ] [websocket transport] receive task canceled.\n", trace_level::info); } @@ -341,12 +341,12 @@ TEST(websocket_transport_receive_loop, receive_loop_logs_std_exception) { receive_loop_logs_exception_runner( std::runtime_error("exception"), - _XPLATSTR("[error ] [websocket transport] error receiving response from websocket: exception\n"), + "[error ] [websocket transport] error receiving response from websocket: exception\n", trace_level::errors); } template -void receive_loop_logs_exception_runner(const T& e, const utility::string_t& expected_message, trace_level trace_level) +void receive_loop_logs_exception_runner(const T& e, const std::string& expected_message, trace_level trace_level) { event receive_event; auto client = std::make_shared(); @@ -360,9 +360,9 @@ void receive_loop_logs_exception_runner(const T& e, const utility::string_t& exp std::shared_ptr writer(std::make_shared()); auto ws_transport = websocket_transport::create([&](){ return client; }, logger(writer, trace_level), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://url")) + ws_transport->connect("ws://url") .then([&receive_event]() { receive_event.wait(); @@ -374,7 +374,7 @@ void receive_loop_logs_exception_runner(const T& e, const utility::string_t& exp auto log_entries = std::dynamic_pointer_cast(writer)->get_log_entries(); ASSERT_NE(std::find_if(log_entries.begin(), log_entries.end(), - [&expected_message](utility::string_t entry) { return remove_date_from_log_entry(entry) == expected_message; }), + [&expected_message](std::string entry) { return remove_date_from_log_entry(entry) == expected_message; }), log_entries.end()); } @@ -387,9 +387,9 @@ TEST(websocket_transport_receive_loop, process_response_callback_called_when_mes }); auto process_response_event = std::make_shared(); - auto msg = std::make_shared(); + auto msg = std::make_shared(); - auto process_response = [msg, process_response_event](const utility::string_t& message) + auto process_response = [msg, process_response_event](const std::string& message) { *msg = message; process_response_event->set(); @@ -398,11 +398,11 @@ TEST(websocket_transport_receive_loop, process_response_callback_called_when_mes auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), process_response, [](const std::exception&){}); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); process_response_event->wait(1000); - ASSERT_EQ(utility::string_t(_XPLATSTR("msg")), *msg); + ASSERT_EQ(std::string("msg"), *msg); } TEST(websocket_transport_receive_loop, error_callback_called_when_exception_thrown) @@ -430,9 +430,9 @@ TEST(websocket_transport_receive_loop, error_callback_called_when_exception_thro }; auto ws_transport = websocket_transport::create([&](){ return client; }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, error_callback); + [](const std::string&){}, error_callback); - ws_transport->connect(_XPLATSTR("ws://fakeuri.org")).get(); + ws_transport->connect("ws://fakeuri.org").get(); error_event->wait(1000); @@ -445,7 +445,7 @@ TEST(websocket_transport_get_transport_type, get_transport_type_returns_websocke auto ws_transport = websocket_transport::create( [](){ return std::make_shared(); }, logger(std::make_shared(), trace_level::none), - [](const utility::string_t&){}, [](const std::exception&){}); + [](const std::string&){}, [](const std::exception&){}); ASSERT_EQ(transport_type::websockets, ws_transport->get_transport_type()); }