add a travis file

This commit is contained in:
Benjamin Sergeant
2019-01-07 18:04:28 -08:00
parent ea75432f12
commit 1cf8b7e952
20 changed files with 835 additions and 32 deletions

View File

@ -2,13 +2,12 @@
# Author: Benjamin Sergeant
# Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
#
cmake_minimum_required (VERSION 3.4.1)
project (ixwebsocket_unittest)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../third_party/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
find_package(Sanitizers)
cmake_minimum_required (VERSION 3.4.1)
project (ixwebsocket_unittest)
set (CMAKE_CXX_STANDARD 11)
if (NOT WIN32)

View File

@ -36,7 +36,7 @@ namespace ix
makeCancellationRequestWithTimeout(timeoutSecs, requestInitCancellation);
bool success = socket->connect(host, port, errMsg, isCancellationRequested);
std::cerr << "errMsg: " << errMsg << std::endl;
Logger() << "errMsg: " << errMsg;
REQUIRE(success);
std::cout << "Sending request: " << request

View File

@ -9,6 +9,7 @@
#include <chrono>
#include <thread>
#include <mutex>
#include <string>
#include <fstream>
#include <iostream>
@ -18,6 +19,7 @@ namespace ix
{
std::atomic<size_t> incomingBytes(0);
std::atomic<size_t> outgoingBytes(0);
std::mutex Logger::_mutex;
void setupWebSocketTrafficTrackerCallback()
{
@ -38,9 +40,9 @@ namespace ix
void reportWebSocketTraffic()
{
std::cout << incomingBytes << std::endl;
std::cout << "Incoming bytes: " << incomingBytes << std::endl;
std::cout << "Outgoing bytes: " << outgoingBytes << std::endl;
Logger() << incomingBytes;
Logger() << "Incoming bytes: " << incomingBytes;
Logger() << "Outgoing bytes: " << outgoingBytes;
}
void msleep(int ms)
@ -58,4 +60,10 @@ namespace ix
return std::to_string(seconds);
}
void log(const std::string& msg)
{
Logger() << msg;
}
}

View File

@ -9,6 +9,7 @@
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
namespace ix
{
@ -21,4 +22,32 @@ namespace ix
// Record and report websocket traffic
void setupWebSocketTrafficTrackerCallback();
void reportWebSocketTraffic();
struct Logger
{
public:
Logger& operator<<(const std::string& msg)
{
std::lock_guard<std::mutex> lock(_mutex);
std::cerr << msg;
std::cerr << std::endl;
return *this;
}
template <typename T>
Logger& operator<<(T const& obj)
{
std::lock_guard<std::mutex> lock(_mutex);
std::cerr << obj;
std::cerr << std::endl;
return *this;
}
private:
static std::mutex _mutex;
};
void log(const std::string& msg);
}

View File

@ -32,17 +32,17 @@ namespace ix
{
if (messageType == ix::WebSocket_MessageType_Open)
{
std::cerr << "New connection" << std::endl;
std::cerr << "Uri: " << openInfo.uri << std::endl;
std::cerr << "Headers:" << std::endl;
Logger() << "New connection";
Logger() << "Uri: " << openInfo.uri;
Logger() << "Headers:";
for (auto it : openInfo.headers)
{
std::cerr << it.first << ": " << it.second << std::endl;
Logger() << it.first << ": " << it.second;
}
}
else if (messageType == ix::WebSocket_MessageType_Close)
{
std::cerr << "Closed connection" << std::endl;
Logger() << "Closed connection";
}
else if (messageType == ix::WebSocket_MessageType_Message)
{
@ -62,7 +62,7 @@ namespace ix
auto res = server.listen();
if (!res.first)
{
std::cerr << res.second << std::endl;
Logger() << res.second;
return false;
}
@ -121,7 +121,7 @@ TEST_CASE("Websocket_server", "[websocket_server]")
bool success = socket.connect(host, port, errMsg, isCancellationRequested);
REQUIRE(success);
std::cout << "writeBytes" << std::endl;
Logger() << "writeBytes";
socket.writeBytes("GET /\r\n", isCancellationRequested);
auto lineResult = socket.readLine(isCancellationRequested);

View File

@ -19,11 +19,6 @@ 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");
void log(const std::string& msg)
{
std::cout << msg << std::endl;
}
}
namespace

View File

@ -43,8 +43,6 @@ namespace
std::pair<std::string, std::string> decodeMessage(const std::string& str);
private:
void log(const std::string& msg);
std::string _user;
std::string _session;
@ -76,11 +74,6 @@ namespace
_webSocket.stop();
}
void WebSocketChat::log(const std::string& msg)
{
std::cerr << msg << std::endl;
}
void WebSocketChat::start()
{
std::string url("ws://localhost:8090/");
@ -188,17 +181,17 @@ namespace
{
if (messageType == ix::WebSocket_MessageType_Open)
{
std::cerr << "New connection" << std::endl;
std::cerr << "Uri: " << openInfo.uri << std::endl;
std::cerr << "Headers:" << std::endl;
Logger() << "New connection";
Logger() << "Uri: " << openInfo.uri;
Logger() << "Headers:";
for (auto it : openInfo.headers)
{
std::cerr << it.first << ": " << it.second << std::endl;
Logger() << it.first << ": " << it.second;
}
}
else if (messageType == ix::WebSocket_MessageType_Close)
{
std::cerr << "Closed connection" << std::endl;
log("Closed connection");
}
else if (messageType == ix::WebSocket_MessageType_Message)
{
@ -218,7 +211,7 @@ namespace
auto res = server.listen();
if (!res.first)
{
std::cerr << res.second << std::endl;
log(res.second);
return false;
}