added a few little tests, made style changes in order to fit on printed pages more easily, added some TODOs

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2089 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber 2002-11-26 04:22:33 +00:00
parent 98138634aa
commit e1403feb25

View File

@ -46,37 +46,88 @@
/**
* TestCase constructor - no work
*/
TranslatorRosterTest::TranslatorRosterTest(std::string name) : BTestCase(name) {
TranslatorRosterTest::TranslatorRosterTest(std::string name)
: BTestCase(name)
{
}
/**
* Default destructor - no work
*/
TranslatorRosterTest::~TranslatorRosterTest() {
TranslatorRosterTest::~TranslatorRosterTest()
{
}
CppUnit::Test *
TranslatorRosterTest::Suite() {
TranslatorRosterTest::Suite()
{
/* create our suite */
CppUnit::TestSuite *suite = new CppUnit::TestSuite("TranslatorRoster");
/* add suckers */
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Initialize Test", &TranslatorRosterTest::InitializeTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Constructor Test", &TranslatorRosterTest::ConstructorTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Default Test", &TranslatorRosterTest::DefaultTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Instantiate Test", &TranslatorRosterTest::InstantiateTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Version Test", &TranslatorRosterTest::VersionTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::AddTranslators Test", &TranslatorRosterTest::AddTranslatorsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Archive Test", &TranslatorRosterTest::ArchiveTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::GetAllTranslators Test", &TranslatorRosterTest::GetAllTranslatorsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::GetConfigurationMessage Test", &TranslatorRosterTest::GetConfigurationMessageTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::GetInputFormats Test", &TranslatorRosterTest::GetInputFormatsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::GetOutputFormats Test", &TranslatorRosterTest::GetOutputFormatsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::GetTranslatorInfo Test", &TranslatorRosterTest::GetTranslatorInfoTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::GetTranslators Test", &TranslatorRosterTest::GetTranslatorsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Identify Test", &TranslatorRosterTest::IdentifyTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::MakeConfigurationView Test", &TranslatorRosterTest::MakeConfigurationViewTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>("TranslatorRosterTest::Translate Test", &TranslatorRosterTest::TranslateTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Initialize Test",
&TranslatorRosterTest::InitializeTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Constructor Test",
&TranslatorRosterTest::ConstructorTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Default Test",
&TranslatorRosterTest::DefaultTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Instantiate Test",
&TranslatorRosterTest::InstantiateTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Version Test",
&TranslatorRosterTest::VersionTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::AddTranslators Test",
&TranslatorRosterTest::AddTranslatorsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Archive Test",
&TranslatorRosterTest::ArchiveTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::GetAllTranslators Test",
&TranslatorRosterTest::GetAllTranslatorsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::GetConfigurationMessage Test",
&TranslatorRosterTest::GetConfigurationMessageTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::GetInputFormats Test",
&TranslatorRosterTest::GetInputFormatsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::GetOutputFormats Test",
&TranslatorRosterTest::GetOutputFormatsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::GetTranslatorInfo Test",
&TranslatorRosterTest::GetTranslatorInfoTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::GetTranslators Test",
&TranslatorRosterTest::GetTranslatorsTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Identify Test",
&TranslatorRosterTest::IdentifyTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::MakeConfigurationView Test",
&TranslatorRosterTest::MakeConfigurationViewTest));
suite->addTest(new CppUnit::TestCaller<TranslatorRosterTest>(
"TranslatorRosterTest::Translate Test",
&TranslatorRosterTest::TranslateTest));
return suite;
}
@ -84,24 +135,29 @@ TranslatorRosterTest::Suite() {
/**
* Tries to aquire the default roster
*/
void TranslatorRosterTest::InitializeTest() {
void
TranslatorRosterTest::InitializeTest()
{
//aquire default roster
NextSubTest();
BTranslatorRoster *proster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(proster != NULL);
CPPUNIT_ASSERT(proster);
//print version information
int32 outCurVersion;
int32 outMinVersion;
long inAppVersion;
const char *info = proster->Version(&outCurVersion, &outMinVersion, inAppVersion);
const char *info = proster->Version(&outCurVersion, &outMinVersion,
inAppVersion);
printf("Default TranslatorRoster aquired. Version: %s\n", info);
}
/**
* Construct proster using different kinds of constructors
*/
void TranslatorRosterTest::ConstructorTest() {
void
TranslatorRosterTest::ConstructorTest()
{
//shared instance of TranslatorRoster
BTranslatorRoster *proster;
@ -116,7 +172,8 @@ void TranslatorRosterTest::ConstructorTest() {
//Create TranslatorRoster using BMessage constructor
NextSubTest();
BMessage translator_message;
translator_message.AddString("be:translator_path", "/boot/home/config/add-ons/Translators");
translator_message.AddString("be:translator_path",
"/boot/home/config/add-ons/Translators");
proster = new BTranslatorRoster(&translator_message);
CPPUNIT_ASSERT(proster != NULL);
@ -184,7 +241,9 @@ void TranslatorRosterTest::ConstructorTest() {
* Tests:
* BTranslatorRoster *Default()
*/
void TranslatorRosterTest::DefaultTest() {
void
TranslatorRosterTest::DefaultTest()
{
NextSubTest();
BTranslatorRoster *proster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(proster != NULL);
@ -210,11 +269,11 @@ void TranslatorRosterTest::DefaultTest() {
NextSubTest();
translator_id *pids = NULL;
int32 ncount = -1;
status_t result = proster->GetAllTranslators(&pids, &ncount);
CPPUNIT_ASSERT(proster->GetAllTranslators(&pids, &ncount) == B_OK);
CPPUNIT_ASSERT(pids);
CPPUNIT_ASSERT(ncount > 0);
delete[] pids;
pids = NULL;
CPPUNIT_ASSERT(ncount > 0);
// Delete again to be sure that it still won't blow up
NextSubTest();
@ -229,7 +288,9 @@ void TranslatorRosterTest::DefaultTest() {
* @return B_OK if everything went ok, B_ERROR if not
*/
// ArchiveTest() also tests BTranslatorRoster::Instantiate()
void TranslatorRosterTest::InstantiateTest() {
void
TranslatorRosterTest::InstantiateTest()
{
//shared instance of TranslatorRoster
BTranslatorRoster* proster = NULL;
BMessage bmsg;
@ -242,6 +303,9 @@ void TranslatorRosterTest::InstantiateTest() {
delete proster;
proster = NULL;
// TODO: Add test where the BMessage is valid, but does not contain
// TODO: any translators
// BMessage containing a single Translator to load
NextSubTest();
status_t result;
@ -262,7 +326,8 @@ void TranslatorRosterTest::InstantiateTest() {
CPPUNIT_ASSERT(ncount == 1);
const char *strName = NULL, *strInfo = NULL;
int32 nversion = -1;
result = proster->GetTranslatorInfo(pids[0], &strName, &strInfo, &nversion);
result = proster->GetTranslatorInfo(pids[0], &strName, &strInfo,
&nversion);
CPPUNIT_ASSERT(result == B_OK);
CPPUNIT_ASSERT(strName);
CPPUNIT_ASSERT(strInfo);
@ -290,16 +355,19 @@ void TranslatorRosterTest::InstantiateTest() {
/**
* Tests:
* const char *Version(int32 *outCurVersion, int32 *outMinVersion, int32 *inAppVersion = B_TRANSLATION_CURRENT_VERSION)
* const char *Version(int32 *outCurVersion, int32 *outMinVersion,
* int32 *inAppVersion = B_TRANSLATION_CURRENT_VERSION)
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::VersionTest() {
void
TranslatorRosterTest::VersionTest()
{
NextSubTest();
int32 outCurVersion = 0;
int32 outMinVersion = 0;
const char* info = NULL;
NextSubTest();
info = BTranslatorRoster::Version(&outCurVersion, &outMinVersion);
CPPUNIT_ASSERT(info != NULL);
CPPUNIT_ASSERT(outCurVersion > 0);
@ -311,7 +379,8 @@ void TranslatorRosterTest::VersionTest() {
// ensure that they have the same translators and the
// same number of translators
//
void CompareWithDefault(BTranslatorRoster *proster)
void
CompareWithDefault(BTranslatorRoster *proster)
{
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
@ -322,19 +391,24 @@ void CompareWithDefault(BTranslatorRoster *proster)
CPPUNIT_ASSERT(proster->GetAllTranslators(&pInstids, &instcount) == B_OK);
CPPUNIT_ASSERT(pInstids);
CPPUNIT_ASSERT(instcount > 0);
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&pDefids, &defcount) == B_OK);
CPPUNIT_ASSERT(pDefids);
CPPUNIT_ASSERT(defcount > 0);
CPPUNIT_ASSERT(defcount == instcount);
// make sure that every translator that is in the default
// BTranslatorRoster is in proster, once and only once
for (int32 i = 0; i < defcount; i++) {
int32 matches;
matches = 0;
CPPUNIT_ASSERT(
pDefRoster->GetTranslatorInfo(pDefids[i], &strDefName, &strDummy, &ndummy) == B_OK);
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(proster->GetTranslatorInfo(pInstids[k],
&strInstName, &strDummy, &ndummy) == B_OK);
CPPUNIT_ASSERT(strInstName);
if (strcmp(strDefName, strInstName) == 0)
@ -348,33 +422,31 @@ void CompareWithDefault(BTranslatorRoster *proster)
delete[] pDefids;
pDefids = NULL;
}
/**
* Tests:
* virtual status_t AddTranslators(const char *load_path = NULL)
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::AddTranslatorsTest() {
void
TranslatorRosterTest::AddTranslatorsTest()
{
//create basic translatorroster
NextSubTest();
BTranslatorRoster* proster = new BTranslatorRoster();
//load wrong path (generate parse error)
/*
CPPUNIT_ASSERT(translator_roster->AddTranslators("?") == B_BAD_VALUE);
*/
//load correct path
CPPUNIT_ASSERT(
proster->AddTranslators("/boot/home/config/add-ons/Translators/:/system/add-ons/Translators/") == B_OK);
CPPUNIT_ASSERT(proster);
CPPUNIT_ASSERT(proster->AddTranslators(
"/boot/home/config/add-ons/Translators/:/system/add-ons/Translators/") == B_OK);
NextSubTest();
int32 instcount = 0;
translator_id* translators = NULL;
proster->GetAllTranslators(&translators, &instcount);
CPPUNIT_ASSERT(translators);
CPPUNIT_ASSERT(instcount > 0);
// TODO: count the number of files in all of the directories specified above
// TODO: and make certain that it matches instcount
// TODO: count the number of files in all of the directories specified
// TODO: above and make certain that it matches instcount
delete[] translators;
translators = NULL;
@ -398,13 +470,14 @@ void TranslatorRosterTest::AddTranslatorsTest() {
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::ArchiveTest() {
void
TranslatorRosterTest::ArchiveTest()
{
NextSubTest();
//archive default, and count entries (must be more than 1!)
BMessage translator_message;
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
NextSubTest();
CPPUNIT_ASSERT(pDefRoster != NULL);
CPPUNIT_ASSERT(pDefRoster);
CPPUNIT_ASSERT(pDefRoster->Archive(&translator_message) == B_OK);
// make sure instantiate makes an "exact" copy of the default translator
@ -412,7 +485,7 @@ void TranslatorRosterTest::ArchiveTest() {
BTranslatorRoster *proster = NULL;
proster = dynamic_cast<BTranslatorRoster *>
(BTranslatorRoster::Instantiate(&translator_message));
CPPUNIT_ASSERT(proster != NULL);
CPPUNIT_ASSERT(proster);
// make sure that every translator in the pDefRoster is in
// proster, and make certain that it is in there ONLY ONCE
@ -428,13 +501,13 @@ void TranslatorRosterTest::ArchiveTest() {
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::GetAllTranslatorsTest() {
int32 nloaded = 42;
translator_id* pids = NULL;
void
TranslatorRosterTest::GetAllTranslatorsTest()
{
// bad parameters
NextSubTest();
int32 nloaded = 42;
translator_id* pids = NULL;
BTranslatorRoster roster;
CPPUNIT_ASSERT(roster.GetAllTranslators(NULL, &nloaded) == B_BAD_VALUE);
CPPUNIT_ASSERT(nloaded == 42);
@ -514,64 +587,90 @@ void TranslatorRosterTest::GetAllTranslatorsTest() {
/**
* Tests:
* virtual status_t GetConfigurationMessage(translator_id forTranslator, BMessage *ioExtension)
* virtual status_t GetConfigurationMessage(translator_id forTranslator,
* BMessage *ioExtension)
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::GetConfigurationMessageTest()
void
TranslatorRosterTest::GetConfigurationMessageTest()
{
NextSubTest();
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
NextSubTest();
//get id for a translator (just use the first one)
int32 num_translators = -1;
translator_id* translators = NULL;
pDefRoster->GetAllTranslators(&translators, &num_translators);
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&translators,
&num_translators) == B_OK);
CPPUNIT_ASSERT(translators);
CPPUNIT_ASSERT(num_translators > 0);
NextSubTest();
translator_id translatorid = translators[0];
delete[] translators;
translators = NULL;
//get conf for invalid translator
BMessage translator_message;
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(-1, &translator_message) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(-1,
&translator_message) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(translator_message.IsEmpty());
//get conf for invalid ioExtension (BMessage)
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(translatorid, NULL) == B_BAD_VALUE);
CPPUNIT_ASSERT(
pDefRoster->GetConfigurationMessage(translatorid, NULL) == B_BAD_VALUE);
//get config for actual translator
NextSubTest();
CPPUNIT_ASSERT(translator_message.MakeEmpty() == B_OK);
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(translatorid, &translator_message) == B_OK);
CPPUNIT_ASSERT(pDefRoster->GetConfigurationMessage(translatorid,
&translator_message) == B_OK);
}
// Code used by both GetInputFormatsTest and GetOutputFormatsTest
void GetInputOutputFormatsTest(TranslatorRosterTest *prt, bool binput)
void
GetInputOutputFormatsTest(TranslatorRosterTest *prt, bool binput)
{
prt->NextSubTest();
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
prt->NextSubTest();
translator_id* translators = NULL;
int32 num_translators = -1;
pDefRoster->GetAllTranslators(&translators, &num_translators);
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&translators,
&num_translators) == B_OK);
CPPUNIT_ASSERT(translators);
CPPUNIT_ASSERT(num_translators > 0);
// Run get Input/output format test on each translator
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);
result = pDefRoster->GetInputFormats(translators[i], &fmts,
&num_fmts);
else
result = pDefRoster->GetOutputFormats(translators[i], &fmts, &num_fmts);
result = pDefRoster->GetOutputFormats(translators[i], &fmts,
&num_fmts);
CPPUNIT_ASSERT(result == B_OK);
// test input/output formats
CPPUNIT_ASSERT(num_fmts >= 0);
CPPUNIT_ASSERT(num_fmts == 0 || fmts);
for (int32 k = 0; k < num_fmts; k++) {
CPPUNIT_ASSERT(fmts[k].type);
CPPUNIT_ASSERT(fmts[k].group);
CPPUNIT_ASSERT(fmts[k].quality >= 0 && fmts[k].quality <= 1);
CPPUNIT_ASSERT(fmts[k].capability >= 0 && fmts[k].capability <= 1);
CPPUNIT_ASSERT(strlen(fmts[k].MIME) >= 0);
CPPUNIT_ASSERT(strlen(fmts[k].name) > 0);
}
}
delete[] translators;
translators = NULL;
@ -579,33 +678,39 @@ void GetInputOutputFormatsTest(TranslatorRosterTest *prt, bool binput)
/**
* Tests:
* virtual status_t GetInputFormats(translator_id forTranslator, const translation_format **outFormats, int32 *outNumFormats)
* virtual status_t GetInputFormats(translator_id forTranslator,
* const translation_format **outFormats, int32 *outNumFormats)
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::GetInputFormatsTest()
void
TranslatorRosterTest::GetInputFormatsTest()
{
GetInputOutputFormatsTest(this, true);
}
/**
* Tests:
* virtual status_t GetOutputFormats(translator_id forTranslator, const translation_format **outFormats, int32 *outNumFormats)
* virtual status_t GetOutputFormats(translator_id forTranslator,
* const translation_format **outFormats, int32 *outNumFormats)
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::GetOutputFormatsTest()
void
TranslatorRosterTest::GetOutputFormatsTest()
{
GetInputOutputFormatsTest(this, false);
}
/**
* Tests:
* virtual status_t GetTranslatorInfo(translator_id forTranslator, const char **outName, const char **outInfo, int32 *outVersion)
* virtual status_t GetTranslatorInfo(translator_id forTranslator,
* const char **outName, const char **outInfo, int32 *outVersion)
*
* @return B_OK if everything went ok, B_ERROR if not
*/
void TranslatorRosterTest::GetTranslatorInfoTest()
void
TranslatorRosterTest::GetTranslatorInfoTest()
{
NextSubTest();
translator_id* translators = NULL;
@ -613,17 +718,22 @@ void TranslatorRosterTest::GetTranslatorInfoTest()
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
CPPUNIT_ASSERT(pDefRoster);
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&translators, &num_translators) == B_OK);
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->GetAllTranslators(&translators,
&num_translators) == B_OK);
CPPUNIT_ASSERT(translators);
CPPUNIT_ASSERT(num_translators > 0);
for (int32 i = 0; i < num_translators; i++) {
const char *outName = NULL;
const char *outInfo = NULL;
int32 outVersion = -1;
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->GetTranslatorInfo(-1, &outName, &outInfo, &outVersion) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(
pDefRoster->GetTranslatorInfo(translators[i], &outName, &outInfo, &outVersion) == B_OK);
CPPUNIT_ASSERT(pDefRoster->GetTranslatorInfo(-1, &outName, &outInfo,
&outVersion) == B_NO_TRANSLATOR);
// TODO: Add B_BAD_VALUE cases
CPPUNIT_ASSERT(pDefRoster->GetTranslatorInfo(translators[i],
&outName, &outInfo, &outVersion) == B_OK);
CPPUNIT_ASSERT(outName);
}
delete[] translators;
@ -632,22 +742,28 @@ void TranslatorRosterTest::GetTranslatorInfoTest()
/**
* Tests:
* virtual status_t GetTranslators(BPositionIO *inSource, BMessage *ioExtension, translator_info **outInfo, int32 *outNumInfo, uint32 inHintType = 0, const char *inHintMIME = NULL, uint32 inWantType = 0)
* virtual status_t GetTranslators(BPositionIO *inSource,
* BMessage *ioExtension, translator_info **outInfo, int32 *outNumInfo,
* uint32 inHintType = 0, const char *inHintMIME = NULL, uint32 inWantType = 0)
*
* @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
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);
CPPUNIT_ASSERT(image.InitCheck() == B_OK);
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);
NextSubTest();
translator_info* info = NULL;
int32 outCount = -1;
BTranslatorRoster *pDefRoster = BTranslatorRoster::Default();
@ -655,23 +771,26 @@ void TranslatorRosterTest::GetTranslatorsTest()
//get translator, specifying wrong args
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->GetTranslators(&garbled, NULL, NULL, &outCount) == B_BAD_VALUE);
CPPUNIT_ASSERT(pDefRoster->GetTranslators(&garbled, NULL, NULL,
&outCount) == B_BAD_VALUE);
//get translator, specifying wrong args
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->GetTranslators(&garbled, NULL, &info, NULL) == B_BAD_VALUE);
CPPUNIT_ASSERT(pDefRoster->GetTranslators(&garbled, NULL, &info,
NULL) == B_BAD_VALUE);
//get translator for garbled data
NextSubTest();
CPPUNIT_ASSERT(
pDefRoster->GetTranslators(&garbled, NULL, &info, &outCount) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(pDefRoster->GetTranslators(&garbled, NULL, &info,
&outCount) == B_NO_TRANSLATOR);
//get translator for image
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->GetTranslators(&image, NULL, &info, &outCount) == B_OK);
CPPUNIT_ASSERT(pDefRoster->GetTranslators(&image, NULL, &info,
&outCount) == B_OK);
CPPUNIT_ASSERT(outCount > 0);
// TODO: Add a case where I specify a valid BMessage
delete[] info;
info = NULL;
@ -679,20 +798,25 @@ void TranslatorRosterTest::GetTranslatorsTest()
/**
* Tests:
* virtual status_t Identify(BPositionIO *inSource, BMessage *ioExtension, translator_info *outInfo, uint32 inHintType = 0, const char *inHintMIME = NULL, uint32 inWantType = 0)
* virtual status_t Identify(BPositionIO *inSource, BMessage *ioExtension,
* translator_info *outInfo, uint32 inHintType = 0,
* const char *inHintMIME = NULL, uint32 inWantType = 0)
*
* @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
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);
CPPUNIT_ASSERT(image.InitCheck() == B_OK);
//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);
NextSubTest();
@ -707,7 +831,8 @@ void TranslatorRosterTest::IdentifyTest()
//get translator for garbled data
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->Identify(&garbled, NULL, pinfo) == B_NO_TRANSLATOR);
CPPUNIT_ASSERT(pDefRoster->Identify(&garbled, NULL,
pinfo) == B_NO_TRANSLATOR);
//get translator for image
NextSubTest();
@ -716,22 +841,28 @@ void TranslatorRosterTest::IdentifyTest()
memset(pinfo, 0, sizeof(pinfo));
CPPUNIT_ASSERT(pDefRoster->Identify(&image, NULL, pinfo) == B_OK);
// TODO: Add a test where I actually use pinfo and a BMessage
// TODO: and check their contents
delete pinfo;
pinfo = NULL;
}
/**
* Tests:
* virtual status_t MakeConfigurationView(translator_id forTranslator, BMessage *ioExtension, BView **outView, BRect *outExtent)
* virtual status_t MakeConfigurationView(translator_id forTranslator,
* BMessage *ioExtension, BView **outView, BRect *outExtent)
*
* @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
//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);
//create config view
BView *view = NULL;
@ -748,26 +879,25 @@ void TranslatorRosterTest::MakeConfigurationViewTest()
// 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);
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);
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
CPPUNIT_ASSERT(pDefRoster->MakeConfigurationView(translators[0], NULL,
&view, &extent) == B_OK);
CPPUNIT_ASSERT(extent.IsValid() == true);
// TODO: Add a test that uses a valid BMessage with actual settings in it
//clean up after ourselves
delete[] translators;
@ -776,17 +906,26 @@ void TranslatorRosterTest::MakeConfigurationViewTest()
/**
* Tests:
* virtual status_t Translate(BPositionIO *inSource, const translator_info *inInfo, BMessage *ioExtension, BPositionIO *outDestination, uint32 inWantOutType, uint32 inHintType = 0, const char *inHintMIME = NULL)
* virtual status_t Translate(translator_id inTranslator, BPositionIO *inSource, BMessage *ioExtension, BPositionIO *outDestination, uint32 inWantOutType)
* virtual status_t Translate(BPositionIO *inSource,
* const translator_info *inInfo, BMessage *ioExtension,
* BPositionIO *outDestination, uint32 inWantOutType,
* uint32 inHintType = 0, const char *inHintMIME = NULL)
*
* virtual status_t Translate(translator_id inTranslator,
* BPositionIO *inSource, BMessage *ioExtension,
* BPositionIO *outDestination, uint32 inWantOutType)
*
* @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
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);
//temp file for generic format
@ -808,14 +947,20 @@ void TranslatorRosterTest::TranslateTest()
//translate to generic
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->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
NextSubTest();
CPPUNIT_ASSERT(pDefRoster->Translate(&temp, NULL, NULL, &output, B_TGA_FORMAT) == B_OK);
CPPUNIT_ASSERT(pDefRoster->Translate(&temp, NULL, NULL, &output,
B_TGA_FORMAT) == B_OK);
// TODO: add Translate using ioExtension BMessage and whatever
// TODO: the other NULL parameter is
}
int main()
int
main()
{
//needed by MakeConfigurationView
TranslatorRosterTest test;
@ -826,4 +971,6 @@ int main()
test.VersionTest();
test.AddTranslatorsTest();
test.ArchiveTest();
return 0;
}