dns_resolver_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <string.h>
20 
21 #include <grpc/grpc.h>
22 #include <grpc/support/log.h>
23 
32 
33 static std::shared_ptr<grpc_core::WorkSerializer>* g_work_serializer;
34 
36  void ReportResult(grpc_core::Resolver::Result /*result*/) override {}
37 };
38 
40  const char* string) {
41  gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
42  std::string(factory->scheme()).c_str());
45  if (!uri.ok()) {
46  gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str());
47  GPR_ASSERT(uri.ok());
48  }
50  args.uri = std::move(*uri);
51  args.work_serializer = *g_work_serializer;
52  args.result_handler = absl::make_unique<TestResultHandler>();
54  factory->CreateResolver(std::move(args));
55  GPR_ASSERT(resolver != nullptr);
56 }
57 
59  const char* string) {
60  gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
61  std::string(factory->scheme()).c_str());
64  if (!uri.ok()) {
65  gpr_log(GPR_ERROR, "%s", uri.status().ToString().c_str());
66  GPR_ASSERT(uri.ok());
67  }
69  args.uri = std::move(*uri);
70  args.work_serializer = *g_work_serializer;
71  args.result_handler = absl::make_unique<TestResultHandler>();
73  factory->CreateResolver(std::move(args));
74  GPR_ASSERT(resolver == nullptr);
75 }
76 
77 int main(int argc, char** argv) {
79  grpc_init();
80 
81  auto work_serializer = std::make_shared<grpc_core::WorkSerializer>();
82  g_work_serializer = &work_serializer;
83 
86  .LookupResolverFactory("dns");
87 
88  test_succeeds(dns, "dns:10.2.1.1");
89  test_succeeds(dns, "dns:10.2.1.1:1234");
90  test_succeeds(dns, "dns:www.google.com");
91  test_succeeds(dns, "dns:///www.google.com");
93  GPR_GLOBAL_CONFIG_GET(grpc_dns_resolver);
94  if (gpr_stricmp(resolver.get(), "native") == 0) {
95  test_fails(dns, "dns://8.8.8.8/8.8.8.8:8888");
96  } else {
97  test_succeeds(dns, "dns://8.8.8.8/8.8.8.8:8888");
98  }
99  grpc_shutdown();
100 
101  return 0;
102 }
grpc_core::ResolverRegistry::LookupResolverFactory
ResolverFactory * LookupResolverFactory(absl::string_view scheme) const
Definition: resolver_registry.cc:108
log.h
core_configuration.h
grpc_core::ResolverFactory::CreateResolver
virtual OrphanablePtr< Resolver > CreateResolver(ResolverArgs args) const =0
Returns a new resolver instance.
generate.env
env
Definition: generate.py:37
GPR_GLOBAL_CONFIG_GET
#define GPR_GLOBAL_CONFIG_GET(name)
Definition: global_config_generic.h:24
TestResultHandler
Definition: dns_resolver_test.cc:35
string.h
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::URI::Parse
static absl::StatusOr< URI > Parse(absl::string_view uri_text)
Definition: uri_parser.cc:209
main
int main(int argc, char **argv)
Definition: dns_resolver_test.cc:77
memory.h
g_work_serializer
static std::shared_ptr< grpc_core::WorkSerializer > * g_work_serializer
Definition: dns_resolver_test.cc:33
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
GPR_ASSERT
#define GPR_ASSERT(x)
Definition: include/grpc/impl/codegen/log.h:94
grpc_core::CoreConfiguration::Get
static const CoreConfiguration & Get()
Definition: core_configuration.h:82
grpc_ares_wrapper.h
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
work_serializer.h
grpc_core::Resolver::Result
Results returned by the resolver.
Definition: resolver/resolver.h:56
grpc.h
grpc_core::ResolverArgs
Definition: resolver_factory.h:41
gpr_stricmp
int gpr_stricmp(const char *a, const char *b)
Definition: string.cc:282
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
grpc_core::Resolver::ResultHandler
Definition: resolver/resolver.h:84
grpc_core::ExecCtx
Definition: exec_ctx.h:97
grpc_core::UniquePtr
std::unique_ptr< T, DefaultDeleteChar > UniquePtr
Definition: src/core/lib/gprpp/memory.h:43
resolver_registry.h
test_config.h
TestResultHandler::ReportResult
void ReportResult(grpc_core::Resolver::Result) override
Reports a result to the channel.
Definition: dns_resolver_test.cc:36
absl::StatusOr::ok
ABSL_MUST_USE_RESULT bool ok() const
Definition: abseil-cpp/absl/status/statusor.h:491
test_succeeds
static void test_succeeds(grpc_core::ResolverFactory *factory, const char *string)
Definition: dns_resolver_test.cc:39
test_fails
static void test_fails(grpc_core::ResolverFactory *factory, const char *string)
Definition: dns_resolver_test.cc:58
exec_ctx
grpc_core::ExecCtx exec_ctx
Definition: end2end_binder_transport_test.cc:75
grpc_core::OrphanablePtr
std::unique_ptr< T, Deleter > OrphanablePtr
Definition: orphanable.h:64
dns_resolver_selection.h
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
grpc_core::CoreConfiguration::resolver_registry
const ResolverRegistry & resolver_registry() const
Definition: core_configuration.h:157
GPR_DEBUG
#define GPR_DEBUG
Definition: include/grpc/impl/codegen/log.h:55
absl::StatusOr
Definition: abseil-cpp/absl/status/statusor.h:187
grpc_core::ResolverFactory::scheme
virtual absl::string_view scheme() const =0
grpc_init
GRPCAPI void grpc_init(void)
Definition: init.cc:146
grpc_core::ResolverFactory
Definition: resolver_factory.h:54
grpc_shutdown
GRPCAPI void grpc_shutdown(void)
Definition: init.cc:209
absl::StatusOr::status
const Status & status() const &
Definition: abseil-cpp/absl/status/statusor.h:678


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:17