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