added more test files, removed some duplicate code, added a few new tests
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2282 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -57,6 +57,74 @@ STXTTranslatorTest::tearDown()
|
|||||||
BTestCase::tearDown();
|
BTestCase::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CheckStyled(translator_info *pti)
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT(pti->type == B_STYLED_TEXT_FORMAT);
|
||||||
|
CPPUNIT_ASSERT(pti->translator != 0);
|
||||||
|
CPPUNIT_ASSERT(pti->group == B_TRANSLATOR_TEXT);
|
||||||
|
CPPUNIT_ASSERT(pti->quality == 0.5);
|
||||||
|
CPPUNIT_ASSERT(pti->capability == 0.5);
|
||||||
|
CPPUNIT_ASSERT(strcmp(pti->name, "Be styled text file") == 0);
|
||||||
|
CPPUNIT_ASSERT(strcmp(pti->MIME, "text/x-vnd.Be-stxt") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CheckPlain(translator_info *pti)
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT(pti->type == B_TRANSLATOR_TEXT);
|
||||||
|
CPPUNIT_ASSERT(pti->translator != 0);
|
||||||
|
CPPUNIT_ASSERT(pti->group == B_TRANSLATOR_TEXT);
|
||||||
|
CPPUNIT_ASSERT(pti->quality > 0.39 && pti->quality < 0.41);
|
||||||
|
CPPUNIT_ASSERT(pti->capability > 0.59 && pti->capability < 0.61);
|
||||||
|
CPPUNIT_ASSERT(strcmp(pti->name, "Plain text file") == 0);
|
||||||
|
CPPUNIT_ASSERT(strcmp(pti->MIME, "text/plain") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
IdentifyTests(STXTTranslatorTest *ptest, BTranslatorRoster *proster,
|
||||||
|
const char **paths, bool bplain)
|
||||||
|
{
|
||||||
|
translator_info ti;
|
||||||
|
printf(" [%d] ", (int) bplain);
|
||||||
|
|
||||||
|
for (int32 i = 0; i < sizeof(paths) / sizeof(const char *); i++) {
|
||||||
|
ptest->NextSubTest();
|
||||||
|
BFile file;
|
||||||
|
printf(" [%s] ", paths[i]);
|
||||||
|
CPPUNIT_ASSERT(file.SetTo(paths[i], B_READ_ONLY) == B_OK);
|
||||||
|
|
||||||
|
// Identify (output: B_TRANSLATOR_ANY_TYPE)
|
||||||
|
ptest->NextSubTest();
|
||||||
|
memset(&ti, 0, sizeof(translator_info));
|
||||||
|
CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti) == B_OK);
|
||||||
|
if (bplain)
|
||||||
|
CheckPlain(&ti);
|
||||||
|
else
|
||||||
|
CheckStyled(&ti);
|
||||||
|
|
||||||
|
// Identify (output: B_TRANSLATOR_TEXT)
|
||||||
|
ptest->NextSubTest();
|
||||||
|
memset(&ti, 0, sizeof(translator_info));
|
||||||
|
CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti, 0, NULL,
|
||||||
|
B_TRANSLATOR_TEXT) == B_OK);
|
||||||
|
if (bplain)
|
||||||
|
CheckPlain(&ti);
|
||||||
|
else
|
||||||
|
CheckStyled(&ti);
|
||||||
|
|
||||||
|
// Identify (output: B_STYLED_TEXT_FORMAT)
|
||||||
|
ptest->NextSubTest();
|
||||||
|
memset(&ti, 0, sizeof(translator_info));
|
||||||
|
CPPUNIT_ASSERT(proster->Identify(&file, NULL, &ti, 0, NULL,
|
||||||
|
B_STYLED_TEXT_FORMAT) == B_OK);
|
||||||
|
if (bplain)
|
||||||
|
CheckPlain(&ti);
|
||||||
|
else
|
||||||
|
CheckStyled(&ti);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
STXTTranslatorTest::IdentifyTest()
|
STXTTranslatorTest::IdentifyTest()
|
||||||
{
|
{
|
||||||
@@ -70,12 +138,6 @@ STXTTranslatorTest::IdentifyTest()
|
|||||||
BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
|
BFile wronginput("../src/tests/kits/translation/data/images/image.jpg",
|
||||||
B_READ_ONLY);
|
B_READ_ONLY);
|
||||||
CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
|
CPPUNIT_ASSERT(wronginput.InitCheck() == B_OK);
|
||||||
BFile sinput("../src/tests/kits/translation/data/styled_text.stxt",
|
|
||||||
B_READ_ONLY);
|
|
||||||
CPPUNIT_ASSERT(sinput.InitCheck() == B_OK);
|
|
||||||
BFile tinput("../src/tests/kits/translation/data/plain_text.txt",
|
|
||||||
B_READ_ONLY);
|
|
||||||
CPPUNIT_ASSERT(tinput.InitCheck() == B_OK);
|
|
||||||
|
|
||||||
// Identify (bad input, output types)
|
// Identify (bad input, output types)
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -93,87 +155,46 @@ STXTTranslatorTest::IdentifyTest()
|
|||||||
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
|
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
|
||||||
CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
|
CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
|
||||||
|
|
||||||
// Identify (input: styled output: B_TRANSLATOR_ANY_TYPE)
|
// Identify (wrong magic)
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
memset(&ti, 0, sizeof(translator_info));
|
memset(&ti, 0, sizeof(translator_info));
|
||||||
result = proster->Identify(&sinput, NULL, &ti);
|
BFile wrongmagic("../src/tests/kits/translation/data/text/wrong_magic.stxt",
|
||||||
CPPUNIT_ASSERT(result == B_OK);
|
B_READ_ONLY);
|
||||||
CPPUNIT_ASSERT(ti.type == B_STYLED_TEXT_FORMAT);
|
CPPUNIT_ASSERT(wrongmagic.InitCheck() == B_OK);
|
||||||
CPPUNIT_ASSERT(ti.translator != 0);
|
result = proster->Identify(&wrongmagic, NULL, &ti);
|
||||||
CPPUNIT_ASSERT(ti.group == B_TRANSLATOR_TEXT);
|
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
|
||||||
CPPUNIT_ASSERT(ti.quality == 0.5);
|
CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
|
||||||
CPPUNIT_ASSERT(ti.capability == 0.5);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.name, "Be styled text file") == 0);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.MIME, "text/x-vnd.Be-stxt") == 0);
|
|
||||||
|
|
||||||
// Identify (input: styled output: B_TRANSLATOR_TEXT)
|
// Identify (wrong version)
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
memset(&ti, 0, sizeof(translator_info));
|
memset(&ti, 0, sizeof(translator_info));
|
||||||
result = proster->Identify(&sinput, NULL, &ti, 0, NULL,
|
BFile wrongversion("../src/tests/kits/translation/data/text/wrong_version.stxt",
|
||||||
B_TRANSLATOR_TEXT);
|
B_READ_ONLY);
|
||||||
CPPUNIT_ASSERT(result == B_OK);
|
CPPUNIT_ASSERT(wrongversion.InitCheck() == B_OK);
|
||||||
CPPUNIT_ASSERT(ti.type == B_STYLED_TEXT_FORMAT);
|
result = proster->Identify(&wrongversion, NULL, &ti);
|
||||||
CPPUNIT_ASSERT(ti.translator != 0);
|
CPPUNIT_ASSERT(result == B_NO_TRANSLATOR);
|
||||||
CPPUNIT_ASSERT(ti.group == B_TRANSLATOR_TEXT);
|
CPPUNIT_ASSERT(ti.type == 0 && ti.translator == 0);
|
||||||
CPPUNIT_ASSERT(ti.quality == 0.5);
|
|
||||||
CPPUNIT_ASSERT(ti.capability == 0.5);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.name, "Be styled text file") == 0);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.MIME, "text/x-vnd.Be-stxt") == 0);
|
|
||||||
|
|
||||||
// Identify (input: styled output: B_STYLED_TEXT_FORMAT)
|
const char *aPlainFiles[] = {
|
||||||
NextSubTest();
|
"../src/tests/kits/translation/data/text/ascii.txt",
|
||||||
memset(&ti, 0, sizeof(translator_info));
|
"../src/tests/kits/translation/data/text/japanese.txt",
|
||||||
result = proster->Identify(&sinput, NULL, &ti, 0, NULL,
|
"../src/tests/kits/translation/data/text/multi_byte.txt",
|
||||||
B_STYLED_TEXT_FORMAT);
|
"../src/tests/kits/translation/data/text/one_length.txt",
|
||||||
CPPUNIT_ASSERT(result == B_OK);
|
"../src/tests/kits/translation/data/text/sentence.txt",
|
||||||
CPPUNIT_ASSERT(ti.type == B_STYLED_TEXT_FORMAT);
|
"../src/tests/kits/translation/data/text/symbols.txt",
|
||||||
CPPUNIT_ASSERT(ti.translator != 0);
|
"../src/tests/kits/translation/data/text/zero_length.txt",
|
||||||
CPPUNIT_ASSERT(ti.group == B_TRANSLATOR_TEXT);
|
};
|
||||||
CPPUNIT_ASSERT(ti.quality == 0.5);
|
const char *aStyledFiles[] = {
|
||||||
CPPUNIT_ASSERT(ti.capability == 0.5);
|
"../src/tests/kits/translation/data/text/ascii.stxt",
|
||||||
CPPUNIT_ASSERT(strcmp(ti.name, "Be styled text file") == 0);
|
"../src/tests/kits/translation/data/text/japanese.stxt",
|
||||||
CPPUNIT_ASSERT(strcmp(ti.MIME, "text/x-vnd.Be-stxt") == 0);
|
"../src/tests/kits/translation/data/text/multi_byte.stxt",
|
||||||
|
"../src/tests/kits/translation/data/text/one_length.stxt",
|
||||||
// Identify (input: plain output: B_TRANSLATOR_ANY_TYPE)
|
"../src/tests/kits/translation/data/text/sentence.stxt",
|
||||||
NextSubTest();
|
"../src/tests/kits/translation/data/text/symbols.stxt",
|
||||||
memset(&ti, 0, sizeof(translator_info));
|
"../src/tests/kits/translation/data/text/zero_length.stxt",
|
||||||
result = proster->Identify(&tinput, NULL, &ti);
|
};
|
||||||
CPPUNIT_ASSERT(result == B_OK);
|
IdentifyTests(this, proster, aPlainFiles, true);
|
||||||
CPPUNIT_ASSERT(ti.type == B_TRANSLATOR_TEXT);
|
IdentifyTests(this, proster, aStyledFiles, false);
|
||||||
CPPUNIT_ASSERT(ti.translator != 0);
|
|
||||||
CPPUNIT_ASSERT(ti.group == B_TRANSLATOR_TEXT);
|
|
||||||
CPPUNIT_ASSERT(ti.quality > 0.39 && ti.quality < 0.41);
|
|
||||||
CPPUNIT_ASSERT(ti.capability > 0.59 && ti.capability < 0.61);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.name, "Plain text file") == 0);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.MIME, "text/plain") == 0);
|
|
||||||
|
|
||||||
// Identify (input: plain output: B_TRANSLATOR_TEXT)
|
|
||||||
NextSubTest();
|
|
||||||
memset(&ti, 0, sizeof(translator_info));
|
|
||||||
result = proster->Identify(&tinput, NULL, &ti, 0, NULL,
|
|
||||||
B_TRANSLATOR_TEXT);
|
|
||||||
CPPUNIT_ASSERT(result == B_OK);
|
|
||||||
CPPUNIT_ASSERT(ti.type == B_TRANSLATOR_TEXT);
|
|
||||||
CPPUNIT_ASSERT(ti.translator != 0);
|
|
||||||
CPPUNIT_ASSERT(ti.group == B_TRANSLATOR_TEXT);
|
|
||||||
CPPUNIT_ASSERT(ti.quality > 0.39 && ti.quality < 0.41);
|
|
||||||
CPPUNIT_ASSERT(ti.capability > 0.59 && ti.capability < 0.61);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.name, "Plain text file") == 0);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.MIME, "text/plain") == 0);
|
|
||||||
|
|
||||||
// Identify (input: plain output: B_STYLED_TEXT_FORMAT)
|
|
||||||
NextSubTest();
|
|
||||||
memset(&ti, 0, sizeof(translator_info));
|
|
||||||
result = proster->Identify(&tinput, NULL, &ti, 0, NULL,
|
|
||||||
B_STYLED_TEXT_FORMAT);
|
|
||||||
CPPUNIT_ASSERT(result == B_OK);
|
|
||||||
CPPUNIT_ASSERT(ti.type == B_TRANSLATOR_TEXT);
|
|
||||||
CPPUNIT_ASSERT(ti.translator != 0);
|
|
||||||
CPPUNIT_ASSERT(ti.group == B_TRANSLATOR_TEXT);
|
|
||||||
CPPUNIT_ASSERT(ti.quality > 0.39 && ti.quality < 0.41);
|
|
||||||
CPPUNIT_ASSERT(ti.capability > 0.59 && ti.capability < 0.61);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.name, "Plain text file") == 0);
|
|
||||||
CPPUNIT_ASSERT(strcmp(ti.MIME, "text/plain") == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user