Skip to content

Commit

Permalink
UPDATED configure check for libgtest and libgmock.
Browse files Browse the repository at this point in the history
  --enable-dev-build switch should now work out-of-the box on recent
    Debian or Ubuntu. Others should be able to set GTEST_DIR and GMOCK_DIR
    environment variables to an unzipped gtest/gmock source tree and get
    it working as well (untested). No update of CMake build yet.
ADDED unit test for world/cube3
  • Loading branch information
ksterker committed Sep 4, 2012
1 parent c94b494 commit 59855bd
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 14 deletions.
35 changes: 28 additions & 7 deletions configure.in
Expand Up @@ -86,6 +86,8 @@ AC_ARG_ENABLE(dev-build,
[ --enable-dev-build Enable developer build with unit tests and debug symbols (disabled by default)],
devbuild=$enableval, devbuild=no)

AC_ARG_VAR(GTEST_DIR, [path to Google Test sources (default /usr/src/gtest)])
AC_ARG_VAR(GMOCK_DIR, [path to Google Mock sources (default /usr/src/gmock)])

AC_CHECK_LIB(z, main,,echo "Adonthell requires Zlib. Exitting...";exit 1)

Expand Down Expand Up @@ -339,13 +341,32 @@ dnl ****************************************************************************
if test x$devbuild = xyes; then
CXXFLAGS="$CXXFLAGS -g"

PKG_CHECK_MODULES(libgtest, libgtest >= 0.4.0)
AC_SUBST(libgtest_LIBS)
AC_SUBST(libgtest_CFLAGS)

PKG_CHECK_MODULES(libgmock, libgmock >= 0.4.0)
AC_SUBST(libgmock_LIBS)
AC_SUBST(libgmock_CFLAGS)
test "x$GTEST_DIR" = "x" && GTEST_DIR="/usr/src/gtest"
test "x$GMOCK_DIR" = "x" && GMOCK_DIR="/usr/src/gmock"

AC_CHECK_LIB(gmock_test, main,
[AC_SUBST(libgtest_CFLAGS, "")
AC_SUBST(libgtest_LIBS, "-lgtest")
AM_CONDITIONAL(BUILD_GTEST, false)],
[AC_CHECK_FILE($GTEST_DIR/src/gtest-all.cc,
[AC_SUBST(GTEST_DIR)
AC_SUBST(libgtest_CFLAGS, "-I$GTEST_DIR/include")
AC_SUBST(libgtest_LIBS, '-L$(top_builddir)/src/ -lgtest')
AM_CONDITIONAL(BUILD_GTEST, true)],
[AC_MSG_FAILURE([Missing gtest library])])
])

AC_CHECK_LIB(gmock_main, main,
[AC_SUBST(libgmock_CFLAGS, "")
AC_SUBST(libgmock_LIBS, "-lgmock")
AM_CONDITIONAL(BUILD_GMOCK, false)],
[AC_CHECK_FILE($GMOCK_DIR/src/gmock-all.cc,
[AC_SUBST(GMOCK_DIR)
AC_SUBST(libgmock_CFLAGS, "-I$GMOCK_DIR/include")
AC_SUBST(libgmock_LIBS, '-L$(top_builddir)/src/ -lgmock')
AM_CONDITIONAL(BUILD_GMOCK, true)],
[AC_MSG_FAILURE([Missing gmock library])])
])
fi

dnl *********************
Expand Down
20 changes: 19 additions & 1 deletion src/Makefile.am
@@ -1,5 +1,5 @@
# -- this order is important, as we build with -no-undefined
SUBDIRS = base python py-runtime event gfx input audio rpg gui world main py-wrappers
SUBDIRS = . base python py-runtime event gfx input audio rpg world gui main py-wrappers

EXTRA_DIST = CMakeLists.txt

Expand All @@ -13,3 +13,21 @@ $(top_builddir)/src/run.sh:
$(top_builddir)/src/python.sh:
echo -e "#/bin/sh\nPYTHONPATH=\"$$PYTHONPATH:`pwd`/py-wrappers:`pwd`/py-wrappers/adonthell/.libs\" source `pwd`/run.sh python \$$$$@@" > $@

if BUILD_GTEST

noinst_LIBRARIES = libgtest.a
libgtest_a_SOURCES = $(GTEST_DIR)/src/gtest-all.cc
libgtest_a_CXXFLAGS = -I$(GTEST_DIR)

endif

if BUILD_GMOCK

noinst_LIBRARIES = libgmock.a

libgmock_a_SOURCES = $(GMOCK_DIR)/src/gmock-all.cc
libgmock_a_CXXFLAGS = $(libgtest_CFLAGS)
libgmock_a_LIBADD = $(libgtest_LIBS)

endif

3 changes: 2 additions & 1 deletion src/gui/Makefile.am
Expand Up @@ -55,11 +55,12 @@ libadonthell_gui_la_LIBADD = $(PY_LIBS) \
$(top_builddir)/src/gfx/libadonthell_gfx.la \
$(top_builddir)/src/python/libadonthell_python.la \
$(top_builddir)/src/rpg/libadonthell_rpg.la \
$(top_builddir)/src/world/libadonthell_world.la \
-lstdc++ $(FT2_LIBS)

