From cdb3c9b15c69d0365acb73ec94e96da8ee1e0221 Mon Sep 17 00:00:00 2001 From: offa Date: Fri, 17 Mar 2017 10:42:49 +0100 Subject: [PATCH] Type deduction fixed (#66). --- src/main/c/seasocks/ResponseBuilder.h | 38 +++++++++++++-------------- src/test/c/CMakeLists.txt | 4 ++- src/test/c/ResponseBuilderTests.cpp | 27 +++++++++++++++++++ 3 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 src/test/c/ResponseBuilderTests.cpp diff --git a/src/main/c/seasocks/ResponseBuilder.h b/src/main/c/seasocks/ResponseBuilder.h index 82c1b248..dcc4fd94 100644 --- a/src/main/c/seasocks/ResponseBuilder.h +++ b/src/main/c/seasocks/ResponseBuilder.h @@ -1,26 +1,26 @@ // Copyright (c) 2013-2016, Matt Godbolt // All rights reserved. -// -// Redistribution and use in source and binary forms, with or without +// +// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: -// -// Redistributions of source code must retain the above copyright notice, this +// +// Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation +// +// Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. #pragma once @@ -68,7 +68,7 @@ class ResponseBuilder { template ResponseBuilder& operator << (T&& t) { - (*_stream) << std::forward(t); + (*_stream) << std::forward(t); return *this; } diff --git a/src/test/c/CMakeLists.txt b/src/test/c/CMakeLists.txt index 9da76665..55c4eaee 100644 --- a/src/test/c/CMakeLists.txt +++ b/src/test/c/CMakeLists.txt @@ -11,7 +11,9 @@ add_executable(AllTests test_main.cpp MockServerImpl.h ServerTests.cpp ToStringTests.cpp - EmbeddedContentTests.cpp) + EmbeddedContentTests.cpp + ResponseBuilderTests.cpp + ) add_test(NAME ${TESTS} COMMAND ${TESTS}) target_link_libraries(${TESTS} seasocks "${ZLIB_LIBRARIES}") diff --git a/src/test/c/ResponseBuilderTests.cpp b/src/test/c/ResponseBuilderTests.cpp new file mode 100644 index 00000000..bf100700 --- /dev/null +++ b/src/test/c/ResponseBuilderTests.cpp @@ -0,0 +1,27 @@ + +#include "seasocks/ResponseBuilder.h" +#include "catch.hpp" + +using namespace seasocks; + +TEST_CASE("appendIntValue", "[ResponseBuilderTests]") { + ResponseBuilder builder; + builder << int{3}; + auto result = std::dynamic_pointer_cast(builder.build()); + CHECK_THAT(result->payload(), Equals("3")); +} + +TEST_CASE("appendCStringValue", "[ResponseBuilderTests]") { + ResponseBuilder builder; + const char* cStr = "abc"; + builder << cStr; + auto result = std::dynamic_pointer_cast(builder.build()); + CHECK_THAT(result->payload(), Equals("abc")); +} + +TEST_CASE("appendStringValue", "[ResponseBuilderTests]") { + ResponseBuilder builder; + builder << std::string("xyz"); + auto result = std::dynamic_pointer_cast(builder.build()); + CHECK_THAT(result->payload(), Equals("xyz")); +}