added basic testing

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2907 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber 2003-03-13 03:13:02 +00:00
parent f098890e88
commit 2dc6f398bd
2 changed files with 221 additions and 0 deletions

View File

@ -62,6 +62,33 @@ TIFFTranslatorTest::IdentifyTest()
{
// Init
NextSubTest();
status_t result = B_ERROR;
BTranslatorRoster *proster = new BTranslatorRoster();
CPPUNIT_ASSERT(proster);
CPPUNIT_ASSERT(proster->AddTranslators(
"/boot/home/config/add-ons/Translators/TIFFTranslator") == B_OK);
BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
B_READ_ONLY);
CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
// Identify (bad input, output types)
NextSubTest();
translator_info ti;
memset(&ti, 0, sizeof(translator_info));
result = proster->Identify(&wronginput, NULL, &ti, 0,
NULL, B_TRANSLATOR_TEXT);
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
// Identify (wrong type of input data)
NextSubTest();
memset(&ti, 0, sizeof(translator_info));
result = proster->Identify(&wronginput, NULL, &ti);
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
delete proster;
proster = NULL;
}
void
@ -69,6 +96,165 @@ TIFFTranslatorTest::TranslateTest()
{
// Init
NextSubTest();
status_t result = B_ERROR;
off_t filesize = -1;
BTranslatorRoster *proster = new BTranslatorRoster();
CPPUNIT_ASSERT(proster);
CPPUNIT_ASSERT(proster->AddTranslators(
"/boot/home/config/add-ons/Translators/TIFFTranslator") == B_OK);
BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
B_READ_ONLY);
CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
BFile output("/tmp/tiff_test.out", B_WRITE_ONLY |
B_CREATE_FILE | B_ERASE_FILE);
CPPUNIT_ASSERT(output.InitCheck() == B_OK);
// Translate (bad input, output types)
NextSubTest();
result = proster->Translate(&wronginput, NULL, NULL, &output,
B_TRANSLATOR_TEXT);
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
CPPUNIT_ASSERT(filesize == 0);
// Translate (wrong type of input data)
NextSubTest();
result = proster->Translate(&wronginput, NULL, NULL, &output,
B_TIFF_FORMAT);
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
CPPUNIT_ASSERT(filesize == 0);
// Translate (wrong type of input, B_TRANSLATOR_ANY_TYPE output)
NextSubTest();
result = proster->Translate(&wronginput, NULL, NULL, &output,
B_TRANSLATOR_ANY_TYPE);
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(output.GetSize(&filesize) == B_OK);
CPPUNIT_ASSERT(filesize == 0);
delete proster;
proster = NULL;
}
// Apply a number of tests to a BTranslator * to a TIFFTranslator object
void
TestBTranslator(TIFFTranslatorTest *ptest, BTranslator *ptran)
{
// The translator should only have one reference
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
// Make sure Acquire returns a BTranslator even though its
// already been Acquired once
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->Acquire() == ptran);
// Acquired twice, refcount should be 2
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->ReferenceCount() == 2);
// Release should return ptran because it is still acquired
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->Release() == ptran);
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->Acquire() == ptran);
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->ReferenceCount() == 2);
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->Release() == ptran);
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
// A name would be nice
ptest->NextSubTest();
const char *tranname = ptran->TranslatorName();
CPPUNIT_ASSERT(tranname);
printf(" {%s} ", tranname);
// More info would be nice
ptest->NextSubTest();
const char *traninfo = ptran->TranslatorInfo();
CPPUNIT_ASSERT(traninfo);
printf(" {%s} ", traninfo);
// What version are you?
// (when ver == 100, that means that version is 1.00)
ptest->NextSubTest();
int32 ver = ptran->TranslatorVersion();
CPPUNIT_ASSERT((ver / 100) > 0);
printf(" {%d} ", (int) ver);
// Input formats?
ptest->NextSubTest();
{
int32 incount = 0;
const translation_format *pins = ptran->InputFormats(&incount);
CPPUNIT_ASSERT(incount == 2);
CPPUNIT_ASSERT(pins);
// must support B_TIFF_FORMAT and B_TRANSLATOR_BITMAP formats
for (int32 i = 0; i < incount; i++) {
CPPUNIT_ASSERT(pins[i].group == B_TRANSLATOR_BITMAP);
CPPUNIT_ASSERT(pins[i].MIME);
CPPUNIT_ASSERT(pins[i].name);
if (pins[i].type == B_TRANSLATOR_BITMAP) {
CPPUNIT_ASSERT(pins[i].quality > 0 && pins[i].quality <= 1);
CPPUNIT_ASSERT(pins[i].capability > 0 && pins[i].capability <= 1);
CPPUNIT_ASSERT(strcmp(pins[i].MIME, BBT_MIME_STRING) == 0);
CPPUNIT_ASSERT(strcmp(pins[i].name,
"Be Bitmap Format (TIFFTranslator)") == 0);
} else if (pins[i].type == B_TIFF_FORMAT) {
CPPUNIT_ASSERT(pins[i].quality > 0 && pins[i].quality <= 0.11);
CPPUNIT_ASSERT(pins[i].capability > 0 && pins[i].capability <= 0.11);
CPPUNIT_ASSERT(strcmp(pins[i].MIME, TIFF_MIME_STRING) == 0);
CPPUNIT_ASSERT(strcmp(pins[i].name, "TIFF Image") == 0);
} else
CPPUNIT_ASSERT(false);
}
}
// Output formats?
ptest->NextSubTest();
{
int32 outcount = 0;
const translation_format *pouts = ptran->OutputFormats(&outcount);
CPPUNIT_ASSERT(outcount == 2);
CPPUNIT_ASSERT(pouts);
// must support B_TIFF_FORMAT and B_TRANSLATOR_BITMAP formats
for (int32 i = 0; i < outcount; i++) {
CPPUNIT_ASSERT(pouts[i].group == B_TRANSLATOR_BITMAP);
CPPUNIT_ASSERT(pouts[i].MIME);
CPPUNIT_ASSERT(pouts[i].name);
if (pouts[i].type == B_TRANSLATOR_BITMAP) {
CPPUNIT_ASSERT(pouts[i].quality > 0 && pouts[i].quality <= 1);
CPPUNIT_ASSERT(pouts[i].capability > 0 && pouts[i].capability <= 1);
CPPUNIT_ASSERT(strcmp(pouts[i].MIME, BBT_MIME_STRING) == 0);
CPPUNIT_ASSERT(strcmp(pouts[i].name,
"Be Bitmap Format (TIFFTranslator)") == 0);
} else if (pouts[i].type == B_TIFF_FORMAT) {
CPPUNIT_ASSERT(pouts[i].quality < 0.1);
CPPUNIT_ASSERT(pouts[i].capability < 0.1);
CPPUNIT_ASSERT(strcmp(pouts[i].MIME, TIFF_MIME_STRING) == 0);
CPPUNIT_ASSERT(strcmp(pouts[i].name, "TIFF Image") == 0);
} else
CPPUNIT_ASSERT(false);
}
}
// Release should return NULL because Release has been called
// as many times as it has been acquired
ptest->NextSubTest();
CPPUNIT_ASSERT(ptran->Release() == NULL);
ptran = NULL;
}
#if !TEST_R5
@ -78,6 +264,38 @@ TIFFTranslatorTest::LoadAddOnTest()
{
// Make sure the add_on loads
NextSubTest();
const char *path = "/boot/home/config/add-ons/Translators/TIFFTranslator";
image_id image = load_add_on(path);
CPPUNIT_ASSERT(image >= 0);
// Load in function to make the object
NextSubTest();
BTranslator *(*pMakeNthTranslator)(int32 n,image_id you,uint32 flags,...);
status_t err = get_image_symbol(image, "make_nth_translator",
B_SYMBOL_TYPE_TEXT, (void **)&pMakeNthTranslator);
CPPUNIT_ASSERT(!err);
// Make sure the function returns a pointer to a BTranslator
NextSubTest();
BTranslator *ptran = pMakeNthTranslator(0, image, 0);
CPPUNIT_ASSERT(ptran);
// Make sure the function only returns one BTranslator
NextSubTest();
CPPUNIT_ASSERT(!pMakeNthTranslator(1, image, 0));
CPPUNIT_ASSERT(!pMakeNthTranslator(2, image, 0));
CPPUNIT_ASSERT(!pMakeNthTranslator(3, image, 0));
CPPUNIT_ASSERT(!pMakeNthTranslator(16, image, 0));
CPPUNIT_ASSERT(!pMakeNthTranslator(1023, image, 0));
// Run a number of tests on the BTranslator object
TestBTranslator(this, ptran);
// NOTE: this function Release()s ptran
ptran = NULL;
// Unload Add-on
NextSubTest();
CPPUNIT_ASSERT(unload_add_on(image) == B_OK);
}
#endif // #if !TEST_R5

View File

@ -6,6 +6,9 @@
#include <TestCase.h>
#include <TestShell.h>
#define BBT_MIME_STRING "image/x-be-bitmap"
#define TIFF_MIME_STRING "image/tiff"
class CppUnit::Test;
class TIFFTranslatorTest : public BTestCase {