Permalink
Browse files

Use googletest test framework

Change-Id: Ie46887bfd26c861c886df47bf97eff6b9cf32498
Reviewed-on: http://review.couchbase.org/15151
Reviewed-by: Dustin Sallings <dustin@spy.net>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent e069743 commit 4a34fd9ad0f3370933bd7c514dfef9c27bedc76e @trondn trondn committed Apr 24, 2012
Showing with 730 additions and 774 deletions.
  1. +2 −2 .gitignore
  2. +12 −64 Makefile.am
  3. +32 −0 configure.ac
  4. +7 −0 m4/couchbase.m4
  5. +25 −0 tests/cbio_unit_tests.cc
  6. +252 −0 tests/document_unit_tests.cc
  7. +400 −0 tests/instance_unit_tests.cc
  8. +0 −708 tests/testapp.c
View
@@ -16,7 +16,7 @@
/Makefile.in
/aclocal.m4
/autom4te.cache
-/build/
+/cbio_unit_tests.log
/config.cache
/config.log
/config.status
@@ -39,4 +39,4 @@ config.h
config.h.in
core*
stamp-h1
-tests/test_*
+tests/cbio_unit_tests
View
@@ -27,61 +27,19 @@ libcbio_la_SOURCES = src/document.c src/error.c src/instance.c src/internal.h
libcbio_la_LDFLAGS = $(AM_LDFLAGS) -lcouchstore \
-version-info $(LIBCBIO_API_CURRENT):$(LIBCBIO_API_REVISION):$(LIBCBIO_API_AGE) -no-undefined
-check_PROGRAMS = tests/test_open_empty_filename \
- tests/test_create_database tests/test_get_miss \
- tests/test_store_single_document tests/test_get_hit \
- tests/test_delete_document \
- tests/test_delete_nonexistent_document \
- tests/test_get_deleted_document \
- tests/test_bulk_store_documents \
- tests/test_changes_since \
- tests/test_local_documents
+check_PROGRAMS =
-TESTS=${check_PROGRAMS}
-
-tests_test_open_empty_filename_SOURCES = tests/testapp.c
-tests_test_open_empty_filename_DEPENDENCIES = libcbio.la
-tests_test_open_empty_filename_LDFLAGS = libcbio.la
-
-tests_test_create_database_SOURCES = tests/testapp.c
-tests_test_create_database_DEPENDENCIES = libcbio.la
-tests_test_create_database_LDFLAGS = libcbio.la
-
-tests_test_get_hit_SOURCES = tests/testapp.c
-tests_test_get_hit_DEPENDENCIES = libcbio.la
-tests_test_get_hit_LDFLAGS = libcbio.la
-
-tests_test_get_miss_SOURCES = tests/testapp.c
-tests_test_get_miss_DEPENDENCIES = libcbio.la
-tests_test_get_miss_LDFLAGS = libcbio.la
-
-tests_test_store_single_document_SOURCES = tests/testapp.c
-tests_test_store_single_document_DEPENDENCIES = libcbio.la
-tests_test_store_single_document_LDFLAGS = libcbio.la
+if HAVE_GOOGLETEST
+check_PROGRAMS += tests/cbio_unit_tests
+endif
-tests_test_delete_document_SOURCES = tests/testapp.c
-tests_test_delete_document_DEPENDENCIES = libcbio.la
-tests_test_delete_document_LDFLAGS = libcbio.la
-
-tests_test_delete_nonexistent_document_SOURCES = tests/testapp.c
-tests_test_delete_nonexistent_document_DEPENDENCIES = libcbio.la
-tests_test_delete_nonexistent_document_LDFLAGS = libcbio.la
-
-tests_test_get_deleted_document_SOURCES = tests/testapp.c
-tests_test_get_deleted_document_DEPENDENCIES = libcbio.la
-tests_test_get_deleted_document_LDFLAGS = libcbio.la
-
-tests_test_bulk_store_documents_SOURCES = tests/testapp.c
-tests_test_bulk_store_documents_DEPENDENCIES = libcbio.la
-tests_test_bulk_store_documents_LDFLAGS = libcbio.la
-
-tests_test_changes_since_SOURCES = tests/testapp.c
-tests_test_changes_since_DEPENDENCIES = libcbio.la
-tests_test_changes_since_LDFLAGS = libcbio.la
+TESTS=${check_PROGRAMS}
-tests_test_local_documents_SOURCES = tests/testapp.c
-tests_test_local_documents_DEPENDENCIES = libcbio.la
-tests_test_local_documents_LDFLAGS = libcbio.la
+tests_cbio_unit_tests_SOURCES = tests/cbio_unit_tests.cc \
+ tests/document_unit_tests.cc \
+ tests/instance_unit_tests.cc
+tests_cbio_unit_tests_DEPENDENCIES = libcbio.la
+tests_cbio_unit_tests_LDFLAGS = -lgtest libcbio.la
LINTFLAGS=-Iinclude -b -c -errchk=%all \
-erroff=E_INCL_NUSD,E_CAST_INT_TO_SMALL_INT,E_PTRDIFF_OVERFLOW \
@@ -95,17 +53,7 @@ VALGRIND_OPTIONS=--tool=Memcheck --num-callers=50 \
--error-limit=yes --track-origins=yes --malloc-fill=55 \
--free-fill=aa --dsymutil=yes -q
-VALGRIND_TEST=tests/.libs/test_open_empty_filename \
- tests/.libs/test_create_database \
- tests/.libs/test_get_miss \
- tests/.libs/test_store_single_document \
- tests/.libs/test_get_hit \
- tests/.libs/test_delete_document \
- tests/.libs/test_delete_nonexistent_document \
- tests/.libs/test_get_deleted_document \
- tests/.libs/test_bulk_store_documents \
- tests/.libs/test_changes_since \
- tests/.libs/test_local_documents
+VALGRIND_TEST=tests/.libs/cbio_unit_tests
valgrind: ${check_PROGRAMS}
@for f in $(VALGRIND_TEST); \
@@ -132,5 +80,5 @@ reformat:
--align-reference=name \
$(top_srcdir)/include/libcbio/*.[ch] \
$(top_srcdir)/src/*.[ch] \
- $(top_srcdir)/tests/*.[ch]
+ $(top_srcdir)/tests/*.[ch][ch]
View
@@ -20,6 +20,7 @@ AC_CONFIG_SRCDIR([src/internal.h])
AC_CONFIG_AUX_DIR(config)
AC_USE_SYSTEM_EXTENSIONS
AM_INIT_AUTOMAKE(subdir-objects)
+AC_PROG_CXX
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_LN_S
@@ -42,6 +43,25 @@ AC_SUBST(LIBCBIO_API_CURRENT)
AC_SUBST(LIBCBIO_API_REVISION)
AC_SUBST(LIBCBIO_API_AGE)
+AC_CACHE_CHECK([for gtest], [ac_cv_have_gtest], [
+ AC_LANG_PUSH([C++])
+ SAVED_LIBS="$LIBS"
+ LIBS="-lgtest"
+ AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [
+#include "gtest/gtest.h"
+ ],
+ [
+return 0;
+ ])],
+ [ac_cv_have_gtest=yes],
+ [ac_cv_have_gtest=no])
+ AC_LANG_POP([C++])
+ LIBS="$SAVED_LIBS"
+])
+
+AM_CONDITIONAL(HAVE_GOOGLETEST, [test "$ac_cv_have_gtest" = "yes"])
AC_CHECK_HEADERS_ONCE([libcouchstore/couch_common.h])
AS_IF([test "x$ac_cv_header_libcouchstore_couch_common_h" != "xyes"],
@@ -84,3 +104,15 @@ AH_BOTTOM([
dnl ----------------------------------------------------------------------------
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
+AS_IF([test "$ac_cv_have_gtest" != "yes"],
+ [
+ echo "*****"
+ echo "*"
+ echo "* WARNING: I couldn't find the googletest testsuite framework."
+ echo "* This means you cannot run the test suite to verify"
+ echo "* that the library works as expected."
+ echo "* You should consider installing it from:"
+ echo "* http://code.google.com/p/googletest/"
+ echo "*"
+ echo "*****"
+ ])
View
@@ -22,6 +22,13 @@ AC_DEFUN([COUCHBASE_GENERIC_COMPILER], [
[ac_cv_enable_debug="yes"],
[ac_cv_enable_debug="no"])
+ AC_CACHE_CHECK([whether the C++ compiler works], [ac_cv_prog_cxx_works], [
+ AC_LANG_PUSH([C++])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
+ [ac_cv_prog_cxx_works=yes],
+ [ac_cv_prog_cxx_works=no])
+ AC_LANG_POP([C++])])
+
C_LANGUAGE_SPEC=c99
m4_foreach([arg], [$*],
[
View
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ * Copyright 2012 Couchbase, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <gtest/gtest.h>
+
+int main(int argc, char **argv)
+{
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
+
+
Oops, something went wrong.

0 comments on commit 4a34fd9

Please sign in to comment.