added some more testing, modified some existing testing, made style changes

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2046 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2002-11-21 05:06:40 +00:00
parent e81d8d7a95
commit ef3a275d0f
@@ -36,6 +36,7 @@
#include <Archivable.h> #include <Archivable.h>
#include <File.h> #include <File.h>
#include <Application.h> #include <Application.h>
#include <OS.h>
/* cppunit framework */ /* cppunit framework */
#include <cppunit/Test.h> #include <cppunit/Test.h>
@@ -187,6 +188,7 @@ void TranslatorRosterTest::DefaultTest() {
NextSubTest(); NextSubTest();
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster *proster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(proster != NULL); CPPUNIT_ASSERT(proster != NULL);
// TODO: actually check if all the right translators are loaded
// delete the default BTranslatorRoster // delete the default BTranslatorRoster
// (may not always be the appropriate thing to do, // (may not always be the appropriate thing to do,
@@ -194,7 +196,30 @@ void TranslatorRosterTest::DefaultTest() {
NextSubTest(); NextSubTest();
delete proster; delete proster;
proster = NULL; proster = NULL;
CPPUNIT_ASSERT(BTranslatorRoster::Default());
// If the default BTranslatorRoster was not
// deleted properly, it would likely show up in
// this test or the next
NextSubTest();
proster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(proster);
// Make sure the default BTranslatorRoster works
// after a delete has been performed
// TODO: actually check if all the right translators are loaded
NextSubTest();
translator_id *pids = NULL;
int32 ncount = -1;
status_t result = proster->GetAllTranslators(&pids, &ncount);
CPPUNIT_ASSERT(pids);
delete[] pids;
pids = NULL;
CPPUNIT_ASSERT(ncount > 0);
// Delete again to be sure that it still won't blow up
NextSubTest();
delete proster;
proster = NULL;
} }
/** /**
@@ -207,19 +232,60 @@ void TranslatorRosterTest::DefaultTest() {
void TranslatorRosterTest::InstantiateTest() { void TranslatorRosterTest::InstantiateTest() {
//shared instance of TranslatorRoster //shared instance of TranslatorRoster
BTranslatorRoster* proster = NULL; BTranslatorRoster* proster = NULL;
BMessage bmsg;
//Create our BMessage
BMessage translator_message;
//create BTranslatorRoster using empty message (must return NULL) //create BTranslatorRoster using empty message (must return NULL)
proster = (BTranslatorRoster *) BTranslatorRoster::Instantiate(&translator_message); NextSubTest();
proster = dynamic_cast<BTranslatorRoster *>
(BTranslatorRoster::Instantiate(&bmsg));
CPPUNIT_ASSERT(proster == NULL); CPPUNIT_ASSERT(proster == NULL);
delete proster; delete proster;
proster = NULL; proster = NULL;
// TODO: add a case with a BMessage containing a single Translator to load // BMessage containing a single Translator to load
NextSubTest();
status_t result;
result = bmsg.AddString("class", "BTranslatorRoster");
CPPUNIT_ASSERT(result == B_OK);
result = bmsg.AddString("be:translator_path",
"/boot/home/config/add-ons/Translators/BMPTranslator");
CPPUNIT_ASSERT(result == B_OK);
proster = dynamic_cast<BTranslatorRoster *>
(BTranslatorRoster::Instantiate(&bmsg));
CPPUNIT_ASSERT(proster);
translator_id *pids = NULL;
int32 ncount = -1;
result = proster->GetAllTranslators(&pids, &ncount);
CPPUNIT_ASSERT(result == B_OK);
CPPUNIT_ASSERT(pids);
CPPUNIT_ASSERT(ncount == 1);
const char *strName = NULL, *strInfo = NULL;
int32 nversion = -1;
result = proster->GetTranslatorInfo(pids[0], &strName, &strInfo, &nversion);
CPPUNIT_ASSERT(result == B_OK);
CPPUNIT_ASSERT(strName);
CPPUNIT_ASSERT(strInfo);
CPPUNIT_ASSERT(nversion > 0);
CPPUNIT_ASSERT(strcmp("BMP Images", strName) == 0);
delete proster;
proster = NULL;
// TODO: add a case with a BMessage containing multiple Translators to load // TODO: add a case with a BMessage containing multiple Translators to load
// TODO: add a case with a slightly corrupt BMessage
// slightly corrupt BMessage, Instantiate
// should fail because class information is missing
NextSubTest();
result = bmsg.MakeEmpty();
CPPUNIT_ASSERT(result == B_OK);
result = bmsg.AddString("be:translator_path",
"/boot/home/config/add-ons/Translators/BMPTranslator");
CPPUNIT_ASSERT(result == B_OK);
proster = dynamic_cast<BTranslatorRoster *>
(BTranslatorRoster::Instantiate(&bmsg));
CPPUNIT_ASSERT(proster == NULL);
delete proster;
proster = NULL;
} }
/** /**
@@ -240,6 +306,48 @@ void TranslatorRosterTest::VersionTest() {
CPPUNIT_ASSERT(outMinVersion > 0); CPPUNIT_ASSERT(outMinVersion > 0);
} }
//
// Compares proster to the default BTranslatorRoster to
// ensure that they have the same translators and the
// same number of translators
//
void CompareWithDefault(BTranslatorRoster *proster)
{
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
translator_id *pInstids = NULL, *pDefids = NULL;
int32 instcount = 0, defcount = 0, ndummy = 0;
const char *strDefName = NULL, *strInstName = NULL, *strDummy = NULL;
CPPUNIT_ASSERT(proster->GetAllTranslators(&pInstids, &instcount) == B_OK);
CPPUNIT_ASSERT(pInstids);
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&pDefids, &defcount) == B_OK);
CPPUNIT_ASSERT(pDefids);
CPPUNIT_ASSERT(defcount == instcount);
for (int32 i = 0; i < defcount; i++) {
int32 matches;
matches = 0;
CPPUNIT_ASSERT(
pDefRoster->GetTranslatorInfo(pDefids[i], &strDefName, &strDummy, &ndummy) == B_OK);
CPPUNIT_ASSERT(strDefName);
for (int32 k = 0; k < instcount; k++) {
CPPUNIT_ASSERT(
proster->GetTranslatorInfo(pInstids[k], &strInstName, &strDummy, &ndummy) == B_OK);
CPPUNIT_ASSERT(strInstName);
if (strcmp(strDefName, strInstName) == 0)
matches++;
}
CPPUNIT_ASSERT(matches == 1);
}
delete[] pInstids;
pInstids = NULL;
delete[] pDefids;
pDefids = NULL;
}
/** /**
* Tests: * Tests:
* virtual status_t AddTranslators(const char *load_path = NULL) * virtual status_t AddTranslators(const char *load_path = NULL)
@@ -261,14 +369,12 @@ void TranslatorRosterTest::AddTranslatorsTest() {
proster->AddTranslators("/boot/home/config/add-ons/Translators/:/system/add-ons/Translators/") == B_OK); proster->AddTranslators("/boot/home/config/add-ons/Translators/:/system/add-ons/Translators/") == B_OK);
NextSubTest(); NextSubTest();
int32 num_translators = 0; int32 instcount = 0;
translator_id* translators = NULL; translator_id* translators = NULL;
proster->GetAllTranslators(&translators, &num_translators); proster->GetAllTranslators(&translators, &instcount);
CPPUNIT_ASSERT(instcount > 0);
// TODO: count the number of files in all of the directories specified above // TODO: count the number of files in all of the directories specified above
// TODO: and make certain that it matches num_translators // TODO: and make certain that it matches instcount
CPPUNIT_ASSERT(num_translators > 0);
delete[] translators; delete[] translators;
translators = NULL; translators = NULL;
@@ -278,15 +384,10 @@ void TranslatorRosterTest::AddTranslatorsTest() {
proster = new BTranslatorRoster(); proster = new BTranslatorRoster();
CPPUNIT_ASSERT(proster->AddTranslators() == B_OK); CPPUNIT_ASSERT(proster->AddTranslators() == B_OK);
// make sure that every translator in the Default BTranslatorRoster is in
// proster, and make certain that it is in there ONLY ONCE
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetAllTranslators(&translators, &num_translators) == B_OK); CompareWithDefault(proster);
CPPUNIT_ASSERT(num_translators > 0);
// TODO: compare the translators and number of translators from proster
// TODO: to the default translators from BTranslatorRoster::Default()
delete[] translators;
translators = NULL;
delete proster; delete proster;
proster = NULL; proster = NULL;
} }
@@ -304,43 +405,21 @@ void TranslatorRosterTest::ArchiveTest() {
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(pDefRoster != NULL); CPPUNIT_ASSERT(pDefRoster != NULL);
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->Archive(&translator_message) == B_OK); CPPUNIT_ASSERT(pDefRoster->Archive(&translator_message) == B_OK);
// make sure instantiate makes an "exact" copy of the default translator // make sure instantiate makes an "exact" copy of the default translator
NextSubTest(); NextSubTest();
BTranslatorRoster *proster = NULL; BTranslatorRoster *proster = NULL;
proster = (BTranslatorRoster*) BTranslatorRoster::Instantiate(&translator_message); proster = dynamic_cast<BTranslatorRoster *>
(BTranslatorRoster::Instantiate(&translator_message));
CPPUNIT_ASSERT(proster != NULL); CPPUNIT_ASSERT(proster != NULL);
NextSubTest();
translator_id *pDefids = NULL, *pInstids = NULL;
int32 defcount = 0, instcount = 42;
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&pDefids, &defcount) == B_OK);
NextSubTest();
CPPUNIT_ASSERT(proster->GetAllTranslators(&pInstids, &instcount) == B_OK);
NextSubTest();
CPPUNIT_ASSERT(defcount == instcount);
// make sure that every translator in the pDefRoster is in // make sure that every translator in the pDefRoster is in
// proster, and make certain that it is in there ONLY ONCE // proster, and make certain that it is in there ONLY ONCE
NextSubTest(); NextSubTest();
for (int32 i = 0; i < defcount; i++) { CompareWithDefault(proster);
int32 matches; delete proster;
matches = 0; proster = NULL;
for (int32 k = 0; k < instcount; k++) {
if (pDefids[i] == pInstids[k])
matches++;
}
CPPUNIT_ASSERT(matches == 1);
}
delete[] pDefids;
pDefids = NULL;
delete[] pInstids;
pInstids = NULL;
} }
/** /**
@@ -374,9 +453,9 @@ void TranslatorRosterTest::GetAllTranslatorsTest() {
// default translators // default translators
NextSubTest(); NextSubTest();
nloaded = 42; nloaded = 42;
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT( CPPUNIT_ASSERT(
proster->GetAllTranslators(&pids, &nloaded) == B_NO_ERROR); pDefRoster->GetAllTranslators(&pids, &nloaded) == B_NO_ERROR);
CPPUNIT_ASSERT(nloaded > 0); CPPUNIT_ASSERT(nloaded > 0);
CPPUNIT_ASSERT(pids != NULL); CPPUNIT_ASSERT(pids != NULL);
@@ -412,7 +491,7 @@ void TranslatorRosterTest::GetAllTranslatorsTest() {
kTranslatorName = kTranslatorInfo = NULL; kTranslatorName = kTranslatorInfo = NULL;
nTranslatorVersion = -246; nTranslatorVersion = -246;
proster->GetTranslatorInfo(pids[i], &kTranslatorName, pDefRoster->GetTranslatorInfo(pids[i], &kTranslatorName,
&kTranslatorInfo, &nTranslatorVersion); &kTranslatorInfo, &nTranslatorVersion);
CPPUNIT_ASSERT(kTranslatorName); CPPUNIT_ASSERT(kTranslatorName);
@@ -439,30 +518,63 @@ void TranslatorRosterTest::GetAllTranslatorsTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::GetConfigurationMessageTest() { void TranslatorRosterTest::GetConfigurationMessageTest()
BMessage translator_message; {
BTranslatorRoster *proster = BTranslatorRoster::Default(); NextSubTest();
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
//get id for a translator (just use the first one) //get id for a translator (just use the first one)
unsigned long translatorid; int32 num_translators = -1;
int32 num_translators; translator_id* translators = NULL;
translator_id* translators; pDefRoster->GetAllTranslators(&translators, &num_translators);
proster->GetAllTranslators(&translators, &num_translators); CPPUNIT_ASSERT(translators);
translatorid = translators[0];
translator_id translatorid = translators[0];
delete[] translators; delete[] translators;
translators = NULL; translators = NULL;
//get conf for invalid translator //get conf for invalid translator
CPPUNIT_ASSERT(proster->GetConfigurationMessage(-1, &translator_message) == B_NO_TRANSLATOR); BMessage translator_message;
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(-1, &translator_message) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(translator_message.IsEmpty());
//get conf for invalid ioExtension (BMessage) //get conf for invalid ioExtension (BMessage)
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetConfigurationMessage(translatorid, NULL) == B_BAD_VALUE); CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(translatorid, NULL) == B_BAD_VALUE);
//get config for actual translator //get config for actual translator
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetConfigurationMessage(translatorid, &translator_message) == B_OK); CPPUNIT_ASSERT(translator_message.MakeEmpty() == B_OK);
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(translatorid, &translator_message) == B_OK);
}
// Code used by both GetInputFormatsTest and GetOutputFormatsTest
void GetInputOutputFormatsTest(TranslatorRosterTest *prt, bool binput)
{
prt->NextSubTest();
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
translator_id* translators = NULL;
int32 num_translators = -1;
pDefRoster->GetAllTranslators(&translators, &num_translators);
CPPUNIT_ASSERT(num_translators > 0);
for (int32 i = 0; i < num_translators; i++) {
const translation_format *fmts = NULL;
int32 num_fmts = -1;
status_t result;
prt->NextSubTest();
if (binput)
result = pDefRoster->GetInputFormats(translators[i], &fmts, &num_fmts);
else
result = pDefRoster->GetOutputFormats(translators[i], &fmts, &num_fmts);
CPPUNIT_ASSERT(result == B_OK);
CPPUNIT_ASSERT(num_fmts >= 0);
}
delete[] translators;
translators = NULL;
} }
/** /**
@@ -471,21 +583,9 @@ void TranslatorRosterTest::GetConfigurationMessageTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::GetInputFormatsTest() { void TranslatorRosterTest::GetInputFormatsTest()
translator_id* translators; {
int32 num_translators; GetInputOutputFormatsTest(this, true);
BTranslatorRoster *proster = BTranslatorRoster::Default();
proster->GetAllTranslators(&translators, &num_translators);
CPPUNIT_ASSERT(num_translators > 0);
NextSubTest();
for (int32 i=0;i<num_translators;i++) {
const translation_format *fmts;
int32 num_fmts;
proster->GetInputFormats(translators[i], &fmts, &num_fmts);
CPPUNIT_ASSERT(num_fmts >= 0);
}
delete [] translators;
} }
/** /**
@@ -494,21 +594,9 @@ void TranslatorRosterTest::GetInputFormatsTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::GetOutputFormatsTest() { void TranslatorRosterTest::GetOutputFormatsTest()
translator_id* translators; {
int32 num_translators; GetInputOutputFormatsTest(this, false);
BTranslatorRoster *proster = BTranslatorRoster::Default();
proster->GetAllTranslators(&translators, &num_translators);
CPPUNIT_ASSERT(num_translators > 0);
NextSubTest();
for (int32 i=0;i<num_translators;i++) {
const translation_format *fmts;
int32 num_fmts;
proster->GetOutputFormats(translators[i], &fmts, &num_fmts);
CPPUNIT_ASSERT(num_fmts >= 0);
}
delete [] translators;
} }
/** /**
@@ -517,20 +605,26 @@ void TranslatorRosterTest::GetOutputFormatsTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::GetTranslatorInfoTest() { void TranslatorRosterTest::GetTranslatorInfoTest()
translator_id* translators; {
int32 num_translators; NextSubTest();
BTranslatorRoster *proster = BTranslatorRoster::Default(); translator_id* translators = NULL;
proster->GetAllTranslators(&translators, &num_translators); int32 num_translators = -1;
for (int32 i=0;i<num_translators;i++) { BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
const char* outName; CPPUNIT_ASSERT(pDefRoster);
const char* outInfo;
int32 outVersion; CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&translators, &num_translators) == B_OK);
for (int32 i = 0; i < num_translators; i++) {
CPPUNIT_ASSERT(proster->GetTranslatorInfo(-1, &outName, &outInfo, &outVersion) == B_NO_TRANSLATOR); const char *outName = NULL;
const char *outInfo = NULL;
int32 outVersion = -1;
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetTranslatorInfo(translators[i], &outName, &outInfo, &outVersion) == B_OK); CPPUNIT_ASSERT(
pDefRoster->GetTranslatorInfo(-1, &outName, &outInfo, &outVersion) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(
pDefRoster->GetTranslatorInfo(translators[i], &outName, &outInfo, &outVersion) == B_OK);
CPPUNIT_ASSERT(outName);
} }
delete[] translators; delete[] translators;
translators = NULL; translators = NULL;
@@ -542,7 +636,9 @@ void TranslatorRosterTest::GetTranslatorInfoTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::GetTranslatorsTest() { void TranslatorRosterTest::GetTranslatorsTest()
{
NextSubTest();
BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest"); BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest");
//open image to get a translator for //open image to get a translator for
BFile image("../src/tests/kits/translation/data/images/image.png", B_READ_ONLY); BFile image("../src/tests/kits/translation/data/images/image.png", B_READ_ONLY);
@@ -552,28 +648,29 @@ void TranslatorRosterTest::GetTranslatorsTest() {
BFile garbled("../src/tests/kits/translation/data/garbled_data", B_READ_ONLY); BFile garbled("../src/tests/kits/translation/data/garbled_data", B_READ_ONLY);
CPPUNIT_ASSERT(garbled.InitCheck() == B_OK); CPPUNIT_ASSERT(garbled.InitCheck() == B_OK);
translator_info* info; translator_info* info = NULL;
int32 outCount; int32 outCount = -1;
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
//get translator, specifying wrong args //get translator, specifying wrong args
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetTranslators(&garbled, NULL, NULL, &outCount) == B_BAD_VALUE); CPPUNIT_ASSERT(
pDefRoster->GetTranslators(&garbled, NULL, NULL, &outCount) == B_BAD_VALUE);
//get translator, specifying wrong args //get translator, specifying wrong args
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetTranslators(&garbled, NULL, &info, NULL) == B_BAD_VALUE); CPPUNIT_ASSERT(
pDefRoster->GetTranslators(&garbled, NULL, &info, NULL) == B_BAD_VALUE);
//get translator for garbled data //get translator for garbled data
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetTranslators(&garbled, NULL, &info, &outCount) == B_NO_TRANSLATOR); CPPUNIT_ASSERT(
pDefRoster->GetTranslators(&garbled, NULL, &info, &outCount) == B_NO_TRANSLATOR);
//get translator for image //get translator for image
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->GetTranslators(&image, NULL, &info, &outCount) == B_OK); CPPUNIT_ASSERT(pDefRoster->GetTranslators(&image, NULL, &info, &outCount) == B_OK);
NextSubTest();
CPPUNIT_ASSERT(outCount > 0); CPPUNIT_ASSERT(outCount > 0);
delete[] info; delete[] info;
@@ -586,7 +683,9 @@ void TranslatorRosterTest::GetTranslatorsTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::IdentifyTest() { void TranslatorRosterTest::IdentifyTest()
{
NextSubTest();
BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest"); BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest");
//open image to get a translator for //open image to get a translator for
BFile image("../src/tests/kits/translation/data/images/image.png", B_READ_ONLY); BFile image("../src/tests/kits/translation/data/images/image.png", B_READ_ONLY);
@@ -595,26 +694,30 @@ void TranslatorRosterTest::IdentifyTest() {
//NextSubTest(); //NextSubTest();
BFile garbled("../src/tests/kits/translation/data/garbled_data", B_READ_ONLY); BFile garbled("../src/tests/kits/translation/data/garbled_data", B_READ_ONLY);
CPPUNIT_ASSERT(garbled.InitCheck() == B_OK); CPPUNIT_ASSERT(garbled.InitCheck() == B_OK);
translator_info* info = new translator_info; NextSubTest();
BTranslatorRoster *proster = BTranslatorRoster::Default(); translator_info *pinfo = new translator_info;
memset(pinfo, 0, sizeof(translator_info));
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
//get translator, specifying wrong args //get translator, specifying wrong args
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->Identify(&garbled, NULL, NULL) == B_BAD_VALUE); CPPUNIT_ASSERT(pDefRoster->Identify(&garbled, NULL, NULL) == B_BAD_VALUE);
//get translator for garbled data //get translator for garbled data
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->Identify(&garbled, NULL, info) == B_NO_TRANSLATOR); CPPUNIT_ASSERT(pDefRoster->Identify(&garbled, NULL, pinfo) == B_NO_TRANSLATOR);
//get translator for image //get translator for image
NextSubTest(); NextSubTest();
delete info; delete pinfo;
info = new translator_info; pinfo = new translator_info;
CPPUNIT_ASSERT(proster->Identify(&image, NULL, info) == B_OK); memset(pinfo, 0, sizeof(pinfo));
CPPUNIT_ASSERT(pDefRoster->Identify(&image, NULL, pinfo) == B_OK);
delete info; delete pinfo;
info = NULL; pinfo = NULL;
} }
/** /**
@@ -623,19 +726,45 @@ void TranslatorRosterTest::IdentifyTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::MakeConfigurationViewTest() { void TranslatorRosterTest::MakeConfigurationViewTest()
{
//create invalid rect - if it is valid after the //create invalid rect - if it is valid after the
//MakeConfigurationView call the test has succeded //MakeConfigurationView call the test has succeded
NextSubTest();
BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest"); BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest");
BRect extent(-1, -1, -1, -1); BRect extent(-1, -1, -1, -1);
//create config view //create config view
BView* view; BView *view = NULL;
translator_id* translators; translator_id *translators = NULL;
int32 num_translators; int32 num_translators = -1;
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
proster->GetAllTranslators(&translators, &num_translators); CPPUNIT_ASSERT(pDefRoster);
proster->MakeConfigurationView(translators[0], NULL, &view, &extent);
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->GetAllTranslators(&translators, &num_translators) == B_OK);
CPPUNIT_ASSERT(translators);
CPPUNIT_ASSERT(num_translators > 0);
// bad parameters
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->MakeConfigurationView(translators[0], NULL, &view, NULL) == B_BAD_VALUE);
CPPUNIT_ASSERT(
pDefRoster->MakeConfigurationView(translators[0], NULL, NULL, &extent) == B_BAD_VALUE);
CPPUNIT_ASSERT(
pDefRoster->MakeConfigurationView(translators[0], NULL, NULL, NULL) == B_BAD_VALUE);
// bad translator id
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->MakeConfigurationView(-1, NULL, &view, &extent) == B_NO_TRANSLATOR);
// should work
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->MakeConfigurationView(translators[0], NULL, &view, &extent) == B_OK);
// TODO: Add a test that uses a valid BMessage with actual settings in it
//check validity //check validity
CPPUNIT_ASSERT(extent.IsValid() == true); CPPUNIT_ASSERT(extent.IsValid() == true);
@@ -652,10 +781,11 @@ void TranslatorRosterTest::MakeConfigurationViewTest() {
* *
* @return B_OK if everything went ok, B_ERROR if not * @return B_OK if everything went ok, B_ERROR if not
*/ */
void TranslatorRosterTest::TranslateTest() { void TranslatorRosterTest::TranslateTest()
{
NextSubTest();
BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest"); BApplication app("application/x-vnd.OpenBeOS-translationkit_translatorrostertest");
//input //input
NextSubTest();
BFile input("../src/tests/kits/translation/data/images/image.jpg", B_READ_ONLY); BFile input("../src/tests/kits/translation/data/images/image.jpg", B_READ_ONLY);
CPPUNIT_ASSERT(input.InitCheck() == B_OK); CPPUNIT_ASSERT(input.InitCheck() == B_OK);
@@ -673,19 +803,20 @@ void TranslatorRosterTest::TranslateTest() {
//get default translators //get default translators
NextSubTest(); NextSubTest();
BTranslatorRoster *proster = BTranslatorRoster::Default(); BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(proster != NULL); CPPUNIT_ASSERT(pDefRoster != NULL);
//translate to generic //translate to generic
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->Translate(&input, NULL, NULL, &temp, B_TRANSLATOR_BITMAP) == B_OK); CPPUNIT_ASSERT(pDefRoster->Translate(&input, NULL, NULL, &temp, B_TRANSLATOR_BITMAP) == B_OK);
//translate to specific //translate to specific
NextSubTest(); NextSubTest();
CPPUNIT_ASSERT(proster->Translate(&temp, NULL, NULL, &output, B_TGA_FORMAT) == B_OK); CPPUNIT_ASSERT(pDefRoster->Translate(&temp, NULL, NULL, &output, B_TGA_FORMAT) == B_OK);
} }
int main() { int main()
{
//needed by MakeConfigurationView //needed by MakeConfigurationView
TranslatorRosterTest test; TranslatorRosterTest test;
test.InitializeTest(); test.InitializeTest();