* fix gcc4 build of translator add-on tests

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30583 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe 2009-05-02 19:01:32 +00:00
parent bd3cb5f1b0
commit 5b3152c4fb
6 changed files with 63 additions and 52 deletions

View File

@ -1,6 +1,7 @@
// TranslatorTestAddOn.cpp
#include <stdio.h>
#include <string.h>
#include <Translator.h>
#include <OS.h>
#include "TranslatorTestAddOn.h"
@ -36,14 +37,14 @@ CompareStreams(BPositionIO &a, BPositionIO &b)
off_t alen = 0, blen = 0;
const uint32 kbuflen = 2048;
uint8 abuf[kbuflen], bbuf[kbuflen];
a.Seek(0, SEEK_END);
alen = a.Position();
b.Seek(0, SEEK_END);
blen = b.Position();
blen = b.Position();
if (alen != blen)
return false;
if (a.Seek(0, SEEK_SET) != 0)
return false;
if (b.Seek(0, SEEK_SET) != 0)
@ -56,13 +57,13 @@ CompareStreams(BPositionIO &a, BPositionIO &b)
return false;
if (b.Read(bbuf, read) != read)
return false;
if (memcmp(abuf, bbuf, read) != 0)
return false;
alen -= read;
}
return true;
}
@ -94,7 +95,7 @@ CompareTranslationFormat(const translation_format *pleft,
CPPUNIT_ASSERT(pright->MIME);
CPPUNIT_ASSERT(pleft->name);
CPPUNIT_ASSERT(pright->name);
if (pleft->group != pright->group)
return false;
if (pleft->type != pright->type)
@ -109,13 +110,13 @@ CompareTranslationFormat(const translation_format *pleft,
return false;
if (strcmp(pleft->name, pright->name) != 0)
return false;
return true;
}
// Apply a number of tests to a BTranslator * to a TGATranslator object
void
TestBTranslator(BTestCase *ptest, BTranslator *ptran,
TestBTranslator(BTestCase *ptest, BTranslator *ptran,
const translation_format *pExpectedIns, uint32 nExpectedIns,
const translation_format *pExpectedOuts, uint32 nExpectedOuts,
int32 expectedVer)
@ -123,68 +124,68 @@ TestBTranslator(BTestCase *ptest, BTranslator *ptran,
const uint32 knmatches = 50;
uint8 matches[knmatches];
CPPUNIT_ASSERT(nExpectedIns <= knmatches && nExpectedOuts <= knmatches);
// 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 == expectedVer);
printf(" {0x%.8lx} ", ver);
// Input formats?
ptest->NextSubTest();
{
printf("input:");
int32 incount = 0;
const translation_format *pins = ptran->InputFormats(&incount);
CPPUNIT_ASSERT((unsigned)incount == nExpectedIns);
CPPUNIT_ASSERT(pins);
memset(matches, 0, sizeof(uint8) * nExpectedIns);
for (int32 i = 0; i < incount; i++) {
bool bmatch = false;
@ -193,25 +194,25 @@ TestBTranslator(BTestCase *ptest, BTranslator *ptran,
if (bmatch)
matches[k] = 1;
}
CPPUNIT_ASSERT(bmatch);
}
// make sure that each expected input format was matched
for (uint32 i = 0; i < nExpectedIns; i++)
CPPUNIT_ASSERT(matches[i]);
}
// Output formats?
ptest->NextSubTest();
{
printf("output:");
int32 outcount = 0;
const translation_format *pouts = ptran->OutputFormats(&outcount);
CPPUNIT_ASSERT((unsigned)outcount == nExpectedOuts);
CPPUNIT_ASSERT(pouts);
memset(matches, 0, sizeof(uint8) * nExpectedOuts);
for (int32 i = 0; i < outcount; i++) {
bool bmatch = false;
@ -220,15 +221,15 @@ TestBTranslator(BTestCase *ptest, BTranslator *ptran,
if (bmatch)
matches[k] = 1;
}
CPPUNIT_ASSERT(bmatch);
}
// make sure that each expected input format was matched
for (uint32 i = 0; i < nExpectedOuts; i++)
CPPUNIT_ASSERT(matches[i]);
}
// Release should return NULL because Release has been called
// as many times as it has been acquired
ptest->NextSubTest();
@ -246,7 +247,7 @@ TranslatorLoadAddOnTest(const char *path, BTestCase *ptest,
ptest->NextSubTest();
image_id image = load_add_on(path);
CPPUNIT_ASSERT(image >= 0);
// Load in function to make the object
ptest->NextSubTest();
BTranslator *(*pMakeNthTranslator)(int32 n,image_id you,uint32 flags,...);
@ -258,7 +259,7 @@ TranslatorLoadAddOnTest(const char *path, BTestCase *ptest,
ptest->NextSubTest();
BTranslator *ptran = pMakeNthTranslator(0, image, 0);
CPPUNIT_ASSERT(ptran);
// Make sure the function only returns one BTranslator
ptest->NextSubTest();
CPPUNIT_ASSERT(!pMakeNthTranslator(1, image, 0));
@ -266,14 +267,14 @@ TranslatorLoadAddOnTest(const char *path, BTestCase *ptest,
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(ptest, ptran, pExpectedIns, nExpectedIns,
pExpectedOuts, nExpectedOuts, expectedVer);
// NOTE: this function Release()s ptran
ptran = NULL;
// Unload Add-on
ptest->NextSubTest();
CPPUNIT_ASSERT(unload_add_on(image) == B_OK);
CPPUNIT_ASSERT(unload_add_on(image) == B_OK);
}

View File

@ -9,15 +9,17 @@
#define BBT_MIME_STRING "image/x-be-bitmap"
#define BMP_MIME_STRING "image/x-bmp"
class CppUnit::Test;
namespace CppUnit {
class Test;
}
class BMPTranslatorTest : public BTestCase {
public:
static CppUnit::Test* Suite();
// This function called before *each* test added in Suite()
void setUp();
// This function called after *each* test added in Suite()
void tearDown();

View File

@ -9,15 +9,17 @@
#define BBT_MIME_STRING "image/x-be-bitmap"
#define PNG_MIME_STRING "image/png"
class CppUnit::Test;
namespace CppUnit {
class Test;
}
class PNGTranslatorTest : public BTestCase {
public:
static CppUnit::Test* Suite();
// This function called before *each* test added in Suite()
void setUp();
// This function called after *each* test added in Suite()
void tearDown();

View File

@ -9,15 +9,17 @@
#define TEXT_MIME_STRING "text/plain"
#define STXT_MIME_STRING "text/x-vnd.Be-stxt"
class CppUnit::Test;
namespace CppUnit {
class Test;
}
class STXTTranslatorTest : public BTestCase {
public:
static CppUnit::Test* Suite();
// This function called before *each* test added in Suite()
void setUp();
// This function called after *each* test added in Suite()
void tearDown();

View File

@ -9,15 +9,17 @@
#define BBT_MIME_STRING "image/x-be-bitmap"
#define TGA_MIME_STRING "image/x-targa"
class CppUnit::Test;
namespace CppUnit {
class Test;
}
class TGATranslatorTest : public BTestCase {
public:
static CppUnit::Test* Suite();
// This function called before *each* test added in Suite()
void setUp();
// This function called after *each* test added in Suite()
void tearDown();

View File

@ -9,15 +9,17 @@
#define BBT_MIME_STRING "image/x-be-bitmap"
#define TIFF_MIME_STRING "image/tiff"
class CppUnit::Test;
namespace CppUnit {
class Test;
}
class TIFFTranslatorTest : public BTestCase {
public:
static CppUnit::Test* Suite();
// This function called before *each* test added in Suite()
void setUp();
// This function called after *each* test added in Suite()
void tearDown();