TestVideoUtils.cpp (4697B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "VideoUtils.h" 8 #include "gtest/gtest.h" 9 #include "nsMimeTypes.h" 10 #include "nsString.h" 11 12 using namespace mozilla; 13 14 TEST(MediaMIMETypes, IsMediaMIMEType) 15 { 16 EXPECT_TRUE(IsMediaMIMEType(AUDIO_MP4)); 17 EXPECT_TRUE(IsMediaMIMEType(VIDEO_MP4)); 18 EXPECT_TRUE(IsMediaMIMEType("application/x-mp4")); 19 20 EXPECT_TRUE(IsMediaMIMEType("audio/m")); 21 EXPECT_FALSE(IsMediaMIMEType("audio/")); 22 23 EXPECT_FALSE(IsMediaMIMEType("vide/mp4")); 24 EXPECT_FALSE(IsMediaMIMEType("videos/mp4")); 25 26 // Expect lowercase only. 27 EXPECT_FALSE(IsMediaMIMEType("Video/mp4")); 28 } 29 30 TEST(StringListRange, MakeStringListRange) 31 { 32 static const struct { 33 const char* mList; 34 const char* mExpectedSkipEmpties; 35 const char* mExpectedProcessAll; 36 const char* mExpectedProcessEmpties; 37 } tests[] = { 38 // string skip all empties 39 {"", "", "|", ""}, 40 {" ", "", "|", "|"}, 41 {",", "", "||", "||"}, 42 {" , ", "", "||", "||"}, 43 {"a", "a|", "a|", "a|"}, 44 {" a ", "a|", "a|", "a|"}, 45 {"a,", "a|", "a||", "a||"}, 46 {"a, ", "a|", "a||", "a||"}, 47 {",a", "a|", "|a|", "|a|"}, 48 {" ,a", "a|", "|a|", "|a|"}, 49 {"aa,bb", "aa|bb|", "aa|bb|", "aa|bb|"}, 50 {" a a , b b ", "a a|b b|", "a a|b b|", "a a|b b|"}, 51 {" , ,a 1,, ,b 2,", "a 1|b 2|", "||a 1|||b 2||", "||a 1|||b 2||"}}; 52 53 for (const auto& test : tests) { 54 nsCString list(test.mList); 55 nsCString out; 56 for (const auto& item : MakeStringListRange(list)) { 57 out += item; 58 out += "|"; 59 } 60 EXPECT_STREQ(test.mExpectedSkipEmpties, out.Data()); 61 out.SetLength(0); 62 63 for (const auto& item : 64 MakeStringListRange<StringListRangeEmptyItems::ProcessAll>(list)) { 65 out += item; 66 out += "|"; 67 } 68 EXPECT_STREQ(test.mExpectedProcessAll, out.Data()); 69 out.SetLength(0); 70 71 for (const auto& item : 72 MakeStringListRange<StringListRangeEmptyItems::ProcessEmptyItems>( 73 list)) { 74 out += item; 75 out += "|"; 76 } 77 EXPECT_STREQ(test.mExpectedProcessEmpties, out.Data()); 78 } 79 } 80 81 TEST(StringListRange, StringListContains) 82 { 83 static const struct { 84 const char* mList; 85 const char* mItemToSearch; 86 bool mExpectedSkipEmpties; 87 bool mExpectedProcessAll; 88 bool mExpectedProcessEmpties; 89 } tests[] = {// haystack needle skip all empties 90 {"", "", false, true, false}, 91 {" ", "", false, true, true}, 92 {"", "a", false, false, false}, 93 {" ", "a", false, false, false}, 94 {",", "a", false, false, false}, 95 {" , ", "", false, true, true}, 96 {" , ", "a", false, false, false}, 97 {"a", "a", true, true, true}, 98 {"a", "b", false, false, false}, 99 {" a ", "a", true, true, true}, 100 {"aa,bb", "aa", true, true, true}, 101 {"aa,bb", "bb", true, true, true}, 102 {"aa,bb", "cc", false, false, false}, 103 {"aa,bb", " aa ", false, false, false}, 104 {" a a , b b ", "a a", true, true, true}, 105 {" , ,a 1,, ,b 2,", "a 1", true, true, true}, 106 {" , ,a 1,, ,b 2,", "b 2", true, true, true}, 107 {" , ,a 1,, ,b 2,", "", false, true, true}, 108 {" , ,a 1,, ,b 2,", " ", false, false, false}, 109 {" , ,a 1,, ,b 2,", "A 1", false, false, false}, 110 {" , ,A 1,, ,b 2,", "a 1", false, false, false}}; 111 112 for (const auto& test : tests) { 113 nsCString list(test.mList); 114 nsCString itemToSearch(test.mItemToSearch); 115 EXPECT_EQ(test.mExpectedSkipEmpties, StringListContains(list, itemToSearch)) 116 << "trying to find \"" << itemToSearch.Data() << "\" in \"" 117 << list.Data() << "\" (skipping empties)"; 118 EXPECT_EQ(test.mExpectedProcessAll, 119 StringListContains<StringListRangeEmptyItems::ProcessAll>( 120 list, itemToSearch)) 121 << "trying to find \"" << itemToSearch.Data() << "\" in \"" 122 << list.Data() << "\" (processing everything)"; 123 EXPECT_EQ(test.mExpectedProcessEmpties, 124 StringListContains<StringListRangeEmptyItems::ProcessEmptyItems>( 125 list, itemToSearch)) 126 << "trying to find \"" << itemToSearch.Data() << "\" in \"" 127 << list.Data() << "\" (processing empties)"; 128 } 129 }