Commit f0edd52c authored by Thomas Markwalder's avatar Thomas Markwalder
Browse files

[3186] Initial classes in DHCP user check hook library

Adds new source tree branch, bind10/src/hooks, for maintaining
custom hooks libraries.  Adds bare bones implementation of UserRegistry
for use in custom DHCP hooks library.
parent b080f05c
......@@ -1288,6 +1288,10 @@ AC_CONFIG_FILES([Makefile
src/bin/usermgr/Makefile
src/bin/usermgr/tests/Makefile
src/bin/tests/Makefile
src/hooks/Makefile
src/hooks/dhcp/Makefile
src/hooks/dhcp/user_chk/Makefile
src/hooks/dhcp/user_chk/tests/Makefile
src/lib/Makefile
src/lib/asiolink/Makefile
src/lib/asiolink/tests/Makefile
......
SUBDIRS = lib bin
# hooks lib could be a configurable switch
SUBDIRS += hooks
EXTRA_DIST = \
cppcheck-suppress.lst \
......
SUBDIRS = . tests
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CXXFLAGS = $(B10_CXXFLAGS)
# Some versions of GCC warn about some versions of Boost regarding
# missing initializer for members in its posix_time.
# https://svn.boost.org/trac/boost/ticket/3477
# But older GCC compilers don't have the flag.
AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
# Define rule to build logging source files from message file
# hooks_messages.h hooks_messages.cc: s-messages
# s-messages: hooks_messages.mes
# $(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/lib/hooks/hooks_messages.mes
# touch $@
# Tell automake that the message files are built as part of the build process
# (so that they are built before the main library is built).
# BUILT_SOURCES = hooks_messages.h hooks_messages.cc
BUILT_SOURCES =
# Ensure that the message file is included in the distribution
EXTRA_DIST =
# Get rid of generated message files on a clean
# CLEANFILES = *.gcno *.gcda hooks_messages.h hooks_messages.cc s-messages
CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libdhcp_user_chk.la
libdhcp_user_chk_la_SOURCES =
libdhcp_user_chk_la_SOURCES += load_unload.cc
libdhcp_user_chk_la_SOURCES += user.cc user.h
libdhcp_user_chk_la_SOURCES += user_data_source.cc user_data_source.h
libdhcp_user_chk_la_SOURCES += user_registry.cc user_registry.h
libdhcp_user_chk_la_SOURCES += version.cc
#nodist_libdhcp_user_chk_la_SOURCES = hooks_messages.cc hooks_messages.h
nodist_libdhcp_user_chk_la_SOURCES =
libdhcp_user_chk_la_CXXFLAGS = $(AM_CXXFLAGS)
libdhcp_user_chk_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
libdhcp_user_chk_la_LDFLAGS = $(AM_LDFLAGS)
libdhcp_user_chk_la_LDFLAGS += -avoid-version -export-dynamic -module
libdhcp_user_chk_la_LIBADD =
libdhcp_user_chk_la_LIBADD += $(top_builddir)/src/lib/hooks/libb10-hooks.la
libdhcp_user_chk_la_LIBADD += $(top_builddir)/src/lib/log/libb10-log.la
libdhcp_user_chk_la_LIBADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
libdhcp_user_chk_la_LIBADD += $(top_builddir)/src/lib/util/libb10-util.la
libdhcp_user_chk_la_LIBADD += $(top_builddir)/src/lib/util/threads/libb10-threads.la
if USE_CLANGPP
# Disable unused parameter warning caused by some of the
# Boost headers when compiling with clang.
libdhcp_user_chk_la_CXXFLAGS += -Wno-unused-parameter
endif
// Copyright (C) 2013 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.
// load_unload.cc
#include <hooks/hooks.h>
using namespace isc::hooks;
extern "C" {
int load(LibraryHandle&) {
// @todo instantiate registry here
return (0);
}
int unload() {
// @todo destruct registry here
return (0);
}
}
SUBDIRS = .
AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/hooks/dhcp/user_chk
AM_CPPFLAGS += $(BOOST_INCLUDES) $(BOTAN_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/hooks/dhcp/user_chk/tests\"
AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
# Some versions of GCC warn about some versions of Boost regarding
# missing initializer for members in its posix_time.
# https://svn.boost.org/trac/boost/ticket/3477
# But older GCC compilers don't have the flag.
AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
USER_CHK_LIB = $(top_builddir)/src/hooks/dhcp/user_chk/libdhcp_user_chk.la
if USE_STATIC_LINK
AM_LDFLAGS = -static
endif
CLEANFILES = *.gcno *.gcda
TESTS_ENVIRONMENT = \
$(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
TESTS =
if HAVE_GTEST
TESTS += libdhcp_user_chk_unittests
libdhcp_user_chk_unittests_SOURCES =
libdhcp_user_chk_unittests_SOURCES += ../user.cc ../user.h
libdhcp_user_chk_unittests_SOURCES += ../user_data_source.cc ../user_data_source.h
libdhcp_user_chk_unittests_SOURCES += ../user_registry.cc ../user_registry.h
libdhcp_user_chk_unittests_SOURCES += run_unittests.cc
libdhcp_user_chk_unittests_SOURCES += userid_unittests.cc
libdhcp_user_chk_unittests_SOURCES += user_unittests.cc
libdhcp_user_chk_unittests_SOURCES += user_registry_unittests.cc
libdhcp_user_chk_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) $(LOG4CPLUS_INCLUDES)
libdhcp_user_chk_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
libdhcp_user_chk_unittests_CXXFLAGS = $(AM_CXXFLAGS)
if USE_CLANGPP
# This is to workaround unused variables tcout and tcerr in
# log4cplus's streams.h and unused parameters from some of the
# Boost headers.
libdhcp_user_chk_unittests_CXXFLAGS += -Wno-unused-parameter
endif
libdhcp_user_chk_unittests_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libb10-dhcp++.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
#libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/hooks/dhcp/user_chk/libdhcp_user_chk.la
libdhcp_user_chk_unittests_LDADD += ${BOTAN_LIBS} ${BOTAN_RPATH}
libdhcp_user_chk_unittests_LDADD += $(GTEST_LDADD)
endif
noinst_PROGRAMS = $(TESTS)
// Copyright (C) 2013 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 <log/logger_support.h>
#include <gtest/gtest.h>
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::log::initLogger();
int result = RUN_ALL_TESTS();
return (result);
}
// Copyright (C) 2013 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 <dhcp/hwaddr.h>
#include <exceptions/exceptions.h>
#include <user_registry.h>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
using namespace std;
namespace {
TEST(UserRegistry, constructor) {
UserRegistryPtr reg;
ASSERT_NO_THROW(reg.reset(new UserRegistry()));
}
TEST(UserRegistry, userBasics) {
UserRegistryPtr reg;
ASSERT_NO_THROW(reg.reset(new UserRegistry()));
UserIdPtr id, id2;
// Make user ids.
ASSERT_NO_THROW(id.reset(new UserId(UserId::HW_ADDRESS, "01010101")));
ASSERT_NO_THROW(id2.reset(new UserId(UserId::HW_ADDRESS, "02020202")));
UserPtr user, user2;
// Verify that a blank user cannot be added.
ASSERT_THROW(reg->addUser(user), isc::BadValue);
// Make new users.
ASSERT_NO_THROW(user.reset(new User(*id)));
ASSERT_NO_THROW(user2.reset(new User(*id)));
// Add first user.
ASSERT_NO_THROW(reg->addUser(user));
// Verify user added can be found.
UserPtr found_user;
ASSERT_NO_THROW(found_user = reg->findUser(*id));
EXPECT_TRUE(found_user);
EXPECT_EQ(*id, found_user->getUserId());
// Verify user not added cannot be found.
ASSERT_NO_THROW(found_user = reg->findUser(*id2));
EXPECT_FALSE(found_user);
// Verfiy user can no longer be found.
ASSERT_NO_THROW(reg->removeUser(*id));
ASSERT_NO_THROW(found_user = reg->findUser(*id));
EXPECT_FALSE(found_user);
}
TEST(UserRegistry, findByHWAddr) {
UserRegistryPtr reg;
ASSERT_NO_THROW(reg.reset(new UserRegistry()));
// Make a user.
UserPtr user;
ASSERT_NO_THROW(user.reset(new User(UserId::HW_ADDRESS, "01010101")));
// Verify user can be added.
ASSERT_NO_THROW(reg->addUser(user));
// Make a HWAddr instance using the same id value.
isc::dhcp::HWAddr hwaddr(user->getUserId().getId(),
isc::dhcp::HTYPE_ETHER);
// Verify user can be found by HWAddr.
UserPtr found_user;
ASSERT_NO_THROW(found_user = reg->findUser(hwaddr));
EXPECT_TRUE(found_user);
EXPECT_EQ(user->getUserId(), found_user->getUserId());
}
TEST(UserRegistry, findByDUID) {
UserRegistryPtr reg;
ASSERT_NO_THROW(reg.reset(new UserRegistry()));
// Make a user.
UserPtr user;
ASSERT_NO_THROW(user.reset(new User(UserId::DUID, "01010101")));
// Verify user can be added.
ASSERT_NO_THROW(reg->addUser(user));
// Make a HWAddr instance using the same id value.
isc::dhcp::DUID duid(user->getUserId().getId());
// Verify user can be found by HWAddr.
UserPtr found_user;
ASSERT_NO_THROW(found_user = reg->findUser(duid));
EXPECT_TRUE(found_user);
EXPECT_EQ(user->getUserId(), found_user->getUserId());
}
TEST(UserRegistry, findByClientId) {
UserRegistryPtr reg;
ASSERT_NO_THROW(reg.reset(new UserRegistry()));
// Make a user.
UserPtr user;
ASSERT_NO_THROW(user.reset(new User(UserId::CLIENT_ID, "01010101")));
// Verify user can be added.
ASSERT_NO_THROW(reg->addUser(user));
// Make a HWAddr instance using the same id value.
isc::dhcp::ClientId client_id(user->getUserId().getId());
// Verify user can be found by HWAddr.
UserPtr found_user;
ASSERT_NO_THROW(found_user = reg->findUser(client_id));
EXPECT_TRUE(found_user);
EXPECT_EQ(user->getUserId(), found_user->getUserId());
}
} // end of anonymous namespace
// Copyright (C) 2013 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 <exceptions/exceptions.h>
#include <user.h>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
using namespace std;
namespace {
TEST(UserTest, construction) {
std::string test_address("01FF02AC030B0709");
UserIdPtr id;
ASSERT_NO_THROW(id.reset(new UserId(UserId::HW_ADDRESS, test_address)));
UserPtr user;
// Verify construction from a UserId.
ASSERT_NO_THROW(user.reset(new User(*id)));
// Verify construction from a type and an address vector.
ASSERT_NO_THROW(user.reset(new User(UserId::HW_ADDRESS, id->getId())));
ASSERT_NO_THROW(user.reset(new User(UserId::DUID, id->getId())));
ASSERT_NO_THROW(user.reset(new User(UserId::CLIENT_ID, id->getId())));
// Verify construction from a type and an address string.
ASSERT_NO_THROW(user.reset(new User(UserId::HW_ADDRESS, test_address)));
ASSERT_NO_THROW(user.reset(new User(UserId::DUID, test_address)));
ASSERT_NO_THROW(user.reset(new User(UserId::CLIENT_ID, test_address)));
}
TEST(UserTest, properties) {
UserPtr user;
ASSERT_NO_THROW(user.reset(new User(UserId::DUID, "01020304050607")));
std::string value = "";
EXPECT_NO_THROW(user->setProperty("one","1"));
EXPECT_NO_THROW(value = user->getProperty("one"));
EXPECT_EQ(value, "1");
EXPECT_NO_THROW(user->setProperty("one","1.0"));
EXPECT_NO_THROW(value = user->getProperty("one"));
EXPECT_EQ(value, "1.0");
EXPECT_NO_THROW(user->delProperty("one"));
EXPECT_NO_THROW(value = user->getProperty("one"));
EXPECT_TRUE(value.empty());
EXPECT_THROW(user->setProperty("", "blah"), isc::BadValue);
EXPECT_NO_THROW(user->setProperty("one", ""));
EXPECT_NO_THROW(value = user->getProperty("one"));
EXPECT_TRUE(value.empty());
}
} // end of anonymous namespace
// Copyright (C) 2013 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 <exceptions/exceptions.h>
#include <user.h>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
using namespace std;
namespace {
TEST(UserIdTest, invalidConstructors) {
// Verify that constructor does not allow empty id vector.
std::vector<uint8_t> empty_bytes;
ASSERT_THROW(UserId(UserId::HW_ADDRESS, empty_bytes), isc::BadValue);
ASSERT_THROW(UserId(UserId::DUID, empty_bytes), isc::BadValue);
ASSERT_THROW(UserId(UserId::CLIENT_ID, empty_bytes), isc::BadValue);
// Verify that constructor does not allow empty id string.
ASSERT_THROW(UserId(UserId::HW_ADDRESS, ""), isc::BadValue);
ASSERT_THROW(UserId(UserId::DUID, ""), isc::BadValue);
ASSERT_THROW(UserId(UserId::CLIENT_ID, ""), isc::BadValue);
}
TEST(UserIdTest, hwAddress_type) {
EXPECT_EQ(std::string(UserId::HW_ADDRESS_STR),
UserId::lookupTypeStr(UserId::HW_ADDRESS));
EXPECT_EQ(UserId::HW_ADDRESS,
UserId::lookupType(UserId::HW_ADDRESS_STR));
uint8_t tmp[] = { 0x01, 0xFF, 0x02, 0xAC, 0x03, 0x0B, 0x07, 0x08 };
std::vector<uint8_t> bytes(tmp, tmp + (sizeof(tmp)/sizeof(uint8_t)));
UserIdPtr id;
ASSERT_NO_THROW(id.reset(new UserId(UserId::HW_ADDRESS, bytes)));
EXPECT_EQ(id->getType(), UserId::HW_ADDRESS);
EXPECT_EQ(bytes, id->getId());
// Verify a == b;
UserIdPtr id2;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::HW_ADDRESS, id->toText())));
EXPECT_TRUE(*id == *id2);
EXPECT_FALSE(*id != *id2);
EXPECT_FALSE(*id < *id2);
// Verify a < b;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::HW_ADDRESS,
"01FF02AC030B0709")));
EXPECT_FALSE(*id == *id2);
EXPECT_TRUE(*id != *id2);
EXPECT_TRUE(*id < *id2);
// Verify a > b;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::HW_ADDRESS,
"01FF02AC030B0707")));
EXPECT_FALSE(*id == *id2);
EXPECT_TRUE(*id != *id2);
EXPECT_FALSE(*id < *id2);
}
TEST(UserIdTest, duid_type) {
EXPECT_EQ(std::string(UserId::DUID_STR),
UserId::lookupTypeStr(UserId::DUID));
EXPECT_EQ(UserId::DUID,
UserId::lookupType(UserId::DUID_STR));
uint8_t tmp[] = { 0x01, 0xFF, 0x02, 0xAC, 0x03, 0x0B, 0x07, 0x08 };
std::vector<uint8_t> bytes(tmp, tmp + (sizeof(tmp)/sizeof(uint8_t)));
UserIdPtr id;
ASSERT_NO_THROW(id.reset(new UserId(UserId::DUID, bytes)));
EXPECT_EQ(id->getType(), UserId::DUID);
EXPECT_EQ(bytes, id->getId());
// Verify a == b;
UserIdPtr id2;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::DUID, id->toText())));
EXPECT_TRUE(*id == *id2);
EXPECT_FALSE(*id != *id2);
EXPECT_FALSE(*id < *id2);
// Verify a < b;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::DUID, "01FF02AC030B0709")));
EXPECT_FALSE(*id == *id2);
EXPECT_TRUE(*id != *id2);
EXPECT_TRUE(*id < *id2);
// Verify a > b;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::DUID, "01FF02AC030B0707")));
EXPECT_FALSE(*id == *id2);
EXPECT_TRUE(*id != *id2);
EXPECT_FALSE(*id < *id2);
}
TEST(UserIdTest, client_id_type) {
EXPECT_EQ(std::string(UserId::CLIENT_ID_STR),
UserId::lookupTypeStr(UserId::CLIENT_ID));
EXPECT_EQ(UserId::CLIENT_ID,
UserId::lookupType(UserId::CLIENT_ID_STR));
uint8_t tmp[] = { 0x01, 0xFF, 0x02, 0xAC, 0x03, 0x0B, 0x07, 0x08 };
std::vector<uint8_t> bytes(tmp, tmp + (sizeof(tmp)/sizeof(uint8_t)));
UserIdPtr id;
ASSERT_NO_THROW(id.reset(new UserId(UserId::CLIENT_ID, bytes)));
EXPECT_EQ(id->getType(), UserId::CLIENT_ID);
EXPECT_EQ(bytes, id->getId());
// Verify a == b;
UserIdPtr id2;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::CLIENT_ID, id->toText())));
EXPECT_TRUE(*id == *id2);
EXPECT_FALSE(*id != *id2);
EXPECT_FALSE(*id < *id2);
// Verify a < b;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::CLIENT_ID,
"01FF02AC030B0709")));
EXPECT_FALSE(*id == *id2);
EXPECT_TRUE(*id != *id2);
EXPECT_TRUE(*id < *id2);
// Verify a > b;
ASSERT_NO_THROW(id2.reset(new UserId(UserId::CLIENT_ID,
"01FF02AC030B0707")));
EXPECT_FALSE(*id == *id2);
EXPECT_TRUE(*id != *id2);
EXPECT_FALSE(*id < *id2);
}
TEST(UserIdTest, type_compare) {
UserIdPtr hw, duid, client;
ASSERT_NO_THROW(hw.reset(new UserId(UserId::HW_ADDRESS,
"01FF02AC030B0709")));
ASSERT_NO_THROW(duid.reset(new UserId(UserId::DUID,
"01FF02AC030B0709")));
ASSERT_NO_THROW(client.reset(new UserId(UserId::CLIENT_ID,
"01FF02AC030B0709")));
// Verify that UserIdType influences logical comparators.
EXPECT_NE(*hw, *duid);
EXPECT_NE(*hw , *client);
EXPECT_NE(*duid, *client);
}
} // end of anonymous namespace
// Copyright (C) 2013 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 <dhcp/hwaddr.h>
#include <dhcp/duid.h>