1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gtest/gtest.h"
7 #include "nsMimeTypes.h"
9 #include "VideoUtils.h"
11 using namespace mozilla
;
13 TEST(MediaMIMETypes
, IsMediaMIMEType
)
15 EXPECT_TRUE(IsMediaMIMEType(AUDIO_MP4
));
16 EXPECT_TRUE(IsMediaMIMEType(VIDEO_MP4
));
17 EXPECT_TRUE(IsMediaMIMEType("application/x-mp4"));
19 EXPECT_TRUE(IsMediaMIMEType("audio/m"));
20 EXPECT_FALSE(IsMediaMIMEType("audio/"));
22 EXPECT_FALSE(IsMediaMIMEType("vide/mp4"));
23 EXPECT_FALSE(IsMediaMIMEType("videos/mp4"));
25 // Expect lowercase only.
26 EXPECT_FALSE(IsMediaMIMEType("Video/mp4"));
29 TEST(StringListRange
, MakeStringListRange
)
33 const char* mExpectedSkipEmpties
;
34 const char* mExpectedProcessAll
;
35 const char* mExpectedProcessEmpties
;
37 // string skip all empties
40 {",", "", "||", "||"},
41 {" , ", "", "||", "||"},
42 {"a", "a|", "a|", "a|"},
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 {"aa,bb", "aa|bb|", "aa|bb|", "aa|bb|"},
49 {" a a , b b ", "a a|b b|", "a a|b b|", "a a|b b|"},
50 {" , ,a 1,, ,b 2,", "a 1|b 2|", "||a 1|||b 2||", "||a 1|||b 2||"}};
52 for (const auto& test
: tests
) {
53 nsCString
list(test
.mList
);
55 for (const auto& item
: MakeStringListRange(list
)) {
59 EXPECT_STREQ(test
.mExpectedSkipEmpties
, out
.Data());
62 for (const auto& item
:
63 MakeStringListRange
<StringListRangeEmptyItems::ProcessAll
>(list
)) {
67 EXPECT_STREQ(test
.mExpectedProcessAll
, out
.Data());
70 for (const auto& item
:
71 MakeStringListRange
<StringListRangeEmptyItems::ProcessEmptyItems
>(
76 EXPECT_STREQ(test
.mExpectedProcessEmpties
, out
.Data());
80 TEST(StringListRange
, StringListContains
)
84 const char* mItemToSearch
;
85 bool mExpectedSkipEmpties
;
86 bool mExpectedProcessAll
;
87 bool mExpectedProcessEmpties
;
88 } tests
[] = {// haystack needle skip all empties
89 {"", "", false, true, false},
90 {" ", "", false, true, true},
91 {"", "a", false, false, false},
92 {" ", "a", false, false, false},
93 {",", "a", false, false, false},
94 {" , ", "", false, true, true},
95 {" , ", "a", false, false, false},
96 {"a", "a", true, true, true},
97 {"a", "b", false, false, false},
98 {" a ", "a", true, true, true},
99 {"aa,bb", "aa", true, true, true},
100 {"aa,bb", "bb", true, true, true},
101 {"aa,bb", "cc", false, false, false},
102 {"aa,bb", " aa ", false, false, false},
103 {" a a , b b ", "a a", true, true, true},
104 {" , ,a 1,, ,b 2,", "a 1", true, true, true},
105 {" , ,a 1,, ,b 2,", "b 2", true, true, true},
106 {" , ,a 1,, ,b 2,", "", false, true, true},
107 {" , ,a 1,, ,b 2,", " ", false, false, false},
108 {" , ,a 1,, ,b 2,", "A 1", false, false, false},
109 {" , ,A 1,, ,b 2,", "a 1", false, false, false}};
111 for (const auto& test
: tests
) {
112 nsCString
list(test
.mList
);
113 nsCString
itemToSearch(test
.mItemToSearch
);
114 EXPECT_EQ(test
.mExpectedSkipEmpties
, StringListContains(list
, itemToSearch
))
115 << "trying to find \"" << itemToSearch
.Data() << "\" in \""
116 << list
.Data() << "\" (skipping empties)";
117 EXPECT_EQ(test
.mExpectedProcessAll
,
118 StringListContains
<StringListRangeEmptyItems::ProcessAll
>(
120 << "trying to find \"" << itemToSearch
.Data() << "\" in \""
121 << list
.Data() << "\" (processing everything)";
122 EXPECT_EQ(test
.mExpectedProcessEmpties
,
123 StringListContains
<StringListRangeEmptyItems::ProcessEmptyItems
>(
125 << "trying to find \"" << itemToSearch
.Data() << "\" in \""
126 << list
.Data() << "\" (processing empties)";