• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "discovery/mdns/testing/mdns_test_util.h"
6 
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
11 namespace openscreen {
12 namespace discovery {
13 
MakeTxtRecord(std::initializer_list<absl::string_view> strings)14 TxtRecordRdata MakeTxtRecord(std::initializer_list<absl::string_view> strings) {
15   std::vector<TxtRecordRdata::Entry> texts;
16   for (const auto& string : strings) {
17     texts.push_back(TxtRecordRdata::Entry(string.begin(), string.end()));
18   }
19   return TxtRecordRdata(std::move(texts));
20 }
21 
GetFakePtrRecord(const DomainName & target,std::chrono::seconds ttl)22 MdnsRecord GetFakePtrRecord(const DomainName& target,
23                             std::chrono::seconds ttl) {
24   DomainName name(++target.labels().begin(), target.labels().end());
25   PtrRecordRdata rdata(target);
26   return MdnsRecord(std::move(name), DnsType::kPTR, DnsClass::kIN,
27                     RecordType::kShared, ttl, std::move(rdata));
28 }
29 
GetFakeSrvRecord(const DomainName & name,std::chrono::seconds ttl)30 MdnsRecord GetFakeSrvRecord(const DomainName& name, std::chrono::seconds ttl) {
31   return GetFakeSrvRecord(name, name, ttl);
32 }
33 
GetFakeSrvRecord(const DomainName & name,const DomainName & target,std::chrono::seconds ttl)34 MdnsRecord GetFakeSrvRecord(const DomainName& name,
35                             const DomainName& target,
36                             std::chrono::seconds ttl) {
37   SrvRecordRdata rdata(0, 0, kFakeSrvRecordPort, target);
38   return MdnsRecord(name, DnsType::kSRV, DnsClass::kIN, RecordType::kUnique,
39                     ttl, std::move(rdata));
40 }
41 
GetFakeTxtRecord(const DomainName & name,std::chrono::seconds ttl)42 MdnsRecord GetFakeTxtRecord(const DomainName& name, std::chrono::seconds ttl) {
43   TxtRecordRdata rdata;
44   return MdnsRecord(name, DnsType::kTXT, DnsClass::kIN, RecordType::kUnique,
45                     ttl, std::move(rdata));
46 }
47 
GetFakeARecord(const DomainName & name,std::chrono::seconds ttl)48 MdnsRecord GetFakeARecord(const DomainName& name, std::chrono::seconds ttl) {
49   ARecordRdata rdata(kFakeARecordAddress);
50   return MdnsRecord(name, DnsType::kA, DnsClass::kIN, RecordType::kUnique, ttl,
51                     std::move(rdata));
52 }
53 
GetFakeAAAARecord(const DomainName & name,std::chrono::seconds ttl)54 MdnsRecord GetFakeAAAARecord(const DomainName& name, std::chrono::seconds ttl) {
55   AAAARecordRdata rdata(kFakeAAAARecordAddress);
56   return MdnsRecord(name, DnsType::kAAAA, DnsClass::kIN, RecordType::kUnique,
57                     ttl, std::move(rdata));
58 }
59 
60 }  // namespace discovery
61 }  // namespace openscreen
62