Made some minor adjustments to help figuring out how mime update
calls work (still in progress). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1278 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3645,6 +3645,10 @@ MimeTypeTest::UpdateMimeInfoTest()
|
|||||||
}
|
}
|
||||||
#endif // TEST_OBOS
|
#endif // TEST_OBOS
|
||||||
|
|
||||||
|
// cout << "begin..." << endl;
|
||||||
|
// CHK(RES(update_mime_info(NULL, true, true, false)) == B_OK);
|
||||||
|
// cout << "end..." << endl;
|
||||||
|
|
||||||
// directory
|
// directory
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
// create
|
// create
|
||||||
@@ -3690,11 +3694,11 @@ MimeTypeTest::UpdateMimeInfoTest()
|
|||||||
BEntry entry(files[0].name.c_str());
|
BEntry entry(files[0].name.c_str());
|
||||||
CHK(entry.InitCheck() == B_OK);
|
CHK(entry.InitCheck() == B_OK);
|
||||||
CHK(entry.Exists() == false);
|
CHK(entry.Exists() == false);
|
||||||
#if TEST_R5
|
//#if TEST_R5
|
||||||
CHK(update_mime_info(files[0].name.c_str(), false, true, false) == B_OK);
|
CHK(update_mime_info(files[0].name.c_str(), false, true, false) == B_OK);
|
||||||
#else
|
//#else
|
||||||
CHK(update_mime_info(files[0].name.c_str(), false, true, false) == B_ENTRY_NOT_FOUND);
|
// CHK(update_mime_info(files[0].name.c_str(), false, true, false) == B_ENTRY_NOT_FOUND);
|
||||||
#endif
|
//#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteStringAttr
|
// WriteStringAttr
|
||||||
@@ -3709,23 +3713,29 @@ WriteStringAttr(BNode &node, string name, string _value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uint32 MINI_ICON_TYPE = 'MICN';
|
const uint32 MINI_ICON_TYPE = 'MICN';
|
||||||
|
const uint32 LARGE_ICON_TYPE = 'ICON';
|
||||||
|
|
||||||
// helper class for create_app_meta_mime() tests
|
// helper class for create_app_meta_mime() tests
|
||||||
class AppMimeTestFile {
|
class AppMimeTestFile {
|
||||||
public:
|
public:
|
||||||
AppMimeTestFile(string name, string type, string signature,
|
AppMimeTestFile(string name, string type, string signature,
|
||||||
const void *icon = NULL)
|
string snifferRule,
|
||||||
|
const void *miniIcon = NULL, const void *largeIcon = NULL)
|
||||||
: name(name),
|
: name(name),
|
||||||
type(type),
|
type(type),
|
||||||
signature(signature),
|
signature(signature),
|
||||||
miniIcon(NULL)
|
snifferRule(snifferRule),
|
||||||
|
miniIcon(NULL),
|
||||||
|
largeIcon(NULL)
|
||||||
{
|
{
|
||||||
SetMiniIcon(icon);
|
SetMiniIcon(miniIcon);
|
||||||
|
SetLargeIcon(largeIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
~AppMimeTestFile()
|
~AppMimeTestFile()
|
||||||
{
|
{
|
||||||
SetMiniIcon(NULL);
|
SetMiniIcon(NULL);
|
||||||
|
SetLargeIcon(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMiniIcon(const void *icon)
|
void SetMiniIcon(const void *icon)
|
||||||
@@ -3740,6 +3750,18 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetLargeIcon(const void *icon)
|
||||||
|
{
|
||||||
|
if (largeIcon) {
|
||||||
|
delete[] largeIcon;
|
||||||
|
largeIcon = NULL;
|
||||||
|
}
|
||||||
|
if (icon) {
|
||||||
|
largeIcon = new char[1024];
|
||||||
|
memcpy(largeIcon, icon, 1024);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status_t Create(bool setAttributes, bool setResources)
|
status_t Create(bool setAttributes, bool setResources)
|
||||||
{
|
{
|
||||||
BFile file(name.c_str(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
BFile file(name.c_str(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
@@ -3752,6 +3774,9 @@ public:
|
|||||||
// signature
|
// signature
|
||||||
if (error == B_OK)
|
if (error == B_OK)
|
||||||
error = WriteStringAttr(file, "BEOS:APP_SIG", signature);
|
error = WriteStringAttr(file, "BEOS:APP_SIG", signature);
|
||||||
|
// sniffer rule
|
||||||
|
if (error == B_OK)
|
||||||
|
error = WriteStringAttr(file, "BEOS:SNIFF_RULE", snifferRule);
|
||||||
// mini icon
|
// mini icon
|
||||||
if (error == B_OK && miniIcon) {
|
if (error == B_OK && miniIcon) {
|
||||||
ssize_t written = file.WriteAttr("BEOS:M:STD_ICON",
|
ssize_t written = file.WriteAttr("BEOS:M:STD_ICON",
|
||||||
@@ -3762,30 +3787,40 @@ public:
|
|||||||
else if (written != 256)
|
else if (written != 256)
|
||||||
error = B_ERROR;
|
error = B_ERROR;
|
||||||
}
|
}
|
||||||
|
// large icon (ignored)
|
||||||
|
if (error == B_OK && largeIcon) {
|
||||||
|
ssize_t written = file.WriteAttr("META:L:STD_ICON",
|
||||||
|
LARGE_ICON_TYPE, 0, largeIcon,
|
||||||
|
1024);
|
||||||
|
if (written < 0)
|
||||||
|
error = written;
|
||||||
|
else if (written != 1024)
|
||||||
|
error = B_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// resources
|
// resources
|
||||||
if (error == B_OK && setResources) {
|
if (error == B_OK && setResources) {
|
||||||
BResources resources;
|
BResources resources;
|
||||||
error = resources.SetTo(&file, true);
|
error = resources.SetTo(&file, true);
|
||||||
// type
|
// type (ignored)
|
||||||
if (error == B_OK && type.length() > 0) {
|
if (error == B_OK && type.length() > 0) {
|
||||||
error = resources.AddResource(B_STRING_TYPE, 2, type.c_str(),
|
error = resources.AddResource(B_STRING_TYPE, 2, type.c_str(),
|
||||||
type.length() + 1, "BEOS:TYPE");
|
type.length() + 1, "BEOS:TYPE");
|
||||||
}
|
}
|
||||||
// signature
|
// signature (ignored)
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
error = resources.AddResource(B_STRING_TYPE, 1,
|
error = resources.AddResource(B_STRING_TYPE, 1,
|
||||||
signature.c_str(),
|
signature.c_str(),
|
||||||
signature.length() + 1,
|
signature.length() + 1,
|
||||||
"BEOS:APP_SIG");
|
"BEOS:APP_SIG");
|
||||||
}
|
}
|
||||||
// mini icon
|
// mini icon (ignored)
|
||||||
if (error == B_OK && miniIcon) {
|
if (error == B_OK && miniIcon) {
|
||||||
error = resources.AddResource(MINI_ICON_TYPE, 101, miniIcon,
|
error = resources.AddResource(MINI_ICON_TYPE, 101, miniIcon,
|
||||||
256, "BEOS:M:STD_ICON");
|
256, "BEOS:M:STD_ICON");
|
||||||
}
|
}
|
||||||
// file types
|
// file types (ignored)
|
||||||
/* if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
BMessage msg;
|
BMessage msg;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
error = msg.AddString("types", "text/x-email");
|
error = msg.AddString("types", "text/x-email");
|
||||||
@@ -3802,7 +3837,7 @@ public:
|
|||||||
error = resources.AddResource(B_MESSAGE_TYPE, 1, buffer,
|
error = resources.AddResource(B_MESSAGE_TYPE, 1, buffer,
|
||||||
msg.FlattenedSize(), "BEOS:FILE_TYPES");
|
msg.FlattenedSize(), "BEOS:FILE_TYPES");
|
||||||
delete [] buffer;
|
delete [] buffer;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -3823,7 +3858,9 @@ public:
|
|||||||
string name;
|
string name;
|
||||||
string type;
|
string type;
|
||||||
string signature;
|
string signature;
|
||||||
|
string snifferRule;
|
||||||
char *miniIcon;
|
char *miniIcon;
|
||||||
|
char *largeIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
// CheckAppMetaMime
|
// CheckAppMetaMime
|
||||||
@@ -3858,6 +3895,12 @@ CheckAppMetaMime(AppMimeTestFile &file)
|
|||||||
CHK(type.GetIcon(&icon, B_MINI_ICON) == B_OK);
|
CHK(type.GetIcon(&icon, B_MINI_ICON) == B_OK);
|
||||||
CHK(memcmp(icon.Bits(), file.miniIcon, 256) == 0);
|
CHK(memcmp(icon.Bits(), file.miniIcon, 256) == 0);
|
||||||
}
|
}
|
||||||
|
// large icon
|
||||||
|
/* if (file.miniIcon) {
|
||||||
|
BBitmap icon(BRect(0, 0, 31, 31), B_CMAP8);
|
||||||
|
CHK(type.GetIcon(&icon, B_LARGE_ICON) == B_OK);
|
||||||
|
CHK(memcmp(icon.Bits(), file.largeIcon, 1024) == 0);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAppMetaMimeTest
|
// CreateAppMetaMimeTest
|
||||||
@@ -3872,19 +3915,45 @@ MimeTypeTest::CreateAppMetaMimeTest()
|
|||||||
// * The recursive flag isn't tested -- the BeBook sais, it is unused.
|
// * The recursive flag isn't tested -- the BeBook sais, it is unused.
|
||||||
// * Updating all apps is not tested as it takes too long.
|
// * Updating all apps is not tested as it takes too long.
|
||||||
|
|
||||||
|
// Create a couple of icons to play around with
|
||||||
|
char miniIcon1[256];
|
||||||
|
char miniIcon2[256];
|
||||||
|
for (int ch = 0; ch < 256; ch++) {
|
||||||
|
miniIcon1[ch] = ch;
|
||||||
|
miniIcon2[ch] = 255-ch;
|
||||||
|
}
|
||||||
|
char largeIcon1[1024];
|
||||||
|
char largeIcon2[1024];
|
||||||
|
for (int i = 0; i < 1024; i++) {
|
||||||
|
char ch = i % 256;
|
||||||
|
largeIcon1[i] = ch;
|
||||||
|
largeIcon2[i] = 255-ch;
|
||||||
|
}
|
||||||
|
|
||||||
// attributes and resources
|
// attributes and resources
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
execCommand(string("mkdir ") + testDir + "/subdir1 "
|
execCommand(string("mkdir ") + testDir + "/subdir1 "
|
||||||
+ testDir + "/subdir2 "
|
+ testDir + "/subdir2 "
|
||||||
+ testDir + "/subdir2/subsubdir1");
|
+ testDir + "/subdir2/subsubdir1");
|
||||||
AppMimeTestFile files[] = {
|
AppMimeTestFile files[] = {
|
||||||
AppMimeTestFile(string(testDir) + "/file1", "",
|
AppMimeTestFile(string(testDir) + "/file1",
|
||||||
"application/x-vnd.obos.mime.test.test1"),
|
"",
|
||||||
AppMimeTestFile(string(testDir) + "/file2", "text/x-source-code",
|
"application/x-vnd.obos.mime.test.test1",
|
||||||
"application/x-vnd.obos.mime.test.test2"),
|
"0.0 ('abc')",
|
||||||
|
miniIcon1,
|
||||||
|
NULL),
|
||||||
|
AppMimeTestFile(string(testDir) + "/file2",
|
||||||
|
"text/x-source-code",
|
||||||
|
"application/x-vnd.obos.mime.test.test2",
|
||||||
|
"0.0 ('xyz')",
|
||||||
|
miniIcon2,
|
||||||
|
largeIcon2),
|
||||||
AppMimeTestFile(string(testDir) + "/file3",
|
AppMimeTestFile(string(testDir) + "/file3",
|
||||||
"application/x-vnd.Be-elfexecutable",
|
"application/x-vnd.Be-elfexecutable",
|
||||||
"application/x-vnd.obos.mime.test.test3"),
|
"application/x-vnd.obos.mime.test.test3",
|
||||||
|
"0.0 ('rst')",
|
||||||
|
NULL,
|
||||||
|
largeIcon1),
|
||||||
};
|
};
|
||||||
const int fileCount = sizeof(files) / sizeof(AppMimeTestFile);
|
const int fileCount = sizeof(files) / sizeof(AppMimeTestFile);
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -3894,13 +3963,14 @@ MimeTypeTest::CreateAppMetaMimeTest()
|
|||||||
// create file, create_app_meta_mime()
|
// create file, create_app_meta_mime()
|
||||||
AppMimeTestFile &file = files[i];
|
AppMimeTestFile &file = files[i];
|
||||||
CHK(file.Create(true, true) == B_OK);
|
CHK(file.Create(true, true) == B_OK);
|
||||||
CHK(create_app_meta_mime(file.name.c_str(), false, true, false)
|
CHK(RES(create_app_meta_mime(file.name.c_str(), false, true, false))
|
||||||
== B_OK);
|
== B_OK);
|
||||||
// check the MIME type
|
// check the MIME type
|
||||||
CheckAppMetaMime(file);
|
CheckAppMetaMime(file);
|
||||||
// clean up
|
// clean up
|
||||||
CHK(file.Delete(true) == B_OK);
|
// CHK(file.Delete(true) == B_OK);
|
||||||
}
|
}
|
||||||
|
// snooze(999000000);
|
||||||
|
|
||||||
// attributes only
|
// attributes only
|
||||||
NextSubTest();
|
NextSubTest();
|
||||||
@@ -3924,6 +3994,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
|
|||||||
CHK(file.Create(false, true) == B_OK);
|
CHK(file.Create(false, true) == B_OK);
|
||||||
CHK(create_app_meta_mime(file.name.c_str(), false, true, false)
|
CHK(create_app_meta_mime(file.name.c_str(), false, true, false)
|
||||||
== B_OK);
|
== B_OK);
|
||||||
|
// check the MIME type
|
||||||
BMimeType type;
|
BMimeType type;
|
||||||
CHK(type.SetTo(file.signature.c_str()) == B_OK);
|
CHK(type.SetTo(file.signature.c_str()) == B_OK);
|
||||||
CHK(type.IsInstalled() == false);
|
CHK(type.IsInstalled() == false);
|
||||||
|
|||||||
Reference in New Issue
Block a user