+ Updated InstalledTypesTest() to recheck GetInstalledTypes()
and friends after installing and deleting from the database. + Updated database dir constant per the recent mime migration git-svn-id: file:///srv/svn/repos/haiku/trunk/current@859 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,7 +20,7 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Mime.h>
|
#include <Mime.h>
|
||||||
#if !TEST_R5
|
#if !TEST_R5
|
||||||
#include <MimeDatabase.h>
|
#include <mime/database_support.h>
|
||||||
#endif
|
#endif
|
||||||
#include <MimeTypeTest.h>
|
#include <MimeTypeTest.h>
|
||||||
#include <Path.h> // Only needed for entry_ref dumps
|
#include <Path.h> // Only needed for entry_ref dumps
|
||||||
@@ -38,7 +38,7 @@ static const char *R5DatabaseDir = "/boot/home/config/settings/beos_mime";
|
|||||||
#if TEST_R5
|
#if TEST_R5
|
||||||
static std::string mimeDatabaseDir = R5DatabaseDir;
|
static std::string mimeDatabaseDir = R5DatabaseDir;
|
||||||
#else
|
#else
|
||||||
static std::string mimeDatabaseDir = BPrivate::MimeDatabase::kDefaultDatabaseDir;
|
static std::string mimeDatabaseDir = BPrivate::Storage::Mime::kDatabaseDir;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// MIME Test Types
|
// MIME Test Types
|
||||||
@@ -1606,7 +1606,82 @@ bool isMIMESupertype(const char *type) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
VerifyInstalledTypes() {
|
||||||
|
BMessage msg;
|
||||||
|
|
||||||
|
// Get the list of installed types
|
||||||
|
CHK(BMimeType::GetInstalledTypes(&msg) == B_OK);
|
||||||
|
|
||||||
|
// Add all the type strings to a std::set
|
||||||
|
std::set<std::string> typeSet;
|
||||||
|
SetAdapter typeAdapter(typeSet);
|
||||||
|
FillWithMimeTypes(typeAdapter, msg, "types");
|
||||||
|
|
||||||
|
// Manually verify that the set of types returned by GetInstalledTypes()
|
||||||
|
// and the types present in the database are exactly the same (ignoring
|
||||||
|
// any files with names made of invalid characters, in case some bozo
|
||||||
|
// manually added such a file :-)
|
||||||
|
BDirectory rootDir(mimeDatabaseDir.c_str());
|
||||||
|
BEntry superEntry;
|
||||||
|
CHK(rootDir.InitCheck() == B_OK);
|
||||||
|
rootDir.Rewind();
|
||||||
|
while (true) {
|
||||||
|
status_t err = rootDir.GetNextEntry(&superEntry);
|
||||||
|
if (err == B_ENTRY_NOT_FOUND)
|
||||||
|
break; // End of directory listing
|
||||||
|
|
||||||
|
CHK(!err); // Any other error is unacceptable :-)
|
||||||
|
|
||||||
|
// Get the leaf name
|
||||||
|
char superLeafMixed[B_PATH_NAME_LENGTH+1];
|
||||||
|
CHK(superEntry.GetName(superLeafMixed) == B_OK);
|
||||||
|
std::string superLeaf;
|
||||||
|
to_lower(superLeafMixed, superLeaf);
|
||||||
|
|
||||||
|
// We're only interested in directories, as they map to
|
||||||
|
// supertypes (and since they map thusly, they must also
|
||||||
|
// be valid MIME strings)
|
||||||
|
if (superEntry.IsDirectory() && BMimeType::IsValid(superLeaf.c_str())) {
|
||||||
|
// First, find and remove the supertype from our set
|
||||||
|
CHK(typeSet.find(superLeaf.c_str()) != typeSet.end());
|
||||||
|
typeSet.erase(superLeaf.c_str());
|
||||||
|
|
||||||
|
// Second, iterate through all the entries in the directory.
|
||||||
|
// If the entry designates a valid MIME string, find it
|
||||||
|
// in the set and remove it.
|
||||||
|
BDirectory superDir(&superEntry);
|
||||||
|
BEntry subEntry;
|
||||||
|
CHK(superDir.InitCheck() == B_OK);
|
||||||
|
superDir.Rewind();
|
||||||
|
while (true) {
|
||||||
|
status_t err = superDir.GetNextEntry(&subEntry);
|
||||||
|
if (err == B_ENTRY_NOT_FOUND)
|
||||||
|
break; // End of directory listing
|
||||||
|
|
||||||
|
CHK(!err); // Any other error is unacceptable :-)
|
||||||
|
|
||||||
|
// Get the leaf name
|
||||||
|
char subLeafMixed[B_PATH_NAME_LENGTH+1];
|
||||||
|
CHK(subEntry.GetName(subLeafMixed) == B_OK);
|
||||||
|
std::string subLeaf;
|
||||||
|
to_lower(subLeafMixed, subLeaf);
|
||||||
|
|
||||||
|
// Verify it's a valid mime string. If so, find and remove from our set
|
||||||
|
std::string subType = superLeaf + "/" + subLeaf;
|
||||||
|
if (BMimeType::IsValid(subType.c_str())) {
|
||||||
|
CHK(typeSet.find(subType.c_str()) != typeSet.end());
|
||||||
|
typeSet.erase(subType.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// At this point our set should be empty :-) If it's not, you might check
|
||||||
|
// that you haven't added any superfluous files to your MIME database (like
|
||||||
|
// a __mime_table backup, for instance).
|
||||||
|
CHK(typeSet.size() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MimeTypeTest::InstalledTypesTest() {
|
MimeTypeTest::InstalledTypesTest() {
|
||||||
@@ -1615,21 +1690,22 @@ MimeTypeTest::InstalledTypesTest() {
|
|||||||
BMessage msg;
|
BMessage msg;
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
#if !TEST_R5
|
#if !TEST_R5
|
||||||
CHK(RES(BMimeType::GetInstalledTypes(NULL)) != B_OK); // R5 == CRASH!!!
|
CHK(BMimeType::GetInstalledTypes(NULL) != B_OK); // R5 == CRASH!!!, OBOS == B_BAD_VALUE
|
||||||
#endif
|
#endif
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
#if !TEST_R5
|
#if !TEST_R5
|
||||||
CHK(RES(BMimeType::GetInstalledTypes("text", NULL)) != B_OK); // R5 == CRASH!!!
|
CHK(BMimeType::GetInstalledTypes("text", NULL) != B_OK); // R5 == CRASH!!!, OBOS == B_BAD_VALUE
|
||||||
#endif
|
#endif
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
CHK(BMimeType::GetInstalledTypes(NULL, &msg) == B_OK); // Same as GetInstalledTypes(&msg)
|
CHK(BMimeType::GetInstalledTypes(NULL, &msg) == B_OK); // Same as GetInstalledTypes(&msg)
|
||||||
|
// msg.PrintToStream();
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
#if !TEST_R5
|
#if !TEST_R5
|
||||||
CHK(RES(BMimeType::GetInstalledTypes(NULL, NULL)) != B_OK); // R5 == CRASH!!!
|
CHK(BMimeType::GetInstalledTypes(NULL, NULL) != B_OK); // R5 == CRASH!!!, OBOS == B_BAD_VALUE
|
||||||
#endif
|
#endif
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
#if !TEST_R5
|
#if !TEST_R5
|
||||||
CHK(RES(BMimeType::GetInstalledSupertypes(NULL)) != B_OK); // R5 == CRASH!!!
|
CHK(BMimeType::GetInstalledSupertypes(NULL) != B_OK); // R5 == CRASH!!!, OBOS == B_BAD_VALUE
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// Invalid supertype param to GetInstalledTypes(char *super, BMessage*)
|
// Invalid supertype param to GetInstalledTypes(char *super, BMessage*)
|
||||||
@@ -1647,79 +1723,20 @@ MimeTypeTest::InstalledTypesTest() {
|
|||||||
// the actual database directory listings and verifies they're identical.
|
// the actual database directory listings and verifies they're identical.
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
{
|
{
|
||||||
BMessage msg;
|
VerifyInstalledTypes();
|
||||||
|
BMimeType mime(testTypeApp1);
|
||||||
// Get the list of installed types
|
CHK(mime.InitCheck() == B_OK);
|
||||||
CHK(BMimeType::GetInstalledTypes(&msg) == B_OK);
|
if (mime.IsInstalled()) {
|
||||||
|
CHK(mime.Delete() == B_OK);
|
||||||
// Add all the type strings to a std::set
|
VerifyInstalledTypes();
|
||||||
std::set<std::string> typeSet;
|
CHK(mime.Install() == B_OK);
|
||||||
SetAdapter typeAdapter(typeSet);
|
VerifyInstalledTypes();
|
||||||
FillWithMimeTypes(typeAdapter, msg, "types");
|
} else {
|
||||||
|
CHK(mime.Install() == B_OK);
|
||||||
// Manually verify that the set of types returned by GetInstalledTypes()
|
VerifyInstalledTypes();
|
||||||
// and the types present in the database are exactly the same (ignoring
|
CHK(mime.Delete() == B_OK);
|
||||||
// any files with names made of invalid characters, in case some bozo
|
VerifyInstalledTypes();
|
||||||
// manually added such a file :-)
|
|
||||||
BDirectory rootDir(mimeDatabaseDir.c_str());
|
|
||||||
BEntry superEntry;
|
|
||||||
CHK(rootDir.InitCheck() == B_OK);
|
|
||||||
rootDir.Rewind();
|
|
||||||
while (true) {
|
|
||||||
status_t err = rootDir.GetNextEntry(&superEntry);
|
|
||||||
if (err == B_ENTRY_NOT_FOUND)
|
|
||||||
break; // End of directory listing
|
|
||||||
|
|
||||||
CHK(!err); // Any other error is unacceptable :-)
|
|
||||||
|
|
||||||
// Get the leaf name
|
|
||||||
char superLeafMixed[B_PATH_NAME_LENGTH+1];
|
|
||||||
CHK(superEntry.GetName(superLeafMixed) == B_OK);
|
|
||||||
std::string superLeaf;
|
|
||||||
to_lower(superLeafMixed, superLeaf);
|
|
||||||
|
|
||||||
// We're only interested in directories, as they map to
|
|
||||||
// supertypes (and since they map thusly, they must also
|
|
||||||
// be valid MIME strings)
|
|
||||||
if (superEntry.IsDirectory() && BMimeType::IsValid(superLeaf.c_str())) {
|
|
||||||
// First, find and remove the supertype from our set
|
|
||||||
CHK(typeSet.find(superLeaf.c_str()) != typeSet.end());
|
|
||||||
typeSet.erase(superLeaf.c_str());
|
|
||||||
|
|
||||||
// Second, iterate through all the entries in the directory.
|
|
||||||
// If the entry designates a valid MIME string, find it
|
|
||||||
// in the set and remove it.
|
|
||||||
BDirectory superDir(&superEntry);
|
|
||||||
BEntry subEntry;
|
|
||||||
CHK(superDir.InitCheck() == B_OK);
|
|
||||||
superDir.Rewind();
|
|
||||||
while (true) {
|
|
||||||
status_t err = superDir.GetNextEntry(&subEntry);
|
|
||||||
if (err == B_ENTRY_NOT_FOUND)
|
|
||||||
break; // End of directory listing
|
|
||||||
|
|
||||||
CHK(!err); // Any other error is unacceptable :-)
|
|
||||||
|
|
||||||
// Get the leaf name
|
|
||||||
char subLeafMixed[B_PATH_NAME_LENGTH+1];
|
|
||||||
CHK(subEntry.GetName(subLeafMixed) == B_OK);
|
|
||||||
std::string subLeaf;
|
|
||||||
to_lower(subLeafMixed, subLeaf);
|
|
||||||
|
|
||||||
// Verify it's a valid mime string. If so, find and remove from our set
|
|
||||||
std::string subType = superLeaf + "/" + subLeaf;
|
|
||||||
if (BMimeType::IsValid(subType.c_str())) {
|
|
||||||
CHK(typeSet.find(subType.c_str()) != typeSet.end());
|
|
||||||
typeSet.erase(subType.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point our set should be empty :-) If it's not, you might check
|
|
||||||
// that you haven't added any superfluous files to your MIME database (like
|
|
||||||
// a __mime_table backup, for instance).
|
|
||||||
CHK(typeSet.size() == 0);
|
|
||||||
}
|
}
|
||||||
// Normal Function -- GetInstalledSupertypes()/GetInstalledTypes(char*,BMessage*)
|
// Normal Function -- GetInstalledSupertypes()/GetInstalledTypes(char*,BMessage*)
|
||||||
// This test gets the list of installed super types, then iterates through
|
// This test gets the list of installed super types, then iterates through
|
||||||
@@ -1730,6 +1747,7 @@ MimeTypeTest::InstalledTypesTest() {
|
|||||||
|
|
||||||
// Get the list of installed types
|
// Get the list of installed types
|
||||||
CHK(BMimeType::GetInstalledSupertypes(&msg) == B_OK);
|
CHK(BMimeType::GetInstalledSupertypes(&msg) == B_OK);
|
||||||
|
// msg.PrintToStream();
|
||||||
|
|
||||||
// Add all the type strings to a std::set
|
// Add all the type strings to a std::set
|
||||||
std::set<std::string> typeSet;
|
std::set<std::string> typeSet;
|
||||||
@@ -1769,6 +1787,8 @@ MimeTypeTest::InstalledTypesTest() {
|
|||||||
// to a std::set to be used for verification
|
// to a std::set to be used for verification
|
||||||
BMessage msg;
|
BMessage msg;
|
||||||
CHK(BMimeType::GetInstalledTypes(superLeaf.c_str(), &msg) == B_OK);
|
CHK(BMimeType::GetInstalledTypes(superLeaf.c_str(), &msg) == B_OK);
|
||||||
|
// msg.PrintToStream();
|
||||||
|
|
||||||
std::set<std::string> subtypeSet;
|
std::set<std::string> subtypeSet;
|
||||||
SetAdapter subtypeAdapter(subtypeSet);
|
SetAdapter subtypeAdapter(subtypeSet);
|
||||||
FillWithMimeTypes(subtypeAdapter, msg, "types");
|
FillWithMimeTypes(subtypeAdapter, msg, "types");
|
||||||
|
|||||||
Reference in New Issue
Block a user