Permalink
Browse files

use CppCutter as a testing framework.

  • Loading branch information...
1 parent e948d7e commit 49d332e3c17be3073f792a9d729586321ab4028d @kou kou committed Nov 15, 2009
Showing with 148 additions and 2 deletions.
  1. +3 −1 Makefile.am
  2. +13 −1 configure.ac
  3. +13 −0 test/Makefile.am
  4. +24 −0 test/lib/Makefile.am
  5. +67 −0 test/lib/test-storage-tc.cc
  6. +28 −0 test/run-test.sh
View
@@ -8,4 +8,6 @@
datarootdir = @datarootdir@
# subdirs
-SUBDIRS = src
+SUBDIRS = \
+ src \
+ test
View
@@ -95,6 +95,16 @@ else
fi
AC_MSG_RESULT($enable_memory_allocation_check)
+# Test
+m4_ifdef([AC_CHECK_CPPCUTTER], [
+AC_CHECK_CPPCUTTER
+],
+[ac_cv_use_cppcutter="no"])
+AM_CONDITIONAL([WITH_CUTTER], [test "$ac_cv_use_cppcutter" != "no"])
+if test "$ac_cv_use_cppcutter" != "no"; then
+ AC_DEFINE(WITH_CUTTER, 1, [Define to 1 if you use Cutter])
+fi
+
# pthread options
PTHREAD_DEFS="-pthread -D_REENTRANT -D_THREAD_SAFE"
@@ -110,5 +120,7 @@ AC_CONFIG_FILES([Makefile \
src/lib/Makefile \
src/flared/Makefile \
src/flarei/Makefile \
- src/flarefs/Makefile])
+ src/flarefs/Makefile \
+ test/Makefile \
+ test/lib/Makefile])
AC_OUTPUT
View
@@ -0,0 +1,13 @@
+SUBDIRS = \
+ lib
+
+if WITH_CUTTER
+TESTS = run-test.sh
+TESTS_ENVIRONMENT = NO_MAKE=yes CUTTER="$(CUTTER)"
+endif
+
+EXTRA_DIST = \
+ run-test.sh
+
+echo-cutter:
+ @echo $(CUTTER)
View
@@ -0,0 +1,24 @@
+if WITH_CUTTER
+noinst_LTLIBRARIES = \
+ test-storage-tc.la
+endif
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/src/lib
+
+AM_CXXFLAGS = \
+ $(FLARE_CXXFLAGS) \
+ $(CPPCUTTER_CFLAGS)
+
+AM_LDFLAGS = \
+ -module \
+ -rpath $(libdir) \
+ -avoid-version \
+ $(FLARE_LDFLAGS)
+
+LIBS = \
+ $(top_builddir)/src/lib/libflare.la \
+ $(CPPCUTTER_LIBS)
+
+test_storage_tc_la_SOURCES = test-storage-tc.cc
@@ -0,0 +1,67 @@
+/**
+ * test-storage-tc.cc
+ *
+ * @author Kouhei Sutou <kou@clear-code.com>
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <cppcutter.h>
+
+#include <storage_tch.h>
+
+using namespace std;
+using namespace gree::flare;
+
+namespace test_storage
+{
+ const char tmp_dir[] = "tmp";
+ storage_tch *storage;
+
+ void setup()
+ {
+ const char *db_dir;
+ storage = NULL;
+
+ // db_dir = cut_build_path(tmp_dir, "storage", "tc", NULL);
+ db_dir = tmp_dir;
+ mkdir(db_dir, 0700);
+ string compress("");
+ storage = new storage_tch(db_dir,
+ 32,
+ 4,
+ 131071,
+ 65536,
+ compress,
+ true);
+ storage->open();
+ }
+
+ void teardown()
+ {
+ if (storage)
+ delete storage;
+ cut_remove_path(tmp_dir, NULL);
+ }
+
+ void test_set_and_get()
+ {
+ storage::entry entry;
+ std::string name("Bob");
+ storage::result result;
+ entry.key = "name";
+ entry.size = name.length() + 1;
+ entry.data = gree::flare::shared_byte(new uint8_t(entry.size));
+ memcpy(entry.data.get(), name.c_str(), entry.size);
+ cppcut_assert_equal(0, storage->set(entry, result));
+
+ storage::entry new_entry;
+ new_entry.key = "name";
+ cppcut_assert_equal(0, storage->get(new_entry, result));
+ char actual_name_c_str[new_entry.size];
+ memcpy(actual_name_c_str, new_entry.data.get(), new_entry.size);
+ string actual_name(actual_name_c_str);
+ cppcut_assert_equal(name, actual_name);
+ }
+}
View
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+export BASE_DIR="`dirname $0`"
+top_dir="$BASE_DIR/.."
+
+if test x"$NO_MAKE" != x"yes"; then
+ make -C $top_dir > /dev/null || exit 1
+fi
+
+if test -z "$CUTTER"; then
+ CUTTER="`make -s -C $BASE_DIR echo-cutter`"
+fi
+export CUTTER
+
+CUTTER_ARGS=
+CUTTER_WRAPPER=
+if test x"$CUTTER_DEBUG" = x"yes"; then
+ CUTTER_WRAPPER="$top_dir/libtool --mode=execute gdb --args"
+ CUTTER_ARGS="--keep-opening-modules"
+elif test x"$CUTTER_CHECK_LEAK" = x"yes"; then
+ CUTTER_WRAPPER="$top_dir/libtool --mode=execute valgrind "
+ CUTTER_WRAPPER="$CUTTER_WRAPPER --leak-check=full --show-reachable=yes -v"
+ CUTTER_ARGS="--keep-opening-modules"
+fi
+
+CUTTER_ARGS="$CUTTER_ARGS -s $BASE_DIR"
+
+$CUTTER_WRAPPER $CUTTER $CUTTER_ARGS "$@" $BASE_DIR

0 comments on commit 49d332e

Please sign in to comment.