Skip to content

Commit

Permalink
Merge pull request #67 from offa/issue66/type_deduction_fix
Browse files Browse the repository at this point in the history
Type deduction fixed
  • Loading branch information
mattgodbolt committed Mar 17, 2017
2 parents ea485c5 + cdb3c9b commit 6488d1a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
38 changes: 19 additions & 19 deletions src/main/c/seasocks/ResponseBuilder.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -68,7 +68,7 @@ class ResponseBuilder {

template<typename T>
ResponseBuilder& operator << (T&& t) {
(*_stream) << std::forward(t);
(*_stream) << std::forward<T>(t);
return *this;
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
27 changes: 27 additions & 0 deletions src/test/c/ResponseBuilderTests.cpp
Original file line number Diff line number Diff line change
@@ -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<SynchronousResponse>(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<SynchronousResponse>(builder.build());
CHECK_THAT(result->payload(), Equals("abc"));
}

TEST_CASE("appendStringValue", "[ResponseBuilderTests]") {
ResponseBuilder builder;
builder << std::string("xyz");
auto result = std::dynamic_pointer_cast<SynchronousResponse>(builder.build());
CHECK_THAT(result->payload(), Equals("xyz"));
}

0 comments on commit 6488d1a

Please sign in to comment.