// This magic data is fake; just a way to test various features. static const char s_magicData[] = "MIME-Magic\0\n" "[50:application/x-desktop]\n" ">0=\0\017[Desktop Entry]+11\n" ">2=\0\002[A&\xff\001\n" // '[' and then any non-even value "1>4=\0\001]\n" "[40:application/vnd.ms-tnef]\n" ">0=\0\004\x78\x9f\x3e\x22\n" // tnef magic, in "ready to use" form // https://bugs.freedesktop.org/show_bug.cgi?id=435 // "[30:text/x-test-mime-host16]\n" ">0=\0\002\x12\x34~2\n" // "[30:text/x-test-mime-big16]\n" ">0=\0\002\x12\x78\n" // "[30:text/x-test-mime-little16]\n" ">0=\0\002\x78\x55\n" // "[30:text/x-test-mime-host32]\n" ">0=\0\004\x12\x34\x56\x78~4\n" "[50:application/vnd.ms-powerpoint]\n" // fixed ppt magic, see https://bugs.freedesktop.org/show_bug.cgi?id=435 ">0=\0\004\xd0\xcf\x11\xe0\n"; QTest::addColumn("testData"); QTest::addColumn("expected"); QTest::newRow("First rule, no offset") << "[Desktop Entry]" << "application/x-desktop"; QTest::newRow("First rule, with offset") << "# Comment\n[Desktop Entry]" << "application/x-desktop"; QTest::newRow("Missing char") << "# Comment\n[Desktop Entry" << QString(); QTest::newRow("Second rule, two-level match") << "AB[C]" << "application/x-desktop"; QTest::newRow("Second rule, failure at first level (mask)") << "AB[B]" << QString(); QTest::newRow("Second rule, failure at second level") << "AB[CN" << QString(); QTest::newRow("Tnef magic, should pass") << "\x78\x9f\x3e\x22" << "application/vnd.ms-tnef"; QTest::newRow("Tnef magic, should fail") << "\x22\x3e\x9f\x78" << QString(); QTest::newRow("Powerpoint rule, for endianness check, should pass") << "\xd0\xcf\x11\xe0" << "application/vnd.ms-powerpoint"; QTest::newRow("Powerpoint rule, no swapping, should fail") << "\x11\xe0\xd0\xcf" << QString(); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN QTest::newRow("Test mime, host16, wrong endianness") << "\x12\x34" << QString(); QTest::newRow("Test mime, host16, little endian, ok") << "\x34\x12" << "text/x-test-mime-host16"; QTest::newRow("Test mime, host32, wrong endianness") << "\x12\x34\x56\x78" << QString(); QTest::newRow("Test mime, host32, little endian, ok") << "\x78\x56\x34\x12" << "text/x-test-mime-host32"; #else QTest::newRow("Test mime, host16, big endian, ok") << "\x12\x34" << "text/x-test-mime-host16"; QTest::newRow("Test mime, host16, wrong endianness") << "\x34\x12" << QString(); QTest::newRow("Test mime, host32, big endian, ok") << "\x12\x34\x56\x78" << "text/x-test-mime-host32"; QTest::newRow("Test mime, host32, wrong endianness") << "\x78\x56\x34\x12" << QString(); #endif QTest::newRow("Test mime, little16, little endian, ok") << "\x78\x55" << "text/x-test-mime-little16"; QTest::newRow("Test mime, little16, wrong endianness") << "\x55\x78" << QString(); QTest::newRow("Test mime, big16, little endian, ok") << "\x12\x78" << "text/x-test-mime-big16"; QTest::newRow("Test mime, big16, wrong endianness") << "\x78\x12" << QString();