From 31b14cbbf85a9a53eb8bf9d9b41f53351d0cbb8b Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 19 Jan 2005 01:30:41 +0000 Subject: [PATCH] Added dump_mime_types, a small test program that prints out all installed MIME types with several of its attributes. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10861 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/storage/Jamfile | 1 + src/tests/kits/storage/testapps/Jamfile | 3 + .../kits/storage/testapps/dump_mime_types.cpp | 119 ++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 src/tests/kits/storage/testapps/Jamfile create mode 100644 src/tests/kits/storage/testapps/dump_mime_types.cpp diff --git a/src/tests/kits/storage/Jamfile b/src/tests/kits/storage/Jamfile index e104bb763b..5a7804377e 100644 --- a/src/tests/kits/storage/Jamfile +++ b/src/tests/kits/storage/Jamfile @@ -43,4 +43,5 @@ CommonTestLib libstoragetest.so } SubInclude OBOS_TOP src tests kits storage disk_device ; +SubInclude OBOS_TOP src tests kits storage testapps ; SubInclude OBOS_TOP src tests kits storage virtualdrive ; diff --git a/src/tests/kits/storage/testapps/Jamfile b/src/tests/kits/storage/testapps/Jamfile new file mode 100644 index 0000000000..495c080664 --- /dev/null +++ b/src/tests/kits/storage/testapps/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src tests kits storage testapps ; + +SimpleTest dump_mime_types : dump_mime_types.cpp : be net ; diff --git a/src/tests/kits/storage/testapps/dump_mime_types.cpp b/src/tests/kits/storage/testapps/dump_mime_types.cpp new file mode 100644 index 0000000000..0f7d6a39b2 --- /dev/null +++ b/src/tests/kits/storage/testapps/dump_mime_types.cpp @@ -0,0 +1,119 @@ +// dump_mime_types.cpp + +#include +#include +#include + +#include +#include +#include + +// main +int +main() +{ + // create a BApplication on BeOS + struct utsname unameInfo; + if (uname(&unameInfo) < 0 || strcmp(unameInfo.sysname, "Haiku") != 0) + new BApplication("application/x-vnd.haiku.dump-mime-types"); + + // get the list of installed types + BMessage installedTypes; + status_t error = BMimeType::GetInstalledTypes(&installedTypes); + if (error != B_OK) { + fprintf(stderr, "Failed to get installed types: %s\n", strerror(error)); + exit(1); + } + + // print the types (including some additional info) + const char *type; + for (int i = 0; installedTypes.FindString("types", i, &type) == B_OK; i++) { + printf("%s:\n", type); + + // get mime type + BMimeType mimeType; + error = mimeType.SetTo(type); + if (error != B_OK) { + printf(" failed to init type: %s\n", strerror(error)); + continue; + } + + // preferred app + char preferredApp[B_MIME_TYPE_LENGTH]; + if (mimeType.GetPreferredApp(preferredApp) == B_OK) + printf(" preferred app: %s\n", preferredApp); + + // short description + char shortDescription[256]; + if (mimeType.GetShortDescription(shortDescription) == B_OK) + printf(" short description: %s\n", shortDescription); + + // long description + char longDescription[256]; + if (mimeType.GetLongDescription(longDescription) == B_OK) + printf(" long description: %s\n", longDescription); + + // extensions + BMessage extensions; + if (mimeType.GetFileExtensions(&extensions) == B_OK) { + printf(" extensions: "); + const char *extension; + for (int k = 0; + extensions.FindString("extensions", k, &extension) == B_OK; + k++) { + if (k > 0) + printf(" "); + printf("%s", extension); + } + printf("\n"); + } + + // supporting apps + BMessage supportingApps; + if (mimeType.GetSupportingApps(&supportingApps) == B_OK) { + const char *app; + for (int k = 0; + supportingApps.FindString("applications", k, &app) == B_OK; + k++) { + if (k == 0) + printf(" supporting apps: "); + else + printf(" "); + printf("%s\n", app); + } + } + + // attr info + BMessage attrInfo; + if (mimeType.GetAttrInfo(&attrInfo) == B_OK) { + printf(" attributes:\n"); + const char *name; + const char *publicName; + type_code type; + bool isViewable; + bool isPublic; + bool isEditable; + for (int k = 0; + attrInfo.FindString("attr:name", k, &name) == B_OK + && (attrInfo.FindString("attr:public_name", k, + &publicName) == B_OK || (publicName = name, true)) + && (attrInfo.FindInt32("attr:type", k, (int32*)&type) == B_OK + || (type = '____', true)) + && (attrInfo.FindBool("attr:viewable", k, &isViewable) == B_OK + || (isViewable = false, true)) + && (attrInfo.FindBool("attr:public", k, &isPublic) == B_OK + || (isPublic = isViewable, true)) + && (attrInfo.FindBool("attr:editable", k, &isEditable) == B_OK + || (isEditable = false, true)); + k++) { + printf(" `%s' (`%s')\n", name, publicName); + printf(" type: %c%c%c%c (0x%lx)\n", char(type >> 24), + char(type >> 16), char(type >> 8), char(type), type); + printf(" public: %s\n", (isPublic ? "true" : "false")); + printf(" editable: %s\n", (isEditable ? "true" : "false")); + } + } + } + + return 0; +}