zone_table_segment_unittest.cc 2.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright (C) 2012  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.

#include <datasrc/memory/zone_table_segment.h>
#include <gtest/gtest.h>

using namespace isc::datasrc::memory;
using namespace isc::data;
using namespace isc::util;
using namespace std;

namespace {

25
26
27
28
29
30
class ZoneTableSegmentTest : public ::testing::Test {
protected:
    ZoneTableSegmentTest() :
        config_(Element::fromJSON("{}")),
        segment_(ZoneTableSegment::create((*config_.get())))
    {}
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    ~ZoneTableSegmentTest() {
        if (segment_ != NULL) {
            ZoneTableSegment::destroy(segment_);
        }
    }

    void TearDown() {
        // Catch any future leaks here.
        const MemorySegment& mem_sgmt = segment_->getMemorySegment();
        EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());

        ZoneTableSegment::destroy(segment_);
        segment_ = NULL;
    }

    const ElementPtr config_;
    ZoneTableSegment* segment_;
};
50

51

52
53
54
55
TEST_F(ZoneTableSegmentTest, create) {
    // By default, a local zone table segment is created.
    EXPECT_NE(static_cast<void*>(NULL), segment_);
}
56

57
// Helper function to check const and non-const methods.
58
template <typename TS, typename TH, typename TT>
59
60
61
void
testGetHeader(ZoneTableSegment* segment) {
    TH& header = static_cast<TS*>(segment)->getHeader();
62
63

    // The zone table is unset.
64
    TT* table = header.getTable();
65
66
67
    EXPECT_EQ(static_cast<void*>(NULL), table);
}

68
69
TEST_F(ZoneTableSegmentTest, getHeader) {
    // non-const version.
70
    testGetHeader<ZoneTableSegment, ZoneTableHeader, ZoneTable>(segment_);
71

72
    // const version.
73
74
    testGetHeader<const ZoneTableSegment, const ZoneTableHeader,
                  const ZoneTable>(segment_);
75
76
}

77
TEST_F(ZoneTableSegmentTest, getMemorySegment) {
78
    // This doesn't do anything fun except test the API.
79
    MemorySegment& mem_sgmt = segment_->getMemorySegment();
80
81
82
83
    EXPECT_TRUE(mem_sgmt.allMemoryDeallocated());
}

} // anonymous namespace