From 1e255ec19ececda196874f751a81682169cf64c3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 11 Feb 2012 18:32:53 +0300 Subject: Add support for gtest framework. --- build/bmaketests | 79 +++++++++++++++++++++++++++++ build/buildtest | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ build/maketest.sh | 149 ------------------------------------------------------ configure.ac | 13 +++++ src/Makefile.am | 4 ++ src/main.cpp | 17 +++++++ 6 files changed, 262 insertions(+), 149 deletions(-) create mode 100755 build/bmaketests create mode 100755 build/buildtest delete mode 100755 build/maketest.sh diff --git a/build/bmaketests b/build/bmaketests new file mode 100755 index 000000000..e1d980a98 --- /dev/null +++ b/build/bmaketests @@ -0,0 +1,79 @@ +#!/bin/sh + +cd .. + +dir=`pwd` + +export CC=gcc-4.5 +export CXX=g++-4.5 + +export LANG=C +export CXXFLAGS="-Wunreachable-code -Wmissing-field-initializers \ +-Wabi -Wdisabled-optimization -Wuninitialized \ +-Wvolatile-register-var -Winvalid-pch -Wredundant-decls \ +-Wnormalized=nfkc -Wmissing-format-attribute -Wmissing-noreturn \ +-Wswitch-default -Wsign-promo -Waddress -Wmissing-declarations \ +-Wctor-dtor-privacy -Wstrict-null-sentinel \ +-Wunused-parameter -Wlogical-op \ +-Wempty-body -Wsign-compare -Wclobbered -Wcast-align -Wcast-qual \ +-Wtype-limits -Wpointer-arith -Wundef -Wmissing-include-dirs \ +-Wignored-qualifiers -Winit-self -pedantic -Wall -ggdb3 -O2 -pipe \ +-Wpacked -Wshadow -Wunused -Wsynth \ +-Wbuiltin-macro-redefined -Wctor-dtor-privacy -Wdeprecated -Wextra \ +-Wendif-labels -Wformat=1 -Wimport -Wnon-virtual-dtor -Wpsabi \ +-Wsign-promo -Wwrite-strings -D_FORTIFY_SOURCE=2" + +autoreconf -i 2>../build/make.log + +result=$? +if [ "$result" != 0 ]; then + echo autoreconf error + exit 1 +fi + +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=yes \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--enable-unittests=yes + +result=$? +if [ "$result" != 0 ]; then + echo configure error + exit 1 +fi + +cd po +#make -j5 update-po 2>../make1.log +make -j5 update-gmo 2>../build/make1.log + +result=$? +if [ "$result" != 0 ]; then + echo update-gmo error + exit 1 +fi + +cd .. +make -j5 2>build/make2.log + +result=$? +if [ "$result" != 0 ]; then + echo make error + exit 1 +fi + +make install + +result=$? +if [ "$result" != 0 ]; then + echo make install error + exit 1 +fi + +cd run +export GLIBCXX_FORCE_NEW=1 +./bin/manaplus diff --git a/build/buildtest b/build/buildtest new file mode 100755 index 000000000..61b20f0fe --- /dev/null +++ b/build/buildtest @@ -0,0 +1,149 @@ +#!/bin/sh + +dir=`pwd` +export LANG=C + +cd .. +#--enable-applebuild=yes +#--without-librt + +echo start >build/make.log + +autoreconf -i +echo opengl+debug+guichan >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=yes \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no +make -j5 2>>build/make.log + +autoreconf -i +echo opengl+guichan >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no +make -j5 2>>build/make.log + +autoreconf -i +echo opengl >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=no \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no +make -j5 2>>build/make.log + +autoreconf -i +echo opengl+manaserv >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=no \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--enable-manaserv=yes +make -j5 2>>build/make.log + +autoreconf -i +echo opengl+guichan+manaserv >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--enable-manaserv=yes +make -j5 2>>build/make.log + +autoreconf -i +echo guichan >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--without-opengl +make -j5 2>>build/make.log + +autoreconf -i +echo "-" >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=no \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--without-opengl +make -j5 2>>build/make.log + +autoreconf -i +echo guichan+manaserv >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--enable-manaserv=yes \ +--without-opengl +make -j5 2>>build/make.log + +autoreconf -i +echo opengl+debug+guichan+portable >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=yes \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--enable-portable=yes +make -j5 2>>build/make.log + +autoreconf -i +echo opengl+guichan+portable+manaserv >>build/make.log +make clean 2>>build/make.log +./configure --prefix=$dir/run \ +--datadir=$dir/run/share/games \ +--bindir=$dir/run/bin \ +--mandir=$dir/run/share/man \ +--enable-memdebug=no \ +--with-internalguichan=yes \ +--enable-tcmalloc=no \ +--enable-googleprofiler=no \ +--enable-manaserv=yes \ +--enable-portable=yes +make -j5 2>>build/make.log diff --git a/build/maketest.sh b/build/maketest.sh deleted file mode 100755 index 61b20f0fe..000000000 --- a/build/maketest.sh +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/sh - -dir=`pwd` -export LANG=C - -cd .. -#--enable-applebuild=yes -#--without-librt - -echo start >build/make.log - -autoreconf -i -echo opengl+debug+guichan >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=yes \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no -make -j5 2>>build/make.log - -autoreconf -i -echo opengl+guichan >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no -make -j5 2>>build/make.log - -autoreconf -i -echo opengl >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=no \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no -make -j5 2>>build/make.log - -autoreconf -i -echo opengl+manaserv >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=no \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---enable-manaserv=yes -make -j5 2>>build/make.log - -autoreconf -i -echo opengl+guichan+manaserv >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---enable-manaserv=yes -make -j5 2>>build/make.log - -autoreconf -i -echo guichan >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---without-opengl -make -j5 2>>build/make.log - -autoreconf -i -echo "-" >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=no \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---without-opengl -make -j5 2>>build/make.log - -autoreconf -i -echo guichan+manaserv >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---enable-manaserv=yes \ ---without-opengl -make -j5 2>>build/make.log - -autoreconf -i -echo opengl+debug+guichan+portable >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=yes \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---enable-portable=yes -make -j5 2>>build/make.log - -autoreconf -i -echo opengl+guichan+portable+manaserv >>build/make.log -make clean 2>>build/make.log -./configure --prefix=$dir/run \ ---datadir=$dir/run/share/games \ ---bindir=$dir/run/bin \ ---mandir=$dir/run/share/man \ ---enable-memdebug=no \ ---with-internalguichan=yes \ ---enable-tcmalloc=no \ ---enable-googleprofiler=no \ ---enable-manaserv=yes \ ---enable-portable=yes -make -j5 2>>build/make.log diff --git a/configure.ac b/configure.ac index ef92317d6..996ad3f3c 100755 --- a/configure.ac +++ b/configure.ac @@ -209,6 +209,19 @@ esac],[memdebug_enabled=false]) AM_CONDITIONAL(ENABLE_MEM_DEBUG, test x$memdebug_enabled = xtrue) +# Enable unit tests +AC_ARG_ENABLE(unittests, +[ --enable-unittests Turn on unit tests], +[case "${enableval}" in + yes) unittests_enabled=true +LIBS="$LIBS -lgtest" + ;; + no) unittests_enabled=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-tests) ;; +esac],[unittests_enabled=false]) + +AM_CONDITIONAL(ENABLE_UNITTESTS, test x$unittests_enabled = xtrue) + # Enable tcmalloc AC_ARG_ENABLE(tcmalloc, [ --enable-tcmalloc Turn on tcmalloc], diff --git a/src/Makefile.am b/src/Makefile.am index 204c21bfc..62b762af6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,10 @@ else manaplus_SOURCES = endif +if ENABLE_UNITTESTS +manaplus_CXXFLAGS += -DUNITTESTS +endif + if USE_INTERNALGUICHAN manaplus_CXXFLAGS += -DUSE_INTERNALGUICHAN manaplus_SOURCES += guichan/include/guichan/actionevent.hpp \ diff --git a/src/main.cpp b/src/main.cpp index dc87ca9e0..f30e7bc62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,10 @@ #include "utils/stringutils.h" #include "utils/xml.h" +#ifdef UNITTESTS +#include +#endif + #ifdef __MINGW32__ #include #endif @@ -210,6 +214,8 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) extern "C" char const *_nl_locale_name_default(void); #endif +#ifndef UNITTESTS +// main for normal game usage int main(int argc, char *argv[]) { #if defined(__MINGW32__) @@ -262,3 +268,14 @@ int main(int argc, char *argv[]) return client.testsExec(); } } + +#else + +// main for unit testing +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +#endif -- cgit v1.2.3-60-g2f50