xref: /haiku/src/tests/add-ons/translators/tgatranslator/TGATranslatorTest.cpp (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 /*****************************************************************************/
2 // TGATranslatorTest
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // TGATranslatorTest.cpp
6 //
7 // Unit testing code to test the OBOS TGATranslator
8 //
9 //
10 // Copyright (c) 2003 OpenBeOS Project
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a
13 // copy of this software and associated documentation files (the "Software"),
14 // to deal in the Software without restriction, including without limitation
15 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 // and/or sell copies of the Software, and to permit persons to whom the
17 // Software is furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be included
20 // in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 // DEALINGS IN THE SOFTWARE.
29 /*****************************************************************************/
30 #include "TGATranslatorTest.h"
31 #include <cppunit/Test.h>
32 #include <cppunit/TestCaller.h>
33 #include <cppunit/TestSuite.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <unistd.h>
37 #include <image.h>
38 #include <Application.h>
39 #include <Translator.h>
40 #include <TranslatorFormats.h>
41 #include <TranslatorRoster.h>
42 #include <Message.h>
43 #include <View.h>
44 #include <Rect.h>
45 #include <File.h>
46 #include <DataIO.h>
47 #include <Errors.h>
48 #include <OS.h>
49 #include "TranslatorTestAddOn.h"
50 
51 // Suite
52 CppUnit::Test *
53 TGATranslatorTest::Suite()
54 {
55 	CppUnit::TestSuite *suite = new CppUnit::TestSuite();
56 	typedef CppUnit::TestCaller<TGATranslatorTest> TC;
57 
58 	suite->addTest(
59 		new TC("TGATranslator IdentifyTest",
60 			&TGATranslatorTest::IdentifyTest));
61 
62 	suite->addTest(
63 		new TC("TGATranslator TranslateTest",
64 			&TGATranslatorTest::TranslateTest));
65 
66 	suite->addTest(
67 		new TC("TGATranslator ConfigMessageTest",
68 			&TGATranslatorTest::ConfigMessageTest));
69 
70 #if !TEST_R5
71 	suite->addTest(
72 		new TC("TGATranslator LoadAddOnTest",
73 			&TGATranslatorTest::LoadAddOnTest));
74 #endif
75 
76 	return suite;
77 }
78 
79 // setUp
80 void
81 TGATranslatorTest::setUp()
82 {
83 	BTestCase::setUp();
84 }
85 
86 // tearDown
87 void
88 TGATranslatorTest::tearDown()
89 {
90 	BTestCase::tearDown();
91 }
92 
93 void
94 CheckBits_Tga(translator_info *pti)
95 {
96 	CheckTranslatorInfo(pti, B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP,
97 		0.6f, 0.8f, "Be Bitmap Format (TGATranslator)",
98 		"image/x-be-bitmap");
99 }
100 
101 void
102 CheckTga(translator_info *pti, const char *imageType)
103 {
104 	CheckTranslatorInfo(pti, B_TGA_FORMAT, B_TRANSLATOR_BITMAP,
105 		1.0f, 0.6f, imageType, "image/x-targa");
106 }
107 
108 // coveniently group path of image with
109 // the expected Identify() string for that image
110 struct IdentifyInfo {
111 	const char *imagePath;
112 	const char *identifyString;
113 };
114 
115 void
116 IdentifyTests(TGATranslatorTest *ptest, BTranslatorRoster *proster,
117 	const IdentifyInfo *pinfo, int32 len, bool bbits)
118 {
119 	translator_info ti;
120 	printf(" [%d] ", (int) bbits);
121 
122 	for (int32 i = 0; i < len; i++) {
123 		ptest->NextSubTest();
124 		BFile file;
125 		printf(" [%s] ", pinfo[i].imagePath);
126 		CPPUNIT_ASSERT(file.SetTo(pinfo[i].imagePath, B_READ_ONLY) == B_OK);
127 
128 		// Identify (output: B_TRANSLATOR_ANY_TYPE)
129 		ptest->NextSubTest();
130 		memset(&ti, 0, sizeof(translator_info));
131 		CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti) == B_OK);
132 		if (bbits)
133 			CheckBits_Tga(&ti);
134 		else
135 			CheckTga(&ti, pinfo[i].identifyString);
136 
137 		// Identify (output: B_TRANSLATOR_BITMAP)
138 		ptest->NextSubTest();
139 		memset(&ti, 0, sizeof(translator_info));
140 		CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti, 0, NULL,
141 			B_TRANSLATOR_BITMAP) == B_OK);
142 		if (bbits)
143 			CheckBits_Tga(&ti);
144 		else
145 			CheckTga(&ti, pinfo[i].identifyString);
146 
147 		// Identify (output: B_TGA_FORMAT)
148 		ptest->NextSubTest();
149 		memset(&ti, 0, sizeof(translator_info));
150 		CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti, 0, NULL,
151 			B_TGA_FORMAT) == B_OK);
152 		if (bbits)
153 			CheckBits_Tga(&ti);
154 		else
155 			CheckTga(&ti, pinfo[i].identifyString);
156 	}
157 }
158 
159 void
160 TGATranslatorTest::IdentifyTest()
161 {
162 	// Init
163 	NextSubTest();
164 	status_t result = B_ERROR;
165 	BTranslatorRoster *proster = new BTranslatorRoster();
166 	CPPUNIT_ASSERT(proster);
167 	CPPUNIT_ASSERT(proster->AddTranslators(
168 		"/boot/home/config/add-ons/Translators/TGATranslator") == B_OK);
169 	BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
170 		B_READ_ONLY);
171 	CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
172 
173 	// Identify (bad input, output types)
174 	NextSubTest();
175 	translator_info ti;
176 	memset(&ti, 0, sizeof(translator_info));
177 	result = proster->Identify(&wronginput, NULL, &ti, 0,
178 		NULL, B_TRANSLATOR_TEXT);
179 	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
180 	CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
181 
182 	// Identify (wrong type of input data)
183 	NextSubTest();
184 	memset(&ti, 0, sizeof(translator_info));
185 	result = proster->Identify(&wronginput, NULL, &ti);
186 	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
187 	CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
188 
189 	// Identify (successfully identify the following files)
190 	const IdentifyInfo aBitsPaths[] = {
191 		{ "/boot/home/resources/tga/screen1_24.bits", "" },
192 		{ "/boot/home/resources/tga/b_gray1-2.bits", "" },
193 		{ "/boot/home/resources/tga/b_gray1.bits", "" },
194 		{ "/boot/home/resources/tga/b_rgb15.bits", "" },
195 		{ "/boot/home/resources/tga/b_rgb16.bits", "" },
196 		{ "/boot/home/resources/tga/b_rgb32.bits", "" },
197 		{ "/boot/home/resources/tga/b_cmap8.bits", "" }
198 	};
199 	const IdentifyInfo aTgaPaths[] = {
200 		{ "/boot/home/resources/tga/blocks_16_rle_true.tga",
201 			"Targa image (16 bits RLE truecolor)" },
202 		{ "/boot/home/resources/tga/blocks_24_none_true.tga",
203 			"Targa image (24 bits truecolor)" },
204 		{ "/boot/home/resources/tga/blocks_24_rle_true.tga",
205 			"Targa image (24 bits RLE truecolor)" },
206 		{ "/boot/home/resources/tga/blocks_8_none_gray.tga",
207 			"Targa image (8 bits gray)" },
208 		{ "/boot/home/resources/tga/blocks_8_rle_cmap.tga",
209 			"Targa image (8 bits RLE colormap)" },
210 		{ "/boot/home/resources/tga/cloudcg_16_none_true.tga",
211 			"Targa image (16 bits truecolor)" },
212 		{ "/boot/home/resources/tga/cloudcg_16_rle_true.tga",
213 			"Targa image (16 bits RLE truecolor)" },
214 		{ "/boot/home/resources/tga/cloudcg_24_none_true.tga",
215 			"Targa image (24 bits truecolor)" },
216 		{ "/boot/home/resources/tga/cloudcg_24_rle_true.tga",
217 			"Targa image (24 bits RLE truecolor)" },
218 		{ "/boot/home/resources/tga/cloudcg_8_none_cmap.tga",
219 			"Targa image (8 bits colormap)" },
220 		{ "/boot/home/resources/tga/cloudcg_8_none_gray.tga",
221 			"Targa image (8 bits gray)" },
222 		{ "/boot/home/resources/tga/cloudcg_8_rle_cmap.tga",
223 			"Targa image (8 bits RLE colormap)" },
224 		{ "/boot/home/resources/tga/graycloudcg_8_rle_cmap.tga",
225 			"Targa image (8 bits RLE colormap)" },
226 		{ "/boot/home/resources/tga/grayblocks_8_rle_cmap.tga",
227 			"Targa image (8 bits RLE colormap)" },
228 		{ "/boot/home/resources/tga/screen1_16_none_true.tga",
229 			"Targa image (16 bits truecolor)" },
230 		{ "/boot/home/resources/tga/screen1_16_rle_true.tga",
231 			"Targa image (16 bits RLE truecolor)" },
232 		{ "/boot/home/resources/tga/screen1_24_none_true.tga",
233 			"Targa image (24 bits truecolor)" },
234 		{ "/boot/home/resources/tga/screen1_24_rle_true.tga",
235 			"Targa image (24 bits RLE truecolor)" },
236 		{ "/boot/home/resources/tga/screen1_8_none_cmap.tga",
237 			"Targa image (8 bits colormap)" },
238 		{ "/boot/home/resources/tga/screen1_8_none_gray.tga",
239 			"Targa image (8 bits gray)" },
240 		{ "/boot/home/resources/tga/screen1_8_rle_cmap.tga",
241 			"Targa image (8 bits RLE colormap)" },
242 		{ "/boot/home/resources/tga/grayscreen1_8_rle_cmap.tga",
243 			"Targa image (8 bits RLE colormap)" },
244 		{ "/boot/home/resources/tga/ugly_16_none_true.tga",
245 			"Targa image (16 bits truecolor)" },
246 		{ "/boot/home/resources/tga/ugly_24_none_true.tga",
247 			"Targa image (24 bits truecolor)" },
248 		{ "/boot/home/resources/tga/ugly_32_none_true.tga",
249 			"Targa image (32 bits truecolor)" },
250 		{ "/boot/home/resources/tga/ugly_8_none_cmap.tga",
251 			"Targa image (8 bits colormap)" }
252 	};
253 
254 	IdentifyTests(this, proster, aTgaPaths,
255 		sizeof(aTgaPaths) / sizeof(IdentifyInfo), false);
256 	IdentifyTests(this, proster, aBitsPaths,
257 		sizeof(aBitsPaths) / sizeof(IdentifyInfo), true);
258 
259 	delete proster;
260 	proster = NULL;
261 }
262 
263 // coveniently group path of tga image with
264 // path of bits image that it should translate to
265 struct TranslatePaths {
266 	const char *tgaPath;
267 	const char *bitsPath;
268 	bool bcompress;
269 };
270 
271 void
272 TranslateTests(TGATranslatorTest *ptest, BTranslatorRoster *proster,
273 	const TranslatePaths *paths, int32 len, bool btgainput)
274 {
275 	// Setup BMessages for specifying TGATranslator settings
276 	const char *krleoption = "tga /rle";
277 	BMessage compmsg, nocompmsg, *pmsg;
278 	CPPUNIT_ASSERT(compmsg.AddBool(krleoption, true) == B_OK);
279 	CPPUNIT_ASSERT(nocompmsg.AddBool(krleoption, false) == B_OK);
280 
281 	// Perform translations on every file in the array
282 	for (int32 i = 0; i < len; i++) {
283 		// Setup input files
284 		ptest->NextSubTest();
285 		BFile tgafile, bitsfile, *pinput;
286 		CPPUNIT_ASSERT(tgafile.SetTo(paths[i].tgaPath, B_READ_ONLY) == B_OK);
287 		CPPUNIT_ASSERT(bitsfile.SetTo(paths[i].bitsPath, B_READ_ONLY) == B_OK);
288 		if (btgainput) {
289 			printf(" [%s] ", paths[i].tgaPath);
290 			pinput = &tgafile;
291 		} else {
292 			printf(" [%s] ", paths[i].bitsPath);
293 			pinput = &bitsfile;
294 		}
295 
296 		// RLE compression option
297 		if (paths[i].bcompress)
298 			pmsg = &compmsg;
299 		else
300 			pmsg = &nocompmsg;
301 
302 		// create temporary files where the translated data will
303 		// be stored
304 		BFile tmpfile("/tmp/tgatmp", B_READ_WRITE | B_CREATE_FILE |
305 			B_ERASE_FILE);
306 		BFile dtmpfile("/tmp/tgadtmp", B_READ_WRITE | B_CREATE_FILE |
307 			B_ERASE_FILE);
308 		CPPUNIT_ASSERT(tmpfile.InitCheck() == B_OK);
309 		CPPUNIT_ASSERT(dtmpfile.InitCheck() == B_OK);
310 
311 		// Convert to B_TRANSLATOR_ANY_TYPE (should be B_TRANSLATOR_BITMAP)
312 		ptest->NextSubTest();
313 		CPPUNIT_ASSERT(tmpfile.Seek(0, SEEK_SET) == 0);
314 		CPPUNIT_ASSERT(tmpfile.SetSize(0) == B_OK);
315 		CPPUNIT_ASSERT(proster->Translate(pinput, NULL, pmsg, &tmpfile,
316 			B_TRANSLATOR_ANY_TYPE) == B_OK);
317 		CPPUNIT_ASSERT(CompareStreams(tmpfile, bitsfile) == true);
318 
319 		// Convert to B_TRANSLATOR_BITMAP
320 		ptest->NextSubTest();
321 		CPPUNIT_ASSERT(tmpfile.Seek(0, SEEK_SET) == 0);
322 		CPPUNIT_ASSERT(tmpfile.SetSize(0) == B_OK);
323 		CPPUNIT_ASSERT(proster->Translate(pinput, NULL, pmsg, &tmpfile,
324 			B_TRANSLATOR_BITMAP) == B_OK);
325 		CPPUNIT_ASSERT(CompareStreams(tmpfile, bitsfile) == true);
326 
327 		// Convert bits tmpfile to B_TRANSLATOR_BITMAP dtmpfile
328 		ptest->NextSubTest();
329 		CPPUNIT_ASSERT(dtmpfile.Seek(0, SEEK_SET) == 0);
330 		CPPUNIT_ASSERT(dtmpfile.SetSize(0) == B_OK);
331 		CPPUNIT_ASSERT(proster->Translate(&tmpfile, NULL, pmsg, &dtmpfile,
332 			B_TRANSLATOR_BITMAP) == B_OK);
333 		CPPUNIT_ASSERT(CompareStreams(dtmpfile, bitsfile) == true);
334 
335 		// Convert to B_TGA_FORMAT
336 		ptest->NextSubTest();
337 		CPPUNIT_ASSERT(tmpfile.Seek(0, SEEK_SET) == 0);
338 		CPPUNIT_ASSERT(tmpfile.SetSize(0) == B_OK);
339 		CPPUNIT_ASSERT(proster->Translate(pinput, NULL, pmsg, &tmpfile,
340 			B_TGA_FORMAT) == B_OK);
341 		CPPUNIT_ASSERT(CompareStreams(tmpfile, tgafile) == true);
342 
343 		if (btgainput || strstr(paths[i].bitsPath, "24")) {
344 			// Convert TGA tmpfile to B_TRANSLATOR_BITMAP dtmpfile
345 			ptest->NextSubTest();
346 			CPPUNIT_ASSERT(dtmpfile.Seek(0, SEEK_SET) == 0);
347 			CPPUNIT_ASSERT(dtmpfile.SetSize(0) == B_OK);
348 			CPPUNIT_ASSERT(proster->Translate(&tmpfile, NULL, pmsg, &dtmpfile,
349 				B_TRANSLATOR_BITMAP) == B_OK);
350 			CPPUNIT_ASSERT(CompareStreams(dtmpfile, bitsfile) == true);
351 
352 			// Convert TGA tmpfile to B_TGA_FORMAT dtmpfile
353 			ptest->NextSubTest();
354 			CPPUNIT_ASSERT(dtmpfile.Seek(0, SEEK_SET) == 0);
355 			CPPUNIT_ASSERT(dtmpfile.SetSize(0) == B_OK);
356 			CPPUNIT_ASSERT(proster->Translate(&tmpfile, NULL, pmsg, &dtmpfile,
357 				B_TGA_FORMAT) == B_OK);
358 			CPPUNIT_ASSERT(CompareStreams(dtmpfile, tgafile) == true);
359 		}
360 	}
361 }
362 
363 void
364 TGATranslatorTest::TranslateTest()
365 {
366 	BApplication
367 		app("application/x-vnd.OpenBeOS-TGATranslatorTest");
368 
369 	// Init
370 	NextSubTest();
371 	status_t result = B_ERROR;
372 	off_t filesize = -1;
373 	BTranslatorRoster *proster = new BTranslatorRoster();
374 	CPPUNIT_ASSERT(proster);
375 	CPPUNIT_ASSERT(proster->AddTranslators(
376 		"/boot/home/config/add-ons/Translators/TGATranslator") == B_OK);
377 	BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
378 		B_READ_ONLY);
379 	CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
380 	BFile output("/tmp/tga_test.out", B_WRITE_ONLY |
381 		B_CREATE_FILE | B_ERASE_FILE);
382 	CPPUNIT_ASSERT(output.InitCheck() == B_OK);
383 
384 	// Translate (bad input, output types)
385 	NextSubTest();
386 	result = proster->Translate(&wronginput, NULL, NULL, &output,
387 		B_TRANSLATOR_TEXT);
388 	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
389 	CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
390 	CPPUNIT_ASSERT(filesize == 0);
391 
392 	// Translate (wrong type of input data)
393 	NextSubTest();
394 	result = proster->Translate(&wronginput, NULL, NULL, &output,
395 		B_TGA_FORMAT);
396 	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
397 	CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
398 	CPPUNIT_ASSERT(filesize == 0);
399 
400 	// Translate (wrong type of input, B_TRANSLATOR_ANY_TYPE output)
401 	NextSubTest();
402 	result = proster->Translate(&wronginput, NULL, NULL, &output,
403 		B_TRANSLATOR_ANY_TYPE);
404 	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
405 	CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
406 	CPPUNIT_ASSERT(filesize == 0);
407 
408 	// Translate TGA images to bits
409 	const TranslatePaths aTgaInputs[] = {
410 		{ "/boot/home/resources/tga/blocks_16_rle_true.tga",
411 			"/boot/home/resources/tga/blocks_color.bits", false },
412 		{ "/boot/home/resources/tga/blocks_24_none_true.tga",
413 			"/boot/home/resources/tga/blocks_color.bits", false },
414 		{ "/boot/home/resources/tga/blocks_24_rle_true.tga",
415 			"/boot/home/resources/tga/blocks_color.bits", false },
416 		{ "/boot/home/resources/tga/blocks_8_none_gray.tga",
417 			"/boot/home/resources/tga/blocks_gray.bits", false },
418 		{ "/boot/home/resources/tga/blocks_8_rle_cmap.tga",
419 			"/boot/home/resources/tga/blocks_color.bits", false },
420 		{ "/boot/home/resources/tga/cloudcg_16_none_true.tga",
421 			"/boot/home/resources/tga/cloudcg_16.bits", false },
422 		{ "/boot/home/resources/tga/cloudcg_16_rle_true.tga",
423 			"/boot/home/resources/tga/cloudcg_16.bits", false },
424 		{ "/boot/home/resources/tga/cloudcg_24_none_true.tga",
425 			"/boot/home/resources/tga/cloudcg_24.bits", false },
426 		{ "/boot/home/resources/tga/cloudcg_24_rle_true.tga",
427 			"/boot/home/resources/tga/cloudcg_24.bits", false },
428 		{ "/boot/home/resources/tga/cloudcg_8_none_cmap.tga",
429 			"/boot/home/resources/tga/cloudcg_8_cmap.bits", false },
430 		{ "/boot/home/resources/tga/cloudcg_8_none_gray.tga",
431 			"/boot/home/resources/tga/cloudcg_8_gray.bits", false },
432 		{ "/boot/home/resources/tga/cloudcg_8_rle_cmap.tga",
433 			"/boot/home/resources/tga/cloudcg_8_cmap.bits", false },
434 		{ "/boot/home/resources/tga/graycloudcg_8_rle_cmap.tga",
435 			"/boot/home/resources/tga/cloudcg_8_gray.bits", false },
436 		{ "/boot/home/resources/tga/grayblocks_8_rle_cmap.tga",
437 			"/boot/home/resources/tga/blocks_gray.bits", false },
438 		{ "/boot/home/resources/tga/screen1_16_none_true.tga",
439 			"/boot/home/resources/tga/screen1_16.bits", false },
440 		{ "/boot/home/resources/tga/screen1_16_rle_true.tga",
441 			"/boot/home/resources/tga/screen1_16.bits", false },
442 		{ "/boot/home/resources/tga/screen1_24_none_true.tga",
443 			"/boot/home/resources/tga/screen1_24.bits", false },
444 		{ "/boot/home/resources/tga/screen1_24_rle_true.tga",
445 			"/boot/home/resources/tga/screen1_24.bits", false },
446 		{ "/boot/home/resources/tga/screen1_8_none_cmap.tga",
447 			"/boot/home/resources/tga/screen1_8_cmap.bits", false },
448 		{ "/boot/home/resources/tga/screen1_8_none_gray.tga",
449 			"/boot/home/resources/tga/screen1_8_gray.bits", false },
450 		{ "/boot/home/resources/tga/screen1_8_rle_cmap.tga",
451 			"/boot/home/resources/tga/screen1_8_cmap.bits", false },
452 		{ "/boot/home/resources/tga/grayscreen1_8_rle_cmap.tga",
453 			"/boot/home/resources/tga/screen1_8_gray.bits", false },
454 		{ "/boot/home/resources/tga/ugly_16_none_true.tga",
455 			"/boot/home/resources/tga/ugly_16_none_true.bits", false },
456 		{ "/boot/home/resources/tga/ugly_24_none_true.tga",
457 			"/boot/home/resources/tga/ugly_24_none_true.bits", false },
458 		{ "/boot/home/resources/tga/ugly_32_none_true.tga",
459 			"/boot/home/resources/tga/ugly_32_none_true.bits", false },
460 		{ "/boot/home/resources/tga/ugly_8_none_cmap.tga",
461 			"/boot/home/resources/tga/ugly_8_none_cmap.bits", false }
462 	};
463 	const TranslatePaths aBitsInputs[] = {
464 		{ "/boot/home/resources/tga/cloudcg_24.tga",
465 			"/boot/home/resources/tga/cloudcg_24.bits", false },
466 		{ "/boot/home/resources/tga/cloudcg_24_rle.tga",
467 			"/boot/home/resources/tga/cloudcg_24.bits", true },
468 		{ "/boot/home/resources/tga/ugly_32.tga",
469 			"/boot/home/resources/tga/ugly_32_none_true.bits", false },
470 		{ "/boot/home/resources/tga/ugly_32_rle.tga",
471 			"/boot/home/resources/tga/ugly_32_none_true.bits", true },
472 		{ "/boot/home/resources/tga/screen1_24_rle.tga",
473 			"/boot/home/resources/tga/screen1_24.bits", true },
474 		{ "/boot/home/resources/tga/ugly_24_rle_true.tga",
475 			"/boot/home/resources/tga/ugly_24_none_true.bits", true },
476 		{ "/boot/home/resources/tga/b_gray1-2.tga",
477 			"/boot/home/resources/tga/b_gray1-2.bits", false },
478 		{ "/boot/home/resources/tga/b_gray1-2_rle.tga",
479 			"/boot/home/resources/tga/b_gray1-2.bits", true },
480 		{ "/boot/home/resources/tga/b_gray1.tga",
481 			"/boot/home/resources/tga/b_gray1.bits", false },
482 		{ "/boot/home/resources/tga/b_gray1_rle.tga",
483 			"/boot/home/resources/tga/b_gray1.bits", true },
484 		{ "/boot/home/resources/tga/b_rgb15.tga",
485 			"/boot/home/resources/tga/b_rgb15.bits", false },
486 		{ "/boot/home/resources/tga/b_rgb15_rle.tga",
487 			"/boot/home/resources/tga/b_rgb15.bits", true },
488 		{ "/boot/home/resources/tga/b_rgb16.tga",
489 			"/boot/home/resources/tga/b_rgb16.bits", false },
490 		{ "/boot/home/resources/tga/b_rgb16_rle.tga",
491 			"/boot/home/resources/tga/b_rgb16.bits", true },
492 		{ "/boot/home/resources/tga/b_rgb32.tga",
493 			"/boot/home/resources/tga/b_rgb32.bits", false },
494 		{ "/boot/home/resources/tga/b_rgb32_rle.tga",
495 			"/boot/home/resources/tga/b_rgb32.bits", true },
496 		{ "/boot/home/resources/tga/b_cmap8.tga",
497 			"/boot/home/resources/tga/b_cmap8.bits", false },
498 		{ "/boot/home/resources/tga/b_cmap8_rle.tga",
499 			"/boot/home/resources/tga/b_cmap8.bits", true },
500 	};
501 
502 	TranslateTests(this, proster, aTgaInputs,
503 		sizeof(aTgaInputs) / sizeof(TranslatePaths), true);
504 	TranslateTests(this, proster, aBitsInputs,
505 		sizeof(aBitsInputs) / sizeof(TranslatePaths), false);
506 
507 	delete proster;
508 	proster = NULL;
509 }
510 
511 // Make certain the TGATranslator
512 // provides a valid configuration message
513 void
514 TGATranslatorTest::ConfigMessageTest()
515 {
516 	// Init
517 	NextSubTest();
518 	status_t result = B_ERROR;
519 	BTranslatorRoster *proster = new BTranslatorRoster();
520 	CPPUNIT_ASSERT(proster);
521 	CPPUNIT_ASSERT(proster->AddTranslators(
522 		"/boot/home/config/add-ons/Translators/TGATranslator") == B_OK);
523 
524 	// GetAllTranslators
525 	NextSubTest();
526 	translator_id tid, *pids = NULL;
527 	int32 count = 0;
528 	CPPUNIT_ASSERT(proster->GetAllTranslators(&pids, &count) == B_OK);
529 	CPPUNIT_ASSERT(pids);
530 	CPPUNIT_ASSERT(count == 1);
531 	tid = pids[0];
532 	delete[] pids;
533 	pids = NULL;
534 
535 	// GetConfigurationMessage
536 	NextSubTest();
537 	BMessage msg;
538 	CPPUNIT_ASSERT(proster->GetConfigurationMessage(tid, &msg) == B_OK);
539 	CPPUNIT_ASSERT(!msg.IsEmpty());
540 
541 	// B_TRANSLATOR_EXT_HEADER_ONLY
542 	NextSubTest();
543 	bool bheaderonly = true;
544 	CPPUNIT_ASSERT(
545 		msg.FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bheaderonly) == B_OK);
546 	CPPUNIT_ASSERT(bheaderonly == false);
547 
548 	// B_TRANSLATOR_EXT_DATA_ONLY
549 	NextSubTest();
550 	bool bdataonly = true;
551 	CPPUNIT_ASSERT(
552 		msg.FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bdataonly) == B_OK);
553 	CPPUNIT_ASSERT(bdataonly == false);
554 
555 	// "tga /rle"
556 	NextSubTest();
557 	bool brle;
558 	CPPUNIT_ASSERT(msg.FindBool("tga /rle", &brle) == B_OK);
559 	CPPUNIT_ASSERT(brle == true || brle == false);
560 }
561 
562 #if !TEST_R5
563 
564 // The input formats that this translator is supposed to support
565 translation_format gTGAInputFormats[] = {
566 	{
567 		B_TRANSLATOR_BITMAP,
568 		B_TRANSLATOR_BITMAP,
569 		0.6f, // quality
570 		0.8f, // capability
571 		"image/x-be-bitmap",
572 		"Be Bitmap Format (TGATranslator)"
573 	},
574 	{
575 		B_TGA_FORMAT,
576 		B_TRANSLATOR_BITMAP,
577 		1.0f,
578 		0.6f,
579 		"image/x-targa",
580 		"Targa image"
581 	}
582 };
583 
584 // The output formats that this translator is supposed to support
585 translation_format gTGAOutputFormats[] = {
586 	{
587 		B_TRANSLATOR_BITMAP,
588 		B_TRANSLATOR_BITMAP,
589 		0.6f, // quality
590 		0.8f, // capability
591 		"image/x-be-bitmap",
592 		"Be Bitmap Format (TGATranslator)"
593 	},
594 	{
595 		B_TGA_FORMAT,
596 		B_TRANSLATOR_BITMAP,
597 		1.0f,
598 		0.7f,
599 		"image/x-targa",
600 		"Targa image"
601 	}
602 };
603 
604 void
605 TGATranslatorTest::LoadAddOnTest()
606 {
607 	TranslatorLoadAddOnTest("/boot/home/config/add-ons/Translators/TGATranslator",
608 		this,
609 		gTGAInputFormats, sizeof(gTGAInputFormats) / sizeof(translation_format),
610 		gTGAOutputFormats, sizeof(gTGAOutputFormats) / sizeof(translation_format));
611 }
612 
613 #endif // #if !TEST_R5
614