rdata_opt_unittest.cc 3.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Copyright (C) 2010  Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

15
#include <util/buffer.h>
16
17
18
19
20
21
22
23
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>

#include <gtest/gtest.h>

24
25
#include <dns/tests/unittest_util.h>
#include <dns/tests/rdata_unittest.h>
26
27
28
29

using isc::UnitTestUtil;
using namespace std;
using namespace isc::dns;
30
using namespace isc::util;
31
32
33
34
35
36
37
38
39
using namespace isc::dns::rdata;

namespace {
class Rdata_OPT_Test : public RdataTest {
    // there's nothing to specialize
};

const generic::OPT rdata_opt;

40
TEST_F(Rdata_OPT_Test, createFromText) {
41
42
43
44
    // OPT RR cannot be created from text.
    EXPECT_THROW(generic::OPT("this does not matter"), InvalidRdataText);
}

45
TEST_F(Rdata_OPT_Test, createFromWire) {
46
47
48
    // Valid cases: in the simple implementation with no supported options,
    // we can only check these don't throw.
    EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass("CLASS4096"),
49
                                         "rdata_opt_fromWire"));
50
    EXPECT_NO_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
51
                                         "rdata_opt_fromWire", 2));
52
53
54

    // short buffer case.
    EXPECT_THROW(rdataFactoryFromFile(RRType::OPT(), RRClass::IN(),
55
                                      "rdata_opt_fromWire", 11),
56
57
58
                 InvalidRdataLength);
}

59
60
61
62
63
64
65
66
TEST_F(Rdata_OPT_Test, createFromLexer) {
    // OPT RR cannot be created from text.
    EXPECT_THROW({
        *test::createRdataUsingLexer(RRType::OPT(), RRClass::IN(),
                                     "this does not matter");
    }, InvalidRdataText);
}

67
TEST_F(Rdata_OPT_Test, toWireBuffer) {
68
69
70
71
    rdata_opt.toWire(obuffer);
    EXPECT_EQ(0, obuffer.getLength());
}

72
TEST_F(Rdata_OPT_Test, toWireRenderer) {
73
74
75
76
    rdata_opt.toWire(renderer);
    EXPECT_EQ(0, obuffer.getLength());
}

77
TEST_F(Rdata_OPT_Test, toText) {
78
79
80
    EXPECT_EQ("", rdata_opt.toText());
}

81
TEST_F(Rdata_OPT_Test, compare) {
82
83
84
    // This simple implementation always returns "true"
    EXPECT_EQ(0, rdata_opt.compare(
                  *rdataFactoryFromFile(RRType::OPT(), RRClass::CH(),
85
                                        "rdata_opt_fromWire", 2)));
86
87
88
89
90

    // comparison attempt between incompatible RR types should be rejected
    EXPECT_THROW(rdata_opt.compare(*RdataTest::rdata_nomatch), bad_cast); 
}
}