Mercurial > fife-parpg
comparison tests/core_tests/test_imagepool.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 #include <iostream> | |
24 #include <iomanip> | |
25 | |
26 // Platform specific includes | |
27 | |
28 // 3rd party library includes | |
29 #include <boost/scoped_ptr.hpp> | |
30 #include <boost/shared_ptr.hpp> | |
31 #include <SDL.h> | |
32 | |
33 // FIFE includes | |
34 // These includes are split up in two parts, separated by one empty line | |
35 // First block: files included from the FIFE root src directory | |
36 // Second block: files included from the same folder | |
37 #include "vfs/vfs.h" | |
38 #include "util/structures/rect.h" | |
39 #include "util/time/timemanager.h" | |
40 #include "vfs/vfs.h" | |
41 #include "vfs/vfsdirectory.h" | |
42 #include "vfs/raw/rawdata.h" | |
43 #include "video/image_location.h" | |
44 #include "video/image.h" | |
45 #include "video/imagepool.h" | |
46 #include "video/sdl/renderbackendsdl.h" | |
47 #include "video/opengl/renderbackendopengl.h" | |
48 #include "loaders/native/video_loaders/image_loader.h" | |
49 #include "loaders/native/video_loaders/subimage_loader.h" | |
50 #include "util/base/exception.h" | |
51 | |
52 #include "fife_unit_test.h" | |
53 | |
54 using boost::unit_test::test_suite; | |
55 using namespace FIFE; | |
56 | |
57 static const std::string IMAGE_FILE = "../data/beach_e1.png"; | |
58 static const std::string SUBIMAGE_FILE = "../data/rpg_tiles_01.png"; | |
59 static const std::string ANIM_FILE = "../data/crate_full_001.xml"; | |
60 | |
61 // Environment | |
62 struct environment { | |
63 boost::shared_ptr<TimeManager> timemanager; | |
64 boost::shared_ptr<VFS> vfs; | |
65 | |
66 environment() | |
67 : timemanager(new TimeManager()) { | |
68 if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER) < 0) { | |
69 throw SDLException(SDL_GetError()); | |
70 } | |
71 } | |
72 }; | |
73 | |
74 #ifdef FIFE_BOOST_VERSION_103300 | |
75 void test_image_pool() { | |
76 #else | |
77 BOOST_AUTO_TEST_CASE( ImagePool_test ) { | |
78 #endif | |
79 environment env; | |
80 RenderBackendSDL renderbackend; | |
81 | |
82 boost::scoped_ptr<VFS> vfs(new VFS()); | |
83 vfs->addSource(new VFSDirectory(vfs.get())); | |
84 | |
85 renderbackend.init(); | |
86 renderbackend.createMainScreen(800, 600, 0, false); | |
87 ImagePool pool; | |
88 pool.addResourceLoader(new SubImageLoader()); | |
89 pool.addResourceLoader(new ImageLoader(vfs.get())); | |
90 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); | |
91 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 0); | |
92 | |
93 pool.addResourceFromLocation(ImageLocation(IMAGE_FILE)); | |
94 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); | |
95 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 1); | |
96 | |
97 ImageLocation location(SUBIMAGE_FILE); | |
98 ImageLoader imgprovider(vfs.get()); | |
99 int fullImgInd = pool.addResourceFromLocation(ImageLocation(SUBIMAGE_FILE)); | |
100 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); | |
101 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 2); | |
102 | |
103 Image& img = pool.getImage(fullImgInd); | |
104 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 1); | |
105 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 1); | |
106 | |
107 location.setParentSource(&img); | |
108 int W = img.getWidth(); | |
109 int w = W / 12; | |
110 int H = img.getHeight(); | |
111 int h = H / 12; | |
112 location.setWidth(w); | |
113 location.setHeight(h); | |
114 pool.addResourceFromLocation(location); | |
115 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 1); | |
116 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 2); | |
117 | |
118 for (int k = 0; k < 3; k++) { | |
119 for (int j = 0, s = pool.getResourceCount(RES_LOADED | RES_NON_LOADED); j < s; j++) { | |
120 std::cout << j << std::endl; | |
121 Image& r = dynamic_cast<Image&>(pool.get(j)); | |
122 int h = r.getHeight(); | |
123 int w = r.getWidth(); | |
124 for (int i = 20; i > 0; i-=2) { | |
125 renderbackend.startFrame(); | |
126 r.render(Rect(i, i, w, h)); | |
127 renderbackend.endFrame(); | |
128 TimeManager::instance()->update(); | |
129 } | |
130 } | |
131 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 3); | |
132 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 0); | |
133 } | |
134 pool.clear(); | |
135 BOOST_CHECK(pool.getResourceCount(RES_LOADED) == 0); | |
136 BOOST_CHECK(pool.getResourceCount(RES_NON_LOADED) == 0); | |
137 } | |
138 | |
139 #ifdef FIFE_BOOST_VERSION_103300 | |
140 test_suite* init_unit_test_suite(int argc, char** const argv) { | |
141 test_suite* test = BOOST_TEST_SUITE("Image Pool Tests"); | |
142 test->add( BOOST_TEST_CASE( &test_image_pool ),0 ); | |
143 return test; | |
144 } | |
145 #endif |