summaryrefslogtreecommitdiffstats
path: root/mDNSResponder/unittests/ResourceRecordTest.c
blob: 3c976c3d0e17c96cf0331dfdf0876e9e09479ebc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "mDNSEmbeddedAPI.h"
#include "../mDNSCore/DNSCommon.h"
#include "ResourceRecordTest.h"

int TXTSetupTest(void);
int ASetupTest(void);
int OPTSetupTest(void);


UNITTEST_HEADER(ResourceRecordTest)
    UNITTEST_TEST(TXTSetupTest)
    UNITTEST_TEST(ASetupTest)
    UNITTEST_TEST(OPTSetupTest)
UNITTEST_FOOTER


UNITTEST_HEADER(TXTSetupTest)

    AuthRecord authRec;
    mDNS_SetupResourceRecord(&authRec, mDNSNULL, mDNSInterface_Any, kDNSType_TXT, kStandardTTL, kDNSRecordTypeShared, AuthRecordAny,mDNSNULL, mDNSNULL);
   // This fails >> UNITTEST_ASSERT_RETURN(authRec.resrec.RecordType == kDNSType_TXT);
    UNITTEST_ASSERT_RETURN(authRec.resrec.rdata->MaxRDLength == sizeof(RDataBody));

    // Retest with a RDataStorage set to a a buffer
UNITTEST_FOOTER


UNITTEST_HEADER(ASetupTest)
    AuthRecord authRec;
    mDNS_SetupResourceRecord(&authRec, mDNSNULL, mDNSInterface_Any, kDNSType_A, kHostNameTTL, kDNSRecordTypeUnique, AuthRecordAny, mDNSNULL, mDNSNULL);

    // This fails >> UNITTEST_ASSERT_RETURN(authRec.resrec.RecordType == kDNSType_A);
    // Add more verifications

UNITTEST_FOOTER


UNITTEST_HEADER(OPTSetupTest)
    AuthRecord opt;
    mDNSu32    updatelease = 7200;
/*  mDNSu8     data[AbsoluteMaxDNSMessageData];
    mDNSu8     *p = data;
    mDNSu16    numAdditionals;
*/
    // Setup the OPT Record
    mDNS_SetupResourceRecord(&opt, mDNSNULL, mDNSInterface_Any, kDNSType_OPT, kStandardTTL, kDNSRecordTypeKnownUnique, AuthRecordAny, mDNSNULL, mDNSNULL);

    // Verify the basic initialization is all ok

    opt.resrec.rrclass    = NormalMaxDNSMessageData;
    opt.resrec.rdlength   = sizeof(rdataOPT);   // One option in this OPT record
    opt.resrec.rdestimate = sizeof(rdataOPT);
    opt.resrec.rdata->u.opt[0].opt           = kDNSOpt_Lease;
    opt.resrec.rdata->u.opt[0].u.updatelease = updatelease;

    // Put the resource record in and verify everything is fine
    // p = PutResourceRecordTTLWithLimit(&data, p, &numAdditionals, &opt.resrec, opt.resrec.rroriginalttl, data + AbsoluteMaxDNSMessageData);


    // Repeat with bad data to make sure it bails out cleanly
UNITTEST_FOOTER