+ Added meta mime file test to sniffing test

+ Added commented out update_meta_mime(NULL) and
  create_app_meta_mime(NULL) calls for the adventurous
  tester.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1335 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-10-01 07:38:53 +00:00
parent aaa3ba11ce
commit e74030b843
+49 -19
View File
@@ -3537,6 +3537,13 @@ public:
void void
MimeTypeTest::UpdateMimeInfoTest() MimeTypeTest::UpdateMimeInfoTest()
{ {
// Uncomment the following lines to enjoy the quiet time provided
// by a nice, full mime update. :-)
// cout << "begin..." << endl;
// CHK(update_mime_info(NULL, true, true, false) == B_OK);
// cout << "end..." << endl;
// tests: // tests:
// * update_mime_info() // * update_mime_info()
@@ -3645,10 +3652,6 @@ 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
@@ -3907,6 +3910,14 @@ CheckAppMetaMime(AppMimeTestFile &file)
void void
MimeTypeTest::CreateAppMetaMimeTest() MimeTypeTest::CreateAppMetaMimeTest()
{ {
// Uncomment the following lines to enjoy the quiet time provided by
// a nice, full create_app_meta_mime() update. :-)
// cout << "begin..." << endl;
// CHK(create_app_meta_mime(NULL, true, true, false) == B_OK);
// cout << "end" << endl;
// tests: // tests:
// * create_app_meta_mime() // * create_app_meta_mime()
@@ -3936,6 +3947,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
+ testDir + "/subdir2 " + testDir + "/subdir2 "
+ testDir + "/subdir2/subsubdir1"); + testDir + "/subdir2/subsubdir1");
AppMimeTestFile files[] = { AppMimeTestFile files[] = {
// AppMimeTestFile(name, type, sig, rule, miniIcon, largeIcon)
AppMimeTestFile(string(testDir) + "/file1", AppMimeTestFile(string(testDir) + "/file1",
"", "",
"application/x-vnd.obos.mime.test.test1", "application/x-vnd.obos.mime.test.test1",
@@ -3960,21 +3972,22 @@ MimeTypeTest::CreateAppMetaMimeTest()
// Synchronous calls // Synchronous calls
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {
NextSubTest();
// 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(RES(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 // 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); // snooze(999000000);
// attributes only // attributes only
NextSubTest();
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {
NextSubTest();
// create file, create_app_meta_mime() // create file, create_app_meta_mime()
AppMimeTestFile &file = files[i]; AppMimeTestFile &file = files[i];
CHK(file.Create(true, false) == B_OK); CHK(file.Create(true, false) == B_OK);
@@ -3987,8 +4000,8 @@ MimeTypeTest::CreateAppMetaMimeTest()
} }
// resources only // resources only
NextSubTest();
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {
NextSubTest();
// create file, create_app_meta_mime() // create file, create_app_meta_mime()
AppMimeTestFile &file = files[i]; AppMimeTestFile &file = files[i];
CHK(file.Create(false, true) == B_OK); CHK(file.Create(false, true) == B_OK);
@@ -4007,6 +4020,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const bigtime_t kSnoozeTime = 500000; const bigtime_t kSnoozeTime = 500000;
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {
NextSubTest();
// 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);
@@ -4021,8 +4035,8 @@ MimeTypeTest::CreateAppMetaMimeTest()
} }
// attributes only // attributes only
NextSubTest();
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {
NextSubTest();
// create file, create_app_meta_mime() // create file, create_app_meta_mime()
AppMimeTestFile &file = files[i]; AppMimeTestFile &file = files[i];
CHK(file.Create(true, false) == B_OK); CHK(file.Create(true, false) == B_OK);
@@ -4037,8 +4051,8 @@ MimeTypeTest::CreateAppMetaMimeTest()
} }
// resources only // resources only
NextSubTest();
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {
NextSubTest();
// create file, create_app_meta_mime() // create file, create_app_meta_mime()
AppMimeTestFile &file = files[i]; AppMimeTestFile &file = files[i];
CHK(file.Create(false, true) == B_OK); CHK(file.Create(false, true) == B_OK);
@@ -4053,6 +4067,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
CHK(file.Delete(false) == B_OK); CHK(file.Delete(false) == B_OK);
} }
// test the force flag // test the force flag
// TODO: The BeBook says: "If force is true, entries are created even if they // TODO: The BeBook says: "If force is true, entries are created even if they
// already exist." // already exist."
@@ -4061,7 +4076,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
// calling it on another file with the same signature, should update the // calling it on another file with the same signature, should update the
// database entry. But the following tests show, that this doesn't happen. // database entry. But the following tests show, that this doesn't happen.
// They fail in the third CheckAppMetaMime(). // They fail in the third CheckAppMetaMime().
#if 0 #if !TEST_R5
// same file, same signature, other parameters // same file, same signature, other parameters
{ {
char icon1[256]; char icon1[256];
@@ -4131,7 +4146,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
CHK(file1.Delete(true) == B_OK); CHK(file1.Delete(true) == B_OK);
CHK(file2.Delete(true) == B_OK); CHK(file2.Delete(true) == B_OK);
} }
#endif // 0 #endif // !TEST_R5
// bad args // bad args
NextSubTest(); NextSubTest();
@@ -4143,6 +4158,7 @@ MimeTypeTest::CreateAppMetaMimeTest()
// non-existing file // non-existing file
CHK(create_app_meta_mime(files[0].name.c_str(), false, true, false) CHK(create_app_meta_mime(files[0].name.c_str(), false, true, false)
== B_OK); == B_OK);
} }
// CheckIconData // CheckIconData
@@ -4585,12 +4601,13 @@ printf("\nerror:\n%s\n", parseError.String());
class SniffingTestFile { class SniffingTestFile {
public: public:
SniffingTestFile(string name, string extensionType, string contentType, SniffingTestFile(string name, string extensionType, string contentType,
const void *data = NULL, int32 size = -1) const void *data = NULL, int32 size = -1, string metaType = "")
: name(name), : name(name)
extensionType(extensionType), , extensionType(extensionType)
contentType(contentType), , contentType(contentType)
data(NULL), , data(NULL)
size(0) , size(0)
, metaType(metaType)
{ {
// replace wildcard types // replace wildcard types
if (this->extensionType == "") if (this->extensionType == "")
@@ -4616,7 +4633,7 @@ public:
status_t Create() status_t Create()
{ {
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);
status_t error = file.InitCheck(); ssize_t error = file.InitCheck();
if (error == B_OK && data) { if (error == B_OK && data) {
ssize_t written = file.Write(data, size); ssize_t written = file.Write(data, size);
if (written < 0) if (written < 0)
@@ -4624,6 +4641,11 @@ public:
else if (written != size) else if (written != size)
error = B_ERROR; error = B_ERROR;
} }
if (!error && metaType.length() > 0) {
error = file.WriteAttr("META:TYPE", B_STRING_TYPE, 0, metaType.c_str(),
metaType.length()+1);
error = error == (ssize_t)(metaType.length()+1) ? B_OK : error;
}
return error; return error;
} }
@@ -4637,6 +4659,7 @@ public:
string contentType; string contentType;
char *data; char *data;
int32 size; int32 size;
string metaType;
}; };
// SniffingTest // SniffingTest
@@ -4702,6 +4725,13 @@ MimeTypeTest::SniffingTest()
"LLNO"), "LLNO"),
SniffingTestFile(string(testDir) + "/file13", "", "", SniffingTestFile(string(testDir) + "/file13", "", "",
"LNNO"), "LNNO"),
// meta mime test
#if !TEST_R5
SniffingTestFile(string(testDir) + "/file14.html",
"text/html", "application/x-vnd.be-meta-mime",
"<html>\n<body>\n</body></html>\n", -1,
"fake-meta-mime-string"),
#endif // !TEST_R5
}; };
int fileCount = sizeof(files) / sizeof(SniffingTestFile); int fileCount = sizeof(files) / sizeof(SniffingTestFile);
for (int32 i = 0; i < fileCount; i++) { for (int32 i = 0; i < fileCount; i++) {