3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <grpc/support/log.h>
23 #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
24 #include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h"
25 #include "src/core/ext/filters/client_channel/resolver_registry.h"
26 #include "src/core/lib/gpr/string.h"
27 #include "src/core/lib/iomgr/combiner.h"
28 #include "test/core/util/test_config.h"
30 static grpc_combiner* g_combiner;
32 static void test_succeeds(grpc_core::ResolverFactory* factory,
34 gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
36 grpc_core::ExecCtx exec_ctx;
37 grpc_uri* uri = grpc_uri_parse(string, 0);
39 grpc_core::ResolverArgs args;
41 args.combiner = g_combiner;
43 grpc_core::MakeUnique<grpc_core::Resolver::ResultHandler>();
44 grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
45 factory->CreateResolver(std::move(args));
46 GPR_ASSERT(resolver != nullptr);
47 grpc_uri_destroy(uri);
50 static void test_fails(grpc_core::ResolverFactory* factory,
52 gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
54 grpc_core::ExecCtx exec_ctx;
55 grpc_uri* uri = grpc_uri_parse(string, 0);
57 grpc_core::ResolverArgs args;
59 args.combiner = g_combiner;
61 grpc_core::MakeUnique<grpc_core::Resolver::ResultHandler>();
62 grpc_core::OrphanablePtr<grpc_core::Resolver> resolver =
63 factory->CreateResolver(std::move(args));
64 GPR_ASSERT(resolver == nullptr);
65 grpc_uri_destroy(uri);
68 int main(int argc, char** argv) {
69 grpc::testing::TestEnvironment env(argc, argv);
72 g_combiner = grpc_combiner_create();
74 grpc_core::ResolverFactory* dns =
75 grpc_core::ResolverRegistry::LookupResolverFactory("dns");
77 test_succeeds(dns, "dns:10.2.1.1");
78 test_succeeds(dns, "dns:10.2.1.1:1234");
79 test_succeeds(dns, "dns:www.google.com");
80 test_succeeds(dns, "dns:///www.google.com");
81 grpc_core::UniquePtr<char> resolver =
82 GPR_GLOBAL_CONFIG_GET(grpc_dns_resolver);
83 if (gpr_stricmp(resolver.get(), "native") == 0) {
84 test_fails(dns, "dns://8.8.8.8/8.8.8.8:8888");
86 test_succeeds(dns, "dns://8.8.8.8/8.8.8.8:8888");
89 grpc_core::ExecCtx exec_ctx;
90 GRPC_COMBINER_UNREF(g_combiner, "test");