1cf51e393SMatthew Wilber // BMPTranslatorTest.cpp
2cf51e393SMatthew Wilber #include "BMPTranslatorTest.h"
3cf51e393SMatthew Wilber #include <cppunit/Test.h>
4cf51e393SMatthew Wilber #include <cppunit/TestCaller.h>
5cf51e393SMatthew Wilber #include <cppunit/TestSuite.h>
6cf51e393SMatthew Wilber #include <stdio.h>
772c21dd2SMatthew Wilber #include <string.h>
8cf51e393SMatthew Wilber #include <unistd.h>
972c21dd2SMatthew Wilber #include <image.h>
10fe2aacfaSMatthew Wilber #include <Application.h>
1172c21dd2SMatthew Wilber #include <Translator.h>
1272c21dd2SMatthew Wilber #include <TranslatorFormats.h>
13c9088353SMatthew Wilber #include <TranslatorRoster.h>
1472c21dd2SMatthew Wilber #include <Message.h>
1572c21dd2SMatthew Wilber #include <View.h>
1672c21dd2SMatthew Wilber #include <Rect.h>
17e11362e6SMatthew Wilber #include <File.h>
18db661ffcSMatthew Wilber #include <DataIO.h>
19c9088353SMatthew Wilber #include <Errors.h>
20c9088353SMatthew Wilber #include <OS.h>
21c9088353SMatthew Wilber #include "TranslatorTestAddOn.h"
22be510fa8SMatthew Wilber
23be510fa8SMatthew Wilber #define BMP_NO_COMPRESS 0
24be510fa8SMatthew Wilber #define BMP_RLE8_COMPRESS 1
25be510fa8SMatthew Wilber #define BMP_RLE4_COMPRESS 2
26be510fa8SMatthew Wilber
27be510fa8SMatthew Wilber struct BMPFileHeader {
28be510fa8SMatthew Wilber // for both MS and OS/2 BMP formats
29be510fa8SMatthew Wilber uint16 magic; // = 'BM'
30be510fa8SMatthew Wilber uint32 fileSize; // file size in bytes
31be510fa8SMatthew Wilber uint32 reserved; // equals 0
32be510fa8SMatthew Wilber uint32 dataOffset; // file offset to actual image
33be510fa8SMatthew Wilber };
34be510fa8SMatthew Wilber
35be510fa8SMatthew Wilber struct MSInfoHeader {
36be510fa8SMatthew Wilber uint32 size; // size of this struct (40)
37be510fa8SMatthew Wilber uint32 width; // bitmap width
38be510fa8SMatthew Wilber uint32 height; // bitmap height
39be510fa8SMatthew Wilber uint16 planes; // number of planes, always 1?
40be510fa8SMatthew Wilber uint16 bitsperpixel; // bits per pixel, (1,4,8,16 or 24)
41be510fa8SMatthew Wilber uint32 compression; // type of compression
42be510fa8SMatthew Wilber uint32 imagesize; // size of image data if compressed
43be510fa8SMatthew Wilber uint32 xpixperm; // horizontal pixels per meter
44be510fa8SMatthew Wilber uint32 ypixperm; // vertical pixels per meter
45be510fa8SMatthew Wilber uint32 colorsused; // number of actually used colors
46be510fa8SMatthew Wilber uint32 colorsimportant; // number of important colors, zero = all
47be510fa8SMatthew Wilber };
48be510fa8SMatthew Wilber
49be510fa8SMatthew Wilber struct OS2InfoHeader {
50be510fa8SMatthew Wilber uint32 size; // size of this struct (12)
51be510fa8SMatthew Wilber uint16 width; // bitmap width
52be510fa8SMatthew Wilber uint16 height; // bitmap height
53be510fa8SMatthew Wilber uint16 planes; // number of planes, always 1?
54be510fa8SMatthew Wilber uint16 bitsperpixel; // bits per pixel, (1,4,8,16 or 24)
55be510fa8SMatthew Wilber };
56cf51e393SMatthew Wilber
57cf51e393SMatthew Wilber // Suite
58cf51e393SMatthew Wilber CppUnit::Test *
Suite()59cf51e393SMatthew Wilber BMPTranslatorTest::Suite()
60cf51e393SMatthew Wilber {
61cf51e393SMatthew Wilber CppUnit::TestSuite *suite = new CppUnit::TestSuite();
62cf51e393SMatthew Wilber typedef CppUnit::TestCaller<BMPTranslatorTest> TC;
63cf51e393SMatthew Wilber
64ec3ff25fSMatthew Wilber suite->addTest(
65c9088353SMatthew Wilber new TC("BMPTranslator IdentifyTest",
66c9088353SMatthew Wilber &BMPTranslatorTest::IdentifyTest));
67c9088353SMatthew Wilber
68c9088353SMatthew Wilber suite->addTest(
69c9088353SMatthew Wilber new TC("BMPTranslator TranslateTest",
70c9088353SMatthew Wilber &BMPTranslatorTest::TranslateTest));
71c9088353SMatthew Wilber
72bedcc993SMatthew Wilber suite->addTest(
73bedcc993SMatthew Wilber new TC("BMPTranslator ConfigMessageTest",
74bedcc993SMatthew Wilber &BMPTranslatorTest::ConfigMessageTest));
75bedcc993SMatthew Wilber
7672c21dd2SMatthew Wilber #if !TEST_R5
7772c21dd2SMatthew Wilber suite->addTest(
78c9088353SMatthew Wilber new TC("BMPTranslator LoadAddOnTest",
79c9088353SMatthew Wilber &BMPTranslatorTest::LoadAddOnTest));
8072c21dd2SMatthew Wilber #endif
81cf51e393SMatthew Wilber
82cf51e393SMatthew Wilber return suite;
83cf51e393SMatthew Wilber }
84cf51e393SMatthew Wilber
85cf51e393SMatthew Wilber // setUp
86cf51e393SMatthew Wilber void
setUp()87cf51e393SMatthew Wilber BMPTranslatorTest::setUp()
88cf51e393SMatthew Wilber {
89cf51e393SMatthew Wilber BTestCase::setUp();
90cf51e393SMatthew Wilber }
91cf51e393SMatthew Wilber
92cf51e393SMatthew Wilber // tearDown
93cf51e393SMatthew Wilber void
tearDown()94cf51e393SMatthew Wilber BMPTranslatorTest::tearDown()
95cf51e393SMatthew Wilber {
96cf51e393SMatthew Wilber BTestCase::tearDown();
97cf51e393SMatthew Wilber }
98cf51e393SMatthew Wilber
9972c21dd2SMatthew Wilber void
CheckBits_Bmp(translator_info * pti)100c9088353SMatthew Wilber CheckBits_Bmp(translator_info *pti)
10172c21dd2SMatthew Wilber {
102c9088353SMatthew Wilber CheckTranslatorInfo(pti, B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP,
103f08ccd95SMatthew Wilber 0.4f, 0.6f, "Be Bitmap Format (BMPTranslator)",
104c9088353SMatthew Wilber "image/x-be-bitmap");
10572c21dd2SMatthew Wilber }
106e11362e6SMatthew Wilber
107e11362e6SMatthew Wilber void
CheckBmp(translator_info * pti,const char * imageType)108c9088353SMatthew Wilber CheckBmp(translator_info *pti, const char *imageType)
109db661ffcSMatthew Wilber {
110c9088353SMatthew Wilber CheckTranslatorInfo(pti, B_BMP_FORMAT, B_TRANSLATOR_BITMAP,
111f08ccd95SMatthew Wilber 0.4f, 0.8f, imageType, "image/x-bmp");
112c9088353SMatthew Wilber }
113db661ffcSMatthew Wilber
114c9088353SMatthew Wilber // coveniently group path of image with
115c9088353SMatthew Wilber // the expected Identify() string for that image
116c9088353SMatthew Wilber struct IdentifyInfo {
117c9088353SMatthew Wilber const char *imagePath;
118c9088353SMatthew Wilber const char *identifyString;
119c9088353SMatthew Wilber };
120db661ffcSMatthew Wilber
121c9088353SMatthew Wilber void
IdentifyTests(BMPTranslatorTest * ptest,BTranslatorRoster * proster,const IdentifyInfo * pinfo,int32 len,bool bbits)122c9088353SMatthew Wilber IdentifyTests(BMPTranslatorTest *ptest, BTranslatorRoster *proster,
123c9088353SMatthew Wilber const IdentifyInfo *pinfo, int32 len, bool bbits)
124c9088353SMatthew Wilber {
125c9088353SMatthew Wilber translator_info ti;
126c9088353SMatthew Wilber printf(" [%d] ", (int) bbits);
127db661ffcSMatthew Wilber
128c9088353SMatthew Wilber for (int32 i = 0; i < len; i++) {
129c9088353SMatthew Wilber ptest->NextSubTest();
130c9088353SMatthew Wilber BFile file;
131c9088353SMatthew Wilber printf(" [%s] ", pinfo[i].imagePath);
132c9088353SMatthew Wilber CPPUNIT_ASSERT(file.SetTo(pinfo[i].imagePath, B_READ_ONLY) == B_OK);
133c9088353SMatthew Wilber
134c9088353SMatthew Wilber // Identify (output: B_TRANSLATOR_ANY_TYPE)
135c9088353SMatthew Wilber ptest->NextSubTest();
136c9088353SMatthew Wilber memset(&ti, 0, sizeof(translator_info));
137c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti) == B_OK);
138c9088353SMatthew Wilber if (bbits)
139c9088353SMatthew Wilber CheckBits_Bmp(&ti);
140c9088353SMatthew Wilber else
141c9088353SMatthew Wilber CheckBmp(&ti, pinfo[i].identifyString);
142c9088353SMatthew Wilber
143c9088353SMatthew Wilber // Identify (output: B_TRANSLATOR_BITMAP)
144c9088353SMatthew Wilber ptest->NextSubTest();
145c9088353SMatthew Wilber memset(&ti, 0, sizeof(translator_info));
146c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti, 0, NULL,
147c9088353SMatthew Wilber B_TRANSLATOR_BITMAP) == B_OK);
148c9088353SMatthew Wilber if (bbits)
149c9088353SMatthew Wilber CheckBits_Bmp(&ti);
150c9088353SMatthew Wilber else
151c9088353SMatthew Wilber CheckBmp(&ti, pinfo[i].identifyString);
152c9088353SMatthew Wilber
153c9088353SMatthew Wilber // Identify (output: B_BMP_FORMAT)
154c9088353SMatthew Wilber ptest->NextSubTest();
155c9088353SMatthew Wilber memset(&ti, 0, sizeof(translator_info));
156c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti, 0, NULL,
157c9088353SMatthew Wilber B_BMP_FORMAT) == B_OK);
158c9088353SMatthew Wilber if (bbits)
159c9088353SMatthew Wilber CheckBits_Bmp(&ti);
160c9088353SMatthew Wilber else
161c9088353SMatthew Wilber CheckBmp(&ti, pinfo[i].identifyString);
162c9088353SMatthew Wilber }
163c9088353SMatthew Wilber }
164c9088353SMatthew Wilber
165c9088353SMatthew Wilber void
IdentifyTest()166c9088353SMatthew Wilber BMPTranslatorTest::IdentifyTest()
167c9088353SMatthew Wilber {
168c9088353SMatthew Wilber // Init
169db661ffcSMatthew Wilber NextSubTest();
170c9088353SMatthew Wilber status_t result = B_ERROR;
171c9088353SMatthew Wilber BTranslatorRoster *proster = new BTranslatorRoster();
172c9088353SMatthew Wilber CPPUNIT_ASSERT(proster);
173c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->AddTranslators(
174c9088353SMatthew Wilber "/boot/home/config/add-ons/Translators/BMPTranslator") == B_OK);
175c9088353SMatthew Wilber BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
176c9088353SMatthew Wilber B_READ_ONLY);
177c9088353SMatthew Wilber CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
178c9088353SMatthew Wilber
179c9088353SMatthew Wilber // Identify (bad input, output types)
180c9088353SMatthew Wilber NextSubTest();
181c9088353SMatthew Wilber translator_info ti;
182c9088353SMatthew Wilber memset(&ti, 0, sizeof(translator_info));
183c9088353SMatthew Wilber result = proster->Identify(&wronginput, NULL, &ti, 0,
184c9088353SMatthew Wilber NULL, B_TRANSLATOR_TEXT);
185c9088353SMatthew Wilber CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
186c9088353SMatthew Wilber CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
187c9088353SMatthew Wilber
188c9088353SMatthew Wilber // Identify (wrong type of input data)
189c9088353SMatthew Wilber NextSubTest();
190c9088353SMatthew Wilber memset(&ti, 0, sizeof(translator_info));
191c9088353SMatthew Wilber result = proster->Identify(&wronginput, NULL, &ti);
192c9088353SMatthew Wilber CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
193c9088353SMatthew Wilber CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
194db661ffcSMatthew Wilber
195db661ffcSMatthew Wilber // empty
196db661ffcSMatthew Wilber NextSubTest();
197db661ffcSMatthew Wilber BMallocIO mallempty;
198c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallempty, NULL, &ti) == B_NO_TRANSLATOR);
199db661ffcSMatthew Wilber
200db661ffcSMatthew Wilber // weird, non-image data
201db661ffcSMatthew Wilber NextSubTest();
202db661ffcSMatthew Wilber const char *strmonkey = "monkey monkey monkey";
203db661ffcSMatthew Wilber BMemoryIO memmonkey(strmonkey, strlen(strmonkey));
204c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&memmonkey, NULL, &ti) == B_NO_TRANSLATOR);
205db661ffcSMatthew Wilber
206db661ffcSMatthew Wilber // abreviated BMPFileHeader
207db661ffcSMatthew Wilber NextSubTest();
208db661ffcSMatthew Wilber BMPFileHeader fheader;
209db661ffcSMatthew Wilber fheader.magic = 'MB';
210c904c6cdSMatthew Wilber fheader.fileSize = 1028;
211db661ffcSMatthew Wilber BMallocIO mallabrev;
212c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallabrev.Write(&fheader.magic, 2) == 2);
213c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallabrev.Write(&fheader.fileSize, 4) == 4);
214c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallabrev, NULL, &ti) == B_NO_TRANSLATOR);
215db661ffcSMatthew Wilber
216db661ffcSMatthew Wilber // Write out the MS and OS/2 headers with various fields being corrupt, only one
217db661ffcSMatthew Wilber // corrupt field at a time, also do abrev test for MS header and OS/2 header
218c904c6cdSMatthew Wilber NextSubTest();
219c904c6cdSMatthew Wilber fheader.magic = 'MB';
220c904c6cdSMatthew Wilber fheader.fileSize = 53; // bad value, too small to contain all of MS header data
22174f9d756SMatthew Wilber // bad values in this field can be, and are ignored by some Windows image viewers
222c904c6cdSMatthew Wilber fheader.reserved = 0;
223c904c6cdSMatthew Wilber fheader.dataOffset = 54;
224c904c6cdSMatthew Wilber MSInfoHeader msheader;
225c904c6cdSMatthew Wilber msheader.size = 40;
226c904c6cdSMatthew Wilber msheader.width = 5;
227c904c6cdSMatthew Wilber msheader.height = 5;
228c904c6cdSMatthew Wilber msheader.planes = 1;
229c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
230c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
231c904c6cdSMatthew Wilber msheader.imagesize = 0;
232c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
233c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
234c904c6cdSMatthew Wilber msheader.colorsused = 0;
235c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
236c904c6cdSMatthew Wilber BMallocIO mallbadfs;
237c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadfs.Write(&fheader.magic, 2) == 2);
238c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadfs.Write(&fheader.fileSize, 4) == 4);
239c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadfs.Write(&fheader.reserved, 4) == 4);
240c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadfs.Write(&fheader.dataOffset, 4) == 4);
241c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadfs.Write(&msheader, 40) == 40);
24274f9d756SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallbadfs, NULL, &ti) == B_OK);
243c904c6cdSMatthew Wilber
244c904c6cdSMatthew Wilber NextSubTest();
245c904c6cdSMatthew Wilber fheader.magic = 'MB';
246c904c6cdSMatthew Wilber fheader.fileSize = 1028;
247c904c6cdSMatthew Wilber fheader.reserved = 7; // bad value, should be zero
248c904c6cdSMatthew Wilber fheader.dataOffset = 54;
249c904c6cdSMatthew Wilber msheader.size = 40;
250c904c6cdSMatthew Wilber msheader.width = 5;
251c904c6cdSMatthew Wilber msheader.height = 5;
252c904c6cdSMatthew Wilber msheader.planes = 1;
253c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
254c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
255c904c6cdSMatthew Wilber msheader.imagesize = 0;
256c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
257c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
258c904c6cdSMatthew Wilber msheader.colorsused = 0;
259c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
260c904c6cdSMatthew Wilber BMallocIO mallbadr;
261c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadr.Write(&fheader.magic, 2) == 2);
262c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadr.Write(&fheader.fileSize, 4) == 4);
263c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadr.Write(&fheader.reserved, 4) == 4);
264c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadr.Write(&fheader.dataOffset, 4) == 4);
265c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbadr.Write(&msheader, 40) == 40);
266c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallbadr, NULL, &ti) == B_NO_TRANSLATOR);
267c904c6cdSMatthew Wilber
268c904c6cdSMatthew Wilber NextSubTest();
269c904c6cdSMatthew Wilber fheader.magic = 'MB';
270c904c6cdSMatthew Wilber fheader.fileSize = 1028;
271c904c6cdSMatthew Wilber fheader.reserved = 0;
272c904c6cdSMatthew Wilber fheader.dataOffset = 53; // bad value, for MS format, needs to be at least 54
273c904c6cdSMatthew Wilber msheader.size = 40;
274c904c6cdSMatthew Wilber msheader.width = 5;
275c904c6cdSMatthew Wilber msheader.height = 5;
276c904c6cdSMatthew Wilber msheader.planes = 1;
277c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
278c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
279c904c6cdSMatthew Wilber msheader.imagesize = 0;
280c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
281c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
282c904c6cdSMatthew Wilber msheader.colorsused = 0;
283c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
284c904c6cdSMatthew Wilber BMallocIO mallbaddo1;
285c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo1.Write(&fheader.magic, 2) == 2);
286c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo1.Write(&fheader.fileSize, 4) == 4);
287c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo1.Write(&fheader.reserved, 4) == 4);
288c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo1.Write(&fheader.dataOffset, 4) == 4);
289c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo1.Write(&msheader, 40) == 40);
290c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallbaddo1, NULL, &ti) == B_NO_TRANSLATOR);
291c904c6cdSMatthew Wilber
292c904c6cdSMatthew Wilber NextSubTest();
293c904c6cdSMatthew Wilber fheader.magic = 'MB';
294c904c6cdSMatthew Wilber fheader.fileSize = 1028;
295c904c6cdSMatthew Wilber fheader.reserved = 0;
296c904c6cdSMatthew Wilber fheader.dataOffset = 25; // bad value, for OS/2 format, needs to be at least 26
297c904c6cdSMatthew Wilber OS2InfoHeader os2header;
298c904c6cdSMatthew Wilber os2header.size = 12;
299c904c6cdSMatthew Wilber os2header.width = 5;
300c904c6cdSMatthew Wilber os2header.height = 5;
301c904c6cdSMatthew Wilber os2header.planes = 1;
302c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
303c904c6cdSMatthew Wilber BMallocIO mallbaddo2;
304c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo2.Write(&fheader.magic, 2) == 2);
305c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo2.Write(&fheader.fileSize, 4) == 4);
306c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo2.Write(&fheader.reserved, 4) == 4);
307c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo2.Write(&fheader.dataOffset, 4) == 4);
308c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo2.Write(&os2header, 12) == 12);
309c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallbaddo2, NULL, &ti) == B_NO_TRANSLATOR);
310c904c6cdSMatthew Wilber
311c904c6cdSMatthew Wilber NextSubTest();
312c904c6cdSMatthew Wilber fheader.magic = 'MB';
313c904c6cdSMatthew Wilber fheader.fileSize = 1028;
314c904c6cdSMatthew Wilber fheader.reserved = 0;
315c904c6cdSMatthew Wilber fheader.dataOffset = 1029; // bad value, larger than the fileSize
31674f9d756SMatthew Wilber // Ignore the fileSize: if it is the case that the actual file size is
31774f9d756SMatthew Wilber // less than the dataOffset field, the translation will error out appropriately.
31874f9d756SMatthew Wilber // Assume the fileSize has nothing to do with the actual size of the file
319c904c6cdSMatthew Wilber os2header.size = 12;
320c904c6cdSMatthew Wilber os2header.width = 5;
321c904c6cdSMatthew Wilber os2header.height = 5;
322c904c6cdSMatthew Wilber os2header.planes = 1;
323c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
324c904c6cdSMatthew Wilber BMallocIO mallbaddo3;
325c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo3.Write(&fheader.magic, 2) == 2);
326c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo3.Write(&fheader.fileSize, 4) == 4);
327c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo3.Write(&fheader.reserved, 4) == 4);
328c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo3.Write(&fheader.dataOffset, 4) == 4);
329c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallbaddo3.Write(&os2header, 12) == 12);
33074f9d756SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallbaddo3, NULL, &ti) == B_OK);
331c904c6cdSMatthew Wilber
332c904c6cdSMatthew Wilber NextSubTest();
333c904c6cdSMatthew Wilber fheader.magic = 'MB';
334c904c6cdSMatthew Wilber fheader.fileSize = 1028;
335c904c6cdSMatthew Wilber fheader.reserved = 0;
336c904c6cdSMatthew Wilber fheader.dataOffset = 26;
337c904c6cdSMatthew Wilber os2header.size = 12;
338c904c6cdSMatthew Wilber os2header.width = 5;
339c904c6cdSMatthew Wilber os2header.height = 5;
340c904c6cdSMatthew Wilber os2header.planes = 1;
341c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
342c904c6cdSMatthew Wilber BMallocIO mallos2abrev;
343c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev.Write(&fheader.magic, 2) == 2);
344c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev.Write(&fheader.fileSize, 4) == 4);
345c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev.Write(&fheader.reserved, 4) == 4);
346c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev.Write(&fheader.dataOffset, 4) == 4);
347c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev.Write(&os2header, 1) == 1); // only 1 byte of the os2 header included
348c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2abrev, NULL, &ti) == B_NO_TRANSLATOR);
349c904c6cdSMatthew Wilber
350c904c6cdSMatthew Wilber NextSubTest();
351c904c6cdSMatthew Wilber fheader.magic = 'MB';
352c904c6cdSMatthew Wilber fheader.fileSize = 1028;
353c904c6cdSMatthew Wilber fheader.reserved = 0;
354c904c6cdSMatthew Wilber fheader.dataOffset = 26;
355c904c6cdSMatthew Wilber os2header.size = 12;
356c904c6cdSMatthew Wilber os2header.width = 5;
357c904c6cdSMatthew Wilber os2header.height = 5;
358c904c6cdSMatthew Wilber os2header.planes = 1;
359c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
360c904c6cdSMatthew Wilber BMallocIO mallos2abrev2;
361c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev2.Write(&fheader.magic, 2) == 2);
362c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev2.Write(&fheader.fileSize, 4) == 4);
363c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev2.Write(&fheader.reserved, 4) == 4);
364c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev2.Write(&fheader.dataOffset, 4) == 4);
365c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2abrev2.Write(&os2header, 5) == 5); // most of the os2 header missing
366c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2abrev2, NULL, &ti) == B_NO_TRANSLATOR);
367c904c6cdSMatthew Wilber
368c904c6cdSMatthew Wilber NextSubTest();
369c904c6cdSMatthew Wilber fheader.magic = 'MB';
370c904c6cdSMatthew Wilber fheader.fileSize = 1028;
371c904c6cdSMatthew Wilber fheader.reserved = 0;
372c904c6cdSMatthew Wilber fheader.dataOffset = 54;
373c904c6cdSMatthew Wilber msheader.size = 40;
374c904c6cdSMatthew Wilber msheader.width = 5;
375c904c6cdSMatthew Wilber msheader.height = 5;
376c904c6cdSMatthew Wilber msheader.planes = 1;
377c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
378c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
379c904c6cdSMatthew Wilber msheader.imagesize = 0;
380c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
381c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
382c904c6cdSMatthew Wilber msheader.colorsused = 0;
383c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
384c904c6cdSMatthew Wilber BMallocIO mallmsabrev1;
385c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev1.Write(&fheader.magic, 2) == 2);
386c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev1.Write(&fheader.fileSize, 4) == 4);
387c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev1.Write(&fheader.reserved, 4) == 4);
388c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev1.Write(&fheader.dataOffset, 4) == 4);
389c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev1.Write(&msheader, 1) == 1); // only 1 byte of ms header written
390c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmsabrev1, NULL, &ti) == B_NO_TRANSLATOR);
391c904c6cdSMatthew Wilber
392c904c6cdSMatthew Wilber NextSubTest();
393c904c6cdSMatthew Wilber fheader.magic = 'MB';
394c904c6cdSMatthew Wilber fheader.fileSize = 1028;
395c904c6cdSMatthew Wilber fheader.reserved = 0;
396c904c6cdSMatthew Wilber fheader.dataOffset = 54;
397c904c6cdSMatthew Wilber msheader.size = 40;
398c904c6cdSMatthew Wilber msheader.width = 5;
399c904c6cdSMatthew Wilber msheader.height = 5;
400c904c6cdSMatthew Wilber msheader.planes = 1;
401c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
402c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
403c904c6cdSMatthew Wilber msheader.imagesize = 0;
404c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
405c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
406c904c6cdSMatthew Wilber msheader.colorsused = 0;
407c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
408c904c6cdSMatthew Wilber BMallocIO mallmsabrev2;
409c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev2.Write(&fheader.magic, 2) == 2);
410c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev2.Write(&fheader.fileSize, 4) == 4);
411c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev2.Write(&fheader.reserved, 4) == 4);
412c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev2.Write(&fheader.dataOffset, 4) == 4);
413c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsabrev2.Write(&msheader, 15) == 15); // less than half of ms header written
414c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmsabrev2, NULL, &ti) == B_NO_TRANSLATOR);
415c904c6cdSMatthew Wilber
416c904c6cdSMatthew Wilber NextSubTest();
417c904c6cdSMatthew Wilber fheader.magic = 'MB';
418c904c6cdSMatthew Wilber fheader.fileSize = 1028;
419c904c6cdSMatthew Wilber fheader.reserved = 0;
420c904c6cdSMatthew Wilber fheader.dataOffset = 54;
421c904c6cdSMatthew Wilber msheader.size = 39; // size too small for MS format
422c904c6cdSMatthew Wilber msheader.width = 5;
423c904c6cdSMatthew Wilber msheader.height = 5;
424c904c6cdSMatthew Wilber msheader.planes = 1;
425c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
426c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
427c904c6cdSMatthew Wilber msheader.imagesize = 0;
428c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
429c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
430c904c6cdSMatthew Wilber msheader.colorsused = 0;
431c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
432c904c6cdSMatthew Wilber BMallocIO mallmssize;
433c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize.Write(&fheader.magic, 2) == 2);
434c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize.Write(&fheader.fileSize, 4) == 4);
435c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize.Write(&fheader.reserved, 4) == 4);
436c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize.Write(&fheader.dataOffset, 4) == 4);
437c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize.Write(&msheader, 40) == 40);
438c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmssize, NULL, &ti) == B_NO_TRANSLATOR);
439c904c6cdSMatthew Wilber
440c904c6cdSMatthew Wilber NextSubTest();
441c904c6cdSMatthew Wilber fheader.magic = 'MB';
442c904c6cdSMatthew Wilber fheader.fileSize = 1028;
443c904c6cdSMatthew Wilber fheader.reserved = 0;
444c904c6cdSMatthew Wilber fheader.dataOffset = 54;
445c904c6cdSMatthew Wilber msheader.size = 41; // size too large for MS format
446c904c6cdSMatthew Wilber msheader.width = 5;
447c904c6cdSMatthew Wilber msheader.height = 5;
448c904c6cdSMatthew Wilber msheader.planes = 1;
449c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
450c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
451c904c6cdSMatthew Wilber msheader.imagesize = 0;
452c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
453c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
454c904c6cdSMatthew Wilber msheader.colorsused = 0;
455c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
456c904c6cdSMatthew Wilber BMallocIO mallmssize2;
457c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize2.Write(&fheader.magic, 2) == 2);
458c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize2.Write(&fheader.fileSize, 4) == 4);
459c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize2.Write(&fheader.reserved, 4) == 4);
460c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize2.Write(&fheader.dataOffset, 4) == 4);
461c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmssize2.Write(&msheader, 40) == 40);
462c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmssize2, NULL, &ti) == B_NO_TRANSLATOR);
463c904c6cdSMatthew Wilber
464c904c6cdSMatthew Wilber NextSubTest();
465c904c6cdSMatthew Wilber fheader.magic = 'MB';
466c904c6cdSMatthew Wilber fheader.fileSize = 1028;
467c904c6cdSMatthew Wilber fheader.reserved = 0;
468c904c6cdSMatthew Wilber fheader.dataOffset = 26;
469c904c6cdSMatthew Wilber os2header.size = 11; // os2 header size should be 12
470c904c6cdSMatthew Wilber os2header.width = 5;
471c904c6cdSMatthew Wilber os2header.height = 5;
472c904c6cdSMatthew Wilber os2header.planes = 1;
473c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
474c904c6cdSMatthew Wilber BMallocIO mallos2size;
475c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size.Write(&fheader.magic, 2) == 2);
476c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size.Write(&fheader.fileSize, 4) == 4);
477c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size.Write(&fheader.reserved, 4) == 4);
478c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size.Write(&fheader.dataOffset, 4) == 4);
479c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size.Write(&os2header, 12) == 12);
480c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2size, NULL, &ti) == B_NO_TRANSLATOR);
481c904c6cdSMatthew Wilber
482c904c6cdSMatthew Wilber NextSubTest();
483c904c6cdSMatthew Wilber fheader.magic = 'MB';
484c904c6cdSMatthew Wilber fheader.fileSize = 1028;
485c904c6cdSMatthew Wilber fheader.reserved = 0;
486c904c6cdSMatthew Wilber fheader.dataOffset = 26;
487c904c6cdSMatthew Wilber os2header.size = 13; // os2 header size should be 12
488c904c6cdSMatthew Wilber os2header.width = 5;
489c904c6cdSMatthew Wilber os2header.height = 5;
490c904c6cdSMatthew Wilber os2header.planes = 1;
491c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
492c904c6cdSMatthew Wilber BMallocIO mallos2size2;
493c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size2.Write(&fheader.magic, 2) == 2);
494c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size2.Write(&fheader.fileSize, 4) == 4);
495c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size2.Write(&fheader.reserved, 4) == 4);
496c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size2.Write(&fheader.dataOffset, 4) == 4);
497c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2size2.Write(&os2header, 12) == 12);
498c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2size2, NULL, &ti) == B_NO_TRANSLATOR);
499c904c6cdSMatthew Wilber
500c904c6cdSMatthew Wilber NextSubTest();
501c904c6cdSMatthew Wilber fheader.magic = 'MB';
502c904c6cdSMatthew Wilber fheader.fileSize = 1028;
503c904c6cdSMatthew Wilber fheader.reserved = 0;
504c904c6cdSMatthew Wilber fheader.dataOffset = 54;
505c904c6cdSMatthew Wilber msheader.size = 40;
506c904c6cdSMatthew Wilber msheader.width = 0; // width of zero is ridiculous
507c904c6cdSMatthew Wilber msheader.height = 5;
508c904c6cdSMatthew Wilber msheader.planes = 1;
509c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
510c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
511c904c6cdSMatthew Wilber msheader.imagesize = 0;
512c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
513c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
514c904c6cdSMatthew Wilber msheader.colorsused = 0;
515c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
516c904c6cdSMatthew Wilber BMallocIO mallmswidth;
517c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmswidth.Write(&fheader.magic, 2) == 2);
518c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmswidth.Write(&fheader.fileSize, 4) == 4);
519c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmswidth.Write(&fheader.reserved, 4) == 4);
520c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmswidth.Write(&fheader.dataOffset, 4) == 4);
521c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmswidth.Write(&msheader, 40) == 40);
522c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmswidth, NULL, &ti) == B_NO_TRANSLATOR);
523c904c6cdSMatthew Wilber
524c904c6cdSMatthew Wilber NextSubTest();
525c904c6cdSMatthew Wilber fheader.magic = 'MB';
526c904c6cdSMatthew Wilber fheader.fileSize = 1028;
527c904c6cdSMatthew Wilber fheader.reserved = 0;
528c904c6cdSMatthew Wilber fheader.dataOffset = 26;
529c904c6cdSMatthew Wilber os2header.size = 12;
530c904c6cdSMatthew Wilber os2header.width = 0; // width of zero is ridiculous
531c904c6cdSMatthew Wilber os2header.height = 5;
532c904c6cdSMatthew Wilber os2header.planes = 1;
533c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
534c904c6cdSMatthew Wilber BMallocIO mallos2width;
535c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2width.Write(&fheader.magic, 2) == 2);
536c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2width.Write(&fheader.fileSize, 4) == 4);
537c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2width.Write(&fheader.reserved, 4) == 4);
538c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2width.Write(&fheader.dataOffset, 4) == 4);
539c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2width.Write(&os2header, 12) == 12);
540c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2width, NULL, &ti) == B_NO_TRANSLATOR);
541c904c6cdSMatthew Wilber
542c904c6cdSMatthew Wilber NextSubTest();
543c904c6cdSMatthew Wilber fheader.magic = 'MB';
544c904c6cdSMatthew Wilber fheader.fileSize = 1028;
545c904c6cdSMatthew Wilber fheader.reserved = 0;
546c904c6cdSMatthew Wilber fheader.dataOffset = 54;
547c904c6cdSMatthew Wilber msheader.size = 40;
548c904c6cdSMatthew Wilber msheader.width = 5;
549c904c6cdSMatthew Wilber msheader.height = 0; // zero is not a good value
550c904c6cdSMatthew Wilber msheader.planes = 1;
551c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
552c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
553c904c6cdSMatthew Wilber msheader.imagesize = 0;
554c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
555c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
556c904c6cdSMatthew Wilber msheader.colorsused = 0;
557c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
558c904c6cdSMatthew Wilber BMallocIO mallmsheight;
559c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsheight.Write(&fheader.magic, 2) == 2);
560c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsheight.Write(&fheader.fileSize, 4) == 4);
561c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsheight.Write(&fheader.reserved, 4) == 4);
562c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsheight.Write(&fheader.dataOffset, 4) == 4);
563c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsheight.Write(&msheader, 40) == 40);
564c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmsheight, NULL, &ti) == B_NO_TRANSLATOR);
565c904c6cdSMatthew Wilber
566c904c6cdSMatthew Wilber NextSubTest();
567c904c6cdSMatthew Wilber fheader.magic = 'MB';
568c904c6cdSMatthew Wilber fheader.fileSize = 1028;
569c904c6cdSMatthew Wilber fheader.reserved = 0;
570c904c6cdSMatthew Wilber fheader.dataOffset = 26;
571c904c6cdSMatthew Wilber os2header.size = 12;
572c904c6cdSMatthew Wilber os2header.width = 5;
573c904c6cdSMatthew Wilber os2header.height = 0; // bad value
574c904c6cdSMatthew Wilber os2header.planes = 1;
575c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
576c904c6cdSMatthew Wilber BMallocIO mallos2height;
577c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2height.Write(&fheader.magic, 2) == 2);
578c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2height.Write(&fheader.fileSize, 4) == 4);
579c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2height.Write(&fheader.reserved, 4) == 4);
580c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2height.Write(&fheader.dataOffset, 4) == 4);
581c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2height.Write(&os2header, 12) == 12);
582c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2height, NULL, &ti) == B_NO_TRANSLATOR);
583c904c6cdSMatthew Wilber
584c904c6cdSMatthew Wilber NextSubTest();
585c904c6cdSMatthew Wilber fheader.magic = 'MB';
586c904c6cdSMatthew Wilber fheader.fileSize = 1028;
587c904c6cdSMatthew Wilber fheader.reserved = 0;
588c904c6cdSMatthew Wilber fheader.dataOffset = 54;
589c904c6cdSMatthew Wilber msheader.size = 40;
590c904c6cdSMatthew Wilber msheader.width = 5;
591c904c6cdSMatthew Wilber msheader.height = 5;
592c904c6cdSMatthew Wilber msheader.planes = 0; // should always be 1
593c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
594c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
595c904c6cdSMatthew Wilber msheader.imagesize = 0;
596c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
597c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
598c904c6cdSMatthew Wilber msheader.colorsused = 0;
599c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
600c904c6cdSMatthew Wilber BMallocIO mallmsplanes;
601c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes.Write(&fheader.magic, 2) == 2);
602c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes.Write(&fheader.fileSize, 4) == 4);
603c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes.Write(&fheader.reserved, 4) == 4);
604c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes.Write(&fheader.dataOffset, 4) == 4);
605c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes.Write(&msheader, 40) == 40);
606c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmsplanes, NULL, &ti) == B_NO_TRANSLATOR);
607c904c6cdSMatthew Wilber
608c904c6cdSMatthew Wilber NextSubTest();
609c904c6cdSMatthew Wilber fheader.magic = 'MB';
610c904c6cdSMatthew Wilber fheader.fileSize = 1028;
611c904c6cdSMatthew Wilber fheader.reserved = 0;
612c904c6cdSMatthew Wilber fheader.dataOffset = 54;
613c904c6cdSMatthew Wilber msheader.size = 40;
614c904c6cdSMatthew Wilber msheader.width = 5;
615c904c6cdSMatthew Wilber msheader.height = 5;
616c904c6cdSMatthew Wilber msheader.planes = 2; // should always be 1
617c904c6cdSMatthew Wilber msheader.bitsperpixel = 24;
618c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
619c904c6cdSMatthew Wilber msheader.imagesize = 0;
620c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
621c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
622c904c6cdSMatthew Wilber msheader.colorsused = 0;
623c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
624c904c6cdSMatthew Wilber BMallocIO mallmsplanes2;
625c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes2.Write(&fheader.magic, 2) == 2);
626c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes2.Write(&fheader.fileSize, 4) == 4);
627c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes2.Write(&fheader.reserved, 4) == 4);
628c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes2.Write(&fheader.dataOffset, 4) == 4);
629c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsplanes2.Write(&msheader, 40) == 40);
630c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmsplanes2, NULL, &ti) == B_NO_TRANSLATOR);
631c904c6cdSMatthew Wilber
632c904c6cdSMatthew Wilber NextSubTest();
633c904c6cdSMatthew Wilber fheader.magic = 'MB';
634c904c6cdSMatthew Wilber fheader.fileSize = 1028;
635c904c6cdSMatthew Wilber fheader.reserved = 0;
636c904c6cdSMatthew Wilber fheader.dataOffset = 26;
637c904c6cdSMatthew Wilber os2header.size = 12;
638c904c6cdSMatthew Wilber os2header.width = 5;
639c904c6cdSMatthew Wilber os2header.height = 5;
640c904c6cdSMatthew Wilber os2header.planes = 0; // should always be 1
641c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
642c904c6cdSMatthew Wilber BMallocIO mallos2planes;
643c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes.Write(&fheader.magic, 2) == 2);
644c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes.Write(&fheader.fileSize, 4) == 4);
645c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes.Write(&fheader.reserved, 4) == 4);
646c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes.Write(&fheader.dataOffset, 4) == 4);
647c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes.Write(&os2header, 12) == 12);
648c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2planes, NULL, &ti) == B_NO_TRANSLATOR);
649c904c6cdSMatthew Wilber
650c904c6cdSMatthew Wilber NextSubTest();
651c904c6cdSMatthew Wilber fheader.magic = 'MB';
652c904c6cdSMatthew Wilber fheader.fileSize = 1028;
653c904c6cdSMatthew Wilber fheader.reserved = 0;
654c904c6cdSMatthew Wilber fheader.dataOffset = 26;
655c904c6cdSMatthew Wilber os2header.size = 12;
656c904c6cdSMatthew Wilber os2header.width = 5;
657c904c6cdSMatthew Wilber os2header.height = 5;
658c904c6cdSMatthew Wilber os2header.planes = 2; // should always be 1
659c904c6cdSMatthew Wilber os2header.bitsperpixel = 24;
660c904c6cdSMatthew Wilber BMallocIO mallos2planes2;
661c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes2.Write(&fheader.magic, 2) == 2);
662c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes2.Write(&fheader.fileSize, 4) == 4);
663c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes2.Write(&fheader.reserved, 4) == 4);
664c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes2.Write(&fheader.dataOffset, 4) == 4);
665c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2planes2.Write(&os2header, 12) == 12);
666c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2planes2, NULL, &ti) == B_NO_TRANSLATOR);
667c904c6cdSMatthew Wilber
668c904c6cdSMatthew Wilber // makes sure invalid bit depths aren't recognized
669c904c6cdSMatthew Wilber const uint16 bitdepths[] = { 0, 2, 3, 5, 6, 7, 9, 23, 25, 31, 33 };
670c904c6cdSMatthew Wilber const int32 knbitdepths = sizeof(bitdepths) / sizeof(uint16);
671c904c6cdSMatthew Wilber for (int32 i = 0; i < knbitdepths; i++) {
672c904c6cdSMatthew Wilber NextSubTest();
673c904c6cdSMatthew Wilber fheader.magic = 'MB';
674c904c6cdSMatthew Wilber fheader.fileSize = 1028;
675c904c6cdSMatthew Wilber fheader.reserved = 0;
676c904c6cdSMatthew Wilber fheader.dataOffset = 54;
677c904c6cdSMatthew Wilber msheader.size = 40;
678c904c6cdSMatthew Wilber msheader.width = 5;
679c904c6cdSMatthew Wilber msheader.height = 5;
680c904c6cdSMatthew Wilber msheader.planes = 1;
681c904c6cdSMatthew Wilber msheader.bitsperpixel = bitdepths[i];
682c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
683c904c6cdSMatthew Wilber msheader.imagesize = 0;
684c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
685c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
686c904c6cdSMatthew Wilber msheader.colorsused = 0;
687c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
688c904c6cdSMatthew Wilber BMallocIO mallmsbitdepth;
689c904c6cdSMatthew Wilber mallmsbitdepth.Seek(0, SEEK_SET);
690c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsbitdepth.Write(&fheader.magic, 2) == 2);
691c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsbitdepth.Write(&fheader.fileSize, 4) == 4);
692c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsbitdepth.Write(&fheader.reserved, 4) == 4);
693c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsbitdepth.Write(&fheader.dataOffset, 4) == 4);
694c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmsbitdepth.Write(&msheader, 40) == 40);
695c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmsbitdepth, NULL, &ti) == B_NO_TRANSLATOR);
696c904c6cdSMatthew Wilber
697c904c6cdSMatthew Wilber NextSubTest();
698c904c6cdSMatthew Wilber fheader.magic = 'MB';
699c904c6cdSMatthew Wilber fheader.fileSize = 1028;
700c904c6cdSMatthew Wilber fheader.reserved = 0;
701c904c6cdSMatthew Wilber fheader.dataOffset = 26;
702c904c6cdSMatthew Wilber os2header.size = 12;
703c904c6cdSMatthew Wilber os2header.width = 5;
704c904c6cdSMatthew Wilber os2header.height = 5;
705c904c6cdSMatthew Wilber os2header.planes = 1;
706c904c6cdSMatthew Wilber os2header.bitsperpixel = bitdepths[i];
707c904c6cdSMatthew Wilber BMallocIO mallos2bitdepth;
708c904c6cdSMatthew Wilber mallos2bitdepth.Seek(0, SEEK_SET);
709c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2bitdepth.Write(&fheader.magic, 2) == 2);
710c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2bitdepth.Write(&fheader.fileSize, 4) == 4);
711c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2bitdepth.Write(&fheader.reserved, 4) == 4);
712c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2bitdepth.Write(&fheader.dataOffset, 4) == 4);
713c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallos2bitdepth.Write(&os2header, 12) == 12);
714c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallos2bitdepth, NULL, &ti) == B_NO_TRANSLATOR);
715c904c6cdSMatthew Wilber }
716c904c6cdSMatthew Wilber
717c904c6cdSMatthew Wilber // makes sure invalid compression values aren't recognized
718c904c6cdSMatthew Wilber const uint16 cbitdepths[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 23, 24, 25, 31, 32, 33 };
719c904c6cdSMatthew Wilber const uint32 compvalues[] = { BMP_RLE4_COMPRESS, BMP_RLE8_COMPRESS, 3, 4, 5, 10 };
720c904c6cdSMatthew Wilber const int32 kncdepths = sizeof(cbitdepths) / sizeof(uint16);
721c904c6cdSMatthew Wilber const int32 kncomps = sizeof(compvalues) / sizeof(uint32);
722c904c6cdSMatthew Wilber for (int32 i = 0; i < kncomps; i++)
723c904c6cdSMatthew Wilber for (int32 n = 0; n < kncdepths; n++) {
724c904c6cdSMatthew Wilber if (!(compvalues[i] == BMP_RLE4_COMPRESS && cbitdepths[n] == 4) &&
725c904c6cdSMatthew Wilber !(compvalues[i] == BMP_RLE8_COMPRESS && cbitdepths[n] == 8)) {
726c904c6cdSMatthew Wilber NextSubTest();
727c904c6cdSMatthew Wilber fheader.magic = 'MB';
728c904c6cdSMatthew Wilber fheader.fileSize = 1028;
729c904c6cdSMatthew Wilber fheader.reserved = 0;
730c904c6cdSMatthew Wilber fheader.dataOffset = 54;
731c904c6cdSMatthew Wilber msheader.size = 40;
732c904c6cdSMatthew Wilber msheader.width = 5;
733c904c6cdSMatthew Wilber msheader.height = 5;
734c904c6cdSMatthew Wilber msheader.planes = 1;
735c904c6cdSMatthew Wilber msheader.bitsperpixel = cbitdepths[n];
736c904c6cdSMatthew Wilber msheader.compression = compvalues[i];
737c904c6cdSMatthew Wilber msheader.imagesize = 0;
738c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
739c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
740c904c6cdSMatthew Wilber msheader.colorsused = 0;
741c904c6cdSMatthew Wilber msheader.colorsimportant = 0;
742c904c6cdSMatthew Wilber BMallocIO mallmscomp;
743c904c6cdSMatthew Wilber mallmscomp.Seek(0, SEEK_SET);
744c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscomp.Write(&fheader.magic, 2) == 2);
745c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscomp.Write(&fheader.fileSize, 4) == 4);
746c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscomp.Write(&fheader.reserved, 4) == 4);
747c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscomp.Write(&fheader.dataOffset, 4) == 4);
748c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscomp.Write(&msheader, 40) == 40);
749c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmscomp, NULL, &ti)
750c904c6cdSMatthew Wilber == B_NO_TRANSLATOR);
751c904c6cdSMatthew Wilber }
752c904c6cdSMatthew Wilber }
753c904c6cdSMatthew Wilber
754c904c6cdSMatthew Wilber // too many colorsused test!
755c904c6cdSMatthew Wilber const uint16 colordepths[] = { 1, 4, 8, 24, 32 };
756c904c6cdSMatthew Wilber const int32 kncolordepths = sizeof(colordepths) / sizeof(uint16);
757c904c6cdSMatthew Wilber for (int32 i = 0; i < kncolordepths; i++) {
758c904c6cdSMatthew Wilber NextSubTest();
759c904c6cdSMatthew Wilber fheader.magic = 'BM';
760c904c6cdSMatthew Wilber fheader.fileSize = 1028;
761c904c6cdSMatthew Wilber fheader.reserved = 0;
762c904c6cdSMatthew Wilber fheader.dataOffset = 54;
763c904c6cdSMatthew Wilber msheader.size = 40;
764c904c6cdSMatthew Wilber msheader.width = 5;
765c904c6cdSMatthew Wilber msheader.height = 5;
766c904c6cdSMatthew Wilber msheader.planes = 1;
767c904c6cdSMatthew Wilber msheader.bitsperpixel = colordepths[i];
768c904c6cdSMatthew Wilber msheader.compression = BMP_NO_COMPRESS;
769c904c6cdSMatthew Wilber msheader.imagesize = 0;
770c904c6cdSMatthew Wilber msheader.xpixperm = 23275;
771c904c6cdSMatthew Wilber msheader.ypixperm = 23275;
772c904c6cdSMatthew Wilber msheader.colorsused = 0; //(1 << colordepths[i])/* + 1*/;
773c904c6cdSMatthew Wilber msheader.colorsimportant = 0; //(1 << colordepths[i])/* + 1*/;
774c904c6cdSMatthew Wilber BMallocIO mallmscolors;
775c904c6cdSMatthew Wilber mallmscolors.Seek(0, SEEK_SET);
776c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscolors.Write(&fheader.magic, 2) == 2);
777c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscolors.Write(&fheader.fileSize, 4) == 4);
778c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscolors.Write(&fheader.reserved, 4) == 4);
779c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscolors.Write(&fheader.dataOffset, 4) == 4);
780c904c6cdSMatthew Wilber CPPUNIT_ASSERT(mallmscolors.Write(&msheader, 40) == 40);
781c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Identify(&mallmscolors, NULL, &ti) == B_NO_TRANSLATOR);
782c904c6cdSMatthew Wilber }
783db661ffcSMatthew Wilber
784c9088353SMatthew Wilber // Identify (successfully identify the following files)
785c9088353SMatthew Wilber const IdentifyInfo aBitsPaths[] = {
786c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_cmap8.bits", "" },
787c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_gray1-2.bits", "" },
788c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_gray1.bits", "" },
789c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb15.bits", "" },
790c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb16.bits", "" },
791c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb32.bits", "" },
792c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks.bits", "" },
793c9088353SMatthew Wilber { "/boot/home/resources/bmp/gnome_beer.bits", "" },
794c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall.bits", "" }
795c9088353SMatthew Wilber };
796c9088353SMatthew Wilber const IdentifyInfo aBmpPaths[] = {
797c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks_24bit.bmp",
798c9088353SMatthew Wilber "BMP image (MS format, 24 bits)" },
799c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks_4bit_rle.bmp",
800c9088353SMatthew Wilber "BMP image (MS format, 4 bits, RLE)" },
801c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks_8bit_rle.bmp",
802c9088353SMatthew Wilber "BMP image (MS format, 8 bits, RLE)" },
803c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_1bit.bmp",
804c9088353SMatthew Wilber "BMP image (MS format, 1 bits)" },
805c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_1bit_os2.bmp",
806c9088353SMatthew Wilber "BMP image (OS/2 format, 1 bits)" },
807c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_24bit.bmp",
808c9088353SMatthew Wilber "BMP image (MS format, 24 bits)" },
809c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_24bit_os2.bmp",
810c9088353SMatthew Wilber "BMP image (OS/2 format, 24 bits)" },
811c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_4bit.bmp",
812c9088353SMatthew Wilber "BMP image (MS format, 4 bits)" },
813c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_4bit_os2.bmp",
814c9088353SMatthew Wilber "BMP image (OS/2 format, 4 bits)" },
815c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_4bit_rle.bmp",
816c9088353SMatthew Wilber "BMP image (MS format, 4 bits, RLE)" },
817c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_8bit.bmp",
818c9088353SMatthew Wilber "BMP image (MS format, 8 bits)" },
819c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_8bit_os2.bmp",
820c9088353SMatthew Wilber "BMP image (OS/2 format, 8 bits)" },
821c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_8bit_rle.bmp",
822c9088353SMatthew Wilber "BMP image (MS format, 8 bits, RLE)" },
823c9088353SMatthew Wilber { "/boot/home/resources/bmp/gnome_beer_24bit.bmp",
824c9088353SMatthew Wilber "BMP image (MS format, 24 bits)" },
825c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_1bit.bmp",
826c9088353SMatthew Wilber "BMP image (MS format, 1 bits)" },
827c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_1bit_os2.bmp",
828c9088353SMatthew Wilber "BMP image (OS/2 format, 1 bits)" },
829c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_24bit.bmp",
830c9088353SMatthew Wilber "BMP image (MS format, 24 bits)" },
831c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_24bit_os2.bmp",
832c9088353SMatthew Wilber "BMP image (OS/2 format, 24 bits)" },
833c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_4bit.bmp",
834c9088353SMatthew Wilber "BMP image (MS format, 4 bits)" },
835c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_4bit_os2.bmp",
836c9088353SMatthew Wilber "BMP image (OS/2 format, 4 bits)" },
837c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_4bit_rle.bmp",
838c9088353SMatthew Wilber "BMP image (MS format, 4 bits, RLE)" },
839c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_8bit.bmp",
840c9088353SMatthew Wilber "BMP image (MS format, 8 bits)" },
841c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_8bit_os2.bmp",
842c9088353SMatthew Wilber "BMP image (OS/2 format, 8 bits)" },
843c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_8bit_rle.bmp",
844c9088353SMatthew Wilber "BMP image (MS format, 8 bits, RLE)" },
845c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb32(32).bmp",
846d2c9e14cSMatthew Wilber "BMP image (MS format, 32 bits)" },
847d2c9e14cSMatthew Wilber { "/boot/home/resources/bmp/double_click_bmap.bmp",
848d2c9e14cSMatthew Wilber "BMP image (MS format, 24 bits)" }
849c9088353SMatthew Wilber };
850db661ffcSMatthew Wilber
851c9088353SMatthew Wilber IdentifyTests(this, proster, aBmpPaths,
852c9088353SMatthew Wilber sizeof(aBmpPaths) / sizeof(IdentifyInfo), false);
853c9088353SMatthew Wilber IdentifyTests(this, proster, aBitsPaths,
854c9088353SMatthew Wilber sizeof(aBitsPaths) / sizeof(IdentifyInfo), true);
855c9088353SMatthew Wilber
856c9088353SMatthew Wilber delete proster;
857c9088353SMatthew Wilber proster = NULL;
858db661ffcSMatthew Wilber }
859db661ffcSMatthew Wilber
860c9088353SMatthew Wilber // coveniently group path of bmp image with
861c9088353SMatthew Wilber // path of bits image that it should translate to
862c9088353SMatthew Wilber struct TranslatePaths {
863c9088353SMatthew Wilber const char *bmpPath;
864c9088353SMatthew Wilber const char *bitsPath;
865c9088353SMatthew Wilber };
866c9088353SMatthew Wilber
867c9088353SMatthew Wilber void
TranslateTests(BMPTranslatorTest * ptest,BTranslatorRoster * proster,const TranslatePaths * paths,int32 len,bool bbmpinput)868c9088353SMatthew Wilber TranslateTests(BMPTranslatorTest *ptest, BTranslatorRoster *proster,
869c9088353SMatthew Wilber const TranslatePaths *paths, int32 len, bool bbmpinput)
8708a024de4SMatthew Wilber {
871c9088353SMatthew Wilber // Perform translations on every file in the array
872c9088353SMatthew Wilber for (int32 i = 0; i < len; i++) {
873c9088353SMatthew Wilber // Setup input files
874c9088353SMatthew Wilber ptest->NextSubTest();
875c9088353SMatthew Wilber BFile bmpfile, bitsfile, *pinput;
876c9088353SMatthew Wilber CPPUNIT_ASSERT(bmpfile.SetTo(paths[i].bmpPath, B_READ_ONLY) == B_OK);
877c9088353SMatthew Wilber CPPUNIT_ASSERT(bitsfile.SetTo(paths[i].bitsPath, B_READ_ONLY) == B_OK);
878c9088353SMatthew Wilber if (bbmpinput) {
879c9088353SMatthew Wilber printf(" [%s] ", paths[i].bmpPath);
880c9088353SMatthew Wilber pinput = &bmpfile;
881c9088353SMatthew Wilber } else {
882c9088353SMatthew Wilber printf(" [%s] ", paths[i].bitsPath);
883c9088353SMatthew Wilber pinput = &bitsfile;
8848a024de4SMatthew Wilber }
8858a024de4SMatthew Wilber
886c9088353SMatthew Wilber BMallocIO mallio, dmallio;
887c9088353SMatthew Wilber
888c9088353SMatthew Wilber // Convert to B_TRANSLATOR_ANY_TYPE (should be B_TRANSLATOR_BITMAP)
889c9088353SMatthew Wilber ptest->NextSubTest();
890c9088353SMatthew Wilber CPPUNIT_ASSERT(mallio.Seek(0, SEEK_SET) == 0);
891c9088353SMatthew Wilber CPPUNIT_ASSERT(mallio.SetSize(0) == B_OK);
892c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Translate(pinput, NULL, NULL, &mallio,
893c9088353SMatthew Wilber B_TRANSLATOR_ANY_TYPE) == B_OK);
894c9088353SMatthew Wilber CPPUNIT_ASSERT(CompareStreams(mallio, bitsfile) == true);
895c9088353SMatthew Wilber
896c9088353SMatthew Wilber // Convert to B_TRANSLATOR_BITMAP
897c9088353SMatthew Wilber ptest->NextSubTest();
898c9088353SMatthew Wilber CPPUNIT_ASSERT(mallio.Seek(0, SEEK_SET) == 0);
899c9088353SMatthew Wilber CPPUNIT_ASSERT(mallio.SetSize(0) == B_OK);
900c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Translate(pinput, NULL, NULL, &mallio,
901c9088353SMatthew Wilber B_TRANSLATOR_BITMAP) == B_OK);
902c9088353SMatthew Wilber CPPUNIT_ASSERT(CompareStreams(mallio, bitsfile) == true);
903c9088353SMatthew Wilber
904c9088353SMatthew Wilber // Convert bits mallio to B_TRANSLATOR_BITMAP dmallio
905c9088353SMatthew Wilber ptest->NextSubTest();
906c9088353SMatthew Wilber CPPUNIT_ASSERT(dmallio.Seek(0, SEEK_SET) == 0);
907c9088353SMatthew Wilber CPPUNIT_ASSERT(dmallio.SetSize(0) == B_OK);
908c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Translate(&mallio, NULL, NULL, &dmallio,
909c9088353SMatthew Wilber B_TRANSLATOR_BITMAP) == B_OK);
910c9088353SMatthew Wilber CPPUNIT_ASSERT(CompareStreams(dmallio, bitsfile) == true);
911c9088353SMatthew Wilber
912c9088353SMatthew Wilber // Only perform the following tests if the BMP is not
913c9088353SMatthew Wilber // an OS/2 format BMP image.
914c9088353SMatthew Wilber // (Need to write special testing for OS/2 images)
915c9088353SMatthew Wilber if (!strstr(paths[i].bmpPath, "os2")) {
916c9088353SMatthew Wilber // Convert to B_BMP_FORMAT
917c9088353SMatthew Wilber ptest->NextSubTest();
918c9088353SMatthew Wilber CPPUNIT_ASSERT(mallio.Seek(0, SEEK_SET) == 0);
919c9088353SMatthew Wilber CPPUNIT_ASSERT(mallio.SetSize(0) == B_OK);
920c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Translate(pinput, NULL, NULL, &mallio,
921c9088353SMatthew Wilber B_BMP_FORMAT) == B_OK);
922c9088353SMatthew Wilber CPPUNIT_ASSERT(CompareStreams(mallio, bmpfile) == true);
923c9088353SMatthew Wilber
924c9088353SMatthew Wilber // Convert BMP mallio to B_TRANSLATOR_BITMAP dmallio
925c9088353SMatthew Wilber if (bbmpinput) {
926c9088353SMatthew Wilber ptest->NextSubTest();
927c9088353SMatthew Wilber CPPUNIT_ASSERT(dmallio.Seek(0, SEEK_SET) == 0);
928c9088353SMatthew Wilber CPPUNIT_ASSERT(dmallio.SetSize(0) == B_OK);
929c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Translate(&mallio, NULL, NULL, &dmallio,
930c9088353SMatthew Wilber B_TRANSLATOR_BITMAP) == B_OK);
931c9088353SMatthew Wilber CPPUNIT_ASSERT(CompareStreams(dmallio, bitsfile) == true);
932c9088353SMatthew Wilber }
933c9088353SMatthew Wilber
934c9088353SMatthew Wilber // Convert BMP mallio to B_BMP_FORMAT dmallio
935c9088353SMatthew Wilber ptest->NextSubTest();
936c9088353SMatthew Wilber CPPUNIT_ASSERT(dmallio.Seek(0, SEEK_SET) == 0);
937c9088353SMatthew Wilber CPPUNIT_ASSERT(dmallio.SetSize(0) == B_OK);
938c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->Translate(&mallio, NULL, NULL, &dmallio,
939c9088353SMatthew Wilber B_BMP_FORMAT) == B_OK);
940c9088353SMatthew Wilber CPPUNIT_ASSERT(CompareStreams(dmallio, bmpfile) == true);
941c9088353SMatthew Wilber }
9428a024de4SMatthew Wilber }
9438a024de4SMatthew Wilber }
9448a024de4SMatthew Wilber
9458a024de4SMatthew Wilber void
TranslateTest()946c9088353SMatthew Wilber BMPTranslatorTest::TranslateTest()
9478a024de4SMatthew Wilber {
948fe2aacfaSMatthew Wilber BApplication
949fe2aacfaSMatthew Wilber app("application/x-vnd.OpenBeOS-BMPTranslatorTest");
950fe2aacfaSMatthew Wilber
951c9088353SMatthew Wilber // Init
9528a024de4SMatthew Wilber NextSubTest();
953c9088353SMatthew Wilber status_t result = B_ERROR;
954c9088353SMatthew Wilber off_t filesize = -1;
955c9088353SMatthew Wilber BTranslatorRoster *proster = new BTranslatorRoster();
956c9088353SMatthew Wilber CPPUNIT_ASSERT(proster);
957c9088353SMatthew Wilber CPPUNIT_ASSERT(proster->AddTranslators(
958c9088353SMatthew Wilber "/boot/home/config/add-ons/Translators/BMPTranslator") == B_OK);
959c9088353SMatthew Wilber BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
960c9088353SMatthew Wilber B_READ_ONLY);
961c9088353SMatthew Wilber CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
962c9088353SMatthew Wilber BFile output("/tmp/bmp_test.out", B_WRITE_ONLY |
963c9088353SMatthew Wilber B_CREATE_FILE | B_ERASE_FILE);
964c9088353SMatthew Wilber CPPUNIT_ASSERT(output.InitCheck() == B_OK);
9658a024de4SMatthew Wilber
966c9088353SMatthew Wilber // Translate (bad input, output types)
9678a024de4SMatthew Wilber NextSubTest();
968c9088353SMatthew Wilber result = proster->Translate(&wronginput, NULL, NULL, &output,
969c9088353SMatthew Wilber B_TRANSLATOR_TEXT);
970c9088353SMatthew Wilber CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
971c9088353SMatthew Wilber CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
972c9088353SMatthew Wilber CPPUNIT_ASSERT(filesize == 0);
9738a024de4SMatthew Wilber
974c9088353SMatthew Wilber // Translate (wrong type of input data)
9758a024de4SMatthew Wilber NextSubTest();
976c9088353SMatthew Wilber result = proster->Translate(&wronginput, NULL, NULL, &output,
977c9088353SMatthew Wilber B_BMP_FORMAT);
978c9088353SMatthew Wilber CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
979c9088353SMatthew Wilber CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
980c9088353SMatthew Wilber CPPUNIT_ASSERT(filesize == 0);
9818a024de4SMatthew Wilber
982c9088353SMatthew Wilber // Translate (wrong type of input, B_TRANSLATOR_ANY_TYPE output)
9838a024de4SMatthew Wilber NextSubTest();
984c9088353SMatthew Wilber result = proster->Translate(&wronginput, NULL, NULL, &output,
985c9088353SMatthew Wilber B_TRANSLATOR_ANY_TYPE);
986c9088353SMatthew Wilber CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
987c9088353SMatthew Wilber CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
988c9088353SMatthew Wilber CPPUNIT_ASSERT(filesize == 0);
9898a024de4SMatthew Wilber
990c9088353SMatthew Wilber // For translating BMP images to bits
991c9088353SMatthew Wilber const TranslatePaths aBmpInput[] = {
992c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks_24bit.bmp",
993c9088353SMatthew Wilber "/boot/home/resources/bmp/blocks.bits" },
994c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks_4bit_rle.bmp",
995c9088353SMatthew Wilber "/boot/home/resources/bmp/blocks.bits" },
996c9088353SMatthew Wilber { "/boot/home/resources/bmp/blocks_8bit_rle.bmp",
997c9088353SMatthew Wilber "/boot/home/resources/bmp/blocks.bits" },
998c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_1bit.bmp",
999c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_1bit.bits" },
1000c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_1bit_os2.bmp",
1001c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_1bit.bits" },
1002c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_24bit.bmp",
1003c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1004c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_24bit_os2.bmp",
1005c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1006c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_4bit.bmp",
1007c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1008c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_4bit_os2.bmp",
1009c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1010c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_4bit_rle.bmp",
1011c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_4bit_rle.bits" },
1012c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_8bit.bmp",
1013c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1014c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_8bit_os2.bmp",
1015c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1016c9088353SMatthew Wilber { "/boot/home/resources/bmp/color_scribbles_8bit_rle.bmp",
1017c9088353SMatthew Wilber "/boot/home/resources/bmp/color_scribbles_24bit.bits" },
1018c9088353SMatthew Wilber { "/boot/home/resources/bmp/gnome_beer_24bit.bmp",
1019c9088353SMatthew Wilber "/boot/home/resources/bmp/gnome_beer.bits" },
1020c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_1bit.bmp",
1021c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1022c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_1bit_os2.bmp",
1023c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1024c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_24bit.bmp",
1025c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1026c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_24bit_os2.bmp",
1027c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1028c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_4bit.bmp",
1029c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1030c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_4bit_os2.bmp",
1031c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1032c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_4bit_rle.bmp",
1033c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1034c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_8bit.bmp",
1035c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1036c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_8bit_os2.bmp",
1037c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1038c9088353SMatthew Wilber { "/boot/home/resources/bmp/vsmall_8bit_rle.bmp",
1039c9088353SMatthew Wilber "/boot/home/resources/bmp/vsmall.bits" },
1040c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb32(32).bmp",
1041c9088353SMatthew Wilber "/boot/home/resources/bmp/b_rgb32.bits" }
10428a024de4SMatthew Wilber };
1043c9088353SMatthew Wilber
1044c9088353SMatthew Wilber // For translating bits images to BMP
1045c9088353SMatthew Wilber const TranslatePaths aBitsInput[] = {
1046c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_gray1-2.bmp",
1047c9088353SMatthew Wilber "/boot/home/resources/bmp/b_gray1-2.bits" },
1048c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_gray1.bmp",
1049c9088353SMatthew Wilber "/boot/home/resources/bmp/b_gray1.bits" },
1050c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb15.bmp",
1051c9088353SMatthew Wilber "/boot/home/resources/bmp/b_rgb15.bits" },
1052c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb16.bmp",
1053c9088353SMatthew Wilber "/boot/home/resources/bmp/b_rgb16.bits" },
1054c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_rgb32(24).bmp",
1055c9088353SMatthew Wilber "/boot/home/resources/bmp/b_rgb32.bits" },
1056c9088353SMatthew Wilber { "/boot/home/resources/bmp/b_cmap8.bmp",
1057c9088353SMatthew Wilber "/boot/home/resources/bmp/b_cmap8.bits" }
10588a024de4SMatthew Wilber };
1059c9088353SMatthew Wilber
1060c9088353SMatthew Wilber TranslateTests(this, proster, aBmpInput,
1061c9088353SMatthew Wilber sizeof(aBmpInput) / sizeof(TranslatePaths), true);
1062c9088353SMatthew Wilber TranslateTests(this, proster, aBitsInput,
1063c9088353SMatthew Wilber sizeof(aBitsInput) / sizeof(TranslatePaths), false);
1064c9088353SMatthew Wilber
1065c9088353SMatthew Wilber delete proster;
1066c9088353SMatthew Wilber proster = NULL;
10678a024de4SMatthew Wilber }
10688a024de4SMatthew Wilber
1069bedcc993SMatthew Wilber // Make certain that the BMPTranslator does not
1070bedcc993SMatthew Wilber // provide a configuration message
1071bedcc993SMatthew Wilber void
ConfigMessageTest()1072bedcc993SMatthew Wilber BMPTranslatorTest::ConfigMessageTest()
1073bedcc993SMatthew Wilber {
1074bedcc993SMatthew Wilber // Init
1075bedcc993SMatthew Wilber NextSubTest();
1076bedcc993SMatthew Wilber BTranslatorRoster *proster = new BTranslatorRoster();
1077bedcc993SMatthew Wilber CPPUNIT_ASSERT(proster);
1078bedcc993SMatthew Wilber CPPUNIT_ASSERT(proster->AddTranslators(
1079bedcc993SMatthew Wilber "/boot/home/config/add-ons/Translators/BMPTranslator") == B_OK);
1080bedcc993SMatthew Wilber
1081bedcc993SMatthew Wilber // GetAllTranslators
1082bedcc993SMatthew Wilber NextSubTest();
1083bedcc993SMatthew Wilber translator_id tid, *pids = NULL;
1084bedcc993SMatthew Wilber int32 count = 0;
1085bedcc993SMatthew Wilber CPPUNIT_ASSERT(proster->GetAllTranslators(&pids, &count) == B_OK);
1086bedcc993SMatthew Wilber CPPUNIT_ASSERT(pids);
1087bedcc993SMatthew Wilber CPPUNIT_ASSERT(count == 1);
1088bedcc993SMatthew Wilber tid = pids[0];
1089bedcc993SMatthew Wilber delete[] pids;
1090bedcc993SMatthew Wilber pids = NULL;
1091bedcc993SMatthew Wilber
1092bedcc993SMatthew Wilber // GetConfigurationMessage
1093bedcc993SMatthew Wilber NextSubTest();
1094bedcc993SMatthew Wilber BMessage msg;
1095be510fa8SMatthew Wilber CPPUNIT_ASSERT(proster->GetConfigurationMessage(tid, &msg) == B_OK);
1096be510fa8SMatthew Wilber CPPUNIT_ASSERT(!msg.IsEmpty());
1097be510fa8SMatthew Wilber
1098be510fa8SMatthew Wilber // B_TRANSLATOR_EXT_HEADER_ONLY
1099be510fa8SMatthew Wilber NextSubTest();
1100be510fa8SMatthew Wilber bool bheaderonly = true;
1101be510fa8SMatthew Wilber CPPUNIT_ASSERT(
1102be510fa8SMatthew Wilber msg.FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bheaderonly) == B_OK);
1103be510fa8SMatthew Wilber CPPUNIT_ASSERT(bheaderonly == false);
1104be510fa8SMatthew Wilber
1105be510fa8SMatthew Wilber // B_TRANSLATOR_EXT_DATA_ONLY
1106be510fa8SMatthew Wilber NextSubTest();
1107be510fa8SMatthew Wilber bool bdataonly = true;
1108be510fa8SMatthew Wilber CPPUNIT_ASSERT(
1109be510fa8SMatthew Wilber msg.FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bdataonly) == B_OK);
1110be510fa8SMatthew Wilber CPPUNIT_ASSERT(bdataonly == false);
1111bedcc993SMatthew Wilber }
1112bedcc993SMatthew Wilber
1113c9088353SMatthew Wilber #if !TEST_R5
11148a024de4SMatthew Wilber
1115c9088353SMatthew Wilber // The input formats that this translator is supposed to support
1116c9088353SMatthew Wilber translation_format gBMPInputFormats[] = {
1117c9088353SMatthew Wilber {
1118c9088353SMatthew Wilber B_TRANSLATOR_BITMAP,
1119c9088353SMatthew Wilber B_TRANSLATOR_BITMAP,
1120f08ccd95SMatthew Wilber 0.4f, // quality
1121f08ccd95SMatthew Wilber 0.6f, // capability
1122c9088353SMatthew Wilber "image/x-be-bitmap",
1123c9088353SMatthew Wilber "Be Bitmap Format (BMPTranslator)"
1124c9088353SMatthew Wilber },
1125c9088353SMatthew Wilber {
1126c9088353SMatthew Wilber B_BMP_FORMAT,
1127c9088353SMatthew Wilber B_TRANSLATOR_BITMAP,
1128f08ccd95SMatthew Wilber 0.4f,
1129c9088353SMatthew Wilber 0.8f,
1130c9088353SMatthew Wilber "image/x-bmp",
1131c9088353SMatthew Wilber "BMP image"
11328a024de4SMatthew Wilber }
1133c9088353SMatthew Wilber };
1134c9088353SMatthew Wilber
1135c9088353SMatthew Wilber // The output formats that this translator is supposed to support
1136c9088353SMatthew Wilber translation_format gBMPOutputFormats[] = {
1137c9088353SMatthew Wilber {
1138c9088353SMatthew Wilber B_TRANSLATOR_BITMAP,
1139c9088353SMatthew Wilber B_TRANSLATOR_BITMAP,
1140f08ccd95SMatthew Wilber 0.4f, // quality
1141f08ccd95SMatthew Wilber 0.6f, // capability
1142c9088353SMatthew Wilber "image/x-be-bitmap",
1143c9088353SMatthew Wilber "Be Bitmap Format (BMPTranslator)"
1144c9088353SMatthew Wilber },
1145c9088353SMatthew Wilber {
1146c9088353SMatthew Wilber B_BMP_FORMAT,
1147c9088353SMatthew Wilber B_TRANSLATOR_BITMAP,
1148f08ccd95SMatthew Wilber 0.4f,
1149f08ccd95SMatthew Wilber 0.8f,
1150c9088353SMatthew Wilber "image/x-bmp",
1151c9088353SMatthew Wilber "BMP image (MS format)"
1152c9088353SMatthew Wilber }
1153c9088353SMatthew Wilber };
11548a024de4SMatthew Wilber
1155db661ffcSMatthew Wilber void
LoadAddOnTest()1156c9088353SMatthew Wilber BMPTranslatorTest::LoadAddOnTest()
1157e11362e6SMatthew Wilber {
1158c9088353SMatthew Wilber TranslatorLoadAddOnTest("/boot/home/config/add-ons/Translators/BMPTranslator",
1159c9088353SMatthew Wilber this,
1160c9088353SMatthew Wilber gBMPInputFormats, sizeof(gBMPInputFormats) / sizeof(translation_format),
1161f08ccd95SMatthew Wilber gBMPOutputFormats, sizeof(gBMPOutputFormats) / sizeof(translation_format),
1162*dfb8c585SMatthew Wilber B_TRANSLATION_MAKE_VERSION(1,0,0));
1163e11362e6SMatthew Wilber }
1164e11362e6SMatthew Wilber
1165e11362e6SMatthew Wilber #endif // #if !TEST_R5
1166