Author: brane
Date: Thu Jul 11 16:40:45 2013
New Revision: 1502282
URL: http://svn.apache.org/r1502282
Log:
Reintegrate the gtest_addition branch to trunk and convert the result to
use Googlemock and begin writing a Googlemock/Googletest-based test suite
for C++HL.
* .: Ignore gmock-fused instead of gtest.
* INSTALL: Note optional dependency on Googlemock.
* get-deps.sh: Rename all getst to gmock and implement Googlemock downloader.
* build.conf (cxxhl-tests): Depend on libgmock and make conditional.
(libgmock): New target.
* configure.ac: Check for Googlemock.
(GMOCK_SRCDIR, SVN_USE_GMOCK): New substituted variables.
* Makefile.in (SVN_USE_GMOCK, GMOCK_INCLUDES, CNOWARNFLAGS, CXXNOWARNFLAGS):
Expand configure variables.
(COMPILE_NOWARN, COMPILE_CXX_NOWARN, LT_COMPILE_CXX_NOWARN):
New generic compilation rules.
(COMPILE_CXXHL_CXX): Rewrite in terms of LT_COMPILE_CXX.
(COMPILE_GMOCK_CXX, COMPILE_CXXHL_GMOCK_CXX): New rules.
* gen-make.py: Add placeholder for --disable-gmock option.
* build/generator/gen_base.py (TargetLinked): Make .cc a source file extension.
* doc/programmer/gtest-guide.txt: New.
* subversion/bindings/cxxhl/tests/cxxhl-tests.cpp,
subversion/bindings/cxxhl/tests/test_aprwrap.cpp: New test suite files.
* subversion/bindings/cxxhl/tests/test_exception.cpp: Temporarily disable.
* tools/dist/make-deps-tarball.sh:
Mergeinfo was updated as a side effect of the merge.
Added:
subversion/trunk/doc/programmer/gtest-guide.txt (contents, props changed)
- copied, changed from r1502138,
subversion/branches/gtest_addition/doc/programmer/gtest-guide.txt
subversion/trunk/subversion/bindings/cxxhl/tests/cxxhl-tests.cpp (with
props)
subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp (with
props)
Modified:
subversion/trunk/ (props changed)
subversion/trunk/INSTALL
subversion/trunk/Makefile.in
subversion/trunk/build.conf
subversion/trunk/build/generator/gen_base.py
subversion/trunk/configure.ac
subversion/trunk/gen-make.py
subversion/trunk/get-deps.sh
subversion/trunk/subversion/bindings/cxxhl/tests/test_exception.cpp
subversion/trunk/tools/dist/make-deps-tarball.sh (props changed)
Propchange: subversion/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Jul 11 16:40:45 2013
@@ -49,7 +49,7 @@ mkmf.log
zlib
sqlite-amalgamation
serf
-gtest
+gmock-fused
.git
.gitignore
compile_commands.json
Propchange: subversion/trunk/
------------------------------------------------------------------------------
Merged /subversion/branches/gtest_addition:r1452117-1502138
Modified: subversion/trunk/INSTALL
URL:
http://svn.apache.org/viewvc/subversion/trunk/INSTALL?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/INSTALL (original)
+++ subversion/trunk/INSTALL Thu Jul 11 16:40:45 2013
@@ -153,6 +153,12 @@ I. INTRODUCTION
configured via auto-props or the mime-types-file option
take precedence.
+ * Googlemock aka Gmock (OPTIONAL)
+
+ This optional package is used by the tests for Subversions'
+ C++ bindings.
+
+
C. Dependencies in Detail
Subversion depends on a number of third party tools and libraries.
@@ -568,6 +574,12 @@ I. INTRODUCTION
--with-libmagic
+ 22. Googlemock (OPTIONAL)
+
+ Googlemock can be installed and built in-tree by invoking
+
+ $ ./get-dep.sh gmock
+
D. Documentation
The primary documentation for Subversion is the free book
Modified: subversion/trunk/Makefile.in
URL:
http://svn.apache.org/viewvc/subversion/trunk/Makefile.in?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/Makefile.in (original)
+++ subversion/trunk/Makefile.in Thu Jul 11 16:40:45 2013
@@ -131,6 +131,9 @@ APACHE_INCLUDES = @APACHE_INCLUDES@
APACHE_LIBEXECDIR = $(DESTDIR)@APACHE_LIBEXECDIR@
APACHE_LDFLAGS = @APACHE_LDFLAGS@
+SVN_USE_GMOCK = @SVN_USE_GMOCK@
+GMOCK_INCLUDES = -I@GMOCK_SRCDIR@
+
SWIG = @SWIG@
SWIG_PY_INCLUDES = @SWIG_PY_INCLUDES@ -I$(SWIG_SRC_DIR)/python/libsvn_swig_py
SWIG_PY_COMPILE = @SWIG_PY_COMPILE@
@@ -166,9 +169,11 @@ DOXYGEN = @DOXYGEN@
# The EXTRA_ parameters can be used to pass extra flags at 'make' time.
CFLAGS = @CFLAGS@ $(EXTRA_CFLAGS)
CMODEFLAGS = @CMODEFLAGS@
+CNOWARNFLAGS = @CNOWARNFLAGS@
CMAINTAINERFLAGS = @CMAINTAINERFLAGS@
CXXFLAGS = @CXXFLAGS@ $(EXTRA_CXXFLAGS)
CXXMODEFLAGS = @CXXMODEFLAGS@
+CXXNOWARNFLAGS = @CXXNOWARNFLAGS@
CXXMAINTAINERFLAGS = @CXXMAINTAINERFLAGS@
### A few of the CFLAGS (e.g. -Wmissing-prototypes, -Wstrict-prototypes,
### -Wmissing-declarations) are not valid for C++, and should be somehow
@@ -178,10 +183,12 @@ LDFLAGS = @LDFLAGS@ $(EXTRA_LDFLAGS)
SWIG_LDFLAGS = @SWIG_LDFLAGS@ $(EXTRA_SWIG_LDFLAGS)
COMPILE = $(CC) $(CMODEFLAGS) $(CPPFLAGS) $(CMAINTAINERFLAGS) $(CFLAGS)
$(INCLUDES)
+COMPILE_NOWARN = $(CC) $(CMODEFLAGS) $(CPPFLAGS) $(CNOWARNFLAGS) $(CFLAGS)
$(INCLUDES)
COMPILE_CXX = $(CXX) $(CXXMODEFLAGS) $(CPPFLAGS) $(CXXMAINTAINERFLAGS)
$(CXXFLAGS) $(INCLUDES)
+COMPILE_CXX_NOWARN = $(CXX) $(CXXMODEFLAGS) $(CPPFLAGS) $(CXXNOWARNFLAGS)
$(CXXFLAGS) $(INCLUDES)
LT_COMPILE = $(LIBTOOL) $(LTFLAGS) --mode=compile $(COMPILE) $(LT_CFLAGS)
LT_COMPILE_CXX = $(LIBTOOL) $(LTCXXFLAGS) --mode=compile $(COMPILE_CXX)
$(LT_CFLAGS)
-
+LT_COMPILE_CXX_NOWARN = $(LIBTOOL) $(LTCXXFLAGS) --mode=compile
$(COMPILE_CXX_NOWARN) $(LT_CFLAGS)
# Execute a command that loads libraries from the build dir
LT_EXECUTE = $(LIBTOOL) $(LTFLAGS) --mode=execute `for f in
$(abs_builddir)/subversion/*/*.la; do echo -dlopen $$f; done`
@@ -199,7 +206,9 @@ COMPILE_JAVAHL_JAVAC = $(JAVAC) $(JAVAC_
COMPILE_JAVAHL_JAVAH = $(JAVAH)
# special compilation for files destined for cxxhl
-COMPILE_CXXHL_CXX = $(LIBTOOL) $(LTCXXFLAGS) --mode=compile $(COMPILE_CXX)
$(LT_CFLAGS) $(CXXHL_INCLUDES) -o $@ -c
+COMPILE_CXXHL_CXX = $(LT_COMPILE_CXX) $(CXXHL_INCLUDES) -o $@ -c
+COMPILE_GMOCK_CXX = $(LT_COMPILE_CXX_NOWARN) $(GMOCK_INCLUDES) -o $@ -c
+COMPILE_CXXHL_GMOCK_CXX = $(LT_COMPILE_CXX) $(CXXHL_INCLUDES)
$(GMOCK_INCLUDES) -o $@ -c
LINK = $(LIBTOOL) $(LTFLAGS) --mode=link $(CC) $(LT_LDFLAGS) $(CFLAGS)
$(LDFLAGS) -rpath $(libdir)
LINK_LIB = $(LINK) $(LT_SO_VERSION)
Modified: subversion/trunk/build.conf
URL:
http://svn.apache.org/viewvc/subversion/trunk/build.conf?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/build.conf (original)
+++ subversion/trunk/build.conf Thu Jul 11 16:40:45 2013
@@ -424,7 +424,6 @@ type = sql-header
path = subversion/libsvn_subr
sources = internal_statements.sql
-
# ----------------------------------------------------------------------------
#
# TARGETS FOR I18N SUPPORT
@@ -676,14 +675,31 @@ link-cmd = $(LINK_CXX_LIB)
[cxxhl-tests]
description = Unit tests for Subversion C++ HighLevel bindings
+when = SVN_USE_GMOCK
type = exe
path = subversion/bindings/cxxhl
-libs = libsvncxxhl libsvn_subr
+libs = libsvncxxhl libgmock libsvn_subr
sources = tests/*.cpp
install = tests
-compile-cmd = $(COMPILE_CXXHL_CXX)
+compile-cmd = $(COMPILE_CXXHL_GMOCK_CXX)
link-cmd = $(LINK_CXX)
+
+# ----------------------------------------------------------------------------
+#
+# Gmock targets
+#
+
+[libgmock]
+description = Googlemock Library
+when = SVN_USE_GMOCK
+type = lib
+path = gmock-fused
+sources = gmock-gtest-all.cc
+install = tests
+compile-cmd = $(COMPILE_GMOCK_CXX)
+link-cmd = $(LINK_CXX_LIB)
+
# ----------------------------------------------------------------------------
#
# TESTING TARGETS
Modified: subversion/trunk/build/generator/gen_base.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/build/generator/gen_base.py?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/build/generator/gen_base.py (original)
+++ subversion/trunk/build/generator/gen_base.py Thu Jul 11 16:40:45 2013
@@ -473,6 +473,8 @@ class TargetLinked(Target):
if glob.glob(src):
if src[-2:] == '.c':
objname = src[:-2] + self.objext
+ elif src[-3:] == '.cc':
+ objname = src[:-3] + self.objext
elif src[-4:] == '.cpp':
objname = src[:-4] + self.objext
else:
Modified: subversion/trunk/configure.ac
URL:
http://svn.apache.org/viewvc/subversion/trunk/configure.ac?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/configure.ac (original)
+++ subversion/trunk/configure.ac Thu Jul 11 16:40:45 2013
@@ -628,6 +628,28 @@ fi
AC_SUBST(SVN_GNOME_KEYRING_INCLUDES)
AC_SUBST(SVN_GNOME_KEYRING_LIBS)
+dnl Googlemock -----------------
+AC_ARG_ENABLE([gmock],
+ AS_HELP_STRING([--disable-gmock],
+ [Do not use the Googlemock testing framework]),
+ [enable_gmock=yes],
+ [enable_gmock="$withval"])
+
+AC_SUBST([GMOCK_SRCDIR], [$abs_srcdir/gmock-fused])
+AC_MSG_CHECKING([whether use Googlemock])
+if test "$enable_gmock" != "no"; then
+ if test -d "$GMOCK_SRCDIR"; then
+ AC_MSG_RESULT([yes])
+ SVN_USE_GMOCK=true
+ else
+ AC_MSG_RESULT([no])
+ SVN_USE_GMOCK=false
+ fi
+else
+ AC_MSG_RESULT([no])
+ SVN_USE_GMOCK_SOURCES=false
+fi
+AC_SUBST([SVN_USE_GMOCK])
dnl Ev2 experimental features ----------------------
dnl Note: The Ev2 implementations will be built unconditionally, but by
Copied: subversion/trunk/doc/programmer/gtest-guide.txt (from r1502138,
subversion/branches/gtest_addition/doc/programmer/gtest-guide.txt)
URL:
http://svn.apache.org/viewvc/subversion/trunk/doc/programmer/gtest-guide.txt?p2=subversion/trunk/doc/programmer/gtest-guide.txt&p1=subversion/branches/gtest_addition/doc/programmer/gtest-guide.txt&r1=1502138&r2=1502282&rev=1502282&view=diff
==============================================================================
--- subversion/branches/gtest_addition/doc/programmer/gtest-guide.txt (original)
+++ subversion/trunk/doc/programmer/gtest-guide.txt Thu Jul 11 16:40:45 2013
@@ -1,53 +1,30 @@
-Googletest Suite for Subversion
----------------------------------
+Googlemock and Googletest Suite for Subversion
+---------------------------------------------
-0. Introduction
-1. Setting up
-2. Literature
-3. Example test case
+Googlemock and Googletest are external packages that are downloaded
+and compiled on request, as part of regular compilations.
-0. Introduction
-----------------
-Googletest is an external package that is downloaded and
-compiled on request, as part of a regular compilations.
+Googlemock is available here:
-From the Googletest Project page:
-"Google's framework for writing C++ tests on a variety of platforms
-(Linux, Mac OS X, Windows, Cygwin, Windows CE, and Symbian). Based on
-the xUnit architecture. Supports automatic test discovery, a rich set
-of assertions, user-defined assertions, death tests, fatal and
-non-fatal failures, value- and type-parameterized tests, various
-options for running the tests, and XML test report generation."
+ https://code.google.com/p/googlemock/
-1. Setting up
---------------
+The source packages already include Googletest, which is available
+here:
-To configure Subversion to use Googletest, type
+ https://code.google.com/p/googletest/
-./get-dep.sh gtest
-./autogen.sh
-./configure --enable-gtest <your other options here>
+Subversion uses Googlemock and Googletest for the C++HL test suite.
-this sets up gtest in the /trunk/libgtest directory.
-Note that currently autogen.sh issues header warnings and the
-configure script prints spurious errormessages of the form ""the
-option --enable-gtest is not recognised."
-Please ignore them, this does not interfere with the functionality of
-Googletest at all, and everything is being installed correctly.
+To configure Subversion to use Googlemock, type
+ ./get-dep.sh gmock
-2. Literature
--------------
+This will download Googlemock and put the fused source into the
+'gmock-fused' directory. Once it's there, configure will pick it up
+automatically (but you do have to re-run autogen.sh and configure).
-Googletest homepage:
-http://code.google.com/p/googletest/
-
-Short tutorial and cheatsheet:
-http://www.ibm.com/developerworks/aix/library/au-googletestingframework.html
-
-3. Simple example test case
-----------------------------
-
-Please see subversion/bindings/cxxhl/gtests/* for a sample set up.
+You can disable building Googlemock (and hence the C++HL test suite)
+with the --disable-gmock configure option. This will tell configure to
+ignore the gmock-fused directory.
Propchange: subversion/trunk/doc/programmer/gtest-guide.txt
------------------------------------------------------------------------------
svn:eol-style = native
Modified: subversion/trunk/gen-make.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/gen-make.py?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/gen-make.py (original)
+++ subversion/trunk/gen-make.py Thu Jul 11 16:40:45 2013
@@ -214,6 +214,8 @@ def _usage_exit(err=None):
print("")
print(" --with-apr_memcache=DIR")
print(" the apr_memcache sources are in DIR")
+ print(" --disable-gmock")
+ print(" do not use Googlemock")
sys.exit(1)
@@ -262,7 +264,7 @@ if __name__ == '__main__':
'disable-shared',
'installed-libs=',
'vsnet-version=',
-
+ 'disable-gmock',
# Keep distributions that help by adding a path
# working. On unix this would be filtered by
# configure, but on Windows gen-make.py is used
Modified: subversion/trunk/get-deps.sh
URL:
http://svn.apache.org/viewvc/subversion/trunk/get-deps.sh?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/get-deps.sh (original)
+++ subversion/trunk/get-deps.sh Thu Jul 11 16:40:45 2013
@@ -36,7 +36,7 @@ APU_VERSION=${APU_VERSION:-"1.5.1"}
SERF_VERSION=${SERF_VERSION:-"1.2.1"}
ZLIB_VERSION=${ZLIB_VERSION:-"1.2.8"}
SQLITE_VERSION=${SQLITE_VERSION:-"3.7.15.1"}
-GTEST_VERSION=${GTEST_VERSION:-"1.6.0"}
+GMOCK_VERSION=${GMOCK_VERSION:-"1.6.0"}
HTTPD_VERSION=${HTTPD_VERSION:-"2.4.3"}
APR_ICONV_VERSION=${APR_ICONV_VERSION:-"1.2.1"}
@@ -46,8 +46,8 @@ SERF=serf-${SERF_VERSION}
ZLIB=zlib-${ZLIB_VERSION}
SQLITE_VERSION_LIST=`echo $SQLITE_VERSION | sed -e 's/\./ /g'`
SQLITE=sqlite-amalgamation-`printf %d%02d%02d%02d $SQLITE_VERSION_LIST`
-GTEST=gtest-${GTEST_VERSION}
-GTEST_URL=http://googletest.googlecode.com/files/
+GMOCK=gmock-${GMOCK_VERSION}
+GMOCK_URL=https://googlemock.googlecode.com/files/
HTTPD=httpd-${HTTPD_VERSION}
APR_ICONV=apr-iconv-${APR_ICONV_VERSION}
@@ -67,7 +67,7 @@ APACHE_MIRROR=http://archive.apache.org/
# helpers
usage() {
echo "Usage: $0"
- echo "Usage: $0 [ apr | serf | zlib | sqlite | gtest ] ..."
+ echo "Usage: $0 [ apr | serf | zlib | sqlite | gmock ] ..."
exit $1
}
@@ -122,23 +122,24 @@ get_sqlite() {
}
-get_gtest() {
- test -d $BASEDIR/gtest && return
+get_gmock() {
+ test -d $BASEDIR/gmock-fused && return
cd $TEMPDIR
- $HTTP_FETCH ${GTEST_URL}/${GTEST}.zip
+ $HTTP_FETCH ${GMOCK_URL}/${GMOCK}.zip
cd $BASEDIR
- unzip -q $TEMPDIR/$GTEST.zip
+ unzip -q $TEMPDIR/$GMOCK.zip
- mv $GTEST gtest
+ mv $GMOCK/fused-src gmock-fused
+ rm -fr $GMOCK
}
# main()
get_deps() {
mkdir -p $TEMPDIR
- for i in zlib serf sqlite-amalgamation apr apr-util gtest; do
+ for i in zlib serf sqlite-amalgamation apr apr-util gmock-fused; do
if [ -d $i ]; then
echo "Local directory '$i' already exists; the downloaded copy won't
be used" >&2
fi
Added: subversion/trunk/subversion/bindings/cxxhl/tests/cxxhl-tests.cpp
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/tests/cxxhl-tests.cpp?rev=1502282&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/tests/cxxhl-tests.cpp (added)
+++ subversion/trunk/subversion/bindings/cxxhl/tests/cxxhl-tests.cpp Thu Jul 11
16:40:45 2013
@@ -0,0 +1,46 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 <cstdlib>
+#include <iostream>
+
+#include <apr_errno.h>
+#include <apr_general.h>
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv)
+{
+ apr_status_t status = apr_initialize();
+ if (status)
+ {
+ char errbuf[512];
+ std::cerr << "APR initialization failed: "
+ << apr_strerror(status, errbuf, sizeof(errbuf) - 1)
+ << std::endl;
+ return 7;
+ }
+ std::atexit(apr_terminate);
+
+ testing::InitGoogleMock(&argc, argv);
+ return RUN_ALL_TESTS();
+}
Propchange: subversion/trunk/subversion/bindings/cxxhl/tests/cxxhl-tests.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp?rev=1502282&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp (added)
+++ subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp Thu Jul
11 16:40:45 2013
@@ -0,0 +1,415 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 <algorithm>
+#include <stdexcept>
+
+#include "../src/aprwrap.hpp"
+
+#include <gmock/gmock.h>
+
+//
+// Pools
+//
+
+TEST(Pools, InitializeGlobalPool)
+{
+ APR::Pool pool;
+ EXPECT_THAT(pool.get(), testing::NotNull());
+ EXPECT_THAT(apr_pool_parent_get(pool.get()), testing::NotNull());
+}
+
+TEST(Pools, CreateSubpool)
+{
+ APR::Pool pool;
+ APR::Pool subpool(&pool);
+ EXPECT_EQ(pool.get(), apr_pool_parent_get(subpool.get()));
+}
+
+TEST(Pools, TypedAllocate)
+{
+ APR::Pool pool;
+ const unsigned char* buffer = pool.alloc<unsigned char>(1);
+ EXPECT_THAT(buffer, testing::NotNull());
+}
+
+// N.B.: This test may pass randomly even if zero-filled allocation
+// does not work correctly, since we cannot make assumptions about the
+// values of uninitialized memory.
+TEST(Pools, TypedAllocateZerofill)
+{
+ APR::Pool pool;
+ static const std::size_t size = 32757;
+ const unsigned char* buffer = pool.allocz<unsigned char>(size);
+ ASSERT_THAT(buffer, testing::NotNull());
+ EXPECT_EQ(size, std::count(buffer, buffer + size, 0));
+}
+
+//
+// Array helper functions
+//
+
+namespace {
+// Create a randomly-ordered array of constant strings.
+apr_array_header_t* fill_array(APR::Pool& pool)
+{
+ apr_array_header_t* a = apr_array_make(pool.get(), 0, sizeof(const char*));
+ APR_ARRAY_PUSH(a, const char*) = "primus";
+ APR_ARRAY_PUSH(a, const char*) = "secundus";
+ APR_ARRAY_PUSH(a, const char*) = "tertius";
+ APR_ARRAY_PUSH(a, const char*) = "quartus";
+ APR_ARRAY_PUSH(a, const char*) = "quintus";
+ APR_ARRAY_PUSH(a, const char*) = "sextus";
+ APR_ARRAY_PUSH(a, const char*) = "septimus";
+ std::random_shuffle(&APR_ARRAY_IDX(a, 0, const char*),
+ &APR_ARRAY_IDX(a, a->nelts, const char*));
+ return a;
+}
+} // anonymous namespace
+
+//
+// Arrays
+//
+
+TEST(Arrays, CreateArray)
+{
+ typedef APR::Array<unsigned char> Array;
+
+ APR::Pool pool;
+ Array array(pool);
+
+ EXPECT_THAT(array.array(), testing::NotNull());
+ EXPECT_EQ(0, array.size());
+ EXPECT_EQ(sizeof(unsigned char), sizeof(Array::value_type));
+ EXPECT_EQ(sizeof(Array::value_type), array.array()->elt_size);
+}
+
+TEST(Arrays, WrapArray)
+{
+ typedef APR::Array<unsigned char> Array;
+
+ APR::Pool pool;
+ apr_array_header_t* apr_array =
+ apr_array_make(pool.get(), 0, sizeof(Array::value_type));
+ ASSERT_THAT(apr_array, testing::NotNull());
+
+ Array array(apr_array);
+ EXPECT_EQ(apr_array, array.array());
+ EXPECT_EQ(0, array.size());
+}
+
+TEST(Arrays, RewrapTypeMismatch)
+{
+ typedef APR::Array<unsigned char> ByteArray;
+ typedef APR::Array<int> IntArray;
+
+ APR::Pool pool;
+ EXPECT_THROW(ByteArray array(IntArray(pool).array()),
+ std::invalid_argument);
+}
+
+TEST(Arrays, OutOfBounds)
+{
+ typedef APR::Array<unsigned char> Array;
+
+ APR::Pool pool;
+ Array array(pool);
+
+ EXPECT_THROW(array.at(-1), std::out_of_range);
+ EXPECT_THROW(array.at(array.size()), std::out_of_range);
+}
+
+TEST(Arrays, Indexing)
+{
+ typedef APR::Array<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ EXPECT_EQ(array[0], APR_ARRAY_IDX(array.array(), 0, Array::value_type));
+ EXPECT_EQ(array[array.size() - 1], APR_ARRAY_IDX(array.array(),
+ array.array()->nelts - 1,
+ Array::value_type));
+}
+
+TEST(Arrays, CheckedIndexing)
+{
+ typedef APR::Array<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ EXPECT_EQ(array.at(0), APR_ARRAY_IDX(array.array(), 0, Array::value_type));
+ EXPECT_EQ(array.at(array.size() - 1), APR_ARRAY_IDX(array.array(),
+ array.array()->nelts - 1,
+ Array::value_type));
+}
+
+TEST(Arrays, Iteration)
+{
+ typedef APR::Array<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ struct Iteration : public Array::Iteration
+ {
+ Iteration(apr_array_header_t* raw_array)
+ : m_index(0), m_raw_array(raw_array)
+ {}
+
+ bool operator()(Array::value_type& value)
+ {
+ EXPECT_EQ(value, APR_ARRAY_IDX(m_raw_array, m_index,
+ Array::value_type));
+ ++m_index;
+ return true;
+ }
+
+ private:
+ Array::size_type m_index;
+ apr_array_header_t* m_raw_array;
+ } callback(array.array());
+
+ array.iterate(callback);
+}
+
+TEST(Arrays, ConstIteration)
+{
+ typedef APR::Array<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ struct Iteration : public Array::ConstIteration
+ {
+ Iteration(const apr_array_header_t* raw_array)
+ : m_index(0), m_raw_array(raw_array)
+ {}
+
+ bool operator()(const Array::value_type& value)
+ {
+ EXPECT_EQ(value, APR_ARRAY_IDX(m_raw_array, m_index,
+ Array::value_type));
+ ++m_index;
+ return true;
+ }
+
+ private:
+ Array::size_type m_index;
+ const apr_array_header_t* m_raw_array;
+ } callback(array.array());
+
+ array.iterate(callback);
+}
+
+TEST(Arrays, Push)
+{
+ typedef APR::Array<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ const Array::size_type point = array.size();
+ const Array::value_type first = array[0];
+ const Array::value_type last = array[point - 1];
+
+ array.push("octavius");
+ array.push("nonus");
+ array.push("decimus");
+
+ EXPECT_EQ(point + 3, array.size());
+ EXPECT_EQ(first, array[0]);
+ EXPECT_EQ(last, array[point - 1]);
+ EXPECT_EQ("octavius", array[point]);
+ EXPECT_EQ("decimus", array[array.size() - 1]);
+}
+
+TEST(Arrays, Pop)
+{
+ typedef APR::Array<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ for (Array::size_type i = 0, z = array.size(); i <= z; ++i)
+ {
+ const char** last = (!array.array()->nelts ? NULL
+ : &APR_ARRAY_IDX(array.array(),
+ array.array()->nelts - 1,
+ const char*));
+ EXPECT_EQ(last, array.pop());
+ }
+}
+
+//
+// ConstArrays
+//
+
+TEST(ConstArrays, WrapArray)
+{
+ typedef APR::ConstArray<unsigned char> Array;
+
+ APR::Pool pool;
+ const apr_array_header_t* apr_array =
+ apr_array_make(pool.get(), 0, sizeof(Array::value_type));
+ ASSERT_THAT(apr_array, testing::NotNull());
+
+ Array array(apr_array);
+ EXPECT_EQ(apr_array, array.array());
+ EXPECT_EQ(0, array.size());
+}
+
+TEST(ConstArrays, RewrapTypeMismatch)
+{
+ typedef APR::ConstArray<unsigned char> ByteArray;
+ typedef APR::Array<int> IntArray;
+
+ APR::Pool pool;
+ EXPECT_THROW(ByteArray array(IntArray(pool).array()),
+ std::invalid_argument);
+}
+
+TEST(ConstArrays, OutOfBounds)
+{
+ typedef APR::ConstArray<unsigned char> Array;
+
+ APR::Pool pool;
+ Array array = Array(APR::Array<Array::value_type>(pool));
+
+ EXPECT_THROW(array.at(-1), std::out_of_range);
+ EXPECT_THROW(array.at(array.size()), std::out_of_range);
+}
+
+TEST(ConstArrays, Indexing)
+{
+ typedef APR::ConstArray<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ EXPECT_EQ(array[0], APR_ARRAY_IDX(array.array(), 0, Array::value_type));
+ EXPECT_EQ(array[array.size() - 1], APR_ARRAY_IDX(array.array(),
+ array.array()->nelts - 1,
+ Array::value_type));
+}
+
+TEST(ConstArrays, CheckedIndexing)
+{
+ typedef APR::ConstArray<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ EXPECT_EQ(array.at(0), APR_ARRAY_IDX(array.array(), 0, Array::value_type));
+ EXPECT_EQ(array.at(array.size() - 1), APR_ARRAY_IDX(array.array(),
+ array.array()->nelts - 1,
+ Array::value_type));
+}
+
+TEST(ConstArrays, Iteration)
+{
+ typedef APR::ConstArray<const char*> Array;
+
+ APR::Pool pool;
+ Array array(fill_array(pool));
+
+ struct Iteration : public Array::Iteration
+ {
+ Iteration(const apr_array_header_t* raw_array)
+ : m_index(0), m_raw_array(raw_array)
+ {}
+
+ bool operator()(const Array::value_type& value)
+ {
+ EXPECT_EQ(value, APR_ARRAY_IDX(m_raw_array, m_index,
+ Array::value_type));
+ ++m_index;
+ return true;
+ }
+
+ private:
+ Array::size_type m_index;
+ const apr_array_header_t* m_raw_array;
+ } callback(array.array());
+
+ array.iterate(callback);
+}
+
+//
+// Hash tables
+//
+
+// TODO: Convert to gmock
+
+#include "../src/aprwrap.hpp"
+static void hashtest()
+{
+ typedef APR::Hash<char, const char, 2> H;
+ typedef APR::Array<H::key_type> A;
+ typedef APR::ConstArray<A::value_type> CA;
+
+ APR::Pool pool;
+ struct CB : public H::Iteration
+ {
+ A m_keys;
+
+ CB(const APR::Pool& array_pool)
+ : m_keys(array_pool)
+ {}
+
+ bool operator() (const H::Key& key, H::value_type value)
+ {
+ m_keys.push(key.get());
+ return true;
+ }
+ } hash_callback(pool);
+
+ H hash(pool);
+
+ hash.set("a", "aaa");
+ hash.set("c", "ccc");
+ hash.set("x", "bbb");
+
+ hash.iterate(hash_callback, pool);
+
+ struct AB : public A::ConstIteration
+ {
+ const H& m_hash;
+
+ AB(const H& hash_reference)
+ : m_hash(hash_reference)
+ {}
+
+ bool operator() (const A::value_type& value)
+ {
+ std::cerr << value << " = " << m_hash.get(value) << std::endl;
+ return true;
+ }
+ } array_callback(hash);
+
+ CA keys(hash_callback.m_keys);
+ keys.iterate(array_callback);
+
+ std::cerr << keys[0] << " maps to " << hash_callback.m_keys[0] << std::endl;
+ std::cerr << keys.at(1) << " maps to " << hash_callback.m_keys.at(1) <<
std::endl;
+ std::cerr << keys[2] << " maps to " << hash_callback.m_keys[2] << std::endl;
+}
Propchange: subversion/trunk/subversion/bindings/cxxhl/tests/test_aprwrap.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: subversion/trunk/subversion/bindings/cxxhl/tests/test_exception.cpp
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/tests/test_exception.cpp?rev=1502282&r1=1502281&r2=1502282&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/tests/test_exception.cpp
(original)
+++ subversion/trunk/subversion/bindings/cxxhl/tests/test_exception.cpp Thu Jul
11 16:40:45 2013
@@ -19,6 +19,8 @@
* ====================================================================
*/
+// ### TODO: Convert to Googlemock/Googletest
+
#include <algorithm>
#include <cstdio>
#include <iomanip>
@@ -56,7 +58,7 @@ void traceall(const char *message, const
void tracecheck(svn_error_t* err)
{
std::cout << "C-API handler:" << std::endl;
- svn_handle_error2(err, stdout, false, " test_exception");
+ svn_handle_error2(err, stdout, false, " test_exception: ");
svn_error_clear(err);
}
@@ -136,7 +138,8 @@ int test_error()
return false;
}
-int main()
+
+int disabled_main()
{
apr_initialize();
Propchange: subversion/trunk/tools/dist/make-deps-tarball.sh
------------------------------------------------------------------------------
Merged
/subversion/branches/gtest_addition/tools/dist/make-deps-tarball.sh:r1452117-1502138