reformat everything with clang-format
This commit is contained in:
@ -4,13 +4,12 @@
|
||||
* Copyright (c) 2017 Machine Zone. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <ixwebsocket/IXWebSocket.h>
|
||||
#include "IXTest.h"
|
||||
|
||||
#include "catch.hpp"
|
||||
#include <iostream>
|
||||
#include <ixwebsocket/IXWebSocket.h>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
using namespace ix;
|
||||
|
||||
@ -19,19 +18,19 @@ namespace
|
||||
const std::string WEBSOCKET_DOT_ORG_URL("wss://echo.websocket.org");
|
||||
const std::string GOOGLE_URL("wss://google.com");
|
||||
const std::string UNKNOWN_URL("wss://asdcasdcaasdcasdcasdcasdcasdcasdcasassdd.com");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace
|
||||
{
|
||||
class IXWebSocketTestConnectionDisconnection
|
||||
{
|
||||
public:
|
||||
IXWebSocketTestConnectionDisconnection();
|
||||
void start(const std::string& url);
|
||||
void stop();
|
||||
public:
|
||||
IXWebSocketTestConnectionDisconnection();
|
||||
void start(const std::string& url);
|
||||
void stop();
|
||||
|
||||
private:
|
||||
ix::WebSocket _webSocket;
|
||||
private:
|
||||
ix::WebSocket _webSocket;
|
||||
};
|
||||
|
||||
IXWebSocketTestConnectionDisconnection::IXWebSocketTestConnectionDisconnection()
|
||||
@ -51,45 +50,43 @@ namespace
|
||||
std::stringstream ss;
|
||||
log(std::string("Connecting to url: ") + url);
|
||||
|
||||
_webSocket.setOnMessageCallback(
|
||||
[](const ix::WebSocketMessagePtr& msg)
|
||||
_webSocket.setOnMessageCallback([](const ix::WebSocketMessagePtr& msg) {
|
||||
std::stringstream ss;
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
std::stringstream ss;
|
||||
if (msg->type == ix::WebSocketMessageType::Open)
|
||||
{
|
||||
log("TestConnectionDisconnection: connected !");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||
{
|
||||
log("TestConnectionDisconnection: disconnected !");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||
{
|
||||
ss << "TestConnectionDisconnection: Error! ";
|
||||
ss << msg->errorInfo.reason;
|
||||
log(ss.str());
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
log("TestConnectionDisconnection: received message.!");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Ping)
|
||||
{
|
||||
log("TestConnectionDisconnection: received ping message.!");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Pong)
|
||||
{
|
||||
log("TestConnectionDisconnection: received pong message.!");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Fragment)
|
||||
{
|
||||
log("TestConnectionDisconnection: received fragment.!");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Invalid ix::WebSocketMessageType");
|
||||
}
|
||||
});
|
||||
log("TestConnectionDisconnection: connected !");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Close)
|
||||
{
|
||||
log("TestConnectionDisconnection: disconnected !");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Error)
|
||||
{
|
||||
ss << "TestConnectionDisconnection: Error! ";
|
||||
ss << msg->errorInfo.reason;
|
||||
log(ss.str());
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Message)
|
||||
{
|
||||
log("TestConnectionDisconnection: received message.!");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Ping)
|
||||
{
|
||||
log("TestConnectionDisconnection: received ping message.!");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Pong)
|
||||
{
|
||||
log("TestConnectionDisconnection: received pong message.!");
|
||||
}
|
||||
else if (msg->type == ix::WebSocketMessageType::Fragment)
|
||||
{
|
||||
log("TestConnectionDisconnection: received fragment.!");
|
||||
}
|
||||
else
|
||||
{
|
||||
log("Invalid ix::WebSocketMessageType");
|
||||
}
|
||||
});
|
||||
|
||||
_webSocket.enableAutomaticReconnection();
|
||||
REQUIRE(_webSocket.isAutomaticReconnectionEnabled() == true);
|
||||
@ -100,11 +97,12 @@ namespace
|
||||
// Start the connection
|
||||
_webSocket.start();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
//
|
||||
// We try to connect to different servers, and make sure there are no crashes.
|
||||
// FIXME: We could do more checks (make sure that we were not able to connect to unknown servers, etc...)
|
||||
// FIXME: We could do more checks (make sure that we were not able to connect to unknown servers,
|
||||
// etc...)
|
||||
//
|
||||
TEST_CASE("websocket_connections", "[websocket]")
|
||||
{
|
||||
@ -121,7 +119,8 @@ TEST_CASE("websocket_connections", "[websocket]")
|
||||
test.stop();
|
||||
}
|
||||
|
||||
SECTION("Try to connect and disconnect with different timing, not enough time to succesfully connect")
|
||||
SECTION("Try to connect and disconnect with different timing, not enough time to succesfully "
|
||||
"connect")
|
||||
{
|
||||
IXWebSocketTestConnectionDisconnection test;
|
||||
log(std::string("50 Runs"));
|
||||
@ -141,7 +140,8 @@ TEST_CASE("websocket_connections", "[websocket]")
|
||||
|
||||
// This test breaks on travis CI - Ubuntu Xenial + gcc + tsan
|
||||
// We should fix this.
|
||||
SECTION("Try to connect and disconnect with different timing, from not enough time to successfull connect")
|
||||
SECTION("Try to connect and disconnect with different timing, from not enough time to "
|
||||
"successfull connect")
|
||||
{
|
||||
IXWebSocketTestConnectionDisconnection test;
|
||||
log(std::string("20 Runs"));
|
||||
@ -152,7 +152,7 @@ TEST_CASE("websocket_connections", "[websocket]")
|
||||
test.start(WEBSOCKET_DOT_ORG_URL);
|
||||
|
||||
log(std::string("Sleeping"));
|
||||
ix::msleep(i*50);
|
||||
ix::msleep(i * 50);
|
||||
|
||||
log(std::string("Stopping"));
|
||||
test.stop();
|
||||
|
Reference in New Issue
Block a user