TEST(MediaMIMETypes, MediaExtendedMIMEType) { // Some generic tests first. static const struct { const char* mTypeString; const char* mTypeAsString; bool mApplication; bool mAudio; bool mVideo; bool mEqualsLiteralVideoSlashMp4; // tests `== "video/mp4"` bool mHaveCodecs; } tests[] = { // in Type().AsString app audio video ==v/mp4 codecs { "video/mp4", "video/mp4", false, false, true, true, false }, { "video/mp4; codecs=0", "video/mp4", false, false, true, true, true }, { "VIDEO/MP4", "video/mp4", false, false, true, true, false }, { "audio/mp4", "audio/mp4", false, true, false, false, false }, { "application/x", "application/x", true, false, false, false, false } }; for (const auto& test : tests) { Maybe<MediaExtendedMIMEType> type = MakeMediaExtendedMIMEType(test.mTypeString); EXPECT_TRUE(type.isSome()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\").isSome()"; EXPECT_TRUE(type->OriginalString().EqualsASCII(test.mTypeString)) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->AsString() == \"" << test.mTypeAsString << "\""; EXPECT_TRUE(type->Type().AsString().EqualsASCII(test.mTypeAsString)) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->AsString() == \"" << test.mTypeAsString << "\""; EXPECT_EQ(test.mApplication, type->Type().HasApplicationMajorType()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->Type().HasApplicationMajorType() == " << (test.mApplication ? "true" : "false"); EXPECT_EQ(test.mAudio, type->Type().HasAudioMajorType()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->Type().HasAudioMajorType() == " << (test.mAudio ? "true" : "false"); EXPECT_EQ(test.mVideo, type->Type().HasVideoMajorType()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->Type().HasVideoMajorType() == " << (test.mVideo ? "true" : "false"); EXPECT_EQ(test.mEqualsLiteralVideoSlashMp4, type->Type() == MEDIAMIMETYPE("video/mp4")) << "*MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->Type() == MEDIAMIMETYPE(\"video/mp4\")"; EXPECT_EQ(test.mHaveCodecs, type->HaveCodecs()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->HaveCodecs() == " << (test.mHaveCodecs ? "true" : "false"); EXPECT_NE(test.mHaveCodecs, type->Codecs().IsEmpty()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->Codecs.IsEmpty() != " << (test.mHaveCodecs ? "true" : "false"); EXPECT_FALSE(type->GetWidth()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->GetWidth()"; EXPECT_FALSE(type->GetHeight()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->GetHeight()"; EXPECT_FALSE(type->GetFramerate()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->GetFramerate()"; EXPECT_FALSE(type->GetBitrate()) << "MakeMediaExtendedMIMEType(\"" << test.mTypeString << "\")->GetBitrate()"; } // Test all extra parameters. Maybe<MediaExtendedMIMEType> type = MakeMediaExtendedMIMEType( "video/mp4; codecs=\"a,b\"; width=1024; Height=768; FrameRate=60; BITRATE=100000"); EXPECT_TRUE(type->HaveCodecs()); EXPECT_FALSE(type->Codecs().IsEmpty()); EXPECT_TRUE(type->Codecs().AsString().EqualsASCII("a,b")); EXPECT_TRUE(type->Codecs().Contains(NS_LITERAL_STRING("a"))); EXPECT_TRUE(type->Codecs().Contains(NS_LITERAL_STRING("b"))); EXPECT_TRUE(!!type->GetWidth()); EXPECT_EQ(1024, *type->GetWidth()); EXPECT_TRUE(!!type->GetHeight()); EXPECT_EQ(768, *type->GetHeight()); EXPECT_TRUE(!!type->GetFramerate()); EXPECT_EQ(60, *type->GetFramerate()); EXPECT_TRUE(!!type->GetBitrate()); EXPECT_EQ(100000, *type->GetBitrate()); }