Mercurial > fife-parpg
changeset 43:6daa907234e1
removed old boost based unit tests
author | jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 13 Jul 2008 07:46:49 +0000 |
parents | 4c8334b0ab30 |
children | 5a2db5e7ab54 |
files | tests/core_tests/fife_unit_test.h tests/core_tests/test_dat1.cpp tests/core_tests/test_dat2.cpp tests/core_tests/test_gui.cpp tests/core_tests/test_imagepool.cpp tests/core_tests/test_images.cpp tests/core_tests/test_rect.cpp tests/core_tests/test_vfs.cpp tests/core_tests/test_zip.cpp |
diffstat | 9 files changed, 0 insertions(+), 1139 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/core_tests/fife_unit_test.h Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef FIFE_UTIL_FIFE_UNIT_TEST_H -#define FIFE_UTIL_FIFE_UNIT_TEST_H - -// Standard C++ library includes - -// 3rd party library includes -#include <boost/version.hpp> -#if BOOST_VERSION > 103400 - #define BOOST_TEST_DYN_LINK - #define BOOST_TEST_MAIN -#else - #define FIFE_BOOST_VERSION_103300 -#endif - -#include <boost/test/unit_test.hpp> - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder - -#endif
--- a/tests/core_tests/test_dat1.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes -#include <iostream> -#include <iomanip> - -// Platform specific includes - -// 3rd party library includes - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/dat/dat1.h" -#include "vfs/raw/rawdata.h" -#include "util/base/exception.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -static const std::string COMPRESSED_FILE = "../data/dat1vfstest.dat"; -static const std::string RAW_FILE = "../data/test.map"; - -#ifdef FIFE_BOOST_VERSION_103300 -void test_decoder() { -#else -BOOST_AUTO_TEST_CASE( DAT1_test ) { -#endif - boost::shared_ptr<VFS> vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - if ((!vfs->exists(COMPRESSED_FILE))) { - BOOST_ERROR("Test source " << COMPRESSED_FILE << " not found"); - return; - } - - vfs->addSource(new DAT1(vfs.get(), COMPRESSED_FILE)); - - if ((!vfs->exists(RAW_FILE)) || (!vfs->exists("dat1vfstest.map"))) { - BOOST_ERROR("Test files not found"); - } - - RawData* fraw = vfs->open(RAW_FILE); - RawData* fcomp = vfs->open("dat1vfstest.map"); - - if (fraw->getDataLength() != fcomp->getDataLength()) { - std::cout << "raw length = " << fraw->getDataLength() \ - << ", compressed length = " << fcomp->getDataLength() << std::endl; - BOOST_ERROR("Data length mismatch"); - } else { - std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl; - } - - unsigned int smaller_len = fraw->getDataLength(); - if (fcomp->getDataLength() < smaller_len) { - smaller_len = fcomp->getDataLength(); - } - - uint8_t* d_raw = new uint8_t[fraw->getDataLength()]; - uint8_t* d_comp = new uint8_t[fcomp->getDataLength()]; - fraw->readInto(d_raw,fraw->getDataLength()); - fcomp->readInto(d_comp,fcomp->getDataLength()); - - std::cout << "scanning data..." << std::endl; - for (unsigned int i = 0; i < smaller_len; i++) { - uint8_t rawc = d_raw[i]; - uint8_t compc = d_comp[i]; - if (rawc != compc) { - BOOST_ERROR("Data mismatch"); - std::cout - << "raw: " << std::setbase(16) << rawc - << " comp: " << std::setbase(16) << compc << std::endl; - break; - } - } - std::cout << "scanning finished" << std::endl; - delete[] d_raw; - delete[] d_comp; - delete fraw; - delete fcomp; -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("DAT1 tests"); - test->add(BOOST_TEST_CASE(&test_decoder), 0); - return test; -} -#endif
--- a/tests/core_tests/test_dat2.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes -#include <iostream> -#include <iomanip> - -// Platform specific includes - -// 3rd party library includes - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "util/time/timemanager.h" -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/dat/dat2.h" -#include "vfs/raw/rawdata.h" -#include "util/base/exception.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -// Environment -struct environment { - boost::shared_ptr<TimeManager> timemanager; - - environment() - : timemanager(new TimeManager()) {} -}; - -using boost::unit_test::test_suite; -using namespace FIFE; - -static const std::string COMPRESSED_FILE = "../data/dat2vfstest.dat"; -static const std::string RAW_FILE = "../data/test.map"; - -#ifdef FIFE_BOOST_VERSION_103300 -void test_decoder() { -#else -BOOST_AUTO_TEST_CASE( OGL_animtest ) { -#endif - environment env; - - boost::shared_ptr<VFS> vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - if ((!vfs->exists(COMPRESSED_FILE))) { - BOOST_ERROR("Test source " << COMPRESSED_FILE << " not found"); - return; - } - - vfs->addSource(new DAT2(vfs.get(), COMPRESSED_FILE)); - - if ((!vfs->exists(RAW_FILE)) || (!vfs->exists("dat2vfstest.map"))) { - BOOST_ERROR("Test files not found"); - } - - RawData* fraw = vfs->open(RAW_FILE); - RawData* fcomp = vfs->open("dat2vfstest.map"); - - if (fraw->getDataLength() != fcomp->getDataLength()) { - std::cout << "raw length = " << fraw->getDataLength() \ - << ", compressed length = " << fcomp->getDataLength() << std::endl; - BOOST_ERROR("Data length mismatch"); - } else { - std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl; - } - - unsigned int smaller_len = fraw->getDataLength(); - if (fcomp->getDataLength() < smaller_len) { - smaller_len = fcomp->getDataLength(); - } - - uint8_t* d_raw = new uint8_t[fraw->getDataLength()]; - uint8_t* d_comp = new uint8_t[fcomp->getDataLength()]; - fraw->readInto(d_raw,fraw->getDataLength()); - fcomp->readInto(d_comp,fcomp->getDataLength()); - - std::cout << "scanning data..." << std::endl; - for (unsigned int i = 0; i < smaller_len; i++) { - uint8_t rawc = d_raw[i]; - uint8_t compc = d_comp[i]; - if (rawc != compc) { - BOOST_ERROR("Data mismatch"); - std::cout - << "raw: " << std::setbase(16) << rawc - << " comp: " << std::setbase(16) << compc << std::endl; - break; - } - } - std::cout << "scanning finished" << std::endl; - delete[] d_raw; - delete[] d_comp; - delete fraw; - delete fcomp; -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("DAT2 tests"); - test->add(BOOST_TEST_CASE(&test_decoder), 0); - return test; -} -#endif
--- a/tests/core_tests/test_gui.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes - -// Platform specific includes - -// 3rd party library includes -#include <boost/scoped_ptr.hpp> -#include <boost/shared_ptr.hpp> -#include <SDL.h> -#include <guichan.hpp> - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "util/structures/rect.h" -#include "util/time/timemanager.h" -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/raw/rawdata.h" -#include "video/image_location.h" -#include "video/image.h" -#include "video/imagepool.h" -#include "video/sdl/renderbackendsdl.h" -#include "video/opengl/renderbackendopengl.h" -#include "loaders/native/video_loaders/image_loader.h" -#include "loaders/native/video_loaders/subimage_loader.h" -#include "util/base/exception.h" -#include "gui/base/opengl/opengl_gui_graphics.h" -#include "gui/base/sdl/sdl_gui_graphics.h" -#include "gui/base/gui_image.h" -#include "gui/base/gui_imageloader.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -static const std::string IMAGE_FILE = "../data/beach_e1.png"; -static const std::string SUBIMAGE_FILE = "../data/rpg_tiles_01.png"; - -// Environment -struct environment { - boost::shared_ptr<TimeManager> timemanager; - - environment() - : timemanager(new TimeManager()) { - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { - throw SDLException(SDL_GetError()); - } - } -}; - -void test_gui_image(RenderBackend& renderbackend, gcn::Graphics& graphics, ImagePool& pool) { - boost::scoped_ptr<VFS> vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - pool.addResourceLoader(new SubImageLoader()); - pool.addResourceLoader(new ImageLoader(vfs.get())); - - GuiImageLoader imageloader(pool); - gcn::Image::setImageLoader(&imageloader); - - gcn::Container* top = new gcn::Container(); - top->setDimension(gcn::Rectangle(0, 0, 200, 300)); - gcn::Gui* gui = new gcn::Gui(); - gui->setGraphics(&graphics); - gui->setTop(top); - gcn::Label* label = new gcn::Label("Label"); -; gcn::Image* guiimage = gcn::Image::load(IMAGE_FILE); - gcn::Icon* icon = new gcn::Icon(guiimage); - - top->add(label, 10, 10); - top->add(icon, 10, 30); - - ImageLoader provider(vfs.get()); - boost::scoped_ptr<Image> img(dynamic_cast<Image*>(provider.loadResource(ImageLocation(IMAGE_FILE)))); - - int h = img->getHeight(); - int w = img->getWidth(); - for (int i = 0; i < 100; i+=2) { - renderbackend.startFrame(); - img->render(Rect(i, i, w, h)); - gui->logic(); - gui->draw(); - renderbackend.endFrame(); - } - delete label; - delete icon; - delete guiimage; -} - -#ifdef FIFE_BOOST_VERSION_103300 -void test_sdl_gui_image() { -#else -BOOST_AUTO_TEST_CASE( SDL_gui_test ) { -#endif - environment env; - RenderBackendSDL renderbackend; - renderbackend.init(); - ImagePool pool; - Image* screen = renderbackend.createMainScreen(800, 600, 0, false); - SdlGuiGraphics graphics(pool); - graphics.setTarget(screen->getSurface()); - test_gui_image(renderbackend, graphics, pool); -} - - -#ifdef FIFE_BOOST_VERSION_103300 -void test_ogl_gui_image() { -#else -BOOST_AUTO_TEST_CASE( OGL_gui_test ) { -#endif - environment env; - RenderBackendOpenGL renderbackend; - renderbackend.init(); - ImagePool pool; - renderbackend.createMainScreen(800, 600, 0, false); - OpenGLGuiGraphics graphics(pool); - test_gui_image(renderbackend, graphics, pool); -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("Gui Tests"); - test->add( BOOST_TEST_CASE( &test_ogl_gui_image ),0 ); - test->add( BOOST_TEST_CASE( &test_sdl_gui_image ),0 ); - - return test; -} -#endif
--- a/tests/core_tests/test_imagepool.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,145 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes -#include <iostream> -#include <iomanip> - -// Platform specific includes - -// 3rd party library includes -#include <boost/scoped_ptr.hpp> -#include <boost/shared_ptr.hpp> -#include <SDL.h> - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "util/structures/rect.h" -#include "util/time/timemanager.h" -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/raw/rawdata.h" -#include "video/image_location.h" -#include "video/image.h" -#include "video/imagepool.h" -#include "video/sdl/renderbackendsdl.h" -#include "video/opengl/renderbackendopengl.h" -#include "loaders/native/video_loaders/image_loader.h" -#include "loaders/native/video_loaders/subimage_loader.h" -#include "util/base/exception.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -static const std::string IMAGE_FILE = "../data/beach_e1.png"; -static const std::string SUBIMAGE_FILE = "../data/rpg_tiles_01.png"; -static const std::string ANIM_FILE = "../data/crate_full_001.xml"; - -// Environment -struct environment { - boost::shared_ptr<TimeManager> timemanager; - boost::shared_ptr<VFS> vfs; - - environment() - : timemanager(new TimeManager()) { - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { - throw SDLException(SDL_GetError()); - } - } -}; - -#ifdef FIFE_BOOST_VERSION_103300 -void test_image_pool() { -#else -BOOST_AUTO_TEST_CASE( ImagePool_test ) { -#endif - environment env; - RenderBackendSDL renderbackend; - - boost::scoped_ptr<VFS> vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - renderbackend.init(); - renderbackend.createMainScreen(800, 600, 0, false); - ImagePool pool; - pool.addResourceLoader(new SubImageLoader()); - pool.addResourceLoader(new ImageLoader(vfs.get())); - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 0); - - pool.addResourceFromLocation(ImageLocation(IMAGE_FILE)); - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 1); - - ImageLocation location(SUBIMAGE_FILE); - ImageLoader imgprovider(vfs.get()); - int fullImgInd = pool.addResourceFromLocation(ImageLocation(SUBIMAGE_FILE)); - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 2); - - Image& img = pool.getImage(fullImgInd); - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 1); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 1); - - location.setParentSource(&img); - int W = img.getWidth(); - int w = W / 12; - int H = img.getHeight(); - int h = H / 12; - location.setWidth(w); - location.setHeight(h); - pool.addResourceFromLocation(location); - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 1); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 2); - - for (int k = 0; k < 3; k++) { - for (int j = 0, s = pool.getResourceCount(RES_LOADED | RES_NON_LOADED); j < s; j++) { - std::cout << j << std::endl; - Image& r = dynamic_cast<Image&>(pool.get(j)); - int h = r.getHeight(); - int w = r.getWidth(); - for (int i = 20; i > 0; i-=2) { - renderbackend.startFrame(); - r.render(Rect(i, i, w, h)); - renderbackend.endFrame(); - TimeManager::instance()->update(); - } - } - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 3); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 0); - } - pool.clear(); - BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); - BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 0); -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("Image Pool Tests"); - test->add( BOOST_TEST_CASE( &test_image_pool ),0 ); - return test; -} -#endif
--- a/tests/core_tests/test_images.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes - -// Platform specific includes - -// 3rd party library includes -#include <boost/scoped_ptr.hpp> -#include <boost/shared_ptr.hpp> -#include <SDL.h> - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "util/structures/rect.h" -#include "util/time/timemanager.h" -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/raw/rawdata.h" -#include "video/image_location.h" -#include "video/image.h" -#include "video/imagepool.h" -#include "video/sdl/renderbackendsdl.h" -#include "video/opengl/renderbackendopengl.h" -#include "loaders/native/video_loaders/image_loader.h" -#include "loaders/native/video_loaders/subimage_loader.h" -#include "util/base/exception.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -static const std::string IMAGE_FILE = "../data/beach_e1.png"; -static const std::string ALPHA_IMAGE_FILE = "../data/alpha_fidgit.png"; -static const std::string SUBIMAGE_FILE = "../data/rpg_tiles_01.png"; - -// Environment -struct environment { - boost::shared_ptr<TimeManager> timemanager; - boost::shared_ptr<VFS> vfs; - - environment() - : timemanager(new TimeManager()), - vfs(new VFS()) { - vfs->addSource(new VFSDirectory(vfs.get())); - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { - throw SDLException(SDL_GetError()); - } - } -}; - -void test_image(VFS* vfs, RenderBackend& renderbackend) { - renderbackend.init(); - renderbackend.createMainScreen(800, 600, 0, false); - - ImageLoader provider(vfs); - boost::scoped_ptr<Image> img(dynamic_cast<Image*>(provider.loadResource(ImageLocation(IMAGE_FILE)))); - - int h = img->getHeight(); - int w = img->getWidth(); - for (int i = 0; i < 100; i++) { - renderbackend.startFrame(); - img->render(Rect(i, i, w, h)); - renderbackend.endFrame(); - } - for (int j = 0; j < 5; j++) { - for (int i = -10; i < 10; i++) { - renderbackend.startFrame(); - img->setXShift(i); - img->setYShift(i); - img->render(Rect(200, 200, w, h)); - renderbackend.endFrame(); - } - } -} - -void test_subimage(VFS* vfs, RenderBackend& renderbackend) { - renderbackend.init(); - renderbackend.createMainScreen(800, 600, 0, false); - - ImageLoader imgprovider(vfs); - boost::scoped_ptr<Image> img(dynamic_cast<Image*>(imgprovider.loadResource(ImageLocation(SUBIMAGE_FILE)))); - - ImageLocation location(SUBIMAGE_FILE); - location.setParentSource(&*img); - int W = img->getWidth(); - int w = W / 12; - int H = img->getHeight(); - int h = H / 12; - location.setWidth(w); - location.setHeight(h); - std::vector<Image*> subimages; - - SubImageLoader subprovider; - for (int x = 0; x < (W - w); x+=w) { - for (int y = 0; y < (H - h); y+=h) { - location.setXShift(x); - location.setYShift(y); - Image* sub = dynamic_cast<Image*>(subprovider.loadResource(location)); - subimages.push_back(sub); - } - } - - for (unsigned int i = 0; i < 200; i++) { - renderbackend.startFrame(); - subimages[i / 40]->render(Rect(200, 200, w, h)); - renderbackend.endFrame(); - } - std::vector<Image*>::iterator i = subimages.begin(); - while (i != subimages.end()) { - delete *i; - i++; - } - -} - -void test_sdl_alphaoptimize() { - environment env; - RenderBackendSDL renderbackend; - renderbackend.init(); - renderbackend.createMainScreen(800, 600, 0, false); - renderbackend.setAlphaOptimizerEnabled(true); - - ImageLoader provider(env.vfs.get()); - boost::scoped_ptr<Image> img(dynamic_cast<Image*>(provider.loadResource(ImageLocation(IMAGE_FILE)))); - - boost::scoped_ptr<Image> alpha_img(dynamic_cast<Image*>(provider.loadResource(ImageLocation(ALPHA_IMAGE_FILE)))); - - int h0 = img->getHeight(); - int w0 = img->getWidth(); - - int h1 = alpha_img->getHeight(); - int w1 = alpha_img->getWidth(); - for(int i=0; i != 200; ++i) { - renderbackend.startFrame(); - img->render(Rect(i, i, w0, h0)); - alpha_img->render(Rect(i, i, w1, h1)); - alpha_img->render(Rect(i, h0+i, w1, h1)); - img->render(Rect(i, h0+i, w0, h0)); - renderbackend.endFrame(); - } - - BOOST_CHECK(img->getSurface()->format->Amask == 0); - BOOST_CHECK(alpha_img->getSurface()->format->Amask != 0); -} - -#ifdef FIFE_BOOST_VERSION_103300 -void test_sdl_image() { -#else -BOOST_AUTO_TEST_CASE( SDL_image_test ) { -#endif - environment env; - RenderBackendSDL renderbackend; - test_image(env.vfs.get(), renderbackend); -} - -#ifdef FIFE_BOOST_VERSION_103300 -void test_ogl_image() { -#else -BOOST_AUTO_TEST_CASE( OGL_image_test ) { -#endif - environment env; - RenderBackendOpenGL renderbackend; - test_image(env.vfs.get(), renderbackend); -} - -#ifdef FIFE_BOOST_VERSION_103300 -void test_sdl_subimage() { -#else -BOOST_AUTO_TEST_CASE( SDL_subimage_test ) { -#endif - environment env; - RenderBackendSDL renderbackend; - test_subimage(env.vfs.get(), renderbackend); -} - -#ifdef FIFE_BOOST_VERSION_103300 -void test_ogl_subimage() { -#else -BOOST_AUTO_TEST_CASE( OGL_subimage_test ) { -#endif - environment env; - RenderBackendOpenGL renderbackend; - test_subimage(env.vfs.get(), renderbackend); -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("Image Tests"); - test->add( BOOST_TEST_CASE( &test_sdl_subimage ),0 ); - test->add( BOOST_TEST_CASE( &test_ogl_subimage ),0 ); - test->add( BOOST_TEST_CASE( &test_sdl_image ),0 ); - test->add( BOOST_TEST_CASE( &test_ogl_image ),0 ); - test->add( BOOST_TEST_CASE( &test_sdl_alphaoptimize ),0 ); - - return test; -} -#endif
--- a/tests/core_tests/test_rect.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes -#include <ctime> -#include <vector> - -// Platform specific includes - -// 3rd party library includes - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "util/structures/rect.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -#ifdef FIFE_BOOST_VERSION_103300 -void rectangle_intersection() { -#else -BOOST_AUTO_TEST_CASE( Rectangle_test ) { -#endif - Rect a(0,0,10,10); - - std::vector<Rect> do_intersect; -#define ADD_RECT(x,y,w,h) do_intersect.push_back( Rect(x,y,w,h) ) - - ADD_RECT(5,5,10,10); - ADD_RECT(-5,5,10,10); - ADD_RECT(-5,-5,10,10); - ADD_RECT(5,-5,10,10); - - ADD_RECT(-5,5,20,1); - ADD_RECT(-5,5,10,1); - - ADD_RECT(5,-5,1,20); - ADD_RECT(5,-5,1,10); - - ADD_RECT(5,5,3,3); - - ADD_RECT(-5,-5,30,30); - - for(size_t i=0; i<do_intersect.size(); ++i) { - BOOST_CHECK(a.intersects(do_intersect[i])); - BOOST_CHECK(do_intersect[i].intersects(a)); - } - - std::vector<Rect> dont_intersect; - -#undef ADD_RECT -#define ADD_RECT(x,y,w,h) dont_intersect.push_back( Rect(x,y,w,h) ) - - ADD_RECT(-5,-5,4,4); - ADD_RECT(-5,-5,40,4); - ADD_RECT(-5,-5,4,40); - ADD_RECT(-5,-5,4,4); - - ADD_RECT(15,15,4,4); - ADD_RECT(15,15,40,4); - ADD_RECT(15,15,4,40); - - for(size_t i=0; i<dont_intersect.size(); ++i) { - BOOST_CHECK(!a.intersects(dont_intersect[i])); - BOOST_CHECK(!dont_intersect[i].intersects(a)); - } - -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("Rectangle Tests"); - - test->add( BOOST_TEST_CASE( &rectangle_intersection ),0 ); - - return test; -} -#endif
--- a/tests/core_tests/test_vfs.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes - -// Platform specific includes - -// 3rd party library includes -#include <boost/scoped_ptr.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/filesystem/convenience.hpp> - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "util/structures/rect.h" -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/raw/rawdata.h" -#include "util/base/exception.h" -#include "vfs/directoryprovider.h" - -#include "fife_unit_test.h" - -static const std::string FIFE_TEST_DIR = "fifetestdir"; - -using boost::unit_test::test_suite; -using namespace FIFE; - -#ifdef FIFE_BOOST_VERSION_103300 -void test_is_directory() { -#else -BOOST_AUTO_TEST_CASE( OGL_gui_test ) { -#endif - boost::shared_ptr<VFS> vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - if(boost::filesystem::exists(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)) { - boost::filesystem::remove(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR); - } - - if(boost::filesystem::exists(FIFE_TEST_DIR)) { - boost::filesystem::remove(FIFE_TEST_DIR); - } - - // Check root dir - BOOST_CHECK(vfs->isDirectory("")); - BOOST_CHECK(vfs->isDirectory("/")); - - BOOST_CHECK(!vfs->isDirectory(FIFE_TEST_DIR)); - boost::filesystem::create_directory(FIFE_TEST_DIR); - BOOST_CHECK(vfs->isDirectory(FIFE_TEST_DIR)); - BOOST_CHECK(!vfs->isDirectory(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)); - boost::filesystem::create_directories(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR); - BOOST_CHECK(vfs->isDirectory(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)); - - boost::filesystem::remove(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR); - boost::filesystem::remove(FIFE_TEST_DIR); -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("VFS Tests"); - - test->add( BOOST_TEST_CASE( &test_is_directory ),0 ); - - return test; -} -#endif
--- a/tests/core_tests/test_zip.cpp Sun Jul 13 07:43:33 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2008 by the FIFE team * - * http://www.fifengine.de * - * This file is part of FIFE. * - * * - * FIFE 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. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -// Standard C++ library includes -#include <iostream> -#include <iomanip> - -// Platform specific includes - -// 3rd party library includes - -// FIFE includes -// These includes are split up in two parts, separated by one empty line -// First block: files included from the FIFE root src directory -// Second block: files included from the same folder -#include "vfs/vfs.h" -#include "util/time/timemanager.h" -#include "vfs/vfs.h" -#include "vfs/vfsdirectory.h" -#include "vfs/zip/zipsource.h" -#include "vfs/raw/rawdata.h" -#include "util/base/exception.h" - -#include "fife_unit_test.h" - -using boost::unit_test::test_suite; -using namespace FIFE; - -// Environment -struct environment { - boost::shared_ptr<TimeManager> timemanager; - - environment() - : timemanager(new TimeManager()) {} -}; - -using boost::unit_test::test_suite; -using namespace FIFE; - -static const std::string COMPRESSED_FILE = "../data/testmap.zip"; -static const std::string RAW_FILE = "../data/test.map"; - -#ifdef FIFE_BOOST_VERSION_103300 -void test_decoder() { -#else -BOOST_AUTO_TEST_CASE( ZipSource_test ) { -#endif - environment env; - - boost::shared_ptr<VFS> vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - if ((!vfs->exists(COMPRESSED_FILE))) { - BOOST_ERROR("Test source " << COMPRESSED_FILE << " not found"); - return; - } - - vfs->addSource(new ZipSource(vfs.get(), COMPRESSED_FILE)); - - BOOST_CHECK_THROW(vfs->open("does-not-exist"), NotFound); - std::set<std::string> dirlist = vfs->listDirectories("ziptest_content"); - BOOST_CHECK(dirlist.size() == 4); - BOOST_CHECK(std::find(dirlist.begin(), dirlist.end(), "maps") != dirlist.end()); - BOOST_CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir1") != dirlist.end()); - BOOST_CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir2") != dirlist.end()); - BOOST_CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir3") != dirlist.end()); - - std::set<std::string> filelist = vfs->listFiles("ziptest_content"); - BOOST_CHECK(filelist.size() == 0); - filelist = vfs->listFiles("ziptest_content/testdir1"); - BOOST_CHECK(filelist.size() == 4); - BOOST_CHECK(std::find(filelist.begin(), filelist.end(), "file") != filelist.end()); - BOOST_CHECK(std::find(filelist.begin(), filelist.end(), "file-a") != filelist.end()); - BOOST_CHECK(std::find(filelist.begin(), filelist.end(), "file-b") != filelist.end()); - BOOST_CHECK(std::find(filelist.begin(), filelist.end(), "file-c") != filelist.end()); - - BOOST_CHECK(vfs->listFiles("ziptest_content/testdir3").size() == 0); - BOOST_CHECK(vfs->listDirectories("ziptest_content/testdir1").size() == 0); - - - if ((!vfs->exists(RAW_FILE)) || (!vfs->exists("ziptest_content/maps/test.map"))) { - BOOST_ERROR("Test files not found"); - } - - RawData* fraw = vfs->open(RAW_FILE); - RawData* fcomp = vfs->open("ziptest_content/maps/test.map"); - - if (fraw->getDataLength() != fcomp->getDataLength()) { - std::cout << "raw length = " << fraw->getDataLength() \ - << ", compressed length = " << fcomp->getDataLength() << std::endl; - BOOST_ERROR("Data length mismatch"); - } else { - std::cout << "data length match, length = " << fcomp->getDataLength() << std::endl; - } - - unsigned int smaller_len = fraw->getDataLength(); - if (fcomp->getDataLength() < smaller_len) { - smaller_len = fcomp->getDataLength(); - } - - uint8_t* d_raw = new uint8_t[fraw->getDataLength()]; - uint8_t* d_comp = new uint8_t[fcomp->getDataLength()]; - fraw->readInto(d_raw,fraw->getDataLength()); - fcomp->readInto(d_comp,fcomp->getDataLength()); - - std::cout << "scanning data..." << std::endl; - for (unsigned int i = 0; i < smaller_len; i++) { - uint8_t rawc = d_raw[i]; - uint8_t compc = d_comp[i]; - if (rawc != compc) { - BOOST_ERROR("Data mismatch"); - std::cout - << "raw: " << std::setbase(16) << rawc - << " comp: " << std::setbase(16) << compc << std::endl; - break; - } - } - std::cout << "scanning finished" << std::endl; - delete[] d_raw; - delete[] d_comp; - delete fraw; - delete fcomp; -} - -#ifdef FIFE_BOOST_VERSION_103300 -test_suite* init_unit_test_suite(int argc, char** const argv) { - test_suite* test = BOOST_TEST_SUITE("DAT2 tests"); - test->add(BOOST_TEST_CASE(&test_decoder), 0); - return test; -} -#endif