# HG changeset patch # User jasoka@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1215935578 0 # Node ID 5a2db5e7ab54ebbc40f5a6864fa01c3de882407d # Parent 6daa907234e14fca938967816bc970ea2ea2cd67 renamed unittest++ based tests as they were with boost diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/SConscript --- a/tests/core_tests/SConscript Sun Jul 13 07:46:49 2008 +0000 +++ b/tests/core_tests/SConscript Sun Jul 13 07:52:58 2008 +0000 @@ -19,16 +19,16 @@ # The test_fife.py script relies on this specific layout. # Check it, if you change something here -env.Program('testprog_rect', ['test_rect++.cpp']) -env.Program('testprog_dat1', ['test_dat1++.cpp']) -env.Program('testprog_dat2', ['test_dat2++.cpp']) -env.Program('testprog_gui', ['test_gui++.cpp']) -env.Program('testprog_images', ['test_images++.cpp']) -env.Program('testprog_imagepool', ['test_imagepool++.cpp']) -env.Program('testprog_vfs', ['test_vfs++.cpp']) +env.Program('testprog_rect', ['test_rect.cpp']) +env.Program('testprog_dat1', ['test_dat1.cpp']) +env.Program('testprog_dat2', ['test_dat2.cpp']) +env.Program('testprog_gui', ['test_gui.cpp']) +env.Program('testprog_images', ['test_images.cpp']) +env.Program('testprog_imagepool', ['test_imagepool.cpp']) +env.Program('testprog_vfs', ['test_vfs.cpp']) if env['zip']: - env.Program('testprog_zip', ['test_zip++.cpp']) + env.Program('testprog_zip', ['test_zip.cpp']) # vim: set filetype=python : diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_dat1++.cpp --- a/tests/core_tests/test_dat1++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +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 -#include - -// Platform specific includes -#include "fife_unittest++.h" - -// 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/dat/dat2.h" -#include "vfs/raw/rawdata.h" -#include "util/base/exception.h" - -using namespace FIFE; - -static const std::string COMPRESSED_FILE = "../../tests/data/dat1vfstest.dat"; -static const std::string RAW_FILE = "../../tests/data/test.map"; - -TEST(DAT1_test){ - - boost::shared_ptr vfs(new FIFE::VFS()); - vfs->addSource(new FIFE::VFSDirectory(vfs.get())); - CHECK(vfs->exists(COMPRESSED_FILE)); - - - vfs->addSource(new FIFE::DAT1(vfs.get(), COMPRESSED_FILE)); - - CHECK(vfs->exists(RAW_FILE)); - CHECK(vfs->exists("dat1vfstest.map")); - - FIFE::RawData* fraw = vfs->open(RAW_FILE); - FIFE::RawData* fcomp = vfs->open("dat1vfstest.map"); - - CHECK_EQUAL(fraw->getDataLength(), fcomp->getDataLength()); - //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]; - CHECK_EQUAL(compc, rawc); - //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; -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_dat1.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_dat1.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,96 @@ +/*************************************************************************** + * 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 +#include + +// Platform specific includes +#include "fife_unittest++.h" + +// 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/dat/dat2.h" +#include "vfs/raw/rawdata.h" +#include "util/base/exception.h" + +using namespace FIFE; + +static const std::string COMPRESSED_FILE = "../../tests/data/dat1vfstest.dat"; +static const std::string RAW_FILE = "../../tests/data/test.map"; + +TEST(DAT1_test){ + + boost::shared_ptr vfs(new FIFE::VFS()); + vfs->addSource(new FIFE::VFSDirectory(vfs.get())); + CHECK(vfs->exists(COMPRESSED_FILE)); + + + vfs->addSource(new FIFE::DAT1(vfs.get(), COMPRESSED_FILE)); + + CHECK(vfs->exists(RAW_FILE)); + CHECK(vfs->exists("dat1vfstest.map")); + + FIFE::RawData* fraw = vfs->open(RAW_FILE); + FIFE::RawData* fcomp = vfs->open("dat1vfstest.map"); + + CHECK_EQUAL(fraw->getDataLength(), fcomp->getDataLength()); + //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]; + CHECK_EQUAL(compc, rawc); + //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; +} + +int main() { + return UnitTest::RunAllTests(); +} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_dat2++.cpp --- a/tests/core_tests/test_dat2++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +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 -#include - -// Platform specific includes -#include "fife_unittest++.h" - -// 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/dat2.h" -#include "vfs/raw/rawdata.h" -#include "util/base/exception.h" -#include "util/time/timemanager.h" - -using namespace FIFE; - -static const std::string COMPRESSED_FILE = "../data/dat2vfstest.dat"; -static const std::string RAW_FILE = "../data/test.map"; -TEST(DAT2_test){ - - boost::shared_ptr timemanager(new TimeManager()); - - boost::shared_ptr vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - CHECK(vfs->exists(COMPRESSED_FILE)); - - try { - std::cout << "adding Source" << std::endl; - vfs->addSource(new DAT2(vfs.get(), COMPRESSED_FILE)); - std::cout << "added Source" << std::endl; - } - catch (Exception& e) - { - std::cout << e.getMessage() << std::endl; - } - - CHECK(vfs->exists(RAW_FILE)); - CHECK(vfs->exists("dat2vfstest.map")); - - FIFE::RawData* fraw = vfs->open(RAW_FILE); - FIFE::RawData* fcomp = vfs->open("dat2vfstest.map"); - - CHECK_EQUAL(fraw->getDataLength(), fcomp->getDataLength()); - //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]; - CHECK_EQUAL(compc, rawc); - //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; - -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_dat2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_dat2.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,105 @@ +/*************************************************************************** + * 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 +#include + +// Platform specific includes +#include "fife_unittest++.h" + +// 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/dat2.h" +#include "vfs/raw/rawdata.h" +#include "util/base/exception.h" +#include "util/time/timemanager.h" + +using namespace FIFE; + +static const std::string COMPRESSED_FILE = "../data/dat2vfstest.dat"; +static const std::string RAW_FILE = "../data/test.map"; +TEST(DAT2_test){ + + boost::shared_ptr timemanager(new TimeManager()); + + boost::shared_ptr vfs(new VFS()); + vfs->addSource(new VFSDirectory(vfs.get())); + CHECK(vfs->exists(COMPRESSED_FILE)); + + try { + std::cout << "adding Source" << std::endl; + vfs->addSource(new DAT2(vfs.get(), COMPRESSED_FILE)); + std::cout << "added Source" << std::endl; + } + catch (Exception& e) + { + std::cout << e.getMessage() << std::endl; + } + + CHECK(vfs->exists(RAW_FILE)); + CHECK(vfs->exists("dat2vfstest.map")); + + FIFE::RawData* fraw = vfs->open(RAW_FILE); + FIFE::RawData* fcomp = vfs->open("dat2vfstest.map"); + + CHECK_EQUAL(fraw->getDataLength(), fcomp->getDataLength()); + //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]; + CHECK_EQUAL(compc, rawc); + //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; + +} + +int main() { + return UnitTest::RunAllTests(); +} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_gui++.cpp --- a/tests/core_tests/test_gui++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +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 -#include "fife_unittest++.h" - -// 3rd party library includes -#include -#include -#include -#include - -#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" - -using namespace FIFE; - -static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; -static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; -struct environment { - boost::shared_ptr 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(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 img(dynamic_cast(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; - } - - -TEST(test_sdl_gui_image) -{ - 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); -} - -TEST(test_ogl_gui_image) -{ - environment env; - RenderBackendOpenGL renderbackend; - renderbackend.init(); - ImagePool pool; - renderbackend.createMainScreen(800, 600, 0, false); - OpenGLGuiGraphics graphics(pool); - test_gui_image(renderbackend, graphics, pool); -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_gui.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_gui.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,134 @@ +/*************************************************************************** + * 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 +#include "fife_unittest++.h" + +// 3rd party library includes +#include +#include +#include +#include + +#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" + +using namespace FIFE; + +static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; +static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; +struct environment { + boost::shared_ptr 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(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 img(dynamic_cast(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; + } + + +TEST(test_sdl_gui_image) +{ + 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); +} + +TEST(test_ogl_gui_image) +{ + environment env; + RenderBackendOpenGL renderbackend; + renderbackend.init(); + ImagePool pool; + renderbackend.createMainScreen(800, 600, 0, false); + OpenGLGuiGraphics graphics(pool); + test_gui_image(renderbackend, graphics, pool); +} + +int main() { + return UnitTest::RunAllTests(); +} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_imagepool++.cpp --- a/tests/core_tests/test_imagepool++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +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 -#include - -// Platform specific includes -#include "fife_unittest++.h" - -// 3rd party library includes -#include -#include -#include - -// 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/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" - -using namespace FIFE; - -static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; -static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; -static const std::string ANIM_FILE = "../../tests/data/crate_full_001.xml"; - -// Environment -struct environment { - boost::shared_ptr timemanager; - boost::shared_ptr vfs; - - environment() - : timemanager(new TimeManager()) { - if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { - throw SDLException(SDL_GetError()); - } - } -}; - -TEST(test_image_pool) -{ - environment env; - RenderBackendSDL renderbackend; - - boost::scoped_ptr 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())); - - CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); - - pool.addResourceFromLocation(ImageLocation(IMAGE_FILE)); - CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(1, pool.getResourceCount(RES_NON_LOADED)); - ImageLocation location(SUBIMAGE_FILE); - ImageLoader imgprovider(vfs.get()); - int fullImgInd = pool.addResourceFromLocation(ImageLocation(SUBIMAGE_FILE)); - CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(2, pool.getResourceCount(RES_NON_LOADED)); - Image& img = pool.getImage(fullImgInd); - CHECK_EQUAL(1, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(1, pool.getResourceCount(RES_NON_LOADED)); - - 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); - - CHECK_EQUAL(1, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(2, pool.getResourceCount(RES_NON_LOADED)); - - 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(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(); - } - } - CHECK_EQUAL(3, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); - } - CHECK_EQUAL(3, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); - pool.clear(); - CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); - CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_imagepool.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_imagepool.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,137 @@ +/*************************************************************************** + * 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 +#include + +// Platform specific includes +#include "fife_unittest++.h" + +// 3rd party library includes +#include +#include +#include + +// 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/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" + +using namespace FIFE; + +static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; +static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; +static const std::string ANIM_FILE = "../../tests/data/crate_full_001.xml"; + +// Environment +struct environment { + boost::shared_ptr timemanager; + boost::shared_ptr vfs; + + environment() + : timemanager(new TimeManager()) { + if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { + throw SDLException(SDL_GetError()); + } + } +}; + +TEST(test_image_pool) +{ + environment env; + RenderBackendSDL renderbackend; + + boost::scoped_ptr 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())); + + CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); + + pool.addResourceFromLocation(ImageLocation(IMAGE_FILE)); + CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(1, pool.getResourceCount(RES_NON_LOADED)); + ImageLocation location(SUBIMAGE_FILE); + ImageLoader imgprovider(vfs.get()); + int fullImgInd = pool.addResourceFromLocation(ImageLocation(SUBIMAGE_FILE)); + CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(2, pool.getResourceCount(RES_NON_LOADED)); + Image& img = pool.getImage(fullImgInd); + CHECK_EQUAL(1, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(1, pool.getResourceCount(RES_NON_LOADED)); + + 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); + + CHECK_EQUAL(1, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(2, pool.getResourceCount(RES_NON_LOADED)); + + 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(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(); + } + } + CHECK_EQUAL(3, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); + } + CHECK_EQUAL(3, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); + pool.clear(); + CHECK_EQUAL(0, pool.getResourceCount(RES_LOADED)); + CHECK_EQUAL(0, pool.getResourceCount(RES_NON_LOADED)); +} + +int main() { + return UnitTest::RunAllTests(); +} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_images++.cpp --- a/tests/core_tests/test_images++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,201 +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 -#include - -// Platform specific includes -#include "fife_unittest++.h" - -// 3rd party library includes -#include -#include -#include - -// 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/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" - -using namespace FIFE; - -static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; -static const std::string ALPHA_IMAGE_FILE = "../../tests/data/alpha_fidgit.png"; -static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; - -// Environment -struct environment { - boost::shared_ptr timemanager; - boost::shared_ptr 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 img(dynamic_cast(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 img(dynamic_cast(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 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(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::iterator i = subimages.begin(); - while (i != subimages.end()) { - delete *i; - i++; - } - -} - -TEST(test_sdl_alphaoptimize) -{ - environment env; - RenderBackendSDL renderbackend; - renderbackend.init(); - renderbackend.createMainScreen(800, 600, 0, false); - renderbackend.setAlphaOptimizerEnabled(true); - - ImageLoader provider(env.vfs.get()); - env.vfs.get()->exists(IMAGE_FILE); - boost::scoped_ptr img(dynamic_cast(provider.loadResource(ImageLocation(IMAGE_FILE)))); - env.vfs.get()->exists(ALPHA_IMAGE_FILE); - boost::scoped_ptr alpha_img(dynamic_cast(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(); - } - - CHECK(img->getSurface()->format->Amask == 0); - CHECK(alpha_img->getSurface()->format->Amask != 0); -} - -TEST(test_sdl_image) -{ - environment env; - RenderBackendSDL renderbackend; - test_image(env.vfs.get(), renderbackend); -} - -TEST(test_ogl_image) -{ - environment env; - RenderBackendOpenGL renderbackend; - test_image(env.vfs.get(), renderbackend); -} - -TEST(test_sdl_subimage) -{ - environment env; - RenderBackendSDL renderbackend; - CHECK(env.vfs.get()->exists(IMAGE_FILE)); - test_subimage(env.vfs.get(), renderbackend); -} - -TEST(test_ogl_subimage) -{ - environment env; - RenderBackendOpenGL renderbackend; - test_subimage(env.vfs.get(), renderbackend); -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_images.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_images.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,201 @@ +/*************************************************************************** + * 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 +#include + +// Platform specific includes +#include "fife_unittest++.h" + +// 3rd party library includes +#include +#include +#include + +// 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/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" + +using namespace FIFE; + +static const std::string IMAGE_FILE = "../../tests/data/beach_e1.png"; +static const std::string ALPHA_IMAGE_FILE = "../../tests/data/alpha_fidgit.png"; +static const std::string SUBIMAGE_FILE = "../../tests/data/rpg_tiles_01.png"; + +// Environment +struct environment { + boost::shared_ptr timemanager; + boost::shared_ptr 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 img(dynamic_cast(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 img(dynamic_cast(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 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(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::iterator i = subimages.begin(); + while (i != subimages.end()) { + delete *i; + i++; + } + +} + +TEST(test_sdl_alphaoptimize) +{ + environment env; + RenderBackendSDL renderbackend; + renderbackend.init(); + renderbackend.createMainScreen(800, 600, 0, false); + renderbackend.setAlphaOptimizerEnabled(true); + + ImageLoader provider(env.vfs.get()); + env.vfs.get()->exists(IMAGE_FILE); + boost::scoped_ptr img(dynamic_cast(provider.loadResource(ImageLocation(IMAGE_FILE)))); + env.vfs.get()->exists(ALPHA_IMAGE_FILE); + boost::scoped_ptr alpha_img(dynamic_cast(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(); + } + + CHECK(img->getSurface()->format->Amask == 0); + CHECK(alpha_img->getSurface()->format->Amask != 0); +} + +TEST(test_sdl_image) +{ + environment env; + RenderBackendSDL renderbackend; + test_image(env.vfs.get(), renderbackend); +} + +TEST(test_ogl_image) +{ + environment env; + RenderBackendOpenGL renderbackend; + test_image(env.vfs.get(), renderbackend); +} + +TEST(test_sdl_subimage) +{ + environment env; + RenderBackendSDL renderbackend; + CHECK(env.vfs.get()->exists(IMAGE_FILE)); + test_subimage(env.vfs.get(), renderbackend); +} + +TEST(test_ogl_subimage) +{ + environment env; + RenderBackendOpenGL renderbackend; + test_subimage(env.vfs.get(), renderbackend); +} + +int main() { + return UnitTest::RunAllTests(); +} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_rect++.cpp --- a/tests/core_tests/test_rect++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +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 -#include - -// Platform specific includes -#include "fife_unittest++.h" - -// 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" - -using namespace FIFE; - -TEST(rectangle_interesection) -{ - Rect a(0,0,10,10); - - std::vector 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 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 +#include + +// Platform specific includes +#include "fife_unittest++.h" + +// 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" + +using namespace FIFE; + +TEST(rectangle_interesection) +{ + Rect a(0,0,10,10); + + std::vector 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 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 -#include -#include - -// 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" - -static const std::string FIFE_TEST_DIR = "fifetestdir"; -using namespace FIFE; - -TEST(test_is_directory) -{ - boost::shared_ptr 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(vfs->isDirectory("")); - CHECK(vfs->isDirectory("/")); - - CHECK(!vfs->isDirectory(FIFE_TEST_DIR)); - boost::filesystem::create_directory(FIFE_TEST_DIR); - CHECK(vfs->isDirectory(FIFE_TEST_DIR)); - CHECK(!vfs->isDirectory(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)); - boost::filesystem::create_directories(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR); - CHECK(vfs->isDirectory(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)); - -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_vfs.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_vfs.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,73 @@ +/*************************************************************************** + * 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 +#include "fife_unittest++.h" + +// 3rd party library includes +#include +#include +#include + +// 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" + +static const std::string FIFE_TEST_DIR = "fifetestdir"; +using namespace FIFE; + +TEST(test_is_directory) +{ + boost::shared_ptr 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(vfs->isDirectory("")); + CHECK(vfs->isDirectory("/")); + + CHECK(!vfs->isDirectory(FIFE_TEST_DIR)); + boost::filesystem::create_directory(FIFE_TEST_DIR); + CHECK(vfs->isDirectory(FIFE_TEST_DIR)); + CHECK(!vfs->isDirectory(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)); + boost::filesystem::create_directories(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR); + CHECK(vfs->isDirectory(FIFE_TEST_DIR+"/"+FIFE_TEST_DIR)); + +} + +int main() { + return UnitTest::RunAllTests(); +} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_zip++.cpp --- a/tests/core_tests/test_zip++.cpp Sun Jul 13 07:46:49 2008 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +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 -#include - -// Platform specific includes -#include "fife_unittest++.h" - -// 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" - -using namespace FIFE; - -// Environment -struct environment { - boost::shared_ptr timemanager; - - environment() - : timemanager(new TimeManager()) {} -}; - -using namespace FIFE; - -static const std::string COMPRESSED_FILE = "../../tests/data/testmap.zip"; -static const std::string RAW_FILE = "../../tests/data/test.map"; - -TEST(test_decoder) { - environment env; - boost::shared_ptr vfs(new VFS()); - vfs->addSource(new VFSDirectory(vfs.get())); - - CHECK(vfs->exists(COMPRESSED_FILE)); - vfs->addSource(new ZipSource(vfs.get(), COMPRESSED_FILE)); - - CHECK_THROW(vfs->open("does-not-exist"), NotFound); - std::set dirlist = vfs->listDirectories("ziptest_content"); - - CHECK(dirlist.size() == 4); - CHECK(std::find(dirlist.begin(), dirlist.end(), "maps") != dirlist.end()); - CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir1") != dirlist.end()); - CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir2") != dirlist.end()); - CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir3") != dirlist.end()); - - std::set filelist = vfs->listFiles("ziptest_content"); - CHECK(filelist.size() == 0); - filelist = vfs->listFiles("ziptest_content/testdir1"); - - CHECK(filelist.size() == 4); - CHECK(std::find(filelist.begin(), filelist.end(), "file") != filelist.end()); - CHECK(std::find(filelist.begin(), filelist.end(), "file-a") != filelist.end()); - CHECK(std::find(filelist.begin(), filelist.end(), "file-b") != filelist.end()); - CHECK(std::find(filelist.begin(), filelist.end(), "file-c") != filelist.end()); - - CHECK(vfs->listFiles("ziptest_content/testdir3").size() == 0); - CHECK(vfs->listDirectories("ziptest_content/testdir1").size() == 0); - - CHECK(vfs->exists(RAW_FILE) && vfs->exists("ziptest_content/maps/test.map")); - RawData* fraw = vfs->open(RAW_FILE); - RawData* fcomp = vfs->open("ziptest_content/maps/test.map"); - - CHECK(fraw->getDataLength() == fcomp->getDataLength()); - std::cout << "9" << 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]; - CHECK(rawc == compc); - - } - std::cout << "scanning finished" << std::endl; - delete[] d_raw; - delete[] d_comp; - delete fraw; - delete fcomp; -} - -int main() { - return UnitTest::RunAllTests(); -} diff -r 6daa907234e1 -r 5a2db5e7ab54 tests/core_tests/test_zip.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/core_tests/test_zip.cpp Sun Jul 13 07:52:58 2008 +0000 @@ -0,0 +1,120 @@ +/*************************************************************************** + * 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 +#include + +// Platform specific includes +#include "fife_unittest++.h" + +// 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" + +using namespace FIFE; + +// Environment +struct environment { + boost::shared_ptr timemanager; + + environment() + : timemanager(new TimeManager()) {} +}; + +using namespace FIFE; + +static const std::string COMPRESSED_FILE = "../../tests/data/testmap.zip"; +static const std::string RAW_FILE = "../../tests/data/test.map"; + +TEST(test_decoder) { + environment env; + boost::shared_ptr vfs(new VFS()); + vfs->addSource(new VFSDirectory(vfs.get())); + + CHECK(vfs->exists(COMPRESSED_FILE)); + vfs->addSource(new ZipSource(vfs.get(), COMPRESSED_FILE)); + + CHECK_THROW(vfs->open("does-not-exist"), NotFound); + std::set dirlist = vfs->listDirectories("ziptest_content"); + + CHECK(dirlist.size() == 4); + CHECK(std::find(dirlist.begin(), dirlist.end(), "maps") != dirlist.end()); + CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir1") != dirlist.end()); + CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir2") != dirlist.end()); + CHECK(std::find(dirlist.begin(), dirlist.end(), "testdir3") != dirlist.end()); + + std::set filelist = vfs->listFiles("ziptest_content"); + CHECK(filelist.size() == 0); + filelist = vfs->listFiles("ziptest_content/testdir1"); + + CHECK(filelist.size() == 4); + CHECK(std::find(filelist.begin(), filelist.end(), "file") != filelist.end()); + CHECK(std::find(filelist.begin(), filelist.end(), "file-a") != filelist.end()); + CHECK(std::find(filelist.begin(), filelist.end(), "file-b") != filelist.end()); + CHECK(std::find(filelist.begin(), filelist.end(), "file-c") != filelist.end()); + + CHECK(vfs->listFiles("ziptest_content/testdir3").size() == 0); + CHECK(vfs->listDirectories("ziptest_content/testdir1").size() == 0); + + CHECK(vfs->exists(RAW_FILE) && vfs->exists("ziptest_content/maps/test.map")); + RawData* fraw = vfs->open(RAW_FILE); + RawData* fcomp = vfs->open("ziptest_content/maps/test.map"); + + CHECK(fraw->getDataLength() == fcomp->getDataLength()); + std::cout << "9" << 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]; + CHECK(rawc == compc); + + } + std::cout << "scanning finished" << std::endl; + delete[] d_raw; + delete[] d_comp; + delete fraw; + delete fcomp; +} + +int main() { + return UnitTest::RunAllTests(); +}