1/*****************************************************************************/
2// TGATranslatorTest
3// Written by Michael Wilber, Haiku Translation Kit Team
4//
5// TGATranslatorTest.cpp
6//
7// Unit testing code to test the Haiku TGATranslator
8//
9//
10// Copyright (c) 2003 Haiku 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
52CppUnit::Test *
53TGATranslatorTest::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
80void
81TGATranslatorTest::setUp()
82{
83	BTestCase::setUp();
84}
85
86// tearDown
87void
88TGATranslatorTest::tearDown()
89{
90	BTestCase::tearDown();
91}
92
93void
94CheckBits_Tga(translator_info *pti)
95{
96	CheckTranslatorInfo(pti, B_TRANSLATOR_BITMAP, B_TRANSLATOR_BITMAP,
97		0.7f, 0.6f, "Be Bitmap Format (TGATranslator)",
98		"image/x-be-bitmap");
99}
100
101void
102CheckTga(translator_info *pti, const char *imageType)
103{
104	CheckTranslatorInfo(pti, B_TGA_FORMAT, B_TRANSLATOR_BITMAP,
105		0.7f, 0.8f, imageType, "image/x-targa");
106}
107
108// coveniently group path of image with
109// the expected Identify() string for that image
110struct IdentifyInfo {
111	const char *imagePath;
112	const char *identifyString;
113};
114
115void
116IdentifyTests(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
159void
160TGATranslatorTest::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
265struct TranslatePaths {
266	const char *tgaPath;
267	const char *bitsPath;
268	bool bcompress;
269};
270
271void
272TranslateTests(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		// Convert to B_TRANSLATOR_ANY_TYPE (should be B_TRANSLATOR_BITMAP)
311		ptest->NextSubTest();
312		CPPUNIT_ASSERT(tmpfile.Seek(0, SEEK_SET) == 0);
313		CPPUNIT_ASSERT(tmpfile.SetSize(0) == B_OK);
314		CPPUNIT_ASSERT(proster->Translate(pinput, NULL, pmsg, &tmpfile,
315			B_TRANSLATOR_ANY_TYPE) == B_OK);
316		CPPUNIT_ASSERT(CompareStreams(tmpfile, bitsfile) == true);
317
318		// Convert to B_TRANSLATOR_BITMAP
319		ptest->NextSubTest();
320		CPPUNIT_ASSERT(tmpfile.Seek(0, SEEK_SET) == 0);
321		CPPUNIT_ASSERT(tmpfile.SetSize(0) == B_OK);
322		CPPUNIT_ASSERT(proster->Translate(pinput, NULL, pmsg, &tmpfile,
323			B_TRANSLATOR_BITMAP) == B_OK);
324		CPPUNIT_ASSERT(CompareStreams(tmpfile, bitsfile) == true);
325
326		// Convert bits tmpfile to B_TRANSLATOR_BITMAP dtmpfile
327		ptest->NextSubTest();
328		CPPUNIT_ASSERT(dtmpfile.Seek(0, SEEK_SET) == 0);
329		CPPUNIT_ASSERT(dtmpfile.SetSize(0) == B_OK);
330		CPPUNIT_ASSERT(proster->Translate(&tmpfile, NULL, pmsg, &dtmpfile,
331			B_TRANSLATOR_BITMAP) == B_OK);
332		CPPUNIT_ASSERT(CompareStreams(dtmpfile, bitsfile) == true);
333
334		// Convert to B_TGA_FORMAT
335		ptest->NextSubTest();
336		CPPUNIT_ASSERT(tmpfile.Seek(0, SEEK_SET) == 0);
337		CPPUNIT_ASSERT(tmpfile.SetSize(0) == B_OK);
338		CPPUNIT_ASSERT(proster->Translate(pinput, NULL, pmsg, &tmpfile,
339			B_TGA_FORMAT) == B_OK);
340		CPPUNIT_ASSERT(CompareStreams(tmpfile, tgafile) == true);
341
342		if (btgainput || strstr(paths[i].bitsPath, "24")) {
343			// Convert TGA tmpfile to B_TRANSLATOR_BITMAP dtmpfile
344			ptest->NextSubTest();
345			CPPUNIT_ASSERT(dtmpfile.Seek(0, SEEK_SET) == 0);
346			CPPUNIT_ASSERT(dtmpfile.SetSize(0) == B_OK);
347			CPPUNIT_ASSERT(proster->Translate(&tmpfile, NULL, pmsg, &dtmpfile,
348				B_TRANSLATOR_BITMAP) == B_OK);
349			CPPUNIT_ASSERT(CompareStreams(dtmpfile, bitsfile) == true);
350
351			// Convert TGA tmpfile to B_TGA_FORMAT dtmpfile
352			ptest->NextSubTest();
353			CPPUNIT_ASSERT(dtmpfile.Seek(0, SEEK_SET) == 0);
354			CPPUNIT_ASSERT(dtmpfile.SetSize(0) == B_OK);
355			CPPUNIT_ASSERT(proster->Translate(&tmpfile, NULL, pmsg, &dtmpfile,
356				B_TGA_FORMAT) == B_OK);
357			CPPUNIT_ASSERT(CompareStreams(dtmpfile, tgafile) == true);
358		}
359	}
360}
361
362void
363TGATranslatorTest::TranslateTest()
364{
365	BApplication
366		app("application/x-vnd.OpenBeOS-TGATranslatorTest");
367
368	// Init
369	NextSubTest();
370	status_t result = B_ERROR;
371	off_t filesize = -1;
372	BTranslatorRoster *proster = new BTranslatorRoster();
373	CPPUNIT_ASSERT(proster);
374	CPPUNIT_ASSERT(proster->AddTranslators(
375		"/boot/home/config/add-ons/Translators/TGATranslator") == B_OK);
376	BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
377		B_READ_ONLY);
378	CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
379	BFile output("/tmp/tga_test.out", B_WRITE_ONLY |
380		B_CREATE_FILE | B_ERASE_FILE);
381	CPPUNIT_ASSERT(output.InitCheck() == B_OK);
382
383	// Translate (bad input, output types)
384	NextSubTest();
385	result = proster->Translate(&wronginput, NULL, NULL, &output,
386		B_TRANSLATOR_TEXT);
387	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
388	CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
389	CPPUNIT_ASSERT(filesize == 0);
390
391	// Translate (wrong type of input data)
392	NextSubTest();
393	result = proster->Translate(&wronginput, NULL, NULL, &output,
394		B_TGA_FORMAT);
395	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
396	CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
397	CPPUNIT_ASSERT(filesize == 0);
398
399	// Translate (wrong type of input, B_TRANSLATOR_ANY_TYPE output)
400	NextSubTest();
401	result = proster->Translate(&wronginput, NULL, NULL, &output,
402		B_TRANSLATOR_ANY_TYPE);
403	CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
404	CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
405	CPPUNIT_ASSERT(filesize == 0);
406
407	// Translate TGA images to bits
408	const TranslatePaths aTgaInputs[] = {
409		{ "/boot/home/resources/tga/blocks_16_rle_true.tga",
410			"/boot/home/resources/tga/blocks_color.bits", false },
411		{ "/boot/home/resources/tga/blocks_24_none_true.tga",
412			"/boot/home/resources/tga/blocks_color.bits", false },
413		{ "/boot/home/resources/tga/blocks_24_rle_true.tga",
414			"/boot/home/resources/tga/blocks_color.bits", false },
415		{ "/boot/home/resources/tga/blocks_8_none_gray.tga",
416			"/boot/home/resources/tga/blocks_gray.bits", false },
417		{ "/boot/home/resources/tga/blocks_8_rle_cmap.tga",
418			"/boot/home/resources/tga/blocks_color.bits", false },
419		{ "/boot/home/resources/tga/cloudcg_16_none_true.tga",
420			"/boot/home/resources/tga/cloudcg_16.bits", false },
421		{ "/boot/home/resources/tga/cloudcg_16_rle_true.tga",
422			"/boot/home/resources/tga/cloudcg_16.bits", false },
423		{ "/boot/home/resources/tga/cloudcg_24_none_true.tga",
424			"/boot/home/resources/tga/cloudcg_24.bits", false },
425		{ "/boot/home/resources/tga/cloudcg_24_rle_true.tga",
426			"/boot/home/resources/tga/cloudcg_24.bits", false },
427		{ "/boot/home/resources/tga/cloudcg_8_none_cmap.tga",
428			"/boot/home/resources/tga/cloudcg_8_cmap.bits", false },
429		{ "/boot/home/resources/tga/cloudcg_8_none_gray.tga",
430			"/boot/home/resources/tga/cloudcg_8_gray.bits", false },
431		{ "/boot/home/resources/tga/cloudcg_8_rle_cmap.tga",
432			"/boot/home/resources/tga/cloudcg_8_cmap.bits", false },
433		{ "/boot/home/resources/tga/graycloudcg_8_rle_cmap.tga",
434			"/boot/home/resources/tga/cloudcg_8_gray.bits", false },
435		{ "/boot/home/resources/tga/grayblocks_8_rle_cmap.tga",
436			"/boot/home/resources/tga/blocks_gray.bits", false },
437		{ "/boot/home/resources/tga/screen1_16_none_true.tga",
438			"/boot/home/resources/tga/screen1_16.bits", false },
439		{ "/boot/home/resources/tga/screen1_16_rle_true.tga",
440			"/boot/home/resources/tga/screen1_16.bits", false },
441		{ "/boot/home/resources/tga/screen1_24_none_true.tga",
442			"/boot/home/resources/tga/screen1_24.bits", false },
443		{ "/boot/home/resources/tga/screen1_24_rle_true.tga",
444			"/boot/home/resources/tga/screen1_24.bits", false },
445		{ "/boot/home/resources/tga/screen1_8_none_cmap.tga",
446			"/boot/home/resources/tga/screen1_8_cmap.bits", false },
447		{ "/boot/home/resources/tga/screen1_8_none_gray.tga",
448			"/boot/home/resources/tga/screen1_8_gray.bits", false },
449		{ "/boot/home/resources/tga/screen1_8_rle_cmap.tga",
450			"/boot/home/resources/tga/screen1_8_cmap.bits", false },
451		{ "/boot/home/resources/tga/grayscreen1_8_rle_cmap.tga",
452			"/boot/home/resources/tga/screen1_8_gray.bits", false },
453		{ "/boot/home/resources/tga/ugly_16_none_true.tga",
454			"/boot/home/resources/tga/ugly_16_none_true.bits", false },
455		{ "/boot/home/resources/tga/ugly_24_none_true.tga",
456			"/boot/home/resources/tga/ugly_24_none_true.bits", false },
457		{ "/boot/home/resources/tga/ugly_32_none_true.tga",
458			"/boot/home/resources/tga/ugly_32_none_true.bits", false },
459		{ "/boot/home/resources/tga/ugly_8_none_cmap.tga",
460			"/boot/home/resources/tga/ugly_8_none_cmap.bits", false }
461	};
462	const TranslatePaths aBitsInputs[] = {
463		{ "/boot/home/resources/tga/cloudcg_24.tga",
464			"/boot/home/resources/tga/cloudcg_24.bits", false },
465		{ "/boot/home/resources/tga/cloudcg_24_rle.tga",
466			"/boot/home/resources/tga/cloudcg_24.bits", true },
467		{ "/boot/home/resources/tga/ugly_32.tga",
468			"/boot/home/resources/tga/ugly_32_none_true.bits", false },
469		{ "/boot/home/resources/tga/ugly_32_rle.tga",
470			"/boot/home/resources/tga/ugly_32_none_true.bits", true },
471		{ "/boot/home/resources/tga/screen1_24_rle.tga",
472			"/boot/home/resources/tga/screen1_24.bits", true },
473		{ "/boot/home/resources/tga/ugly_24_rle_true.tga",
474			"/boot/home/resources/tga/ugly_24_none_true.bits", true },
475		{ "/boot/home/resources/tga/b_gray1-2.tga",
476			"/boot/home/resources/tga/b_gray1-2.bits", false },
477		{ "/boot/home/resources/tga/b_gray1-2_rle.tga",
478			"/boot/home/resources/tga/b_gray1-2.bits", true },
479		{ "/boot/home/resources/tga/b_gray1.tga",
480			"/boot/home/resources/tga/b_gray1.bits", false },
481		{ "/boot/home/resources/tga/b_gray1_rle.tga",
482			"/boot/home/resources/tga/b_gray1.bits", true },
483		{ "/boot/home/resources/tga/b_rgb15.tga",
484			"/boot/home/resources/tga/b_rgb15.bits", false },
485		{ "/boot/home/resources/tga/b_rgb15_rle.tga",
486			"/boot/home/resources/tga/b_rgb15.bits", true },
487		{ "/boot/home/resources/tga/b_rgb16.tga",
488			"/boot/home/resources/tga/b_rgb16.bits", false },
489		{ "/boot/home/resources/tga/b_rgb16_rle.tga",
490			"/boot/home/resources/tga/b_rgb16.bits", true },
491		{ "/boot/home/resources/tga/b_rgb32.tga",
492			"/boot/home/resources/tga/b_rgb32.bits", false },
493		{ "/boot/home/resources/tga/b_rgb32_rle.tga",
494			"/boot/home/resources/tga/b_rgb32.bits", true },
495		{ "/boot/home/resources/tga/b_cmap8.tga",
496			"/boot/home/resources/tga/b_cmap8.bits", false },
497		{ "/boot/home/resources/tga/b_cmap8_rle.tga",
498			"/boot/home/resources/tga/b_cmap8.bits", true },
499	};
500
501	TranslateTests(this, proster, aTgaInputs,
502		sizeof(aTgaInputs) / sizeof(TranslatePaths), true);
503	TranslateTests(this, proster, aBitsInputs,
504		sizeof(aBitsInputs) / sizeof(TranslatePaths), false);
505
506	delete proster;
507	proster = NULL;
508}
509
510// Make certain the TGATranslator
511// provides a valid configuration message
512void
513TGATranslatorTest::ConfigMessageTest()
514{
515	// Init
516	NextSubTest();
517	BTranslatorRoster *proster = new BTranslatorRoster();
518	CPPUNIT_ASSERT(proster);
519	CPPUNIT_ASSERT(proster->AddTranslators(
520		"/boot/home/config/add-ons/Translators/TGATranslator") == B_OK);
521
522	// GetAllTranslators
523	NextSubTest();
524	translator_id tid, *pids = NULL;
525	int32 count = 0;
526	CPPUNIT_ASSERT(proster->GetAllTranslators(&pids, &count) == B_OK);
527	CPPUNIT_ASSERT(pids);
528	CPPUNIT_ASSERT(count == 1);
529	tid = pids[0];
530	delete[] pids;
531	pids = NULL;
532
533	// GetConfigurationMessage
534	NextSubTest();
535	BMessage msg;
536	CPPUNIT_ASSERT(proster->GetConfigurationMessage(tid, &msg) == B_OK);
537	CPPUNIT_ASSERT(!msg.IsEmpty());
538
539	// B_TRANSLATOR_EXT_HEADER_ONLY
540	NextSubTest();
541	bool bheaderonly = true;
542	CPPUNIT_ASSERT(
543		msg.FindBool(B_TRANSLATOR_EXT_HEADER_ONLY, &bheaderonly) == B_OK);
544	CPPUNIT_ASSERT(bheaderonly == false);
545
546	// B_TRANSLATOR_EXT_DATA_ONLY
547	NextSubTest();
548	bool bdataonly = true;
549	CPPUNIT_ASSERT(
550		msg.FindBool(B_TRANSLATOR_EXT_DATA_ONLY, &bdataonly) == B_OK);
551	CPPUNIT_ASSERT(bdataonly == false);
552
553	// "tga /rle"
554	NextSubTest();
555	bool brle;
556	CPPUNIT_ASSERT(msg.FindBool("tga /rle", &brle) == B_OK);
557	CPPUNIT_ASSERT(brle == true || brle == false);
558
559	// "tga /ignore_alpha"
560	NextSubTest();
561	bool balpha;
562	CPPUNIT_ASSERT(msg.FindBool("tga /ignore_alpha", &balpha) == B_OK);
563	CPPUNIT_ASSERT(balpha == true || balpha == false);
564}
565
566#if !TEST_R5
567
568// The input formats that this translator is supposed to support
569translation_format gTGAInputFormats[] = {
570	{
571		B_TRANSLATOR_BITMAP,
572		B_TRANSLATOR_BITMAP,
573		0.7f, // quality
574		0.6f, // capability
575		"image/x-be-bitmap",
576		"Be Bitmap Format (TGATranslator)"
577	},
578	{
579		B_TGA_FORMAT,
580		B_TRANSLATOR_BITMAP,
581		0.7f,
582		0.8f,
583		"image/x-targa",
584		"Targa image"
585	}
586};
587
588// The output formats that this translator is supposed to support
589translation_format gTGAOutputFormats[] = {
590	{
591		B_TRANSLATOR_BITMAP,
592		B_TRANSLATOR_BITMAP,
593		0.6f, // quality
594		0.8f, // capability
595		"image/x-be-bitmap",
596		"Be Bitmap Format (TGATranslator)"
597	},
598	{
599		B_TGA_FORMAT,
600		B_TRANSLATOR_BITMAP,
601		0.7f,
602		0.6f,
603		"image/x-targa",
604		"Targa image"
605	}
606};
607
608void
609TGATranslatorTest::LoadAddOnTest()
610{
611	TranslatorLoadAddOnTest("/boot/home/config/add-ons/Translators/TGATranslator",
612		this,
613		gTGAInputFormats, sizeof(gTGAInputFormats) / sizeof(translation_format),
614		gTGAOutputFormats, sizeof(gTGAOutputFormats) / sizeof(translation_format),
615		B_TRANSLATION_MAKE_VERSION(1,0,0));
616}
617
618#endif // #if !TEST_R5
619