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