1use crate::tcp::DnsTcpStream;
6use crate::udp::DnsUdpSocket;
7use crate::FuchsiaTime;
8use fuchsia_async as fasync;
9use futures::{Future, FutureExt};
10use trust_dns_proto::error::ProtoError;
11use trust_dns_resolver::name_server::{
12 GenericConnection as Connection, GenericConnectionProvider, RuntimeProvider, Spawn,
13};
14use trust_dns_resolver::AsyncResolver;
15
16#[derive(Clone)]
18pub struct Spawner;
19
20impl Spawn for Spawner {
21 fn spawn_bg<F>(&mut self, future: F)
22 where
23 F: Future<Output = Result<(), ProtoError>> + Send + 'static,
24 {
25 fasync::Task::spawn(future.map(|_| ())).detach()
26 }
27}
28
29#[derive(Clone)]
33pub struct FuchsiaRuntime;
34
35impl RuntimeProvider for FuchsiaRuntime {
36 type Handle = Spawner;
37 type Tcp = DnsTcpStream;
38 type Timer = FuchsiaTime;
39 type Udp = DnsUdpSocket;
40}
41
42pub type ConnectionProvider = GenericConnectionProvider<FuchsiaRuntime>;
44
45pub type Resolver = AsyncResolver<Connection, ConnectionProvider>;
47
48#[cfg(test)]
49mod tests {
50 use crate::FuchsiaExec;
51 use trust_dns_resolver::config::ResolverConfig;
52
53 use super::*;
54
55 #[test]
56 fn test_ip_lookup() {
57 use trust_dns_resolver::testing::ip_lookup_test;
58 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
59 ip_lookup_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner)
60 }
61
62 #[test]
63 fn test_ip_lookup_across_threads() {
64 use trust_dns_resolver::testing::ip_lookup_across_threads_test;
65 ip_lookup_across_threads_test::<FuchsiaExec, FuchsiaRuntime>(Spawner)
66 }
67
68 #[test]
69 fn test_localhost_ipv4() {
70 use trust_dns_resolver::testing::localhost_ipv4_test;
71 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
72 localhost_ipv4_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
73 }
74
75 #[test]
76 fn test_localhost_ipv6() {
77 use trust_dns_resolver::testing::localhost_ipv6_test;
78 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
79 localhost_ipv6_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
80 }
81
82 #[test]
83 fn test_search_ipv4_large_ndots() {
84 use trust_dns_resolver::testing::search_ipv4_large_ndots_test;
85 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
86 search_ipv4_large_ndots_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
87 }
88
89 #[test]
90 fn test_search_ipv6_large_ndots() {
91 use trust_dns_resolver::testing::search_ipv6_large_ndots_test;
92 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
93 search_ipv6_large_ndots_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
94 }
95
96 #[test]
97 fn test_search_ipv6_name_parse_fails() {
98 use trust_dns_resolver::testing::search_ipv6_name_parse_fails_test;
99 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
100 search_ipv6_name_parse_fails_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
101 }
102
103 #[test]
106 #[ignore]
107 fn test_lookup_google() {
108 use trust_dns_resolver::testing::lookup_test;
109 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
110 lookup_test::<FuchsiaExec, FuchsiaRuntime>(ResolverConfig::google(), exec, Spawner)
111 }
112
113 #[test]
116 #[ignore]
117 fn test_lookup_cloudflare() {
118 use trust_dns_resolver::testing::lookup_test;
119 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
120 lookup_test::<FuchsiaExec, FuchsiaRuntime>(ResolverConfig::cloudflare(), exec, Spawner)
121 }
122
123 #[test]
126 #[ignore] fn test_lookup_quad9() {
129 use trust_dns_resolver::testing::lookup_test;
130 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
131 lookup_test::<FuchsiaExec, FuchsiaRuntime>(ResolverConfig::quad9(), exec, Spawner)
132 }
133
134 #[test]
137 #[ignore]
138 fn test_fqdn() {
139 use trust_dns_resolver::testing::fqdn_test;
140 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
141 fqdn_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
142 }
143
144 #[test]
147 #[ignore]
148 fn test_ndots() {
149 use trust_dns_resolver::testing::ndots_test;
150 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
151 ndots_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
152 }
153
154 #[test]
157 #[ignore]
158 fn test_large_ndots() {
159 use trust_dns_resolver::testing::large_ndots_test;
160 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
161 large_ndots_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
162 }
163
164 #[test]
167 #[ignore]
168 fn test_domain_search() {
169 use trust_dns_resolver::testing::domain_search_test;
170 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
171 domain_search_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
172 }
173
174 #[test]
177 #[ignore]
178 fn test_search_list() {
179 use trust_dns_resolver::testing::search_list_test;
180 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
181 search_list_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
182 }
183
184 #[test]
187 #[ignore]
188 fn test_idna() {
189 use trust_dns_resolver::testing::idna_test;
190 let exec = FuchsiaExec::new().expect("failed to create fuchsia executor");
191 idna_test::<FuchsiaExec, FuchsiaRuntime>(exec, Spawner);
192 }
193}