move utilities to a separate file

pull/4714/head
yang-g 9 years ago
parent 1ac6f4594e
commit 9f17314a35
  1. 3
      Makefile
  2. 2
      build.yaml
  3. 21
      test/cpp/end2end/generic_end2end_test.cc
  4. 21
      test/cpp/end2end/hybrid_end2end_test.cc
  5. 60
      test/cpp/util/byte_buffer_proto_helper.cc
  6. 53
      test/cpp/util/byte_buffer_proto_helper.h
  7. 3
      tools/run_tests/sources_and_headers.json
  8. 3
      vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj
  9. 6
      vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters

@ -3161,6 +3161,7 @@ LIBGRPC++_TEST_UTIL_SRC = \
$(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc \
$(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc \
test/cpp/end2end/test_service_impl.cc \
test/cpp/util/byte_buffer_proto_helper.cc \
test/cpp/util/cli_call.cc \
test/cpp/util/create_test_channel.cc \
test/cpp/util/string_ref_helper.cc \
@ -3210,6 +3211,7 @@ ifneq ($(NO_DEPS),true)
endif
endif
$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/byte_buffer_proto_helper.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/cli_call.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/util/string_ref_helper.o: $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc
@ -12921,6 +12923,7 @@ test/cpp/qps/server_async.cc: $(OPENSSL_DEP)
test/cpp/qps/server_sync.cc: $(OPENSSL_DEP)
test/cpp/qps/timer.cc: $(OPENSSL_DEP)
test/cpp/util/benchmark_config.cc: $(OPENSSL_DEP)
test/cpp/util/byte_buffer_proto_helper.cc: $(OPENSSL_DEP)
test/cpp/util/cli_call.cc: $(OPENSSL_DEP)
test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP)
test/cpp/util/string_ref_helper.cc: $(OPENSSL_DEP)

@ -638,6 +638,7 @@ libs:
language: c++
headers:
- test/cpp/end2end/test_service_impl.h
- test/cpp/util/byte_buffer_proto_helper.h
- test/cpp/util/cli_call.h
- test/cpp/util/create_test_channel.h
- test/cpp/util/string_ref_helper.h
@ -647,6 +648,7 @@ libs:
- src/proto/grpc/testing/echo.proto
- src/proto/grpc/testing/duplicate/echo_duplicate.proto
- test/cpp/end2end/test_service_impl.cc
- test/cpp/util/byte_buffer_proto_helper.cc
- test/cpp/util/cli_call.cc
- test/cpp/util/create_test_channel.cc
- test/cpp/util/string_ref_helper.cc

@ -51,6 +51,7 @@
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/util/byte_buffer_proto_helper.h"
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
@ -70,26 +71,6 @@ void verify_ok(CompletionQueue* cq, int i, bool expect_ok) {
EXPECT_EQ(tag(i), got_tag);
}
bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) {
std::vector<Slice> slices;
buffer->Dump(&slices);
grpc::string buf;
buf.reserve(buffer->Length());
for (auto s = slices.begin(); s != slices.end(); s++) {
buf.append(reinterpret_cast<const char*>(s->begin()), s->size());
}
return message->ParseFromString(buf);
}
std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
grpc::protobuf::Message* message) {
grpc::string buf;
message->SerializeToString(&buf);
gpr_slice s = gpr_slice_from_copied_string(buf.c_str());
Slice slice(s, Slice::STEAL_REF);
return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1));
}
class GenericEnd2endTest : public ::testing::Test {
protected:
GenericEnd2endTest() : generic_service_("*"), server_host_("localhost") {}

@ -48,6 +48,7 @@
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
#include "test/cpp/end2end/test_service_impl.h"
#include "test/cpp/util/byte_buffer_proto_helper.h"
namespace grpc {
namespace testing {
@ -68,26 +69,6 @@ void Verify(CompletionQueue* cq, int i, bool expect_ok) {
EXPECT_EQ(expect_ok, VerifyReturnSuccess(cq, i));
}
bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) {
std::vector<Slice> slices;
buffer->Dump(&slices);
grpc::string buf;
buf.reserve(buffer->Length());
for (auto s = slices.begin(); s != slices.end(); s++) {
buf.append(reinterpret_cast<const char*>(s->begin()), s->size());
}
return message->ParseFromString(buf);
}
std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
grpc::protobuf::Message* message) {
grpc::string buf;
message->SerializeToString(&buf);
gpr_slice s = gpr_slice_from_copied_string(buf.c_str());
Slice slice(s, Slice::STEAL_REF);
return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1));
}
// Handlers to handle async request at a server. To be run in a separate thread.
template <class Service>
void HandleEcho(Service* service, ServerCompletionQueue* cq) {

@ -0,0 +1,60 @@
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* 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 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 and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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
* OWNER 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.
*
*/
#include "test/cpp/util/byte_buffer_proto_helper.h"
namespace grpc {
namespace testing {
bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message) {
std::vector<Slice> slices;
buffer->Dump(&slices);
grpc::string buf;
buf.reserve(buffer->Length());
for (auto s = slices.begin(); s != slices.end(); s++) {
buf.append(reinterpret_cast<const char*>(s->begin()), s->size());
}
return message->ParseFromString(buf);
}
std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
grpc::protobuf::Message* message) {
grpc::string buf;
message->SerializeToString(&buf);
gpr_slice s = gpr_slice_from_copied_string(buf.c_str());
Slice slice(s, Slice::STEAL_REF);
return std::unique_ptr<ByteBuffer>(new ByteBuffer(&slice, 1));
}
} // namespace testing
} // namespace grpc

