From 983df2d8f9b0ac86a645947e84d3ffdbe99780b0 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 9 Sep 2019 17:34:36 -0700 Subject: [PATCH] improve some websocket error messages + add a utility function with unittest to parse status line and stop using scanf which triggers warnings on Windows --- test/IXHttpTest.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/IXHttpTest.cpp diff --git a/test/IXHttpTest.cpp b/test/IXHttpTest.cpp new file mode 100644 index 00000000..65da1762 --- /dev/null +++ b/test/IXHttpTest.cpp @@ -0,0 +1,55 @@ +/* + * IXHttpTest.cpp + * Author: Benjamin Sergeant + * Copyright (c) 2019 Machine Zone. All rights reserved. + */ + +#include +#include + +#include "catch.hpp" +#include + +namespace ix +{ + +TEST_CASE("http", "[http]") +{ + SECTION("Normal case") + { + std::string line = "HTTP/1.1 200"; + auto result = Http::parseStatusLine(line); + + REQUIRE(result.first == "HTTP/1.1"); + REQUIRE(result.second == 200); + } + + SECTION("http/1.0 case") + { + std::string line = "HTTP/1.0 200"; + auto result = Http::parseStatusLine(line); + + REQUIRE(result.first == "HTTP/1.0"); + REQUIRE(result.second == 200); + } + + SECTION("empty case") + { + std::string line = ""; + auto result = Http::parseStatusLine(line); + + REQUIRE(result.first == ""); + REQUIRE(result.second == -1); + } + + SECTION("empty case") + { + std::string line = "HTTP/1.1"; + auto result = Http::parseStatusLine(line); + + REQUIRE(result.first == "HTTP/1.1"); + REQUIRE(result.second == -1); + } +} + +}