1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <android-base/strings.h>
18 #include <gtest/gtest.h>
19 #include <resolv_stats_test_utils.h>
20 #include <stats.pb.h>
21
22 namespace android::net {
23
TEST(ResolvStatsUtils,NetworkDnsEventEq)24 TEST(ResolvStatsUtils, NetworkDnsEventEq) {
25 NetworkDnsEventReported event1;
26 // Following fields will not be verified during the test in proto NetworkDnsEventReported.
27 // So don't need to config those values: event_type, return_code, latency_micros,
28 // hints_ai_flags, res_nsend_flags, network_type, private_dns_modes.
29 constexpr char event2[] = R"Event(
30 NetworkDnsEventReported {
31 dns_query_events:
32 {
33 dns_query_event:[
34 {
35 rcode: 3,
36 type: 28,
37 cache_hit: 1,
38 ip_version: 1,
39 protocol: 3,
40 retry_times: 28,
41 dns_server_index: 0,
42 connected: 1,
43 latency_micros: 5,
44 },
45 {
46 rcode: 0,
47 type: 1,
48 cache_hit: 1,
49 ip_version: 1,
50 protocol: 1,
51 retry_times: 56,
52 dns_server_index: 1,
53 connected: 0,
54 latency_micros: 0,
55 }
56 ]
57 }
58 })Event";
59
60 // TODO: Add integration test to verify Level 1 fields of NetworkDnsEventReported.
61 // Level 1 fields, including event_type, return_code, hints_ai_flags, network_type, etc.
62 DnsQueryEvent* dnsQueryEvent1 = event1.mutable_dns_query_events()->add_dns_query_event();
63 dnsQueryEvent1->set_rcode(NS_R_NXDOMAIN);
64 dnsQueryEvent1->set_type(NS_T_AAAA);
65 dnsQueryEvent1->set_cache_hit(CS_NOTFOUND);
66 dnsQueryEvent1->set_ip_version(IV_IPV4);
67 dnsQueryEvent1->set_protocol(PROTO_DOT);
68 dnsQueryEvent1->set_retry_times(28);
69 dnsQueryEvent1->set_dns_server_index(0);
70 dnsQueryEvent1->set_connected(1);
71 dnsQueryEvent1->set_latency_micros(5);
72 DnsQueryEvent* dnsQueryEvent2 = event1.mutable_dns_query_events()->add_dns_query_event();
73 dnsQueryEvent2->set_rcode(NS_R_NO_ERROR);
74 dnsQueryEvent2->set_type(NS_T_A);
75 dnsQueryEvent2->set_cache_hit(CS_NOTFOUND);
76 dnsQueryEvent2->set_ip_version(IV_IPV4);
77 dnsQueryEvent2->set_protocol(PROTO_UDP);
78 dnsQueryEvent2->set_retry_times(56);
79 dnsQueryEvent2->set_dns_server_index(1);
80 dnsQueryEvent2->set_connected(0);
81 dnsQueryEvent2->set_latency_micros(5);
82 EXPECT_THAT(event1, NetworkDnsEventEq(fromNetworkDnsEventReportedStr(event2)));
83 }
84
85 } // namespace android::net
86