]>
Commit | Line | Data |
---|---|---|
21fe35af FM |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/image/image.cpp | |
3 | // Purpose: Test wxImage | |
4 | // Author: Francesco Montorsi | |
5 | // Created: 2009-05-31 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2009 Francesco Montorsi | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ---------------------------------------------------------------------------- | |
12 | // headers | |
13 | // ---------------------------------------------------------------------------- | |
14 | ||
15 | #include "testprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #ifndef WX_PRECOMP | |
22 | #endif // WX_PRECOMP | |
23 | ||
53c2cdb0 | 24 | #include "wx/image.h" |
21fe35af | 25 | #include "wx/url.h" |
9e91447c | 26 | #include "wx/log.h" |
21fe35af FM |
27 | #include "wx/mstream.h" |
28 | #include "wx/zstream.h" | |
29 | #include "wx/wfstream.h" | |
30 | ||
31 | struct testData { | |
32 | const char* file; | |
33 | wxBitmapType type; | |
51fe4100 | 34 | } g_testfiles[] = |
21fe35af FM |
35 | { |
36 | { "horse.ico", wxBITMAP_TYPE_ICO }, | |
37 | { "horse.xpm", wxBITMAP_TYPE_XPM }, | |
38 | { "horse.png", wxBITMAP_TYPE_PNG }, | |
39 | { "horse.ani", wxBITMAP_TYPE_ANI }, | |
40 | { "horse.bmp", wxBITMAP_TYPE_BMP }, | |
41 | { "horse.cur", wxBITMAP_TYPE_CUR }, | |
42 | { "horse.gif", wxBITMAP_TYPE_GIF }, | |
43 | { "horse.jpg", wxBITMAP_TYPE_JPEG }, | |
44 | { "horse.pcx", wxBITMAP_TYPE_PCX }, | |
45 | { "horse.pnm", wxBITMAP_TYPE_PNM }, | |
46 | { "horse.tga", wxBITMAP_TYPE_TGA }, | |
47 | { "horse.tif", wxBITMAP_TYPE_TIF } | |
48 | }; | |
49 | ||
50 | ||
51 | // ---------------------------------------------------------------------------- | |
52 | // test class | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | class ImageTestCase : public CppUnit::TestCase | |
56 | { | |
57 | public: | |
58 | ImageTestCase(); | |
59 | ~ImageTestCase(); | |
60 | ||
61 | private: | |
62 | CPPUNIT_TEST_SUITE( ImageTestCase ); | |
63 | CPPUNIT_TEST( LoadFromSocketStream ); | |
64 | CPPUNIT_TEST( LoadFromZipStream ); | |
65 | CPPUNIT_TEST( LoadFromFile ); | |
2e51fb30 | 66 | CPPUNIT_TEST( SizeImage ); |
21fe35af FM |
67 | CPPUNIT_TEST_SUITE_END(); |
68 | ||
69 | void LoadFromSocketStream(); | |
70 | void LoadFromZipStream(); | |
71 | void LoadFromFile(); | |
2e51fb30 | 72 | void SizeImage(); |
21fe35af FM |
73 | |
74 | DECLARE_NO_COPY_CLASS(ImageTestCase) | |
75 | }; | |
76 | ||
77 | CPPUNIT_TEST_SUITE_REGISTRATION( ImageTestCase ); | |
78 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ImageTestCase, "ImageTestCase" ); | |
79 | ||
80 | ImageTestCase::ImageTestCase() | |
81 | { | |
82 | wxSocketBase::Initialize(); | |
83 | ||
84 | // the formats we're going to test: | |
85 | wxImage::AddHandler(new wxICOHandler); | |
86 | wxImage::AddHandler(new wxXPMHandler); | |
87 | wxImage::AddHandler(new wxPNGHandler); | |
88 | wxImage::AddHandler(new wxANIHandler); | |
89 | wxImage::AddHandler(new wxBMPHandler); | |
90 | wxImage::AddHandler(new wxCURHandler); | |
91 | wxImage::AddHandler(new wxGIFHandler); | |
92 | wxImage::AddHandler(new wxJPEGHandler); | |
93 | wxImage::AddHandler(new wxPCXHandler); | |
94 | wxImage::AddHandler(new wxPNMHandler); | |
95 | wxImage::AddHandler(new wxTGAHandler); | |
96 | wxImage::AddHandler(new wxTIFFHandler); | |
97 | } | |
98 | ||
99 | ImageTestCase::~ImageTestCase() | |
100 | { | |
101 | wxSocketBase::Shutdown(); | |
102 | } | |
103 | ||
104 | void ImageTestCase::LoadFromFile() | |
105 | { | |
106 | wxImage img; | |
107 | for (unsigned int i=0; i<WXSIZEOF(g_testfiles); i++) | |
108 | CPPUNIT_ASSERT(img.LoadFile(g_testfiles[i].file)); | |
109 | } | |
110 | ||
111 | void ImageTestCase::LoadFromSocketStream() | |
112 | { | |
51fe4100 VZ |
113 | // Skip this test when running on a build slave because it just keeps |
114 | // failing erratically and sends build failure notifications when it does. | |
115 | // | |
116 | // Of course, it would be even better to understand why does it fail but so | |
117 | // far we didn't manage to do it so disable until someone can find the | |
118 | // problem. | |
119 | if ( wxGetUserId().Lower().Matches("buildslave*") ) | |
120 | return; | |
121 | ||
c99214eb FM |
122 | if (!IsNetworkAvailable()) // implemented in test.cpp |
123 | { | |
51fe4100 VZ |
124 | wxLogWarning("No network connectivity; skipping the " |
125 | "ImageTestCase::LoadFromSocketStream test unit."); | |
c99214eb FM |
126 | return; |
127 | } | |
128 | ||
21fe35af FM |
129 | struct { |
130 | const char* url; | |
131 | wxBitmapType type; | |
51fe4100 | 132 | } testData[] = |
21fe35af FM |
133 | { |
134 | { "http://wxwidgets.org/logo9.jpg", wxBITMAP_TYPE_JPEG }, | |
135 | { "http://wxwidgets.org/favicon.ico", wxBITMAP_TYPE_ICO } | |
136 | }; | |
51fe4100 | 137 | |
21fe35af FM |
138 | for (unsigned int i=0; i<WXSIZEOF(testData); i++) |
139 | { | |
140 | wxURL url(testData[i].url); | |
141 | CPPUNIT_ASSERT(url.GetError() == wxURL_NOERR); | |
142 | ||
143 | wxInputStream *in_stream = url.GetInputStream(); | |
144 | CPPUNIT_ASSERT(in_stream && in_stream->IsOk()); | |
145 | ||
146 | wxImage img; | |
51fe4100 | 147 | |
21fe35af FM |
148 | // NOTE: it's important to inform wxImage about the type of the image being |
149 | // loaded otherwise it will try to autodetect the format, but that | |
150 | // requires a seekable stream! | |
151 | CPPUNIT_ASSERT(img.LoadFile(*in_stream, testData[i].type)); | |
51fe4100 | 152 | |
21fe35af FM |
153 | delete in_stream; |
154 | } | |
155 | } | |
156 | ||
157 | void ImageTestCase::LoadFromZipStream() | |
158 | { | |
159 | for (unsigned int i=0; i<WXSIZEOF(g_testfiles); i++) | |
160 | { | |
161 | switch (g_testfiles[i].type) | |
162 | { | |
163 | case wxBITMAP_TYPE_XPM: | |
164 | case wxBITMAP_TYPE_GIF: | |
165 | case wxBITMAP_TYPE_PCX: | |
166 | case wxBITMAP_TYPE_TGA: | |
167 | case wxBITMAP_TYPE_TIF: | |
168 | continue; // skip testing those wxImageHandlers which cannot | |
169 | // load data from non-seekable streams | |
51fe4100 | 170 | |
21fe35af FM |
171 | default: |
172 | ; // proceed | |
173 | } | |
51fe4100 | 174 | |
21fe35af FM |
175 | // compress the test file on the fly: |
176 | wxMemoryOutputStream memOut; | |
177 | { | |
178 | wxFileInputStream file(g_testfiles[i].file); | |
179 | CPPUNIT_ASSERT(file.IsOk()); | |
51fe4100 | 180 | |
21fe35af FM |
181 | wxZlibOutputStream compressFilter(memOut, 5, wxZLIB_GZIP); |
182 | CPPUNIT_ASSERT(compressFilter.IsOk()); | |
51fe4100 | 183 | |
21fe35af FM |
184 | file.Read(compressFilter); |
185 | CPPUNIT_ASSERT(file.GetLastError() == wxSTREAM_EOF); | |
186 | } | |
51fe4100 | 187 | |
21fe35af FM |
188 | // now fetch the compressed memory to wxImage, decompressing it on the fly; this |
189 | // allows us to test loading images from non-seekable streams other than socket streams | |
190 | wxMemoryInputStream memIn(memOut); | |
191 | CPPUNIT_ASSERT(memIn.IsOk()); | |
192 | wxZlibInputStream decompressFilter(memIn, wxZLIB_GZIP); | |
193 | CPPUNIT_ASSERT(decompressFilter.IsOk()); | |
51fe4100 | 194 | |
21fe35af | 195 | wxImage img; |
51fe4100 | 196 | |
21fe35af FM |
197 | // NOTE: it's important to inform wxImage about the type of the image being |
198 | // loaded otherwise it will try to autodetect the format, but that | |
199 | // requires a seekable stream! | |
200 | WX_ASSERT_MESSAGE(("Could not load file type '%d' after it was zipped", g_testfiles[i].type), | |
201 | img.LoadFile(decompressFilter, g_testfiles[i].type)); | |
202 | } | |
203 | } | |
204 | ||
2e51fb30 VZ |
205 | void ImageTestCase::SizeImage() |
206 | { | |
207 | // Test the wxImage::Size() function which takes a rectangle from source and | |
208 | // places it in a new image at a given position. This test checks, if the | |
209 | // correct areas are chosen, and clipping is done correctly. | |
210 | ||
211 | // our test image: | |
212 | static const char * xpm_orig[] = { | |
213 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
214 | " .....", | |
215 | " ++++@@@@.", | |
216 | " +... @.", | |
217 | " +.@@++ @.", | |
218 | " +.@ .+ @.", | |
219 | ".@ +. @.+ ", | |
220 | ".@ ++@@.+ ", | |
221 | ".@ ...+ ", | |
222 | ".@@@@++++ ", | |
223 | "..... " | |
224 | }; | |
225 | // the expected results for all tests: | |
226 | static const char * xpm_l_t[] = { | |
227 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
228 | "... @.BB", | |
229 | ".@@++ @.BB", | |
230 | ".@ .+ @.BB", | |
231 | " +. @.+ BB", | |
232 | " ++@@.+ BB", | |
233 | " ...+ BB", | |
234 | "@@@++++ BB", | |
235 | "... BB", | |
236 | "BBBBBBBBBB", | |
237 | "BBBBBBBBBB" | |
238 | }; | |
239 | static const char * xpm_t[] = { | |
240 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
241 | " +... @.", | |
242 | " +.@@++ @.", | |
243 | " +.@ .+ @.", | |
244 | ".@ +. @.+ ", | |
245 | ".@ ++@@.+ ", | |
246 | ".@ ...+ ", | |
247 | ".@@@@++++ ", | |
248 | "..... ", | |
249 | "BBBBBBBBBB", | |
250 | "BBBBBBBBBB" | |
251 | }; | |
252 | static const char * xpm_r_t[] = { | |
253 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
254 | "BB +... ", | |
255 | "BB +.@@++ ", | |
256 | "BB +.@ .+ ", | |
257 | "BB.@ +. @.", | |
258 | "BB.@ ++@@.", | |
259 | "BB.@ ...", | |
260 | "BB.@@@@+++", | |
261 | "BB..... ", | |
262 | "BBBBBBBBBB", | |
263 | "BBBBBBBBBB" | |
264 | }; | |
265 | static const char * xpm_l[] = { | |
266 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
267 | " .....BB", | |
268 | "+++@@@@.BB", | |
269 | "... @.BB", | |
270 | ".@@++ @.BB", | |
271 | ".@ .+ @.BB", | |
272 | " +. @.+ BB", | |
273 | " ++@@.+ BB", | |
274 | " ...+ BB", | |
275 | "@@@++++ BB", | |
276 | "... BB" | |
277 | }; | |
278 | static const char * xpm_r[] = { | |
279 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
280 | "BB ...", | |
281 | "BB ++++@@@", | |
282 | "BB +... ", | |
283 | "BB +.@@++ ", | |
284 | "BB +.@ .+ ", | |
285 | "BB.@ +. @.", | |
286 | "BB.@ ++@@.", | |
287 | "BB.@ ...", | |
288 | "BB.@@@@+++", | |
289 | "BB..... " | |
290 | }; | |
291 | static const char * xpm_l_b[] = { | |
292 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
293 | "BBBBBBBBBB", | |
294 | "BBBBBBBBBB", | |
295 | " .....BB", | |
296 | "+++@@@@.BB", | |
297 | "... @.BB", | |
298 | ".@@++ @.BB", | |
299 | ".@ .+ @.BB", | |
300 | " +. @.+ BB", | |
301 | " ++@@.+ BB", | |
302 | " ...+ BB" | |
303 | }; | |
304 | static const char * xpm_b[] = { | |
305 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
306 | "BBBBBBBBBB", | |
307 | "BBBBBBBBBB", | |
308 | " .....", | |
309 | " ++++@@@@.", | |
310 | " +... @.", | |
311 | " +.@@++ @.", | |
312 | " +.@ .+ @.", | |
313 | ".@ +. @.+ ", | |
314 | ".@ ++@@.+ ", | |
315 | ".@ ...+ " | |
316 | }; | |
317 | static const char * xpm_r_b[] = { | |
318 | "10 10 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
319 | "BBBBBBBBBB", | |
320 | "BBBBBBBBBB", | |
321 | "BB ...", | |
322 | "BB ++++@@@", | |
323 | "BB +... ", | |
324 | "BB +.@@++ ", | |
325 | "BB +.@ .+ ", | |
326 | "BB.@ +. @.", | |
327 | "BB.@ ++@@.", | |
328 | "BB.@ ..." | |
329 | }; | |
330 | static const char * xpm_sm[] = { | |
331 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
332 | " .....", | |
333 | " ++++@@@", | |
334 | " +... ", | |
335 | " +.@@++ ", | |
336 | " +.@ .+ ", | |
337 | ".@ +. @.", | |
338 | ".@ ++@@.", | |
339 | ".@ ..." | |
340 | }; | |
341 | static const char * xpm_gt[] = { | |
342 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
343 | " .....BB", | |
344 | " ++++@@@@.BB", | |
345 | " +... @.BB", | |
346 | " +.@@++ @.BB", | |
347 | " +.@ .+ @.BB", | |
348 | ".@ +. @.+ BB", | |
349 | ".@ ++@@.+ BB", | |
350 | ".@ ...+ BB", | |
351 | ".@@@@++++ BB", | |
352 | "..... BB", | |
353 | "BBBBBBBBBBBB", | |
354 | "BBBBBBBBBBBB" | |
355 | }; | |
356 | static const char * xpm_gt_l_t[] = { | |
357 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
358 | "... @.BBBB", | |
359 | ".@@++ @.BBBB", | |
360 | ".@ .+ @.BBBB", | |
361 | " +. @.+ BBBB", | |
362 | " ++@@.+ BBBB", | |
363 | " ...+ BBBB", | |
364 | "@@@++++ BBBB", | |
365 | "... BBBB", | |
366 | "BBBBBBBBBBBB", | |
367 | "BBBBBBBBBBBB", | |
368 | "BBBBBBBBBBBB", | |
369 | "BBBBBBBBBBBB" | |
370 | }; | |
371 | static const char * xpm_gt_l[] = { | |
372 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
373 | " .....BBBB", | |
374 | "+++@@@@.BBBB", | |
375 | "... @.BBBB", | |
376 | ".@@++ @.BBBB", | |
377 | ".@ .+ @.BBBB", | |
378 | " +. @.+ BBBB", | |
379 | " ++@@.+ BBBB", | |
380 | " ...+ BBBB", | |
381 | "@@@++++ BBBB", | |
382 | "... BBBB", | |
383 | "BBBBBBBBBBBB", | |
384 | "BBBBBBBBBBBB" | |
385 | }; | |
386 | static const char * xpm_gt_l_b[] = { | |
387 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
388 | "BBBBBBBBBBBB", | |
389 | "BBBBBBBBBBBB", | |
390 | " .....BBBB", | |
391 | "+++@@@@.BBBB", | |
392 | "... @.BBBB", | |
393 | ".@@++ @.BBBB", | |
394 | ".@ .+ @.BBBB", | |
395 | " +. @.+ BBBB", | |
396 | " ++@@.+ BBBB", | |
397 | " ...+ BBBB", | |
398 | "@@@++++ BBBB", | |
399 | "... BBBB" | |
400 | }; | |
401 | static const char * xpm_gt_l_bb[] = { | |
402 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
403 | "BBBBBBBBBBBB", | |
404 | "BBBBBBBBBBBB", | |
405 | "BBBBBBBBBBBB", | |
406 | "BBBBBBBBBBBB", | |
407 | " .....BBBB", | |
408 | "+++@@@@.BBBB", | |
409 | "... @.BBBB", | |
410 | ".@@++ @.BBBB", | |
411 | ".@ .+ @.BBBB", | |
412 | " +. @.+ BBBB", | |
413 | " ++@@.+ BBBB", | |
414 | " ...+ BBBB" | |
415 | }; | |
416 | static const char * xpm_gt_t[] = { | |
417 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
418 | " +... @.BB", | |
419 | " +.@@++ @.BB", | |
420 | " +.@ .+ @.BB", | |
421 | ".@ +. @.+ BB", | |
422 | ".@ ++@@.+ BB", | |
423 | ".@ ...+ BB", | |
424 | ".@@@@++++ BB", | |
425 | "..... BB", | |
426 | "BBBBBBBBBBBB", | |
427 | "BBBBBBBBBBBB", | |
428 | "BBBBBBBBBBBB", | |
429 | "BBBBBBBBBBBB" | |
430 | }; | |
431 | static const char * xpm_gt_b[] = { | |
432 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
433 | "BBBBBBBBBBBB", | |
434 | "BBBBBBBBBBBB", | |
435 | " .....BB", | |
436 | " ++++@@@@.BB", | |
437 | " +... @.BB", | |
438 | " +.@@++ @.BB", | |
439 | " +.@ .+ @.BB", | |
440 | ".@ +. @.+ BB", | |
441 | ".@ ++@@.+ BB", | |
442 | ".@ ...+ BB", | |
443 | ".@@@@++++ BB", | |
444 | "..... BB" | |
445 | }; | |
446 | static const char * xpm_gt_bb[] = { | |
447 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
448 | "BBBBBBBBBBBB", | |
449 | "BBBBBBBBBBBB", | |
450 | "BBBBBBBBBBBB", | |
451 | "BBBBBBBBBBBB", | |
452 | " .....BB", | |
453 | " ++++@@@@.BB", | |
454 | " +... @.BB", | |
455 | " +.@@++ @.BB", | |
456 | " +.@ .+ @.BB", | |
457 | ".@ +. @.+ BB", | |
458 | ".@ ++@@.+ BB", | |
459 | ".@ ...+ BB" | |
460 | }; | |
461 | static const char * xpm_gt_r_t[] = { | |
462 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
463 | "BB +... @.", | |
464 | "BB +.@@++ @.", | |
465 | "BB +.@ .+ @.", | |
466 | "BB.@ +. @.+ ", | |
467 | "BB.@ ++@@.+ ", | |
468 | "BB.@ ...+ ", | |
469 | "BB.@@@@++++ ", | |
470 | "BB..... ", | |
471 | "BBBBBBBBBBBB", | |
472 | "BBBBBBBBBBBB", | |
473 | "BBBBBBBBBBBB", | |
474 | "BBBBBBBBBBBB" | |
475 | }; | |
476 | static const char * xpm_gt_r[] = { | |
477 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
478 | "BB .....", | |
479 | "BB ++++@@@@.", | |
480 | "BB +... @.", | |
481 | "BB +.@@++ @.", | |
482 | "BB +.@ .+ @.", | |
483 | "BB.@ +. @.+ ", | |
484 | "BB.@ ++@@.+ ", | |
485 | "BB.@ ...+ ", | |
486 | "BB.@@@@++++ ", | |
487 | "BB..... ", | |
488 | "BBBBBBBBBBBB", | |
489 | "BBBBBBBBBBBB" | |
490 | }; | |
491 | static const char * xpm_gt_r_b[] = { | |
492 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
493 | "BBBBBBBBBBBB", | |
494 | "BBBBBBBBBBBB", | |
495 | "BB .....", | |
496 | "BB ++++@@@@.", | |
497 | "BB +... @.", | |
498 | "BB +.@@++ @.", | |
499 | "BB +.@ .+ @.", | |
500 | "BB.@ +. @.+ ", | |
501 | "BB.@ ++@@.+ ", | |
502 | "BB.@ ...+ ", | |
503 | "BB.@@@@++++ ", | |
504 | "BB..... " | |
505 | }; | |
506 | static const char * xpm_gt_r_bb[] = { | |
507 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
508 | "BBBBBBBBBBBB", | |
509 | "BBBBBBBBBBBB", | |
510 | "BBBBBBBBBBBB", | |
511 | "BBBBBBBBBBBB", | |
512 | "BB .....", | |
513 | "BB ++++@@@@.", | |
514 | "BB +... @.", | |
515 | "BB +.@@++ @.", | |
516 | "BB +.@ .+ @.", | |
517 | "BB.@ +. @.+ ", | |
518 | "BB.@ ++@@.+ ", | |
519 | "BB.@ ...+ " | |
520 | }; | |
521 | static const char * xpm_gt_rr_t[] = { | |
522 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
523 | "BBBB +... ", | |
524 | "BBBB +.@@++ ", | |
525 | "BBBB +.@ .+ ", | |
526 | "BBBB.@ +. @.", | |
527 | "BBBB.@ ++@@.", | |
528 | "BBBB.@ ...", | |
529 | "BBBB.@@@@+++", | |
530 | "BBBB..... ", | |
531 | "BBBBBBBBBBBB", | |
532 | "BBBBBBBBBBBB", | |
533 | "BBBBBBBBBBBB", | |
534 | "BBBBBBBBBBBB" | |
535 | }; | |
536 | static const char * xpm_gt_rr[] = { | |
537 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
538 | "BBBB ...", | |
539 | "BBBB ++++@@@", | |
540 | "BBBB +... ", | |
541 | "BBBB +.@@++ ", | |
542 | "BBBB +.@ .+ ", | |
543 | "BBBB.@ +. @.", | |
544 | "BBBB.@ ++@@.", | |
545 | "BBBB.@ ...", | |
546 | "BBBB.@@@@+++", | |
547 | "BBBB..... ", | |
548 | "BBBBBBBBBBBB", | |
549 | "BBBBBBBBBBBB" | |
550 | }; | |
551 | static const char * xpm_gt_rr_b[] = { | |
552 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
553 | "BBBBBBBBBBBB", | |
554 | "BBBBBBBBBBBB", | |
555 | "BBBB ...", | |
556 | "BBBB ++++@@@", | |
557 | "BBBB +... ", | |
558 | "BBBB +.@@++ ", | |
559 | "BBBB +.@ .+ ", | |
560 | "BBBB.@ +. @.", | |
561 | "BBBB.@ ++@@.", | |
562 | "BBBB.@ ...", | |
563 | "BBBB.@@@@+++", | |
564 | "BBBB..... " | |
565 | }; | |
566 | static const char * xpm_gt_rr_bb[] = { | |
567 | "12 12 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
568 | "BBBBBBBBBBBB", | |
569 | "BBBBBBBBBBBB", | |
570 | "BBBBBBBBBBBB", | |
571 | "BBBBBBBBBBBB", | |
572 | "BBBB ...", | |
573 | "BBBB ++++@@@", | |
574 | "BBBB +... ", | |
575 | "BBBB +.@@++ ", | |
576 | "BBBB +.@ .+ ", | |
577 | "BBBB.@ +. @.", | |
578 | "BBBB.@ ++@@.", | |
579 | "BBBB.@ ..." | |
580 | }; | |
581 | static const char * xpm_sm_ll_tt[] = { | |
582 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
583 | " .+ @.BB", | |
584 | ". @.+ BB", | |
585 | "+@@.+ BB", | |
586 | " ...+ BB", | |
587 | "@++++ BB", | |
588 | ". BB", | |
589 | "BBBBBBBB", | |
590 | "BBBBBBBB" | |
591 | }; | |
592 | static const char * xpm_sm_ll_t[] = { | |
593 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
594 | ". @.BB", | |
595 | "@++ @.BB", | |
596 | " .+ @.BB", | |
597 | ". @.+ BB", | |
598 | "+@@.+ BB", | |
599 | " ...+ BB", | |
600 | "@++++ BB", | |
601 | ". BB" | |
602 | }; | |
603 | static const char * xpm_sm_ll[] = { | |
604 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
605 | " .....BB", | |
606 | "+@@@@.BB", | |
607 | ". @.BB", | |
608 | "@++ @.BB", | |
609 | " .+ @.BB", | |
610 | ". @.+ BB", | |
611 | "+@@.+ BB", | |
612 | " ...+ BB" | |
613 | }; | |
614 | static const char * xpm_sm_ll_b[] = { | |
615 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
616 | "BBBBBBBB", | |
617 | "BBBBBBBB", | |
618 | " .....BB", | |
619 | "+@@@@.BB", | |
620 | ". @.BB", | |
621 | "@++ @.BB", | |
622 | " .+ @.BB", | |
623 | ". @.+ BB" | |
624 | }; | |
625 | static const char * xpm_sm_l_tt[] = { | |
626 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
627 | ".@ .+ @.", | |
628 | " +. @.+ ", | |
629 | " ++@@.+ ", | |
630 | " ...+ ", | |
631 | "@@@++++ ", | |
632 | "... ", | |
633 | "BBBBBBBB", | |
634 | "BBBBBBBB" | |
635 | }; | |
636 | static const char * xpm_sm_l_t[] = { | |
637 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
638 | "... @.", | |
639 | ".@@++ @.", | |
640 | ".@ .+ @.", | |
641 | " +. @.+ ", | |
642 | " ++@@.+ ", | |
643 | " ...+ ", | |
644 | "@@@++++ ", | |
645 | "... " | |
646 | }; | |
647 | static const char * xpm_sm_l[] = { | |
648 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
649 | " .....", | |
650 | "+++@@@@.", | |
651 | "... @.", | |
652 | ".@@++ @.", | |
653 | ".@ .+ @.", | |
654 | " +. @.+ ", | |
655 | " ++@@.+ ", | |
656 | " ...+ " | |
657 | }; | |
658 | static const char * xpm_sm_l_b[] = { | |
659 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
660 | "BBBBBBBB", | |
661 | "BBBBBBBB", | |
662 | " .....", | |
663 | "+++@@@@.", | |
664 | "... @.", | |
665 | ".@@++ @.", | |
666 | ".@ .+ @.", | |
667 | " +. @.+ " | |
668 | }; | |
669 | static const char * xpm_sm_tt[] = { | |
670 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
671 | " +.@ .+ ", | |
672 | ".@ +. @.", | |
673 | ".@ ++@@.", | |
674 | ".@ ...", | |
675 | ".@@@@+++", | |
676 | "..... ", | |
677 | "BBBBBBBB", | |
678 | "BBBBBBBB" | |
679 | }; | |
680 | static const char * xpm_sm_t[] = { | |
681 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
682 | " +... ", | |
683 | " +.@@++ ", | |
684 | " +.@ .+ ", | |
685 | ".@ +. @.", | |
686 | ".@ ++@@.", | |
687 | ".@ ...", | |
688 | ".@@@@+++", | |
689 | "..... " | |
690 | }; | |
691 | static const char * xpm_sm_b[] = { | |
692 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
693 | "BBBBBBBB", | |
694 | "BBBBBBBB", | |
695 | " ...", | |
696 | " ++++@@@", | |
697 | " +... ", | |
698 | " +.@@++ ", | |
699 | " +.@ .+ ", | |
700 | ".@ +. @." | |
701 | }; | |
702 | static const char * xpm_sm_r_tt[] = { | |
703 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
704 | "BB +.@ .", | |
705 | "BB.@ +. ", | |
706 | "BB.@ ++@", | |
707 | "BB.@ .", | |
708 | "BB.@@@@+", | |
709 | "BB..... ", | |
710 | "BBBBBBBB", | |
711 | "BBBBBBBB" | |
712 | }; | |
713 | static const char * xpm_sm_r_t[] = { | |
714 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
715 | "BB +... ", | |
716 | "BB +.@@+", | |
717 | "BB +.@ .", | |
718 | "BB.@ +. ", | |
719 | "BB.@ ++@", | |
720 | "BB.@ .", | |
721 | "BB.@@@@+", | |
722 | "BB..... " | |
723 | }; | |
724 | static const char * xpm_sm_r[] = { | |
725 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
726 | "BB .", | |
727 | "BB ++++@", | |
728 | "BB +... ", | |
729 | "BB +.@@+", | |
730 | "BB +.@ .", | |
731 | "BB.@ +. ", | |
732 | "BB.@ ++@", | |
733 | "BB.@ ." | |
734 | }; | |
735 | static const char * xpm_sm_r_b[] = { | |
736 | "8 8 5 1", "B c Black", " c #00ff00", ". c #0000ff", "+ c #7f7f7f", "@ c #FF0000", | |
737 | "BBBBBBBB", | |
738 | "BBBBBBBB", | |
739 | "BB .", | |
740 | "BB ++++@", | |
741 | "BB +... ", | |
742 | "BB +.@@+", | |
743 | "BB +.@ .", | |
744 | "BB.@ +. " | |
745 | }; | |
746 | ||
747 | // this table defines all tests | |
748 | struct SizeTestData | |
749 | { | |
750 | int w, h, dx, dy; // first parameters for Size() | |
751 | const char **ref_xpm; // expected result | |
752 | } sizeTestData[] = | |
753 | { | |
754 | { 10, 10, 0, 0, xpm_orig}, // same size, same position | |
755 | { 12, 12, 0, 0, xpm_gt}, // target larger, same position | |
756 | { 8, 8, 0, 0, xpm_sm}, // target smaller, same position | |
757 | { 10, 10, -2, -2, xpm_l_t}, // same size, move left up | |
758 | { 10, 10, -2, 0, xpm_l}, // same size, move left | |
759 | { 10, 10, -2, 2, xpm_l_b}, // same size, move left down | |
760 | { 10, 10, 0, -2, xpm_t}, // same size, move up | |
761 | { 10, 10, 0, 2, xpm_b}, // same size, move down | |
762 | { 10, 10, 2, -2, xpm_r_t}, // same size, move right up | |
763 | { 10, 10, 2, 0, xpm_r}, // same size, move right | |
764 | { 10, 10, 2, 2, xpm_r_b}, // same size, move right down | |
765 | { 12, 12, -2, -2, xpm_gt_l_t}, // target larger, move left up | |
766 | { 12, 12, -2, 0, xpm_gt_l}, // target larger, move left | |
767 | { 12, 12, -2, 2, xpm_gt_l_b}, // target larger, move left down | |
768 | { 12, 12, -2, 4, xpm_gt_l_bb}, // target larger, move left down | |
769 | { 12, 12, 0, -2, xpm_gt_t}, // target larger, move up | |
770 | { 12, 12, 0, 2, xpm_gt_b}, // target larger, move down | |
771 | { 12, 12, 0, 4, xpm_gt_bb}, // target larger, move down | |
772 | { 12, 12, 2, -2, xpm_gt_r_t}, // target larger, move right up | |
773 | { 12, 12, 2, 0, xpm_gt_r}, // target larger, move right | |
774 | { 12, 12, 2, 2, xpm_gt_r_b}, // target larger, move right down | |
775 | { 12, 12, 2, 4, xpm_gt_r_bb}, // target larger, move right down | |
776 | { 12, 12, 4, -2, xpm_gt_rr_t}, // target larger, move right up | |
777 | { 12, 12, 4, 0, xpm_gt_rr}, // target larger, move right | |
778 | { 12, 12, 4, 2, xpm_gt_rr_b}, // target larger, move right down | |
779 | { 12, 12, 4, 4, xpm_gt_rr_bb}, // target larger, move right down | |
780 | { 8, 8, -4, -4, xpm_sm_ll_tt}, // target smaller, move left up | |
781 | { 8, 8, -4, -2, xpm_sm_ll_t}, // target smaller, move left up | |
782 | { 8, 8, -4, 0, xpm_sm_ll}, // target smaller, move left | |
783 | { 8, 8, -4, 2, xpm_sm_ll_b}, // target smaller, move left down | |
784 | { 8, 8, -2, -4, xpm_sm_l_tt}, // target smaller, move left up | |
785 | { 8, 8, -2, -2, xpm_sm_l_t}, // target smaller, move left up | |
786 | { 8, 8, -2, 0, xpm_sm_l}, // target smaller, move left | |
787 | { 8, 8, -2, 2, xpm_sm_l_b}, // target smaller, move left down | |
788 | { 8, 8, 0, -4, xpm_sm_tt}, // target smaller, move up | |
789 | { 8, 8, 0, -2, xpm_sm_t}, // target smaller, move up | |
790 | { 8, 8, 0, 2, xpm_sm_b}, // target smaller, move down | |
791 | { 8, 8, 2, -4, xpm_sm_r_tt}, // target smaller, move right up | |
792 | { 8, 8, 2, -2, xpm_sm_r_t}, // target smaller, move right up | |
793 | { 8, 8, 2, 0, xpm_sm_r}, // target smaller, move right | |
794 | { 8, 8, 2, 2, xpm_sm_r_b}, // target smaller, move right down | |
795 | }; | |
796 | ||
797 | const wxImage src_img(xpm_orig); | |
798 | for ( unsigned i = 0; i < WXSIZEOF(sizeTestData); i++ ) | |
799 | { | |
800 | SizeTestData& st = sizeTestData[i]; | |
801 | wxImage | |
802 | actual(src_img.Size(wxSize(st.w, st.h), wxPoint(st.dx, st.dy), 0, 0, 0)), | |
803 | expected(st.ref_xpm); | |
804 | ||
805 | // to check results with an image viewer uncomment this: | |
806 | //actual.SaveFile(wxString::Format("imagetest-%02d-actual.png", i), wxBITMAP_TYPE_PNG); | |
807 | //expected.SaveFile(wxString::Format("imagetest-%02d-exp.png", i), wxBITMAP_TYPE_PNG); | |
808 | ||
809 | CPPUNIT_ASSERT_EQUAL( actual.GetSize().x, expected.GetSize().x ); | |
810 | CPPUNIT_ASSERT_EQUAL( actual.GetSize().y, expected.GetSize().y ); | |
811 | ||
812 | const unsigned data_len = 3 * expected.GetHeight() * expected.GetWidth(); | |
813 | ||
814 | WX_ASSERT_MESSAGE | |
815 | ( | |
816 | ("Resize test #%u: (%d, %d), (%d, %d)", i, st.w, st.h, st.dx, st.dy), | |
817 | memcmp(actual.GetData(), expected.GetData(), data_len) == 0 | |
818 | ); | |
819 | } | |
820 | } | |
821 | ||
822 | ||
21fe35af FM |
823 | /* |
824 | TODO: add lots of more tests to wxImage functions | |
825 | */ |