* 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:
parent
bd3cb5f1b0
commit
5b3152c4fb
@ -1,6 +1,7 @@
|
|||||||
// TranslatorTestAddOn.cpp
|
// TranslatorTestAddOn.cpp
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <Translator.h>
|
#include <Translator.h>
|
||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include "TranslatorTestAddOn.h"
|
#include "TranslatorTestAddOn.h"
|
||||||
@ -36,14 +37,14 @@ CompareStreams(BPositionIO &a, BPositionIO &b)
|
|||||||
off_t alen = 0, blen = 0;
|
off_t alen = 0, blen = 0;
|
||||||
const uint32 kbuflen = 2048;
|
const uint32 kbuflen = 2048;
|
||||||
uint8 abuf[kbuflen], bbuf[kbuflen];
|
uint8 abuf[kbuflen], bbuf[kbuflen];
|
||||||
|
|
||||||
a.Seek(0, SEEK_END);
|
a.Seek(0, SEEK_END);
|
||||||
alen = a.Position();
|
alen = a.Position();
|
||||||
b.Seek(0, SEEK_END);
|
b.Seek(0, SEEK_END);
|
||||||
blen = b.Position();
|
blen = b.Position();
|
||||||
if (alen != blen)
|
if (alen != blen)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (a.Seek(0, SEEK_SET) != 0)
|
if (a.Seek(0, SEEK_SET) != 0)
|
||||||
return false;
|
return false;
|
||||||
if (b.Seek(0, SEEK_SET) != 0)
|
if (b.Seek(0, SEEK_SET) != 0)
|
||||||
@ -56,13 +57,13 @@ CompareStreams(BPositionIO &a, BPositionIO &b)
|
|||||||
return false;
|
return false;
|
||||||
if (b.Read(bbuf, read) != read)
|
if (b.Read(bbuf, read) != read)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (memcmp(abuf, bbuf, read) != 0)
|
if (memcmp(abuf, bbuf, read) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
alen -= read;
|
alen -= read;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ CompareTranslationFormat(const translation_format *pleft,
|
|||||||
CPPUNIT_ASSERT(pright->MIME);
|
CPPUNIT_ASSERT(pright->MIME);
|
||||||
CPPUNIT_ASSERT(pleft->name);
|
CPPUNIT_ASSERT(pleft->name);
|
||||||
CPPUNIT_ASSERT(pright->name);
|
CPPUNIT_ASSERT(pright->name);
|
||||||
|
|
||||||
if (pleft->group != pright->group)
|
if (pleft->group != pright->group)
|
||||||
return false;
|
return false;
|
||||||
if (pleft->type != pright->type)
|
if (pleft->type != pright->type)
|
||||||
@ -109,13 +110,13 @@ CompareTranslationFormat(const translation_format *pleft,
|
|||||||
return false;
|
return false;
|
||||||
if (strcmp(pleft->name, pright->name) != 0)
|
if (strcmp(pleft->name, pright->name) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply a number of tests to a BTranslator * to a TGATranslator object
|
// Apply a number of tests to a BTranslator * to a TGATranslator object
|
||||||
void
|
void
|
||||||
TestBTranslator(BTestCase *ptest, BTranslator *ptran,
|
TestBTranslator(BTestCase *ptest, BTranslator *ptran,
|
||||||
const translation_format *pExpectedIns, uint32 nExpectedIns,
|
const translation_format *pExpectedIns, uint32 nExpectedIns,
|
||||||
const translation_format *pExpectedOuts, uint32 nExpectedOuts,
|
const translation_format *pExpectedOuts, uint32 nExpectedOuts,
|
||||||
int32 expectedVer)
|
int32 expectedVer)
|
||||||
@ -123,68 +124,68 @@ TestBTranslator(BTestCase *ptest, BTranslator *ptran,
|
|||||||
const uint32 knmatches = 50;
|
const uint32 knmatches = 50;
|
||||||
uint8 matches[knmatches];
|
uint8 matches[knmatches];
|
||||||
CPPUNIT_ASSERT(nExpectedIns <= knmatches && nExpectedOuts <= knmatches);
|
CPPUNIT_ASSERT(nExpectedIns <= knmatches && nExpectedOuts <= knmatches);
|
||||||
|
|
||||||
// The translator should only have one reference
|
// The translator should only have one reference
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
|
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
|
||||||
|
|
||||||
// Make sure Acquire returns a BTranslator even though its
|
// Make sure Acquire returns a BTranslator even though its
|
||||||
// already been Acquired once
|
// already been Acquired once
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->Acquire() == ptran);
|
CPPUNIT_ASSERT(ptran->Acquire() == ptran);
|
||||||
|
|
||||||
// Acquired twice, refcount should be 2
|
// Acquired twice, refcount should be 2
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->ReferenceCount() == 2);
|
CPPUNIT_ASSERT(ptran->ReferenceCount() == 2);
|
||||||
|
|
||||||
// Release should return ptran because it is still acquired
|
// Release should return ptran because it is still acquired
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->Release() == ptran);
|
CPPUNIT_ASSERT(ptran->Release() == ptran);
|
||||||
|
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
|
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
|
||||||
|
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->Acquire() == ptran);
|
CPPUNIT_ASSERT(ptran->Acquire() == ptran);
|
||||||
|
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->ReferenceCount() == 2);
|
CPPUNIT_ASSERT(ptran->ReferenceCount() == 2);
|
||||||
|
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->Release() == ptran);
|
CPPUNIT_ASSERT(ptran->Release() == ptran);
|
||||||
|
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
|
CPPUNIT_ASSERT(ptran->ReferenceCount() == 1);
|
||||||
|
|
||||||
// A name would be nice
|
// A name would be nice
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
const char *tranname = ptran->TranslatorName();
|
const char *tranname = ptran->TranslatorName();
|
||||||
CPPUNIT_ASSERT(tranname);
|
CPPUNIT_ASSERT(tranname);
|
||||||
printf(" {%s} ", tranname);
|
printf(" {%s} ", tranname);
|
||||||
|
|
||||||
// More info would be nice
|
// More info would be nice
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
const char *traninfo = ptran->TranslatorInfo();
|
const char *traninfo = ptran->TranslatorInfo();
|
||||||
CPPUNIT_ASSERT(traninfo);
|
CPPUNIT_ASSERT(traninfo);
|
||||||
printf(" {%s} ", traninfo);
|
printf(" {%s} ", traninfo);
|
||||||
|
|
||||||
// What version are you?
|
// What version are you?
|
||||||
// (when ver == 100, that means that version is 1.00)
|
// (when ver == 100, that means that version is 1.00)
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
int32 ver = ptran->TranslatorVersion();
|
int32 ver = ptran->TranslatorVersion();
|
||||||
CPPUNIT_ASSERT(ver == expectedVer);
|
CPPUNIT_ASSERT(ver == expectedVer);
|
||||||
printf(" {0x%.8lx} ", ver);
|
printf(" {0x%.8lx} ", ver);
|
||||||
|
|
||||||
// Input formats?
|
// Input formats?
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
{
|
{
|
||||||
printf("input:");
|
printf("input:");
|
||||||
|
|
||||||
int32 incount = 0;
|
int32 incount = 0;
|
||||||
const translation_format *pins = ptran->InputFormats(&incount);
|
const translation_format *pins = ptran->InputFormats(&incount);
|
||||||
CPPUNIT_ASSERT((unsigned)incount == nExpectedIns);
|
CPPUNIT_ASSERT((unsigned)incount == nExpectedIns);
|
||||||
CPPUNIT_ASSERT(pins);
|
CPPUNIT_ASSERT(pins);
|
||||||
|
|
||||||
memset(matches, 0, sizeof(uint8) * nExpectedIns);
|
memset(matches, 0, sizeof(uint8) * nExpectedIns);
|
||||||
for (int32 i = 0; i < incount; i++) {
|
for (int32 i = 0; i < incount; i++) {
|
||||||
bool bmatch = false;
|
bool bmatch = false;
|
||||||
@ -193,25 +194,25 @@ TestBTranslator(BTestCase *ptest, BTranslator *ptran,
|
|||||||
if (bmatch)
|
if (bmatch)
|
||||||
matches[k] = 1;
|
matches[k] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_ASSERT(bmatch);
|
CPPUNIT_ASSERT(bmatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that each expected input format was matched
|
// make sure that each expected input format was matched
|
||||||
for (uint32 i = 0; i < nExpectedIns; i++)
|
for (uint32 i = 0; i < nExpectedIns; i++)
|
||||||
CPPUNIT_ASSERT(matches[i]);
|
CPPUNIT_ASSERT(matches[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output formats?
|
// Output formats?
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
{
|
{
|
||||||
printf("output:");
|
printf("output:");
|
||||||
|
|
||||||
int32 outcount = 0;
|
int32 outcount = 0;
|
||||||
const translation_format *pouts = ptran->OutputFormats(&outcount);
|
const translation_format *pouts = ptran->OutputFormats(&outcount);
|
||||||
CPPUNIT_ASSERT((unsigned)outcount == nExpectedOuts);
|
CPPUNIT_ASSERT((unsigned)outcount == nExpectedOuts);
|
||||||
CPPUNIT_ASSERT(pouts);
|
CPPUNIT_ASSERT(pouts);
|
||||||
|
|
||||||
memset(matches, 0, sizeof(uint8) * nExpectedOuts);
|
memset(matches, 0, sizeof(uint8) * nExpectedOuts);
|
||||||
for (int32 i = 0; i < outcount; i++) {
|
for (int32 i = 0; i < outcount; i++) {
|
||||||
bool bmatch = false;
|
bool bmatch = false;
|
||||||
@ -220,15 +221,15 @@ TestBTranslator(BTestCase *ptest, BTranslator *ptran,
|
|||||||
if (bmatch)
|
if (bmatch)
|
||||||
matches[k] = 1;
|
matches[k] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_ASSERT(bmatch);
|
CPPUNIT_ASSERT(bmatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure that each expected input format was matched
|
// make sure that each expected input format was matched
|
||||||
for (uint32 i = 0; i < nExpectedOuts; i++)
|
for (uint32 i = 0; i < nExpectedOuts; i++)
|
||||||
CPPUNIT_ASSERT(matches[i]);
|
CPPUNIT_ASSERT(matches[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release should return NULL because Release has been called
|
// Release should return NULL because Release has been called
|
||||||
// as many times as it has been acquired
|
// as many times as it has been acquired
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
@ -246,7 +247,7 @@ TranslatorLoadAddOnTest(const char *path, BTestCase *ptest,
|
|||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
image_id image = load_add_on(path);
|
image_id image = load_add_on(path);
|
||||||
CPPUNIT_ASSERT(image >= 0);
|
CPPUNIT_ASSERT(image >= 0);
|
||||||
|
|
||||||
// Load in function to make the object
|
// Load in function to make the object
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
BTranslator *(*pMakeNthTranslator)(int32 n,image_id you,uint32 flags,...);
|
BTranslator *(*pMakeNthTranslator)(int32 n,image_id you,uint32 flags,...);
|
||||||
@ -258,7 +259,7 @@ TranslatorLoadAddOnTest(const char *path, BTestCase *ptest,
|
|||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
BTranslator *ptran = pMakeNthTranslator(0, image, 0);
|
BTranslator *ptran = pMakeNthTranslator(0, image, 0);
|
||||||
CPPUNIT_ASSERT(ptran);
|
CPPUNIT_ASSERT(ptran);
|
||||||
|
|
||||||
// Make sure the function only returns one BTranslator
|
// Make sure the function only returns one BTranslator
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(!pMakeNthTranslator(1, image, 0));
|
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(3, image, 0));
|
||||||
CPPUNIT_ASSERT(!pMakeNthTranslator(16, image, 0));
|
CPPUNIT_ASSERT(!pMakeNthTranslator(16, image, 0));
|
||||||
CPPUNIT_ASSERT(!pMakeNthTranslator(1023, image, 0));
|
CPPUNIT_ASSERT(!pMakeNthTranslator(1023, image, 0));
|
||||||
|
|
||||||
// Run a number of tests on the BTranslator object
|
// Run a number of tests on the BTranslator object
|
||||||
TestBTranslator(ptest, ptran, pExpectedIns, nExpectedIns,
|
TestBTranslator(ptest, ptran, pExpectedIns, nExpectedIns,
|
||||||
pExpectedOuts, nExpectedOuts, expectedVer);
|
pExpectedOuts, nExpectedOuts, expectedVer);
|
||||||
// NOTE: this function Release()s ptran
|
// NOTE: this function Release()s ptran
|
||||||
ptran = NULL;
|
ptran = NULL;
|
||||||
|
|
||||||
// Unload Add-on
|
// Unload Add-on
|
||||||
ptest->NextSubTest();
|
ptest->NextSubTest();
|
||||||
CPPUNIT_ASSERT(unload_add_on(image) == B_OK);
|
CPPUNIT_ASSERT(unload_add_on(image) == B_OK);
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,17 @@
|
|||||||
#define BBT_MIME_STRING "image/x-be-bitmap"
|
#define BBT_MIME_STRING "image/x-be-bitmap"
|
||||||
#define BMP_MIME_STRING "image/x-bmp"
|
#define BMP_MIME_STRING "image/x-bmp"
|
||||||
|
|
||||||
class CppUnit::Test;
|
namespace CppUnit {
|
||||||
|
class Test;
|
||||||
|
}
|
||||||
|
|
||||||
class BMPTranslatorTest : public BTestCase {
|
class BMPTranslatorTest : public BTestCase {
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* Suite();
|
static CppUnit::Test* Suite();
|
||||||
|
|
||||||
// This function called before *each* test added in Suite()
|
// This function called before *each* test added in Suite()
|
||||||
void setUp();
|
void setUp();
|
||||||
|
|
||||||
// This function called after *each* test added in Suite()
|
// This function called after *each* test added in Suite()
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
|
@ -9,15 +9,17 @@
|
|||||||
#define BBT_MIME_STRING "image/x-be-bitmap"
|
#define BBT_MIME_STRING "image/x-be-bitmap"
|
||||||
#define PNG_MIME_STRING "image/png"
|
#define PNG_MIME_STRING "image/png"
|
||||||
|
|
||||||
class CppUnit::Test;
|
namespace CppUnit {
|
||||||
|
class Test;
|
||||||
|
}
|
||||||
|
|
||||||
class PNGTranslatorTest : public BTestCase {
|
class PNGTranslatorTest : public BTestCase {
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* Suite();
|
static CppUnit::Test* Suite();
|
||||||
|
|
||||||
// This function called before *each* test added in Suite()
|
// This function called before *each* test added in Suite()
|
||||||
void setUp();
|
void setUp();
|
||||||
|
|
||||||
// This function called after *each* test added in Suite()
|
// This function called after *each* test added in Suite()
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
|
@ -9,15 +9,17 @@
|
|||||||
#define TEXT_MIME_STRING "text/plain"
|
#define TEXT_MIME_STRING "text/plain"
|
||||||
#define STXT_MIME_STRING "text/x-vnd.Be-stxt"
|
#define STXT_MIME_STRING "text/x-vnd.Be-stxt"
|
||||||
|
|
||||||
class CppUnit::Test;
|
namespace CppUnit {
|
||||||
|
class Test;
|
||||||
|
}
|
||||||
|
|
||||||
class STXTTranslatorTest : public BTestCase {
|
class STXTTranslatorTest : public BTestCase {
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* Suite();
|
static CppUnit::Test* Suite();
|
||||||
|
|
||||||
// This function called before *each* test added in Suite()
|
// This function called before *each* test added in Suite()
|
||||||
void setUp();
|
void setUp();
|
||||||
|
|
||||||
// This function called after *each* test added in Suite()
|
// This function called after *each* test added in Suite()
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
|
@ -9,15 +9,17 @@
|
|||||||
#define BBT_MIME_STRING "image/x-be-bitmap"
|
#define BBT_MIME_STRING "image/x-be-bitmap"
|
||||||
#define TGA_MIME_STRING "image/x-targa"
|
#define TGA_MIME_STRING "image/x-targa"
|
||||||
|
|
||||||
class CppUnit::Test;
|
namespace CppUnit {
|
||||||
|
class Test;
|
||||||
|
}
|
||||||
|
|
||||||
class TGATranslatorTest : public BTestCase {
|
class TGATranslatorTest : public BTestCase {
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* Suite();
|
static CppUnit::Test* Suite();
|
||||||
|
|
||||||
// This function called before *each* test added in Suite()
|
// This function called before *each* test added in Suite()
|
||||||
void setUp();
|
void setUp();
|
||||||
|
|
||||||
// This function called after *each* test added in Suite()
|
// This function called after *each* test added in Suite()
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
|
@ -9,15 +9,17 @@
|
|||||||
#define BBT_MIME_STRING "image/x-be-bitmap"
|
#define BBT_MIME_STRING "image/x-be-bitmap"
|
||||||
#define TIFF_MIME_STRING "image/tiff"
|
#define TIFF_MIME_STRING "image/tiff"
|
||||||
|
|
||||||
class CppUnit::Test;
|
namespace CppUnit {
|
||||||
|
class Test;
|
||||||
|
}
|
||||||
|
|
||||||
class TIFFTranslatorTest : public BTestCase {
|
class TIFFTranslatorTest : public BTestCase {
|
||||||
public:
|
public:
|
||||||
static CppUnit::Test* Suite();
|
static CppUnit::Test* Suite();
|
||||||
|
|
||||||
// This function called before *each* test added in Suite()
|
// This function called before *each* test added in Suite()
|
||||||
void setUp();
|
void setUp();
|
||||||
|
|
||||||
// This function called after *each* test added in Suite()
|
// This function called after *each* test added in Suite()
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user