Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,22 @@ jobs:
cmake -D CMAKE_BUILD_TYPE=Debug ..
cmake --build .
ctest . -C Debug

embuild:
# Just build with emscripten. There is no way to test the build yet.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup emsdk
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021
with:
version: 4.0.21
actions-cache-folder: 'emsdk-cache'
- name: Verify emsdk
run: emcc -v
- name: build
run: |
mkdir build
cd build/
emcmake cmake ..
emmake make
19 changes: 18 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ FetchContent_Declare(
FetchContent_Declare(
websocketpp
URL https://github.com/zaphoyd/websocketpp/archive/4dfe1be74e684acca19ac1cf96cce0df9eac2a2d.zip)
# Desktop-only, without submodule:
#FetchContent_Declare(
# wswrap
# URL https://github.com/black-sliver/wswrap/archive/e71695c80e0338d0aa4f18e7e0f45b67681206be.zip)
# Complete, with submodule:
FetchContent_Declare(
wswrap
URL https://github.com/black-sliver/wswrap/archive/e71695c80e0338d0aa4f18e7e0f45b67681206be.zip)
GIT_REPOSITORY https://github.com/black-sliver/wswrap.git
GIT_TAG e71695c80e0338d0aa4f18e7e0f45b67681206be)

FetchContent_MakeAvailable(asio json websocketpp wswrap)

add_executable(TestBasic test_basic.cpp)
Expand Down Expand Up @@ -65,6 +72,16 @@ set_target_properties(TestBasic PROPERTIES
CXX_EXTENSIONS NO
)

if(EMSCRIPTEN)
message("Configuring TestBasic for emscripten")
# embind requires C++17
set_target_properties(TestBasic PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
)
target_link_options(TestBasic BEFORE PRIVATE "--bind")
endif()

# enable more warnings
if(MSVC)
target_compile_options(TestBasic PRIVATE /W4)
Expand Down
16 changes: 13 additions & 3 deletions test/test_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#include <chrono>
#include <cstdio>
#include <thread>
#include <websocketpp/server.hpp>
#include <websocketpp/config/asio_no_tls.hpp>

#define usleep(usec) std::this_thread::sleep_for(std::chrono::microseconds(usec))

#ifndef EMSCRIPTEN // we can not run websocket server in wasm
#include <websocketpp/server.hpp>
#include <websocketpp/config/asio_no_tls.hpp>

typedef websocketpp::server<websocketpp::config::asio> Server;

class TestServer final {
Expand Down Expand Up @@ -85,9 +87,11 @@ class TestServer final {
server.send(hdl, roomInfo, websocketpp::frame::opcode::text);
}
};
#endif // ndef EMSCRIPTEN

int main(int, char**)
{
#ifndef EMSCRIPTEN // we can not run websocket server in wasm
printf("Starting server...\n");
TestServer server{38281, 38291};
std::thread serverThread(&TestServer::run, &server);
Expand All @@ -99,13 +103,17 @@ int main(int, char**)
if (!server.is_listening())
throw std::runtime_error("Timeout starting server");
printf("Server listening on %d\n", static_cast<int>(server.get_port()));
const auto port = server.get_port();
#else // !ndef EMSCRIPTEN
const uint16_t port = 38281;
#endif // ndef EMSCRIPTEN

bool error = false;
bool connected = false;
bool roomInfo = false;
bool releaseMode = false;
{
const std::string uri = "ws://localhost:" + std::to_string(server.get_port());
const std::string uri = "ws://localhost:" + std::to_string(port);

printf("Starting client for %s...\n", uri.c_str());
APClient ap{"", "", uri};
Expand Down Expand Up @@ -141,9 +149,11 @@ int main(int, char**)
// FIXME: ~APClient can throw
}

#ifndef EMSCRIPTEN // we can not run websocket server in wasm
printf("Stopping server...\n");
server.stop();
serverThread.join();
#endif // ndef EMSCRIPTEN

if (!connected) {
fprintf(stderr, "FAIL: Could not connect socket\n");
Expand Down
Loading