@ -0,0 +1,53 @@
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* 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 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 and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* 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
* OWNER 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.
*
*/
#ifndef GRPC_TEST_CPP_UTIL_BYTE_BUFFER_PROTO_HELPER_H
#define GRPC_TEST_CPP_UTIL_BYTE_BUFFER_PROTO_HELPER_H
#include <memory>
#include <grpc++/support/byte_buffer.h>
#include <grpc++/support/config_protobuf.h>
namespace grpc {
namespace testing {
bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message);
std::unique_ptr<ByteBuffer> SerializeToByteBuffer(
grpc::protobuf::Message* message);
} // namespace testing
} // namespace grpc
#endif // GRPC_TEST_CPP_UTIL_BYTE_BUFFER_PROTO_HELPER_H

@ -4000,6 +4000,7 @@
"src/proto/grpc/testing/echo_messages.grpc.pb.h",
"src/proto/grpc/testing/echo_messages.pb.h",
"test/cpp/end2end/test_service_impl.h",
"test/cpp/util/byte_buffer_proto_helper.h",
"test/cpp/util/cli_call.h",
"test/cpp/util/create_test_channel.h",
"test/cpp/util/string_ref_helper.h",
@ -4010,6 +4011,8 @@
"src": [
"test/cpp/end2end/test_service_impl.cc",
"test/cpp/end2end/test_service_impl.h",
"test/cpp/util/byte_buffer_proto_helper.cc",
"test/cpp/util/byte_buffer_proto_helper.h",
"test/cpp/util/cli_call.cc",
"test/cpp/util/cli_call.h",
"test/cpp/util/create_test_channel.cc",

@ -148,6 +148,7 @@
<ItemGroup>
<ClInclude Include="$(SolutionDir)\..\test\cpp\end2end\test_service_impl.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\byte_buffer_proto_helper.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\cli_call.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\create_test_channel.h" />
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\string_ref_helper.h" />
@ -180,6 +181,8 @@
</ClInclude>
<ClCompile Include="$(SolutionDir)\..\test\cpp\end2end\test_service_impl.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\byte_buffer_proto_helper.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\cli_call.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\create_test_channel.cc">

@ -13,6 +13,9 @@
<ClCompile Include="$(SolutionDir)\..\test\cpp\end2end\test_service_impl.cc">
<Filter>test\cpp\end2end</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\byte_buffer_proto_helper.cc">
<Filter>test\cpp\util</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\test\cpp\util\cli_call.cc">
<Filter>test\cpp\util</Filter>
</ClCompile>
@ -30,6 +33,9 @@
<ClInclude Include="$(SolutionDir)\..\test\cpp\end2end\test_service_impl.h">
<Filter>test\cpp\end2end</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\byte_buffer_proto_helper.h">
<Filter>test\cpp\util</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\test\cpp\util\cli_call.h">
<Filter>test\cpp\util</Filter>
</ClInclude>

Loading…
Cancel
Save