## Unit tests
test_CXXFLAGS = $(libgmock_CFLAGS) $(libgtest_CFLAGS)
test_LDADD = $(libgmock_LIBS) $(libgtest_LIBS) $(top_builddir)/src/audio/libadonthell_gui.la
test_LDADD = $(libgmock_LIBS) $(libgtest_LIBS) $(top_builddir)/src/gui/libadonthell_gui.la

test_ui_event_manager_SOURCES = test_ui_event_manager.cc
test_ui_event_manager_CXXFLAGS = $(libadonthell_gui_la_CXXFLAGS) $(test_CXXFLAGS)
Expand Down
12 changes: 11 additions & 1 deletion src/world/Makefile.am
Expand Up @@ -88,11 +88,21 @@ libadonthell_world_la_LIBADD = $(PY_LIBS) $(libglog_LIBS) \
test_CXXFLAGS = $(libgmock_CFLAGS) $(libgtest_CFLAGS)
test_LDADD = $(libgmock_LIBS) $(libgtest_LIBS) $(top_builddir)/src/world/libadonthell_world.la

test_cube_SOURCES = test_cube.cc
test_cube_CXXFLAGS = $(libadonthell_world_la_CXXFLAGS) $(test_CXXFLAGS)
test_cube_LDADD = $(libadonthell_world_la_LIBADD) $(test_LDADD)

test_placeable_SOURCES = test_placeable.cc
test_placeable_CXXFLAGS = $(libadonthell_world_la_CXXFLAGS) $(test_CXXFLAGS)
test_placeable_LDADD = $(libadonthell_world_la_LIBADD) $(test_LDADD)

test_renderer_SOURCES = test_renderer.cc
test_renderer_CXXFLAGS = $(libadonthell_world_la_CXXFLAGS) $(test_CXXFLAGS)
test_renderer_LDADD = $(libadonthell_world_la_LIBADD) $(test_LDADD)

TESTS = \
test_renderer
test_cube \
test_renderer \
test_placeable

check_PROGRAMS = $(TESTS)
8 changes: 4 additions & 4 deletions src/world/cube3.h
Expand Up @@ -217,11 +217,14 @@ class cube3
/// the cube's corners
vector3<s_int16> Corners[8];

/// the cube's surface
std::vector<triangle3<s_int16> *> Surface;

/**
* Cleanup.
*/
void clear();

private:
/**
* Split a face of the cube, specified by the indices of its four corner points,
Expand All @@ -233,9 +236,6 @@ class cube3
*/
void convert_face (const u_int16 & a, const u_int16 & b, const u_int16 & c, const u_int16 & d);

/// the cube's surface
std::vector<triangle3<s_int16> *> Surface;

/// bounding box minimum values
vector3<s_int16> Min;
/// bounding box maximum values
Expand Down
93 changes: 93 additions & 0 deletions src/world/test_cube.cc
@@ -0,0 +1,93 @@
/*
Copyright (C) 2012 Kai Sterker <kai.sterker@gmail.com>
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Adonthell 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Adonthell; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <adonthell/base/logging.h>
#include <gtest/gtest.h>

#include "cube3.h"

namespace world
{
class cube_Test : public ::testing::Test, public world::cube3
{
protected:
cube_Test() : world::cube3(1, 1, 1)
{
}

virtual ~cube_Test()
{
}

// If the constructor and destructor are not enough for setting up
// and cleaning up each test, you can define the following methods:

virtual void SetUp()
{
// Code here will be called immediately after the constructor (right
// before each test).
}

virtual void TearDown()
{
// Code here will be called immediately after each test (right
// before the destructor).
}
}; // class{}

TEST_F(cube_Test, checkCreateMesh)
{
this->create_mesh();

EXPECT_EQ(12, Surface.size());

// top
EXPECT_EQ(world::vector3<s_int32>(0,0,1), Surface[0]->normal());
EXPECT_EQ(world::vector3<s_int32>(0,0,1), Surface[1]->normal());

// bottom
EXPECT_EQ(world::vector3<s_int32>(0,0,-1), Surface[2]->normal());
EXPECT_EQ(world::vector3<s_int32>(0,0,-1), Surface[3]->normal());

// front
EXPECT_EQ(world::vector3<s_int32>(0,-1,0), Surface[4]->normal());
EXPECT_EQ(world::vector3<s_int32>(0,-1,0), Surface[5]->normal());

// back
EXPECT_EQ(world::vector3<s_int32>(0,1,0), Surface[6]->normal());
EXPECT_EQ(world::vector3<s_int32>(0,1,0), Surface[7]->normal());

// left
EXPECT_EQ(world::vector3<s_int32>(-1,0,0), Surface[8]->normal());
EXPECT_EQ(world::vector3<s_int32>(-1,0,0), Surface[9]->normal());

// right
EXPECT_EQ(world::vector3<s_int32>(1,0,0), Surface[10]->normal());
EXPECT_EQ(world::vector3<s_int32>(1,0,0), Surface[11]->normal());
}

} // namespace{}


int main(int argc, char **argv)
{
::google::InitGoogleLogging(argv[0]);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 59855bd

Please sign in to comment.