summaryrefslogtreecommitdiffstats
path: root/src/lib/dns/tests/rdata_pimpl_holder_unittest.cc
blob: d6395419496fa2642a3aa4ea2a5e96ee32ac94bc (plain)
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
// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <dns/rdata_pimpl_holder.h>

#include <gtest/gtest.h>

using namespace isc::dns::rdata;

namespace {

TEST(RdataPimplHolderTest, all) {
    // Let's check with an integer
    int* i1 = new int(42);
    RdataPimplHolder<int> holder1(i1);
    // The same pointer must be returned.
    EXPECT_EQ(i1, holder1.get());
    // Obviously the value should match too.
    EXPECT_EQ(42, *holder1.get());
    // We don't explicitly delete i or holder1, so it should not leak
    // anything when the test is done (checked by Valgrind).

    // The following cases are similar:

    // Test no-argument reset()
    int* i2 = new int(43);
    RdataPimplHolder<int> holder2(i2);
    holder2.reset();
    EXPECT_EQ(NULL, holder2.get());

    // Test reset() with argument
    int* i3 = new int(44);
    int* i4 = new int(45);
    RdataPimplHolder<int> holder3(i3);
    EXPECT_EQ(i3, holder3.get());
    holder3.reset(i4);
    EXPECT_EQ(i4, holder3.get());
    EXPECT_EQ(45, *holder3.get());

    // Test release()
    RdataPimplHolder<int> holder4(new int(46));
    EXPECT_NE(static_cast<void*>(NULL), holder4.get());
    EXPECT_EQ(46, *holder4.get());
    int* i5 = holder4.release();
    EXPECT_EQ(NULL, holder4.get());
    EXPECT_NE(static_cast<void*>(NULL), i5);
    EXPECT_EQ(46, *i5);
    delete i5;
}

}