null+****@clear*****
null+****@clear*****
2011年 11月 9日 (水) 13:23:27 JST
Kouhei Sutou 2011-11-09 04:23:27 +0000 (Wed, 09 Nov 2011)
New Revision: 8f86a8072e2fd7d4dc0c214d048aca77d767b513
Log:
[test][dat] add a test for grn::dat::Array.
Added files:
test/unit/core/dat/Makefile.am
test/unit/core/dat/test-array.cpp
Modified files:
configure.ac
test/unit/core/Makefile.am
Modified: configure.ac (+6 -0)
===================================================================
--- configure.ac 2011-11-09 04:18:06 +0000 (8461df8)
+++ configure.ac 2011-11-09 04:23:27 +0000 (12ad3c8)
@@ -190,6 +190,7 @@ AC_CONFIG_FILES([
test/unit/fixtures/story/rurema/Makefile
test/unit/util/Makefile
test/unit/core/Makefile
+ test/unit/core/dat/Makefile
test/unit/memcached/Makefile
test/unit/http/Makefile
test/unit/gqtp/Makefile
@@ -508,11 +509,16 @@ AC_SUBST(GRNTEST)
# check Cutter with GLib support if available
REQUIRED_MINIMUM_CUTTER_VERSION=1.1.6
+REQUIRED_MINIMUM_CPPCUTTER_VERSION=1.2.0
m4_ifdef([AC_CHECK_GCUTTER],
[AC_CHECK_GCUTTER(>= $REQUIRED_MINIMUM_CUTTER_VERSION)],
[cutter_use_cutter="no"])
+m4_ifdef([AC_CHECK_CPPCUTTER],
+ [AC_CHECK_CPPCUTTER(>= $REQUIRED_MINIMUM_CPPCUTTER_VERSION)],
+ [cutter_use_cppcutter="no"])
AM_CONDITIONAL([WITH_CUTTER], [test "$cutter_use_cutter" = "yes"])
+AM_CONDITIONAL([WITH_CPPCUTTER], [test "$cutter_use_cppcutter" = "yes"])
if test "$cutter_use_cutter" = "yes"; then
AC_DEFINE(WITH_CUTTER, 1, [Define to 1 if you use Cutter])
Modified: test/unit/core/Makefile.am (+3 -0)
===================================================================
--- test/unit/core/Makefile.am 2011-11-09 04:18:06 +0000 (6bb948c)
+++ test/unit/core/Makefile.am 2011-11-09 04:23:27 +0000 (f1bfcf2)
@@ -1,3 +1,6 @@
+SUBDIRS = \
+ dat
+
if WITH_CUTTER
noinst_LTLIBRARIES = \
test-context.la \
Added: test/unit/core/dat/Makefile.am (+26 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/Makefile.am 2011-11-09 04:23:27 +0000 (c8de28d)
@@ -0,0 +1,26 @@
+if WITH_CPPCUTTER
+noinst_LTLIBRARIES = \
+ test-array.la
+endif
+
+INCLUDES = \
+ -I$(top_srcdir)/include \
+ -I$(top_srcdir)/lib \
+ -I$(top_srcdir)/test/unit/lib \
+ $(GROONGA_INCLUDEDIR)
+
+AM_CXXFLAGS = \
+ $(GCUTTER_CFLAGS) \
+ $(CPPCUTTER_CFLAGS) \
+ -DGROONGA=\"$(abs_top_builddir)/src/groonga\"
+
+AM_LDFLAGS = -module -rpath $(libdir) -avoid-version
+
+LIBS = \
+ $(top_builddir)/lib/libgroonga.la \
+ $(GCUTTER_LIBS) \
+ $(CPPCUTTER_LIBS) \
+ $(top_builddir)/test/unit/lib/libgrn-test-utils.la \
+ $(top_builddir)/test/unit/lib/libgrn-test-hash-utils.la
+
+test_array_la_SOURCES = test-array.cpp
Added: test/unit/core/dat/test-array.cpp (+78 -0) 100644
===================================================================
--- /dev/null
+++ test/unit/core/dat/test-array.cpp 2011-11-09 04:23:27 +0000 (62600bb)
@@ -0,0 +1,78 @@
+/* -*- c-basic-offset: 2; coding: utf-8 -*- */
+/*
+ Copyright (C) 2011 Brazil
+ Copyright (C) 2011 Kouhei Sutou <kou****@clear*****>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License version 2.1 as published by the Free Software Foundation.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <gcutter.h>
+#include <cppcutter.h>
+
+#include <grn-assertions.h>
+#include <dat/array.hpp>
+
+namespace test_dat_array
+{
+ void test_assign_with_length(void)
+ {
+ char buf[] = "This is a pen.";
+
+ grn::dat::Array<char> array;
+
+ array.assign(buf, sizeof(buf));
+ cppcut_assert_equal(buf, array.ptr());
+ cppcut_assert_equal(sizeof(buf), static_cast<size_t>(array.size()));
+
+ for (std::size_t i = 0; i < sizeof(buf); ++i) {
+ cppcut_assert_equal(buf[i], array[i]);
+ cppcut_assert_equal(buf[i], static_cast<const grn::dat::Array<char> &>(array)[i]);
+ }
+ cppcut_assert_equal(buf, array.begin());
+ cppcut_assert_equal(buf,
+ static_cast<const grn::dat::Array<char> &>(array).begin());
+ cppcut_assert_equal((buf + sizeof(buf)), array.end());
+ cppcut_assert_equal((buf + sizeof(buf)),
+ static_cast<const grn::dat::Array<char> &>(array).end());
+ }
+
+ void test_assign_without_length(void)
+ {
+ char buf[] = "This is a pen.";
+
+ grn::dat::Array<char> array;
+
+ array.assign(buf);
+ cppcut_assert_equal(buf, array.ptr());
+ cppcut_assert_equal(sizeof(buf), static_cast<size_t>(array.size()));
+ }
+
+ void test_copy(void)
+ {
+ char buf[] = "This is a pen.";
+
+ grn::dat::Array<char> clone(buf);
+ cppcut_assert_equal(buf, clone.ptr());
+ cppcut_assert_equal(sizeof(buf), static_cast<size_t>(clone.size()));
+ }
+
+ void test_copy_with_length(void)
+ {
+ char buf[] = "This is a pen.";
+
+ grn::dat::Array<char> clone(buf, sizeof(buf));
+ cppcut_assert_equal(buf, clone.ptr());
+ cppcut_assert_equal(sizeof(buf), static_cast<size_t>(clone.size()));
+ }
+}