diff --git a/src/tests/kits/storage/AppFileInfoTest.cpp b/src/tests/kits/storage/AppFileInfoTest.cpp index 2811303851..d6f470e9e0 100644 --- a/src/tests/kits/storage/AppFileInfoTest.cpp +++ b/src/tests/kits/storage/AppFileInfoTest.cpp @@ -33,20 +33,19 @@ static const char *testFile1 = "/tmp/testDir/file1"; static const char *testFile2 = "/tmp/testDir/file2"; static const char *testFile3 = "/tmp/testDir/file3"; static const char *testFile4 = "/tmp/testDir/file4"; -//static const char *abstractTestEntry = "/tmp/testDir/abstract-entry"; static const char *testType1 = "application/x-vnd.obos.app-file-info-test1"; static const char *testType2 = "application/x-vnd.obos.app-file-info-test2"; static const char *testType3 = "application/x-vnd.obos.app-file-info-test3"; -//static const char *invalidTestType = "invalid-mime-type"; -//static const char *tooLongTestType = -//"0123456789012345678901234567890123456789012345678901234567890123456789" -//"0123456789012345678901234567890123456789012345678901234567890123456789" -//"0123456789012345678901234567890123456789012345678901234567890123456789" -//"0123456789012345678901234567890123456789012345678901234567890123456789" -//; +static const char *invalidTestType = "invalid-mime-type"; +static const char *tooLongTestType = +"0123456789012345678901234567890123456789012345678901234567890123456789" +"0123456789012345678901234567890123456789012345678901234567890123456789" +"0123456789012345678901234567890123456789012345678901234567890123456789" +"0123456789012345678901234567890123456789012345678901234567890123456789" +; static const char *testAppSignature1 = "application/x-vnd.obos.app-file-info-test-app1"; static const char *testAppSignature2 @@ -137,26 +136,26 @@ AppFileInfoTest::Suite() { CppUnit::TestSuite *suite = new CppUnit::TestSuite(); typedef CppUnit::TestCaller TC; - suite->addTest( new TC("BAppFileInfo::Init Test1", - &AppFileInfoTest::InitTest1) ); - suite->addTest( new TC("BAppFileInfo::Init Test2", - &AppFileInfoTest::InitTest2) ); - suite->addTest( new TC("BAppFileInfo::Type Test", - &AppFileInfoTest::TypeTest) ); - suite->addTest( new TC("BAppFileInfo::Signature Test", - &AppFileInfoTest::SignatureTest) ); - suite->addTest( new TC("BAppFileInfo::App Flags Test", - &AppFileInfoTest::AppFlagsTest) ); +// suite->addTest( new TC("BAppFileInfo::Init Test1", +// &AppFileInfoTest::InitTest1) ); +// suite->addTest( new TC("BAppFileInfo::Init Test2", +// &AppFileInfoTest::InitTest2) ); +// suite->addTest( new TC("BAppFileInfo::Type Test", +// &AppFileInfoTest::TypeTest) ); +// suite->addTest( new TC("BAppFileInfo::Signature Test", +// &AppFileInfoTest::SignatureTest) ); +// suite->addTest( new TC("BAppFileInfo::App Flags Test", +// &AppFileInfoTest::AppFlagsTest) ); suite->addTest( new TC("BAppFileInfo::Supported Types Test", &AppFileInfoTest::SupportedTypesTest) ); - suite->addTest( new TC("BAppFileInfo::Icon Test", - &AppFileInfoTest::IconTest) ); - suite->addTest( new TC("BAppFileInfo::Version Info Test", - &AppFileInfoTest::VersionInfoTest) ); - suite->addTest( new TC("BAppFileInfo::Icon For Type Test", - &AppFileInfoTest::IconForTypeTest) ); - suite->addTest( new TC("BAppFileInfo::Info Location Test", - &AppFileInfoTest::InfoLocationTest) ); +// suite->addTest( new TC("BAppFileInfo::Icon Test", +// &AppFileInfoTest::IconTest) ); +// suite->addTest( new TC("BAppFileInfo::Version Info Test", +// &AppFileInfoTest::VersionInfoTest) ); +// suite->addTest( new TC("BAppFileInfo::Icon For Type Test", +// &AppFileInfoTest::IconForTypeTest) ); +// suite->addTest( new TC("BAppFileInfo::Info Location Test", +// &AppFileInfoTest::InfoLocationTest) ); return suite; } @@ -221,6 +220,30 @@ AppFileInfoTest::tearDown() BasicTest::tearDown(); } +// SyncResources +static +void +SyncResources(BAppFileInfo &info) +{ + struct node_info_hack { + virtual ~node_info_hack() {} + BNode *fNode; + uint32 _reserved[2]; + status_t fCStatus; + }; + struct app_file_info_hack : node_info_hack { + virtual ~app_file_info_hack() {} + BResources *fResources; + info_location fWhere; + uint32 _reserved[2]; + }; + app_file_info_hack &hackedInfo + = reinterpret_cast(info); + BResources *resources = hackedInfo.fResources; + if (resources) + resources->Sync(); +} + // ReadAttr static char* @@ -301,6 +324,248 @@ CheckNoAttr(BNode &node, const char *name) CHK(node.GetAttrInfo(name, &info) == B_ENTRY_NOT_FOUND); } +// CheckNoResource +static +void +CheckNoResource(BFile &file, const char *name) +{ + BResources resources; + CHK(resources.SetTo(&file) == B_OK); + type_code typeFound; + int32 idFound; + const char *nameFound; + size_t size; + bool found = false; + for (int32 i = 0; + !found && resources.GetResourceInfo(i, &typeFound, &idFound, + &nameFound, &size); + i++) { + found = !strcmp(nameFound, name); + } + CHK(!found); +} + +// CheckTypeAttr +static +void +CheckTypeAttr(BNode &node, const char *data) +{ + CheckAttr(node, kTypeAttribute, B_MIME_STRING_TYPE, data, + strlen(data) + 1); +} + +// CheckTypeResource +static +void +CheckTypeResource(BFile &file, const char *data) +{ + CheckResource(file, kTypeAttribute, kTypeResourceID, B_MIME_STRING_TYPE, + data, strlen(data) + 1); +} + +// CheckSignatureAttr +static +void +CheckSignatureAttr(BNode &node, const char *data) +{ + CheckAttr(node, kSignatureAttribute, B_MIME_STRING_TYPE, data, + strlen(data) + 1); +} + +// CheckSignatureResource +static +void +CheckSignatureResource(BFile &file, const char *data) +{ + CheckResource(file, kSignatureAttribute, kSignatureResourceID, + B_MIME_STRING_TYPE, data, strlen(data) + 1); +} + +// CheckAppFlagsAttr +static +void +CheckAppFlagsAttr(BNode &node, uint32 flags) +{ + CheckAttr(node, kAppFlagsAttribute, APP_FLAGS_TYPE, &flags, sizeof(flags)); +} + +// CheckAppFlagsResource +static +void +CheckAppFlagsResource(BFile &file, uint32 flags) +{ + CheckResource(file, kAppFlagsAttribute, kAppFlagsResourceID, + APP_FLAGS_TYPE, &flags, sizeof(flags)); +} + +// CheckIconAttr +static +void +CheckIconAttr(BNode &node, BBitmap *data) +{ + const char *attribute = NULL; + uint32 type = 0; + switch (data->Bounds().IntegerWidth()) { + case 15: + attribute = kMiniIconAttribute; + type = MINI_ICON_TYPE; + break; + case 31: + attribute = kLargeIconAttribute; + type = LARGE_ICON_TYPE; + break; + default: + CHK(false); + break; + } + CheckAttr(node, attribute, type, data->Bits(), data->BitsLength()); +} + +// CheckIconResource +static +void +CheckIconResource(BFile &file, BBitmap *data) +{ + const char *attribute = NULL; + int32 resourceID = 0; + uint32 type = 0; + switch (data->Bounds().IntegerWidth()) { + case 15: + attribute = kMiniIconAttribute; + resourceID = kMiniIconResourceID; + type = MINI_ICON_TYPE; + break; + case 31: + attribute = kLargeIconAttribute; + resourceID = kLargeIconResourceID; + type = LARGE_ICON_TYPE; + break; + default: + CHK(false); + break; + } + CheckResource(file, attribute, resourceID, type, data->Bits(), + data->BitsLength()); +} + +// CheckVersionInfoAttr +static +void +CheckVersionInfoAttr(BNode &node, version_info *data) +{ + CheckAttr(node, kVersionInfoAttribute, VERSION_INFO_TYPE, data, + 2 * sizeof(version_info)); +} + +// CheckVersionInfoResource +static +void +CheckVersionInfoResource(BFile &file, version_info *data) +{ + CheckResource(file, kVersionInfoAttribute, kVersionInfoResourceID, + VERSION_INFO_TYPE, data, 2 * sizeof(version_info)); +} + +// CheckIconForTypeAttr +static +void +CheckIconForTypeAttr(BNode &node, const char *type, BBitmap *data) +{ + string attribute; + int32 resourceID = 0; + uint32 iconType = 0; + switch (data->Bounds().IntegerWidth()) { + case 15: + attribute = kMiniIconForTypeAttribute; + resourceID = kMiniIconForTypeResourceID; + iconType = MINI_ICON_TYPE; + break; + case 31: + attribute = kLargeIconForTypeAttribute; + resourceID = kLargeIconForTypeResourceID; + iconType = LARGE_ICON_TYPE; + break; + default: + CHK(false); + break; + } + attribute += type; + CheckAttr(node, attribute.c_str(), iconType, data->Bits(), + data->BitsLength()); +} + +// CheckIconForTypeResource +static +void +CheckIconForTypeResource(BFile &file, const char *type, BBitmap *data, + int32 resourceID = -1) +{ + string attribute; + uint32 iconType = 0; + switch (data->Bounds().IntegerWidth()) { + case 15: + attribute = kMiniIconForTypeAttribute; + if (resourceID < 0) + resourceID = kMiniIconForTypeResourceID; + iconType = MINI_ICON_TYPE; + break; + case 31: + attribute = kLargeIconForTypeAttribute; + if (resourceID < 0) + resourceID = kLargeIconForTypeResourceID; + iconType = LARGE_ICON_TYPE; + break; + default: + CHK(false); + break; + } + attribute += type; + CheckResource(file, attribute.c_str(), resourceID, iconType, data->Bits(), + data->BitsLength()); +} + +// CheckNoIconForTypeAttr +static +void +CheckNoIconForTypeAttr(BNode &node, const char *type, icon_size iconSize) +{ + string attribute; + switch (iconSize) { + case B_MINI_ICON: + attribute = kMiniIconForTypeAttribute; + break; + case B_LARGE_ICON: + attribute = kLargeIconForTypeAttribute; + break; + default: + CHK(false); + break; + } + attribute += type; + CheckNoAttr(node, attribute.c_str()); +} + +// CheckNoIconForTypeResource +static +void +CheckNoIconForTypeResource(BFile &file, const char *type, icon_size iconSize) +{ + string attribute; + switch (iconSize) { + case B_MINI_ICON: + attribute = kMiniIconForTypeAttribute; + break; + case B_LARGE_ICON: + attribute = kLargeIconForTypeAttribute; + break; + default: + CHK(false); + break; + } + attribute += type; + CheckNoResource(file, attribute.c_str()); +} + // InitTest1 void AppFileInfoTest::InitTest1() @@ -407,24 +672,279 @@ AppFileInfoTest::InitTest2() void AppFileInfoTest::TypeTest() { -// virtual status_t GetType(char *type) const; -// virtual status_t SetType(const char *type); + // status_t GetType(char *type) const + // * NULL type => B_BAD_ADDRESS/B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(equals(appFileInfo.GetType(NULL), B_BAD_ADDRESS, B_BAD_VALUE)); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + char type[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetType(type) == B_NO_INIT); + } + // * has no type => B_ENTRY_NOT_FOUND + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + char type[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetType(type) == B_ENTRY_NOT_FOUND); + } + // * set, get, reset, get + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // set + CHK(appFileInfo.SetType(testType1) == B_OK); + // get + char type[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetType(type) == B_OK); + CHK(strcmp(testType1, type) == 0); + CheckTypeAttr(file, testType1); + SyncResources(appFileInfo); + CheckTypeResource(file, testType1); + // reset + CHK(appFileInfo.SetType(testType2) == B_OK); + // get + CHK(appFileInfo.GetType(type) == B_OK); + CHK(strcmp(testType2, type) == 0); + CheckTypeAttr(file, testType2); + SyncResources(appFileInfo); + CheckTypeResource(file, testType2); + } + + // status_t SetType(const char *type) + // * NULL type => B_OK, unsets the type + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetType(NULL) == B_OK); + // get + char type[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetType(type) == B_ENTRY_NOT_FOUND); + CheckNoAttr(file, kTypeAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kTypeAttribute); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetType(testType1) == B_NO_INIT); + } + // * invalid MIME type => B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetType(invalidTestType) == B_OK); + // get + char type[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetType(type) == B_OK); + CHK(strcmp(invalidTestType, type) == 0); + CheckTypeAttr(file, invalidTestType); + SyncResources(appFileInfo); + CheckTypeResource(file, invalidTestType); + } + // * type string too long => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // remove attr first + CHK(appFileInfo.SetType(NULL) == B_OK); + // try to set the too long type + CHK(appFileInfo.SetType(tooLongTestType) == B_BAD_VALUE); + CheckNoAttr(file, kTypeAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kTypeAttribute); + } } // SignatureTest void AppFileInfoTest::SignatureTest() { -// status_t GetSignature(char *signature) const; -// status_t SetSignature(const char *signature); + // status_t GetSignature(char *signature) const + // * NULL signature => B_BAD_ADDRESS/B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(equals(appFileInfo.GetSignature(NULL), B_BAD_ADDRESS, B_BAD_VALUE)); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + char signature[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetSignature(signature) == B_NO_INIT); + } + // * has no signature => B_ENTRY_NOT_FOUND + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + char signature[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetSignature(signature) == B_ENTRY_NOT_FOUND); + } + // * set, get, reset, get + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // set + CHK(appFileInfo.SetSignature(testAppSignature1) == B_OK); + CHK(BMimeType(testAppSignature1).IsInstalled() == false); + // get + char signature[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetSignature(signature) == B_OK); + CHK(strcmp(testAppSignature1, signature) == 0); + CheckSignatureAttr(file, testAppSignature1); + SyncResources(appFileInfo); + CheckSignatureResource(file, testAppSignature1); + // reset + CHK(appFileInfo.SetSignature(testAppSignature2) == B_OK); + CHK(BMimeType(testAppSignature2).IsInstalled() == false); + // get + CHK(appFileInfo.GetSignature(signature) == B_OK); + CHK(strcmp(testAppSignature2, signature) == 0); + CheckSignatureAttr(file, testAppSignature2); + SyncResources(appFileInfo); + CheckSignatureResource(file, testAppSignature2); + } + + // status_t SetSignature(const char *signature) + // * NULL signature => B_OK, unsets the signature + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetSignature(NULL) == B_OK); + // get + char signature[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetSignature(signature) == B_ENTRY_NOT_FOUND); + CheckNoAttr(file, kSignatureAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kSignatureAttribute); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetSignature(testAppSignature1) == B_NO_INIT); + } + // * invalid MIME signature => B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetSignature(invalidTestType) == B_OK); + // get + char signature[B_MIME_TYPE_LENGTH]; + CHK(appFileInfo.GetSignature(signature) == B_OK); + CHK(strcmp(invalidTestType, signature) == 0); + CheckSignatureAttr(file, invalidTestType); + SyncResources(appFileInfo); + CheckSignatureResource(file, invalidTestType); + } + // * signature string too long => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // remove attr first + CHK(appFileInfo.SetSignature(NULL) == B_OK); + // try to set the too long signature + CHK(appFileInfo.SetSignature(tooLongTestType) == B_BAD_VALUE); + CheckNoAttr(file, kSignatureAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kSignatureAttribute); + } } // AppFlagsTest void AppFileInfoTest::AppFlagsTest() { -// status_t GetAppFlags(uint32 *flags) const; -// status_t SetAppFlags(uint32 flags); + // status_t GetAppFlags(uint32 *flags) const + // * NULL flags => B_BAD_ADDRESS/B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(equals(appFileInfo.GetAppFlags(NULL), B_BAD_ADDRESS, B_BAD_VALUE)); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + uint32 flags; + CHK(appFileInfo.GetAppFlags(&flags) == B_NO_INIT); + } + // * has no flags => B_ENTRY_NOT_FOUND + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + uint32 flags; + CHK(appFileInfo.GetAppFlags(&flags) == B_ENTRY_NOT_FOUND); + } + // * set, get, reset, get + NextSubTest(); + { + uint32 testFlags1 = B_SINGLE_LAUNCH | B_BACKGROUND_APP; + uint32 testFlags2 = B_MULTIPLE_LAUNCH | B_ARGV_ONLY; + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // set + CHK(appFileInfo.SetAppFlags(testFlags1) == B_OK); + // get + uint32 flags; + CHK(appFileInfo.GetAppFlags(&flags) == B_OK); + CHK(flags == testFlags1); + CheckAppFlagsAttr(file, testFlags1); + SyncResources(appFileInfo); + CheckAppFlagsResource(file, testFlags1); + // reset + CHK(appFileInfo.SetAppFlags(testFlags2) == B_OK); + // get + CHK(appFileInfo.GetAppFlags(&flags) == B_OK); + CHK(flags == testFlags2); + CheckAppFlagsAttr(file, testFlags2); + SyncResources(appFileInfo); + CheckAppFlagsResource(file, testFlags2); + } + + // status_t SetAppFlags(uint32 flags) + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetAppFlags(B_SINGLE_LAUNCH) == B_NO_INIT); + } } // SupportedTypesTest @@ -442,8 +962,193 @@ AppFileInfoTest::SupportedTypesTest() void AppFileInfoTest::IconTest() { -// virtual status_t GetIcon(BBitmap *icon, icon_size which) const; -// virtual status_t SetIcon(const BBitmap *icon, icon_size which); + // status_t GetIcon(BBitmap *icon, icon_size k) const + // * NULL icon => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.GetIcon(NULL, B_MINI_ICON) == B_BAD_VALUE); + CHK(appFileInfo.GetIcon(NULL, B_LARGE_ICON) == B_BAD_VALUE); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_NO_INIT); + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon2, B_LARGE_ICON) == B_NO_INIT); + } + // * icon dimensions != icon size => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + BBitmap icon(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_BAD_VALUE); + BBitmap icon2(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon2, B_LARGE_ICON) == B_BAD_VALUE); + } + // * has no icon => B_ENTRY_NOT_FOUND + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_ENTRY_NOT_FOUND); + } + // * set, get, reset, get + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // mini + // set + CHK(appFileInfo.SetIcon(fIconM1, B_MINI_ICON) == B_OK); + // get + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM1, &icon)); + CheckIconAttr(file, fIconM1); + SyncResources(appFileInfo); + CheckIconResource(file, fIconM1); + // reset + CHK(appFileInfo.SetIcon(fIconM2, B_MINI_ICON) == B_OK); + // get + BBitmap icon2(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon2, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM2, &icon2)); + CheckIconAttr(file, fIconM2); + SyncResources(appFileInfo); + CheckIconResource(file, fIconM2); + // large + // set + CHK(appFileInfo.SetIcon(fIconL1, B_LARGE_ICON) == B_OK); + // get + BBitmap icon3(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon3, B_LARGE_ICON) == B_OK); + CHK(icon_equal(fIconL1, &icon3)); + CheckIconAttr(file, fIconL1); + SyncResources(appFileInfo); + CheckIconResource(file, fIconL1); + // reset + CHK(appFileInfo.SetIcon(fIconL2, B_LARGE_ICON) == B_OK); + // get + BBitmap icon4(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon4, B_LARGE_ICON) == B_OK); + CHK(icon_equal(fIconL2, &icon4)); + CheckIconAttr(file, fIconL2); + SyncResources(appFileInfo); + CheckIconResource(file, fIconL2); + } + // * bitmap color_space != B_CMAP8 => B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // mini + BBitmap icon(BRect(0, 0, 15, 15), B_RGB32); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_OK); + BBitmap icon2(BRect(0, 0, 15, 15), B_RGB32); + icon2.SetBits(fIconM2->Bits(), fIconM2->BitsLength(), 0, B_CMAP8); + CHK(icon_equal(&icon, &icon2)); + // large +// R5: Crashes for some weird reason in GetIcon(). +#ifndef TEST_R5 + BBitmap icon3(BRect(0, 0, 31, 31), B_RGB32); + CHK(appFileInfo.GetIcon(&icon3, B_LARGE_ICON) == B_OK); + BBitmap icon4(BRect(0, 0, 31, 31), B_RGB32); + icon4.SetBits(fIconL2->Bits(), fIconL2->BitsLength(), 0, B_CMAP8); + CHK(icon_equal(&icon3, &icon4)); +#endif + } + + // status_t SetIcon(const BBitmap *icon, icon_size k) + // * NULL icon => unsets icon, B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // mini + // set + CHK(appFileInfo.SetIcon(NULL, B_MINI_ICON) == B_OK); + // get + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_ENTRY_NOT_FOUND); + CheckNoAttr(file, kMiniIconAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kMiniIconAttribute); + // large + // set + CHK(appFileInfo.SetIcon(NULL, B_LARGE_ICON) == B_OK); + // get + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon2, B_LARGE_ICON) == B_ENTRY_NOT_FOUND); + CheckNoAttr(file, kLargeIconAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kLargeIconAttribute); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.SetIcon(&icon, B_MINI_ICON) == B_NO_INIT); + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.SetIcon(&icon2, B_LARGE_ICON) == B_NO_INIT); + } + // * icon dimensions != icon size => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + BBitmap icon(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.SetIcon(&icon, B_MINI_ICON) == B_BAD_VALUE); + BBitmap icon2(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.SetIcon(&icon2, B_LARGE_ICON) == B_BAD_VALUE); + } + // * file has app signature, set an icon => the icon is also set on the + // MIME type + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // uninstalled signature + BMimeType mimeType(testAppSignature1); + CHK(mimeType.IsInstalled() == false); + CHK(appFileInfo.SetSignature(testAppSignature1) == B_OK); + CHK(appFileInfo.SetIcon(fIconM1, B_MINI_ICON) == B_OK); + CHK(appFileInfo.SetIcon(fIconL1, B_LARGE_ICON) == B_OK); + CHK(mimeType.IsInstalled() == true); + // get mini + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(mimeType.GetIcon(&icon, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM1, &icon)); + // get large + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(mimeType.GetIcon(&icon2, B_LARGE_ICON) == B_OK); + CHK(icon_equal(fIconL1, &icon2)); + // installed signature + CHK(appFileInfo.SetIcon(fIconM2, B_MINI_ICON) == B_OK); + CHK(appFileInfo.SetIcon(fIconL2, B_LARGE_ICON) == B_OK); + // get mini + BBitmap icon3(BRect(0, 0, 15, 15), B_CMAP8); + CHK(mimeType.GetIcon(&icon3, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM2, &icon3)); + // get large + BBitmap icon4(BRect(0, 0, 31, 31), B_CMAP8); + CHK(mimeType.GetIcon(&icon4, B_LARGE_ICON) == B_OK); + CHK(icon_equal(fIconL2, &icon4)); + } } // VersionInfoTest @@ -452,16 +1157,509 @@ AppFileInfoTest::VersionInfoTest() { // status_t GetVersionInfo(version_info *info, version_kind kind) const; // status_t SetVersionInfo(const version_info *info, version_kind kind); + version_info testInfo1 = { 1, 1, 1, 1, 1, "short1", "long1" }; + version_info testInfo2 = { 2, 2, 2, 2, 2, "short2", "long2" }; + version_info testInfo3 = { 3, 3, 3, 3, 3, "short3", "long3" }; + version_info testInfo4 = { 4, 4, 4, 4, 4, "short4", "long4" }; + + + // status_t GetVersionInfo(version_info *info, version_kind kind) const + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + version_info info; + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) + == B_NO_INIT); + version_info info2; + CHK(appFileInfo.GetVersionInfo(&info2, B_SYSTEM_VERSION_KIND) + == B_NO_INIT); + } + // * has no version info => B_ENTRY_NOT_FOUND + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + version_info info; + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) + == B_ENTRY_NOT_FOUND); + version_info info2; + CHK(appFileInfo.GetVersionInfo(&info2, B_SYSTEM_VERSION_KIND) + == B_ENTRY_NOT_FOUND); + } + // * set, get, reset, get + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // set app info + CHK(appFileInfo.SetVersionInfo(&testInfo1, B_APP_VERSION_KIND) + == B_OK); + // get both infos + version_info info; + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) == B_OK); + CHK(info == testInfo1); + CHK(appFileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) == B_OK); + // set app info + CHK(appFileInfo.SetVersionInfo(&testInfo2, B_SYSTEM_VERSION_KIND) + == B_OK); + // get + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) == B_OK); + CHK(info == testInfo1); + CHK(appFileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) == B_OK); + CHK(info == testInfo2); + version_info testInfos1[] = { testInfo1, testInfo2 }; + CheckVersionInfoAttr(file, testInfos1); + SyncResources(appFileInfo); + CheckVersionInfoResource(file, testInfos1); + // reset app info + CHK(appFileInfo.SetVersionInfo(&testInfo3, B_APP_VERSION_KIND) + == B_OK); + // get + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) == B_OK); + CHK(info == testInfo3); + CHK(appFileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) == B_OK); + CHK(info == testInfo2); + version_info testInfos2[] = { testInfo3, testInfo2 }; + CheckVersionInfoAttr(file, testInfos2); + SyncResources(appFileInfo); + CheckVersionInfoResource(file, testInfos2); + // reset system info + CHK(appFileInfo.SetVersionInfo(&testInfo4, B_SYSTEM_VERSION_KIND) + == B_OK); + // get + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) == B_OK); + CHK(info == testInfo3); + CHK(appFileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) == B_OK); + CHK(info == testInfo4); + version_info testInfos3[] = { testInfo3, testInfo4 }; + CheckVersionInfoAttr(file, testInfos3); + SyncResources(appFileInfo); + CheckVersionInfoResource(file, testInfos3); + } + // * NULL info => B_BAD_VALUE +// R5: crashes when passing a NULL version_info +#ifndef TEST_R5 + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(equals(appFileInfo.GetVersionInfo(NULL, B_APP_VERSION_KIND), + B_BAD_ADDRESS, B_BAD_VALUE)); + CHK(equals(appFileInfo.GetVersionInfo(NULL, B_SYSTEM_VERSION_KIND), + B_BAD_ADDRESS, B_BAD_VALUE)); + } +#endif + + // status_t SetVersionInfo(const version_info *info, version_kind kind) + // * NULL info => unsets both infos, B_OK +// R5: crashes when passing a NULL version_info +#ifndef TEST_R5 + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // unset app info + CHK(appFileInfo.SetVersionInfo(NULL, B_APP_VERSION_KIND) + == B_OK); + // try to get + version_info info; + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) + == B_ENTRY_NOT_FOUND); + CHK(appFileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) + == B_ENTRY_NOT_FOUND); + // check + CheckNoAttr(file, kVersionInfoAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kVersionInfoAttribute); + // reset the infos + CHK(appFileInfo.SetVersionInfo(&testInfo1, B_APP_VERSION_KIND) + == B_OK); + CHK(appFileInfo.SetVersionInfo(&testInfo1, B_SYSTEM_VERSION_KIND) + == B_OK); + // unset system info + CHK(appFileInfo.SetVersionInfo(NULL, B_SYSTEM_VERSION_KIND) + // try to get + CHK(appFileInfo.GetVersionInfo(&info, B_APP_VERSION_KIND) + == B_ENTRY_NOT_FOUND); + CHK(appFileInfo.GetVersionInfo(&info, B_SYSTEM_VERSION_KIND) + == B_ENTRY_NOT_FOUND); + // check + CheckNoAttr(file, kVersionInfoAttribute); + SyncResources(appFileInfo); + CheckNoResource(file, kVersionInfoAttribute); + } +#endif + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetVersionInfo(&testInfo1, B_APP_VERSION_KIND) + == B_NO_INIT); + CHK(appFileInfo.GetVersionInfo(&testInfo1, B_SYSTEM_VERSION_KIND) + == B_NO_INIT); + } } // IconForTypeTest void AppFileInfoTest::IconForTypeTest() { -// status_t GetIconForType(const char *type, BBitmap *icon, -// icon_size which) const; -// status_t SetIconForType(const char *type, const BBitmap *icon, -// icon_size which); + // status_t GetIconForType(const char *type, BBitmap *icon, + // icon_size which) const + // * NULL icon => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.GetIconForType(testType1, NULL, B_MINI_ICON) + == B_BAD_VALUE); + CHK(appFileInfo.GetIconForType(testType1, NULL, B_LARGE_ICON) + == B_BAD_VALUE); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) + == B_NO_INIT); + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_NO_INIT); + } + // * icon dimensions != icon size => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + BBitmap icon(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) + == B_BAD_VALUE); + BBitmap icon2(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_BAD_VALUE); + } + // * has no icon => B_ENTRY_NOT_FOUND + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) + == B_ENTRY_NOT_FOUND); + } + // * set, get, reset, get + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // mini + // set + CHK(appFileInfo.SetIconForType(testType1, fIconM1, B_MINI_ICON) + == B_OK); + // get + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM1, &icon)); + CheckIconForTypeAttr(file, testType1, fIconM1); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType1, fIconM1); + // reset + CHK(appFileInfo.SetIconForType(testType1, fIconM2, B_MINI_ICON) + == B_OK); + // get + BBitmap icon2(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon2, B_MINI_ICON) + == B_OK); + CHK(icon_equal(fIconM2, &icon2)); + CheckIconForTypeAttr(file, testType1, fIconM2); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType1, fIconM2); + // large + // set + CHK(appFileInfo.SetIconForType(testType1, fIconL1, B_LARGE_ICON) + == B_OK); + // get + BBitmap icon3(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon3, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL1, &icon3)); + CheckIconForTypeAttr(file, testType1, fIconL1); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType1, fIconL1); + // reset + CHK(appFileInfo.SetIconForType(testType1, fIconL2, B_LARGE_ICON) + == B_OK); + // get + BBitmap icon4(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon4, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL2, &icon4)); + CheckIconForTypeAttr(file, testType1, fIconL2); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType1, fIconL2); + } + // * bitmap color_space != B_CMAP8 => B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // mini + BBitmap icon(BRect(0, 0, 15, 15), B_RGB32); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) == B_OK); + BBitmap icon2(BRect(0, 0, 15, 15), B_RGB32); + icon2.SetBits(fIconM2->Bits(), fIconM2->BitsLength(), 0, B_CMAP8); + CHK(icon_equal(&icon, &icon2)); + // large +// R5: Crashes for some weird reason in GetIconForType(). +#ifndef TEST_R5 + BBitmap icon3(BRect(0, 0, 31, 31), B_RGB32); + CHK(appFileInfo.GetIconForType(testType1, &icon3, B_LARGE_ICON) + == B_OK); + BBitmap icon4(BRect(0, 0, 31, 31), B_RGB32); + icon4.SetBits(fIconL2->Bits(), fIconL2->BitsLength(), 0, B_CMAP8); + CHK(icon_equal(&icon3, &icon4)); +#endif + } + + // status_t SetIconForType(const char *type, const BBitmap *icon, + // icon_size which) + // * NULL icon => unsets icon, B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // mini + // set + CHK(appFileInfo.SetIconForType(testType1, NULL, B_MINI_ICON) == B_OK); + // get + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) + == B_ENTRY_NOT_FOUND); + CheckNoIconForTypeAttr(file, testType1, B_MINI_ICON); + SyncResources(appFileInfo); + CheckNoIconForTypeResource(file, testType1, B_MINI_ICON); + // large + // set + CHK(appFileInfo.SetIconForType(testType1, NULL, B_LARGE_ICON) == B_OK); + // get + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_ENTRY_NOT_FOUND); + CheckNoIconForTypeAttr(file, testType1, B_LARGE_ICON); + SyncResources(appFileInfo); + CheckNoIconForTypeResource(file, testType1, B_LARGE_ICON); + } + // * uninitialized => B_NO_INIT + NextSubTest(); + { + BAppFileInfo appFileInfo; + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.SetIconForType(testType1, &icon, B_MINI_ICON) + == B_NO_INIT); + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.SetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_NO_INIT); + } + // * icon dimensions != icon size => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + BBitmap icon(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.SetIconForType(testType1, &icon, B_MINI_ICON) + == B_BAD_VALUE); + BBitmap icon2(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.SetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_BAD_VALUE); + } + // * NULL type => set standard icon + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetIconForType(NULL, fIconM1, B_MINI_ICON) == B_OK); + CHK(appFileInfo.SetIconForType(NULL, fIconL1, B_LARGE_ICON) == B_OK); + // get mini icon via GetIcon() + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM1, &icon)); + CheckIconAttr(file, fIconM1); + SyncResources(appFileInfo); + CheckIconResource(file, fIconM1); + // get large via GetIcon() + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIcon(&icon2, B_LARGE_ICON) == B_OK); + CHK(icon_equal(fIconL1, &icon2)); + CheckIconAttr(file, fIconL1); + SyncResources(appFileInfo); + CheckIconResource(file, fIconL1); + // get mini icon via GetIconForType() + BBitmap icon3(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(NULL, &icon3, B_MINI_ICON) == B_OK); + CHK(icon_equal(fIconM1, &icon3)); + CheckIconAttr(file, fIconM1); + SyncResources(appFileInfo); + CheckIconResource(file, fIconM1); + // get large via GetIconForType() + BBitmap icon4(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(NULL, &icon4, B_LARGE_ICON) == B_OK); + CHK(icon_equal(fIconL1, &icon4)); + CheckIconAttr(file, fIconL1); + SyncResources(appFileInfo); + CheckIconResource(file, fIconL1); + } + // * set icons for two types + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // set icons for both types + CHK(appFileInfo.SetIconForType(testType1, fIconM1, B_MINI_ICON) + == B_OK); + CHK(appFileInfo.SetIconForType(testType1, fIconL1, B_LARGE_ICON) + == B_OK); + CHK(appFileInfo.SetIconForType(testType2, fIconM2, B_MINI_ICON) + == B_OK); + CHK(appFileInfo.SetIconForType(testType2, fIconL2, B_LARGE_ICON) + == B_OK); + // check first type + // get mini + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon, B_MINI_ICON) + == B_OK); + CHK(icon_equal(fIconM1, &icon)); + CheckIconForTypeAttr(file, testType1, fIconM1); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType1, fIconM1); + // get large + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL1, &icon2)); + CheckIconForTypeAttr(file, testType1, fIconL1); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType1, fIconL1); + // check second type + // get mini + BBitmap icon3(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType2, &icon3, B_MINI_ICON) + == B_OK); + CHK(icon_equal(fIconM2, &icon3)); + CheckIconForTypeAttr(file, testType2, fIconM2); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType2, fIconM2, + kMiniIconForTypeResourceID + 1); + // get large + BBitmap icon4(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(testType2, &icon4, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL2, &icon4)); + CheckIconForTypeAttr(file, testType2, fIconL2); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, testType2, fIconL2, + kLargeIconForTypeResourceID + 1); + // unset both icons + CHK(appFileInfo.SetIconForType(testType1, NULL, B_MINI_ICON) == B_OK); + CHK(appFileInfo.SetIconForType(testType1, NULL, B_LARGE_ICON) == B_OK); + CHK(appFileInfo.SetIconForType(testType2, NULL, B_MINI_ICON) == B_OK); + CHK(appFileInfo.SetIconForType(testType2, NULL, B_LARGE_ICON) == B_OK); + } + // * invalid type => B_OK + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetIconForType(invalidTestType, fIconM1, B_MINI_ICON) + == B_OK); + CHK(appFileInfo.SetIconForType(invalidTestType, fIconL1, B_LARGE_ICON) + == B_OK); + // get mini + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(appFileInfo.GetIconForType(invalidTestType, &icon, B_MINI_ICON) + == B_OK); + CHK(icon_equal(fIconM1, &icon)); + CheckIconForTypeAttr(file, invalidTestType, fIconM1); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, invalidTestType, fIconM1); + // get large + BBitmap icon3(BRect(0, 0, 31, 31), B_CMAP8); + CHK(appFileInfo.GetIconForType(invalidTestType, &icon3, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL1, &icon3)); + CheckIconForTypeAttr(file, invalidTestType, fIconL1); + SyncResources(appFileInfo); + CheckIconForTypeResource(file, invalidTestType, fIconL1); + } + // * too long type => B_BAD_VALUE + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + CHK(appFileInfo.SetIconForType(tooLongTestType, fIconM1, B_MINI_ICON) + == B_BAD_VALUE); + CHK(appFileInfo.SetIconForType(tooLongTestType, fIconL1, B_LARGE_ICON) + == B_BAD_VALUE); + } + // * file has app signature, set an icon => the icon is also set on the + // MIME type + NextSubTest(); + { + BFile file(testFile1, B_READ_WRITE); + BAppFileInfo appFileInfo; + CHK(appFileInfo.SetTo(&file) == B_OK); + // uninstalled signature + BMimeType mimeType(testAppSignature1); + CHK(mimeType.IsInstalled() == false); + CHK(appFileInfo.SetSignature(testAppSignature1) == B_OK); + CHK(appFileInfo.SetIconForType(testType1, fIconM1, B_MINI_ICON) + == B_OK); + CHK(appFileInfo.SetIconForType(testType1, fIconL1, B_LARGE_ICON) + == B_OK); + CHK(mimeType.IsInstalled() == true); + CHK(BMimeType(testType1).IsInstalled() == false); + // get mini + BBitmap icon(BRect(0, 0, 15, 15), B_CMAP8); + CHK(mimeType.GetIconForType(testType1, &icon, B_MINI_ICON) + == B_OK); + CHK(icon_equal(fIconM1, &icon)); + // get large + BBitmap icon2(BRect(0, 0, 31, 31), B_CMAP8); + CHK(mimeType.GetIconForType(testType1, &icon2, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL1, &icon2)); + // installed signature + CHK(appFileInfo.SetIconForType(testType1, fIconM2, B_MINI_ICON) + == B_OK); + CHK(appFileInfo.SetIconForType(testType1, fIconL2, B_LARGE_ICON) + == B_OK); + // get mini + BBitmap icon3(BRect(0, 0, 15, 15), B_CMAP8); + CHK(mimeType.GetIconForType(testType1, &icon3, B_MINI_ICON) + == B_OK); + CHK(icon_equal(fIconM2, &icon3)); + // get large + BBitmap icon4(BRect(0, 0, 31, 31), B_CMAP8); + CHK(mimeType.GetIconForType(testType1, &icon4, B_LARGE_ICON) + == B_OK); + CHK(icon_equal(fIconL2, &icon4)); + } } @@ -483,7 +1681,7 @@ InfoLocationTester(const Value &testValue1, const Value &testValue2, CHK(appFileInfo.IsUsingAttributes() == true); CHK(appFileInfo.IsUsingResources() == true); // force resources synchronization - CHK(appFileInfo.SetTo(&file) == B_OK); + SyncResources(appFileInfo); // get value Value value; CHK(Getter::Get(appFileInfo, value) == B_OK); @@ -498,12 +1696,7 @@ InfoLocationTester(const Value &testValue1, const Value &testValue2, // set value CHK(Setter::Set(appFileInfo, testValue2) == B_OK); // force resources synchronization - CHK(appFileInfo.SetTo(&file) == B_OK); - CHK(appFileInfo.IsUsingAttributes() == true); - CHK(appFileInfo.IsUsingResources() == true); - appFileInfo.SetInfoLocation(B_USE_ATTRIBUTES); - CHK(appFileInfo.IsUsingAttributes() == true); - CHK(appFileInfo.IsUsingResources() == false); + SyncResources(appFileInfo); // get value Value value1; CHK(Getter::Get(appFileInfo, value1) == B_OK); @@ -526,12 +1719,7 @@ InfoLocationTester(const Value &testValue1, const Value &testValue2, // set value CHK(Setter::Set(appFileInfo, testValue3) == B_OK); // force resources synchronization - CHK(appFileInfo.SetTo(&file) == B_OK); - CHK(appFileInfo.IsUsingAttributes() == true); - CHK(appFileInfo.IsUsingResources() == true); - appFileInfo.SetInfoLocation(B_USE_RESOURCES); - CHK(appFileInfo.IsUsingAttributes() == false); - CHK(appFileInfo.IsUsingResources() == true); + SyncResources(appFileInfo); // get value Value value3; CHK(Getter::Get(appFileInfo, value3) == B_OK); @@ -1037,20 +2225,6 @@ AppFileInfoTest::InfoLocationTest() // icon for type NextSubTest(); - { - BFile file(testFile1, B_READ_WRITE); - BAppFileInfo appFileInfo; - CHK(appFileInfo.SetTo(&file) == B_OK); - CHK(appFileInfo.SetSignature(testAppSignature1) == B_OK); - BMimeType type(testAppSignature1); - if (!type.IsInstalled()) - CHK(type.Install() == B_OK); - BMessage supportedTypes; - supportedTypes.AddString("types", testType1); - CHK(appFileInfo.SetSupportedTypes(&supportedTypes) == B_OK); - CHK(type.SetTo(testType1) == B_OK); - CHK(type.SetPreferredApp(testAppSignature1) == B_OK); - } InfoLocationTester( IconForTypeValue(fIconM1, fIconL1),