| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * |
| 3 * Copyright 2015, Google Inc. |
| 4 * All rights reserved. |
| 3 * | 5 * |
| 4 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 6 * met: | 8 * met: |
| 7 * | 9 * |
| 8 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 11 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 12 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 13 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 14 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 15 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 16 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 17 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 18 * this software without specific prior written permission. |
| 17 * | 19 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 * |
| 29 */ | 32 */ |
| 30 | 33 |
| 31 /** | 34 #include "test/cpp/interop/server_helper.h" |
| 32 * Make testing with gtest and gmock nicer by adding pretty print and other | |
| 33 * helper functions. | |
| 34 */ | |
| 35 | 35 |
| 36 #ifndef CSSValueTestHelper_h | 36 #include <memory> |
| 37 #define CSSValueTestHelper_h | |
| 38 | 37 |
| 39 #include "core/css/CSSPrimitiveValue.h" | 38 #include <gflags/gflags.h> |
| 40 #include "core/css/CSSValue.h" | 39 #include <grpc++/security/server_credentials.h> |
| 41 | 40 |
| 42 #include <ostream> | 41 #include "src/core/surface/call_test_only.h" |
| 42 #include "test/core/end2end/data/ssl_test_data.h" |
| 43 | 43 |
| 44 DECLARE_bool(use_tls); |
| 45 |
| 46 namespace grpc { |
| 44 namespace testing { | 47 namespace testing { |
| 45 namespace internal { | |
| 46 | 48 |
| 47 // gtest tests won't compile with clang when trying to EXPECT_EQ a class that | 49 std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() { |
| 48 // has the "template<typename T> operator T*()" private. | 50 if (FLAGS_use_tls) { |
| 49 // (See https://code.google.com/p/googletest/issues/detail?id=442) | 51 SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, |
| 50 // | 52 test_server1_cert}; |
| 51 // Work around is to define this custom IsNullLiteralHelper. | 53 SslServerCredentialsOptions ssl_opts; |
| 52 char(&IsNullLiteralHelper(const blink::CSSValue&))[2]; | 54 ssl_opts.pem_root_certs = ""; |
| 53 | 55 ssl_opts.pem_key_cert_pairs.push_back(pkcp); |
| 54 } | 56 return SslServerCredentials(ssl_opts); |
| 55 } // namespace testing | 57 } else { |
| 56 | 58 return InsecureServerCredentials(); |
| 57 namespace blink { | 59 } |
| 58 | |
| 59 inline bool operator==(const CSSValue& a, const CSSValue& b) | |
| 60 { | |
| 61 return a.equals(b); | |
| 62 } | 60 } |
| 63 | 61 |
| 64 inline void PrintTo(const CSSValue& cssValue, ::std::ostream* os, const char* ty
peName = "CSSValue") | 62 InteropServerContextInspector::InteropServerContextInspector( |
| 65 { | 63 const ::grpc::ServerContext& context) |
| 66 *os << typeName << "(" << cssValue.cssText().utf8().data() << ")"; | 64 : context_(context) {} |
| 65 |
| 66 grpc_compression_algorithm |
| 67 InteropServerContextInspector::GetCallCompressionAlgorithm() const { |
| 68 return grpc_call_test_only_get_compression_algorithm(context_.call_); |
| 67 } | 69 } |
| 68 | 70 |
| 69 inline void PrintTo(const CSSPrimitiveValue& cssValue, ::std::ostream* os, const
char* typeName = "CSSPrimitiveValue") | 71 uint32_t InteropServerContextInspector::GetEncodingsAcceptedByClient() const { |
| 70 { | 72 return grpc_call_test_only_get_encodings_accepted_by_peer(context_.call_); |
| 71 PrintTo(static_cast<const CSSValue&>(cssValue), os, typeName); | |
| 72 } | 73 } |
| 73 | 74 |
| 74 } // namespace blink | 75 std::shared_ptr<const AuthContext> |
| 76 InteropServerContextInspector::GetAuthContext() const { |
| 77 return context_.auth_context(); |
| 78 } |
| 75 | 79 |
| 76 #endif | 80 bool InteropServerContextInspector::IsCancelled() const { |
| 81 return context_.IsCancelled(); |
| 82 } |
| 83 |
| 84 } // namespace testing |
| 85 } // namespace grpc |
| OLD | NEW |