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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
// Copyright (C) 2015,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 <dhcp/dhcp6.h>
#include <dhcpsrv/cfg_rsoo.h>
#include <testutils/test_to_element.h>

#include <gtest/gtest.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc;
using namespace isc::dhcp;

namespace {

// This test verifies that the RSOO configuration holds the default
// RSOO-enabled options.
TEST(CfgRSOOTest, defaults) {
    CfgRSOO rsoo;
    EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
    for (uint16_t code = 0; code < 200; ++code) {
        if (code != D6O_ERP_LOCAL_DOMAIN_NAME) {
            EXPECT_FALSE(rsoo.enabled(code))
                << "expected that the option with code "
                << code << " is by default RSOO-disabled, but"
                " it is enabled";
        }
    }

    // Now, let's see if we can remove the default options.
    ASSERT_NO_THROW(rsoo.clear());
    EXPECT_FALSE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));

    // Make sure it can be added again.
    ASSERT_NO_THROW(rsoo.enable(D6O_ERP_LOCAL_DOMAIN_NAME));
    EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
}

// This test verifies that it is possible to enable more RSOO options
// and later remove all of them.
TEST(CfgRSOOTest, enableAndClear) {<--- syntax error
    CfgRSOO rsoo;
    EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));

    // Enable option 88.
    ASSERT_FALSE(rsoo.enabled(88));
    ASSERT_NO_THROW(rsoo.enable(88));
    EXPECT_TRUE(rsoo.enabled(88));

    // Enable option 89.
    ASSERT_FALSE(rsoo.enabled(89));
    ASSERT_NO_THROW(rsoo.enable(89));
    EXPECT_TRUE(rsoo.enabled(89));

    // Remove them and make sure they have been removed.
    ASSERT_NO_THROW(rsoo.clear());
    for (uint16_t code = 0; code < 200; ++code) {
        EXPECT_FALSE(rsoo.enabled(code))
            << "expected that the option with code "
            << code << " is RSOO-disabled after clearing"
            " the RSOO configuration, but it is not";
    }
}

// This test verifies that the same option may be specified
// multiple times and that the code doesn't fail.
TEST(CfgRSOOTest, enableTwice) {
    CfgRSOO rsoo;
    // By default there should be the default option enabled.
    // Let's try to enable it again. It should pass.
    ASSERT_NO_THROW(rsoo.enable(D6O_ERP_LOCAL_DOMAIN_NAME));
    EXPECT_TRUE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));

    // Enable option 88.
    ASSERT_FALSE(rsoo.enabled(88));
    ASSERT_NO_THROW(rsoo.enable(88));
    EXPECT_TRUE(rsoo.enabled(88));

    // And enable it again.
    ASSERT_NO_THROW(rsoo.enabled(88));
    EXPECT_TRUE(rsoo.enabled(88));

    // Remove all.
    ASSERT_NO_THROW(rsoo.clear());
    ASSERT_FALSE(rsoo.enabled(D6O_ERP_LOCAL_DOMAIN_NAME));
    ASSERT_FALSE(rsoo.enabled(88));
}

// This test verifies that the unparse function returns what is expected.
TEST(CfgRSOOTest, unparse) {
    CfgRSOO rsoo;
    // option codes are put in strings
    isc::test::runToElementTest<CfgRSOO>("[ \"65\" ]", rsoo);
    // isc::test::runToElementTest<CfgRSOO>("[ 65 ]", rsoo);
}

} // end of anonymous namespace