[svn] commit: r118 - in /branches/f2f200910: ./ src/ src/lib/ src/lib/dns/
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Oct 27 00:09:39 UTC 2009
Author: jinmei
Date: Tue Oct 27 00:09:38 2009
New Revision: 118
Log:
ported minimal sets of name methods for code sprint.
added some test cases with gtest.
Added:
branches/f2f200910/src/lib/dns/buffer.cc
branches/f2f200910/src/lib/dns/buffer.h
branches/f2f200910/src/lib/dns/exceptions.h
Modified:
branches/f2f200910/Makefile.in
branches/f2f200910/configure
branches/f2f200910/configure.ac
branches/f2f200910/src/Makefile.in
branches/f2f200910/src/lib/Makefile.in
branches/f2f200910/src/lib/dns/Makefile.am
branches/f2f200910/src/lib/dns/Makefile.in
branches/f2f200910/src/lib/dns/name.cc
branches/f2f200910/src/lib/dns/name.h
branches/f2f200910/src/lib/dns/name_unittest.cc
Modified: branches/f2f200910/Makefile.in
==============================================================================
--- branches/f2f200910/Makefile.in (original)
+++ branches/f2f200910/Makefile.in Tue Oct 27 00:09:38 2009
@@ -34,8 +34,8 @@
subdir = .
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
- $(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
- depcomp install-sh missing
+ $(top_srcdir)/configure AUTHORS COPYING ChangeLog NEWS depcomp \
+ install-sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -110,9 +110,6 @@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
-CPPUNIT_INCLUDES = @CPPUNIT_INCLUDES@
-CPPUNIT_LDADD = @CPPUNIT_LDADD@
-CPPUNIT_LDFLAGS = @CPPUNIT_LDFLAGS@
CXX = @CXX@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
@@ -125,6 +122,9 @@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
GREP = @GREP@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Modified: branches/f2f200910/configure
==============================================================================
--- branches/f2f200910/configure (original)
+++ branches/f2f200910/configure Tue Oct 27 00:09:38 2009
@@ -595,11 +595,11 @@
am__EXEEXT_TRUE
LTLIBOBJS
LIBOBJS
-CPPUNIT_LDADD
-CPPUNIT_LDFLAGS
-CPPUNIT_INCLUDES
-HAVE_CPPUNIT_FALSE
-HAVE_CPPUNIT_TRUE
+GTEST_LDADD
+GTEST_LDFLAGS
+GTEST_INCLUDES
+HAVE_GTEST_FALSE
+HAVE_GTEST_TRUE
EGREP
GREP
CPP
@@ -691,7 +691,7 @@
ac_user_opts='
enable_option_checking
enable_dependency_tracking
-with_cppunit
+with_gtest
'
ac_precious_vars='build_alias
host_alias
@@ -1326,7 +1326,7 @@
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
- --with-cppunit=PATH specify a path to CppUnit header files (PATH/include) and library (PATH/lib)
+ --with-gtest=PATH specify a path to Gtest header files (PATH/include) and library (PATH/lib)
Some influential environment variables:
CXX C++ compiler command
@@ -4476,32 +4476,32 @@
#
-# Check availablity of CppUnit, which will be used for unit tests.
+# Check availablity of gtest, which might be used for unit tests.
#
-# Check whether --with-cppunit was given.
-if test "${with_cppunit+set}" = set; then :
- withval=$with_cppunit; cppunit_path="$withval"
-else
- cppunit_path="no"
-fi
-
-if test "$cppunit_path" != "no"
+# Check whether --with-gtest was given.
+if test "${with_gtest+set}" = set; then :
+ withval=$with_gtest; gtest_path="$withval"
+else
+ gtest_path="no"
+fi
+
+if test "$gtest_path" != "no"
then
- CPPUNIT_INCLUDES="-I${cppunit_path}/include"
- CPPUNIT_LDFLAGS="-L${cppunit_path}/lib"
- CPPUNIT_LDADD="-lcppunit"
-else
- CPPUNIT_INCLUDES=
- CPPUNIT_LDFLAGS=
- CPPUNIT_LDADD=
-fi
- if test $cppunit_path != "no"; then
- HAVE_CPPUNIT_TRUE=
- HAVE_CPPUNIT_FALSE='#'
-else
- HAVE_CPPUNIT_TRUE='#'
- HAVE_CPPUNIT_FALSE=
+ GTEST_INCLUDES="-I${gtest_path}/include"
+ GTEST_LDFLAGS="-L${gtest_path}/lib"
+ GTEST_LDADD="-lgtest"
+else
+ GTEST_INCLUDES=
+ GTEST_LDFLAGS=
+ GTEST_LDADD=
+fi
+ if test $gtest_path != "no"; then
+ HAVE_GTEST_TRUE=
+ HAVE_GTEST_FALSE='#'
+else
+ HAVE_GTEST_TRUE='#'
+ HAVE_GTEST_FALSE=
fi
@@ -4629,8 +4629,8 @@
as_fn_error "conditional \"am__fastdepCC\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
-if test -z "${HAVE_CPPUNIT_TRUE}" && test -z "${HAVE_CPPUNIT_FALSE}"; then
- as_fn_error "conditional \"HAVE_CPPUNIT\" was never defined.
+if test -z "${HAVE_GTEST_TRUE}" && test -z "${HAVE_GTEST_FALSE}"; then
+ as_fn_error "conditional \"HAVE_GTEST\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
Modified: branches/f2f200910/configure.ac
==============================================================================
--- branches/f2f200910/configure.ac (original)
+++ branches/f2f200910/configure.ac Tue Oct 27 00:09:38 2009
@@ -21,25 +21,25 @@
AC_TYPE_SIZE_T
#
-# Check availablity of CppUnit, which will be used for unit tests.
+# Check availablity of gtest, which might be used for unit tests.
#
-AC_ARG_WITH(cppunit,
-[ --with-cppunit=PATH specify a path to CppUnit header files (PATH/include) and library (PATH/lib)],
- cppunit_path="$withval", cppunit_path="no")
-if test "$cppunit_path" != "no"
+AC_ARG_WITH(gtest,
+[ --with-gtest=PATH specify a path to Gtest header files (PATH/include) and library (PATH/lib)],
+ gtest_path="$withval", gtest_path="no")
+if test "$gtest_path" != "no"
then
- CPPUNIT_INCLUDES="-I${cppunit_path}/include"
- CPPUNIT_LDFLAGS="-L${cppunit_path}/lib"
- CPPUNIT_LDADD="-lcppunit"
+ GTEST_INCLUDES="-I${gtest_path}/include"
+ GTEST_LDFLAGS="-L${gtest_path}/lib"
+ GTEST_LDADD="-lgtest"
else
- CPPUNIT_INCLUDES=
- CPPUNIT_LDFLAGS=
- CPPUNIT_LDADD=
+ GTEST_INCLUDES=
+ GTEST_LDFLAGS=
+ GTEST_LDADD=
fi
-AM_CONDITIONAL(HAVE_CPPUNIT, test $cppunit_path != "no")
-AC_SUBST(CPPUNIT_INCLUDES)
-AC_SUBST(CPPUNIT_LDFLAGS)
-AC_SUBST(CPPUNIT_LDADD)
+AM_CONDITIONAL(HAVE_GTEST, test $gtest_path != "no")
+AC_SUBST(GTEST_INCLUDES)
+AC_SUBST(GTEST_LDFLAGS)
+AC_SUBST(GTEST_LDADD)
# Checks for library functions.
Modified: branches/f2f200910/src/Makefile.in
==============================================================================
--- branches/f2f200910/src/Makefile.in (original)
+++ branches/f2f200910/src/Makefile.in Tue Oct 27 00:09:38 2009
@@ -95,9 +95,6 @@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
-CPPUNIT_INCLUDES = @CPPUNIT_INCLUDES@
-CPPUNIT_LDADD = @CPPUNIT_LDADD@
-CPPUNIT_LDFLAGS = @CPPUNIT_LDFLAGS@
CXX = @CXX@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
@@ -110,6 +107,9 @@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
GREP = @GREP@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Modified: branches/f2f200910/src/lib/Makefile.in
==============================================================================
--- branches/f2f200910/src/lib/Makefile.in (original)
+++ branches/f2f200910/src/lib/Makefile.in Tue Oct 27 00:09:38 2009
@@ -95,9 +95,6 @@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
-CPPUNIT_INCLUDES = @CPPUNIT_INCLUDES@
-CPPUNIT_LDADD = @CPPUNIT_LDADD@
-CPPUNIT_LDFLAGS = @CPPUNIT_LDFLAGS@
CXX = @CXX@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
@@ -110,6 +107,9 @@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
GREP = @GREP@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
Modified: branches/f2f200910/src/lib/dns/Makefile.am
==============================================================================
--- branches/f2f200910/src/lib/dns/Makefile.am (original)
+++ branches/f2f200910/src/lib/dns/Makefile.am Tue Oct 27 00:09:38 2009
@@ -1,17 +1,15 @@
AM_CPPFLAGS = -I$(top_srcdir)/src/lib
lib_LIBRARIES = libdns.a
-libdns_a_SOURCES = name.cc name.h
+libdns_a_SOURCES = name.cc buffer.cc name.h buffer.h
-if HAVE_CPPUNIT
-TEST_PROGRAM = run_unittests
-else
-TEST_PROGRAM =
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = name_unittest.cc
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(GTEST_LDFLAGS)
+run_unittests_LDADD = ./libdns.a $(GTEST_LDADD)
endif
-TESTS = $(TEST_PROGRAM)
-noinst_PROGRAMS = $(TEST_PROGRAM)
-run_unittests_SOURCES = name_unittest.cc name_unittest.h run_unittests.cc
-run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_INCLUDES)
-run_unittests_LDFLAGS = $(CPPUNIT_LDFLAGS)
-run_unittests_LDADD = ./libdns.a $(CPPUNIT_LDADD)
+noinst_PROGRAMS = $(TESTS)
Modified: branches/f2f200910/src/lib/dns/Makefile.in
==============================================================================
--- branches/f2f200910/src/lib/dns/Makefile.in (original)
+++ branches/f2f200910/src/lib/dns/Makefile.in Tue Oct 27 00:09:38 2009
@@ -34,7 +34,8 @@
PRE_UNINSTALL = :
POST_UNINSTALL = :
TESTS = $(am__EXEEXT_1)
-noinst_PROGRAMS = $(am__EXEEXT_1)
+ at HAVE_GTEST_TRUE@am__append_1 = run_unittests
+noinst_PROGRAMS = $(am__EXEEXT_2)
subdir = src/lib/dns
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -72,15 +73,18 @@
ARFLAGS = cru
libdns_a_AR = $(AR) $(ARFLAGS)
libdns_a_LIBADD =
-am_libdns_a_OBJECTS = name.$(OBJEXT)
+am_libdns_a_OBJECTS = name.$(OBJEXT) buffer.$(OBJEXT)
libdns_a_OBJECTS = $(am_libdns_a_OBJECTS)
- at HAVE_CPPUNIT_TRUE@am__EXEEXT_1 = run_unittests$(EXEEXT)
+ at HAVE_GTEST_TRUE@am__EXEEXT_1 = run_unittests$(EXEEXT)
+am__EXEEXT_2 = $(am__EXEEXT_1)
PROGRAMS = $(noinst_PROGRAMS)
-am_run_unittests_OBJECTS = run_unittests-name_unittest.$(OBJEXT) \
- run_unittests-run_unittests.$(OBJEXT)
+am__run_unittests_SOURCES_DIST = name_unittest.cc
+ at HAVE_GTEST_TRUE@am_run_unittests_OBJECTS = \
+ at HAVE_GTEST_TRUE@ run_unittests-name_unittest.$(OBJEXT)
run_unittests_OBJECTS = $(am_run_unittests_OBJECTS)
am__DEPENDENCIES_1 =
-run_unittests_DEPENDENCIES = ./libdns.a $(am__DEPENDENCIES_1)
+ at HAVE_GTEST_TRUE@run_unittests_DEPENDENCIES = ./libdns.a \
+ at HAVE_GTEST_TRUE@ $(am__DEPENDENCIES_1)
run_unittests_LINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) \
$(run_unittests_LDFLAGS) $(LDFLAGS) -o $@
DEFAULT_INCLUDES = -I. at am__isrc@ -I$(top_builddir)
@@ -97,7 +101,7 @@
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(libdns_a_SOURCES) $(run_unittests_SOURCES)
-DIST_SOURCES = $(libdns_a_SOURCES) $(run_unittests_SOURCES)
+DIST_SOURCES = $(libdns_a_SOURCES) $(am__run_unittests_SOURCES_DIST)
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
@@ -114,9 +118,6 @@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
-CPPUNIT_INCLUDES = @CPPUNIT_INCLUDES@
-CPPUNIT_LDADD = @CPPUNIT_LDADD@
-CPPUNIT_LDFLAGS = @CPPUNIT_LDFLAGS@
CXX = @CXX@
CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
@@ -129,6 +130,9 @@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
GREP = @GREP@
+GTEST_INCLUDES = @GTEST_INCLUDES@
+GTEST_LDADD = @GTEST_LDADD@
+GTEST_LDFLAGS = @GTEST_LDFLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
@@ -199,13 +203,11 @@
top_srcdir = @top_srcdir@
AM_CPPFLAGS = -I$(top_srcdir)/src/lib
lib_LIBRARIES = libdns.a
-libdns_a_SOURCES = name.cc name.h
- at HAVE_CPPUNIT_FALSE@TEST_PROGRAM =
- at HAVE_CPPUNIT_TRUE@TEST_PROGRAM = run_unittests
-run_unittests_SOURCES = name_unittest.cc name_unittest.h run_unittests.cc
-run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_INCLUDES)
-run_unittests_LDFLAGS = $(CPPUNIT_LDFLAGS)
-run_unittests_LDADD = ./libdns.a $(CPPUNIT_LDADD)
+libdns_a_SOURCES = name.cc buffer.cc name.h buffer.h
+ at HAVE_GTEST_TRUE@run_unittests_SOURCES = name_unittest.cc
+ at HAVE_GTEST_TRUE@run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+ at HAVE_GTEST_TRUE@run_unittests_LDFLAGS = $(GTEST_LDFLAGS)
+ at HAVE_GTEST_TRUE@run_unittests_LDADD = ./libdns.a $(GTEST_LDADD)
all: all-am
.SUFFIXES:
@@ -289,9 +291,9 @@
distclean-compile:
-rm -f *.tab.c
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/buffer.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/name.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/run_unittests-name_unittest.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/run_unittests-run_unittests.Po at am__quote@
.cc.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -320,20 +322,6 @@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='name_unittest.cc' object='run_unittests-name_unittest.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-name_unittest.obj `if test -f 'name_unittest.cc'; then $(CYGPATH_W) 'name_unittest.cc'; else $(CYGPATH_W) '$(srcdir)/name_unittest.cc'; fi`
-
-run_unittests-run_unittests.o: run_unittests.cc
- at am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-run_unittests.o -MD -MP -MF $(DEPDIR)/run_unittests-run_unittests.Tpo -c -o run_unittests-run_unittests.o `test -f 'run_unittests.cc' || echo '$(srcdir)/'`run_unittests.cc
- at am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/run_unittests-run_unittests.Tpo $(DEPDIR)/run_unittests-run_unittests.Po
- at AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='run_unittests.cc' object='run_unittests-run_unittests.o' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-run_unittests.o `test -f 'run_unittests.cc' || echo '$(srcdir)/'`run_unittests.cc
-
-run_unittests-run_unittests.obj: run_unittests.cc
- at am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT run_unittests-run_unittests.obj -MD -MP -MF $(DEPDIR)/run_unittests-run_unittests.Tpo -c -o run_unittests-run_unittests.obj `if test -f 'run_unittests.cc'; then $(CYGPATH_W) 'run_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/run_unittests.cc'; fi`
- at am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/run_unittests-run_unittests.Tpo $(DEPDIR)/run_unittests-run_unittests.Po
- at AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='run_unittests.cc' object='run_unittests-run_unittests.obj' libtool=no @AMDEPBACKSLASH@
- at AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
- at am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(run_unittests_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o run_unittests-run_unittests.obj `if test -f 'run_unittests.cc'; then $(CYGPATH_W) 'run_unittests.cc'; else $(CYGPATH_W) '$(srcdir)/run_unittests.cc'; fi`
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
Modified: branches/f2f200910/src/lib/dns/name.cc
==============================================================================
--- branches/f2f200910/src/lib/dns/name.cc (original)
+++ branches/f2f200910/src/lib/dns/name.cc Tue Oct 27 00:09:38 2009
@@ -16,22 +16,11 @@
#include <stdexcept>
+#include <dns/buffer.h>
#include <dns/name.h>
using namespace std;
using namespace ISC::DNS;
-
-// quick hack exception classes: should be moved to an appropriate place soon.
-class ISCException {};
-class ISCUnexpected : public ISCException {};
-class ISCNoSpace : public ISCException {};
-
-class DNSException {};
-class DNSEmptyLabel : public DNSException {};
-class DNSLabelTooLong : public DNSException {};
-class DNSBadEscape : public DNSException {};
-class DNSBadLabelType : public DNSException {};
-
typedef enum {
ft_init = 0,
@@ -104,8 +93,8 @@
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
-void
-Name::from_string(const string &namestring)
+Name::Name(const std::string& namestr)
+ : length_(0), labels_(0)
{
char c;
ft_state state;
@@ -129,7 +118,7 @@
// Set up the state machine.
//
pos = 0;
- tlen = namestring.length();
+ tlen = namestr.length();
tused = 0;
nrem = 255;
nused = 0;
@@ -138,7 +127,7 @@
state = ft_init;
while (nrem > 0 && tlen > 0 && !done) {
- c = namestring[pos++];
+ c = namestr[pos++];
tlen--;
tused++;
@@ -272,6 +261,101 @@
offsets_[labels] = nused;
}
}
+
+ labels_ = labels;
+ length_ = nused;
+}
+
+Name::Name(NameDecompressor& decompressor, Buffer& buffer)
+{
+ unsigned int nused, labels, n, nmax;
+ unsigned int current;
+ bool done;
+ fw_state state = fw_start;
+ unsigned int c;
+ bool downcase;
+ bool seen_pointer;
+
+ /*
+ * Initialize things to make the compiler happy; they're not required.
+ */
+ n = 0;
+
+ /*
+ * Set up.
+ */
+ labels = 0;
+ done = false;
+ nused = 0;
+
+ /*
+ * Find the maximum number of uncompressed target name
+ * bytes we are willing to generate. This is the smaller
+ * of the available target buffer length and the
+ * maximum legal domain name length (255).
+ */
+ nmax = MAXWIRE;
+
+ current = buffer.get_current();
+
+ /*
+ * Note: The following code is not optimized for speed, but
+ * rather for correctness. Speed will be addressed in the future.
+ */
+ while (current < buffer.get_size() && !done) {
+ c = buffer.read_uint8();
+ current++;
+
+ switch (state) {
+ case fw_start:
+ if (c < 64) {
+ offsets_.push_back(nused);
+ labels++;
+ if (nused + c + 1 > nmax)
+ full:
+ // The name did not fit even though we had a buffer
+ // big enough to fit a maximum-length name.
+ throw DNSNameTooLong();
+ nused += c + 1;
+ ndata_.push_back(c);
+ if (c == 0)
+ done = true;
+ n = c;
+ state = fw_ordinary;
+ } else if (c >= 128 && c < 192) {
+ /*
+ * 14 bit local compression pointer.
+ * Local compression is no longer an
+ * IETF draft.
+ */
+ throw DNSBadLabelType();
+ } else if (c >= 192) {
+ /*
+ * Ordinary 14-bit pointer.
+ */
+ throw DNSBadLabelType(); // XXX not implemented
+ } else
+ throw DNSBadLabelType();
+ break;
+ case fw_ordinary:
+ if (downcase)
+ c = maptolower[c];
+ /* FALLTHROUGH */
+ case fw_copy:
+ ndata_.push_back(c);
+ n--;
+ if (n == 0)
+ state = fw_start;
+ break;
+ case fw_newcurrent:
+ // XXX not implemented, fall through
+ default:
+ throw ISCUnexpected();
+ }
+ }
+
+ if (!done)
+ throw ISCUnexpected();
labels_ = labels;
length_ = nused;
@@ -391,9 +475,16 @@
return (tdata);
}
+void
+Name::to_wire(Buffer& buffer, NameCompressor& c) const
+{
+ // TBD: very simple version for prototyping; e.g. it omits compression.
+ buffer.write_data(ndata_.c_str(), ndata_.size());
+}
+
// Are 'this' name and 'other' equal?
bool
-Name::operator==(const Name& other) const
+Name::equals(const Name& other) const
{
unsigned int l;
unsigned char c, count;
Modified: branches/f2f200910/src/lib/dns/name.h
==============================================================================
--- branches/f2f200910/src/lib/dns/name.h (original)
+++ branches/f2f200910/src/lib/dns/name.h Tue Oct 27 00:09:38 2009
@@ -20,11 +20,13 @@
#include <string>
#include <vector>
+#include <dns/name.h>
+
namespace ISC {
namespace DNS {
-class Buffer;
-class NameCompressor;
-class NameDecompressor;
+// Define them as an empty class for rapid prototyping
+class NameCompressor {};
+class NameDecompressor {};
class NameComparisonResult {
public:
@@ -51,8 +53,7 @@
class Name {
public:
Name() : length_(0), labels_(0) {}
- explicit Name(const std::string& namestr) : length_(0), labels_(0)
- { from_string(namestr); }
+ explicit Name(const std::string& namestr);
explicit Name(NameDecompressor& decompressor, Buffer& buffer);
// copy constructor (default cp-ctor should work fine)
//Name(const Name& orig);
@@ -67,8 +68,8 @@
Name split(unsigned int first, unsigned int n) const;
Name concatenate(const Name& suffix) const;
bool is_wildcard() const;
- bool operator==(const Name& other) const;
- bool equals(const Name& other) const; // alias of ==
+ bool equals(const Name& other) const;
+ bool operator==(const Name& other) const { return (this->equals(other)); }
bool operator!=(const Name& other) const { return (!(*this == other)); }
bool nequals(const Name& other) const; // alias of !=
bool operator<=(const Name& other) const;
Modified: branches/f2f200910/src/lib/dns/name_unittest.cc
==============================================================================
--- branches/f2f200910/src/lib/dns/name_unittest.cc (original)
+++ branches/f2f200910/src/lib/dns/name_unittest.cc Tue Oct 27 00:09:38 2009
@@ -14,29 +14,80 @@
// $Id$
-#include <string>
+#include <dns/exceptions.h>
+#include <dns/buffer.h>
+#include <dns/name.h>
-#include <cppunit/TestAssert.h>
+#include <gtest/gtest.h>
-#include <dns/name.h>
-#include <dns/name_unittest.h>
+namespace {
using ISC::DNS::Name;
+using ISC::DNS::DNSLabelTooLong;
-void
-NameTest::get_length()
+// The fixture for testing class Name.
+class NameTest : public ::testing::Test {
+protected:
+ NameTest()
+ {
+ example_name =
+ new ISC::DNS::Name("www.example.com");
+ //01234567890123456 => length should be 17.
+ }
+ virtual ~NameTest()
+ {
+ delete example_name;
+ }
+
+ ISC::DNS::Name *example_name;
+};
+
+TEST_F(NameTest, get_length)
{
- Name name("www.example.com");
- //01234567890123456 => length should be 17.
-
- CPPUNIT_ASSERT_EQUAL(17, static_cast<int>(name.get_length()));
+ EXPECT_EQ(17, static_cast<int>(example_name->get_length()));
}
-void
-NameTest::to_text()
+TEST_F(NameTest, to_text)
{
- Name name("www.isc.org");
+ EXPECT_EQ(std::string("www.example.com"), example_name->to_text(true));
+ EXPECT_EQ(std::string("www.example.com."), example_name->to_text(false));
+}
- CPPUNIT_ASSERT_EQUAL(std::string("www.isc.org"), name.to_text(true));
- CPPUNIT_ASSERT_EQUAL(std::string("www.isc.org."), name.to_text(false));
+TEST_F(NameTest, invalid_label)
+{
+ EXPECT_THROW(Name invalidlabel("012345678901234567890123456789"
+ "0123456789012345678901234567890123456789"),
+ DNSLabelTooLong);
}
+
+TEST_F(NameTest, equals)
+{
+ EXPECT_EQ(true, example_name->equals(Name("WWW.EXAMPLE.COM")));
+ EXPECT_EQ(true, example_name->equals(Name("www.example.com.")));
+}
+
+TEST_F(NameTest, operator_equals)
+{
+ EXPECT_EQ(true, *example_name == Name("WWW.EXAMPLE.COM"));
+ EXPECT_EQ(true, *example_name == Name("www.example.com."));
+}
+
+TEST_F(NameTest, to_from_wire)
+{
+ ISC::SingleBuffer buffer;
+ ISC::DNS::NameCompressor compressor;
+ ISC::DNS::NameDecompressor decompressor;
+
+ example_name->to_wire(buffer, compressor);
+
+ Name name2(decompressor, buffer);
+ EXPECT_EQ(true, *example_name == name2);
+}
+}
+
+int
+main(int argc, char* argv[])
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return (RUN_ALL_TESTS());
+}
More information about the bind10-changes
mailing list