2 * Copyright (c) 2017-2018 Apple Inc. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "mDNSEmbeddedAPI.h"
18 #include "DNSCommon.h"
19 #import <XCTest/XCTest.h>
21 @interface ResourceRecordTest : XCTestCase
26 @implementation ResourceRecordTest
39 mDNS_SetupResourceRecord(&authRec, mDNSNULL, mDNSInterface_Any, kDNSType_TXT, kStandardTTL, kDNSRecordTypeShared, AuthRecordAny,mDNSNULL, mDNSNULL);
40 XCTAssertEqual(authRec.resrec.rrtype, kDNSType_TXT);
41 XCTAssertEqual(authRec.resrec.RecordType, kDNSRecordTypeShared);
42 XCTAssertEqual(authRec.resrec.rdata->MaxRDLength, sizeof(RDataBody));
48 mDNS_SetupResourceRecord(&authRec, mDNSNULL, mDNSInterface_Any, kDNSType_A, kHostNameTTL, kDNSRecordTypeUnique, AuthRecordAny, mDNSNULL, mDNSNULL);
50 XCTAssertEqual(authRec.resrec.rrtype, kDNSType_A);
51 XCTAssertEqual(authRec.resrec.RecordType, kDNSRecordTypeUnique);
52 // Add more verifications
58 mDNSu32 updatelease = 7200;
60 // Setup the OPT Record
61 mDNS_SetupResourceRecord(&opt, mDNSNULL, mDNSInterface_Any, kDNSType_OPT, kStandardTTL, kDNSRecordTypeKnownUnique, AuthRecordAny, mDNSNULL, mDNSNULL);
63 // Verify the basic initialization is all ok
65 opt.resrec.rrclass = NormalMaxDNSMessageData;
66 opt.resrec.rdlength = sizeof(rdataOPT); // One option in this OPT record
67 opt.resrec.rdestimate = sizeof(rdataOPT);
68 opt.resrec.rdata->u.opt[0].opt = kDNSOpt_Lease;
69 opt.resrec.rdata->u.opt[0].u.updatelease = updatelease;
71 // Put the resource record in and verify everything is fine
73 mDNSu8 data[AbsoluteMaxDNSMessageData];
75 mDNSu16 numAdditionals;
77 p = PutResourceRecordTTLWithLimit((DNSMessage*)&data, p, &numAdditionals, &opt.resrec, opt.resrec.rroriginalttl, data + AbsoluteMaxDNSMessageData);
81 // Repeat with bad data to make sure it bails out cleanly
84 - (void)testPerformanceExample {
85 // This is an example of a performance test case.
87 // Put the code you want to measure the time of here.