Commit 70d50df5 authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

[trac990] gtest tests added for Addr6.

parent d3ef9682
......@@ -20,3 +20,44 @@ check-local:
BIND10_MSGQ_SOCKET_FILE=$(abs_top_builddir)/msgq_socket \
$(PYCOVERAGE_RUN) $(abs_srcdir)/$$pytest || exit ; \
done
AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
AM_CPPFLAGS += -I$(top_builddir)/src/bin # for generated spec_config.h header
AM_CPPFLAGS += -I$(top_srcdir)/src/bin
AM_CPPFLAGS += -I$(top_builddir)/src/lib/cc
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\"
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/testutils/testdata\"
AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
AM_CXXFLAGS = $(B10_CXXFLAGS)
if USE_STATIC_LINK
AM_LDFLAGS = -static
endif
TESTS =
if HAVE_GTEST
TESTS += run_unittests
run_unittests_SOURCES = ../addr6.h ../addr6.cc
run_unittests_SOURCES += ../pkt6.h ../pkt6.cc
run_unittests_SOURCES += ../iface_mgr.h ../iface_mgr.cc
run_unittests_SOURCES += ../dhcp6_srv.h ../dhcp6_srv.cc
run_unittests_SOURCES += addr6_unittest.cc
run_unittests_SOURCES += run_unittests.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
run_unittests_LDADD += $(top_builddir)/src/lib/asiolink/libasiolink.la
run_unittests_LDADD += $(top_builddir)/src/lib/config/libcfgclient.la
run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
run_unittests_LDADD += $(top_builddir)/src/lib/log/liblog.la
endif
noinst_PROGRAMS = $(TESTS)
// Copyright (C) 2011 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 <config.h>
#include <iostream>
#include <sstream>
#include <arpa/inet.h>
#include <gtest/gtest.h>
#include "dhcp6/addr6.h"
using namespace std;
using namespace isc;
class Addr6Test : public ::testing::Test {
public:
Addr6Test() {
}
};
TEST_F(Addr6Test, constructor) {
char buf[16];
string addr1("2001:db8:1::abcd");
inet_pton(AF_INET6, addr1.c_str(), buf);
Addr6 test1(addr1.c_str(), true);
EXPECT_EQ(test1.getPlain(), addr1);
EXPECT_EQ(memcmp(test1.get(),buf, 16), 0);
Addr6 test2(buf, false);
EXPECT_EQ(test2.getPlain(), addr1);
EXPECT_EQ(memcmp(test2.get(),buf, 16), 0);
}
TEST_F(Addr6Test, mcast_linklocal) {
Addr6 mcast("ff00:2001:db8:1::abcd", true);
Addr6 global("2001:db8:1::dead:beef", true);
Addr6 local("fe80::face:b00c", true);
EXPECT_EQ(mcast.multicast(), true);
EXPECT_EQ(mcast.linkLocal(), false);
EXPECT_EQ(global.multicast(), false);
EXPECT_EQ(global.linkLocal(), false);
EXPECT_EQ(local.multicast(), false);
EXPECT_EQ(local.linkLocal(), true);
}
TEST_F(Addr6Test, equal) {
Addr6 one("2001:db8:1::abcd");
Addr6 two("2001:db8:1::abcd");
Addr6 three("2001:db8:1::4321");
EXPECT_EQ( (one==two), true);
EXPECT_EQ( (one==three), false);
}
TEST_F(Addr6Test, stream) {
string plain("2001:db8:1::abcd");
Addr6 addr(plain.c_str(), true);
stringstream tmp;
tmp << addr;
EXPECT_EQ( tmp.str(), plain);
}
// Copyright (C) 2009 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 <stdio.h>
#include <gtest/gtest.h>
#include <log/logger_support.h>
int
main(int argc, char* argv[]) {
::testing::InitGoogleTest(&argc, argv);
isc::log::initLogger();
int result = RUN_ALL_TESTS();
return result;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment