Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/gtest/TestVideoUtils.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#include "gtest/gtest.h"
7
#include "nsMimeTypes.h"
8
#include "nsString.h"
9
#include "VideoUtils.h"
10
11
using namespace mozilla;
12
13
TEST(MediaMIMETypes, IsMediaMIMEType)
14
0
{
15
0
  EXPECT_TRUE(IsMediaMIMEType(AUDIO_MP4));
16
0
  EXPECT_TRUE(IsMediaMIMEType(VIDEO_MP4));
17
0
  EXPECT_TRUE(IsMediaMIMEType("application/x-mp4"));
18
0
19
0
  EXPECT_TRUE(IsMediaMIMEType("audio/m"));
20
0
  EXPECT_FALSE(IsMediaMIMEType("audio/"));
21
0
22
0
  EXPECT_FALSE(IsMediaMIMEType("vide/mp4"));
23
0
  EXPECT_FALSE(IsMediaMIMEType("videos/mp4"));
24
0
25
0
  // Expect lowercase only.
26
0
  EXPECT_FALSE(IsMediaMIMEType("Video/mp4"));
27
0
}
28
29
TEST(StringListRange, MakeStringListRange)
30
0
{
31
0
  static const struct
32
0
  {
33
0
    const char* mList;
34
0
    const char* mExpectedSkipEmpties;
35
0
    const char* mExpectedProcessAll;
36
0
    const char* mExpectedProcessEmpties;
37
0
  } tests[] =
38
0
  { // string              skip         all               empties
39
0
    { "",                  "",          "|",              "" },
40
0
    { " ",                 "",          "|",              "|" },
41
0
    { ",",                 "",          "||",             "||" },
42
0
    { " , ",               "",          "||",             "||" },
43
0
    { "a",                 "a|",        "a|",             "a|" },
44
0
    { "  a  ",             "a|",        "a|",             "a|" },
45
0
    { "a,",                "a|",        "a||",            "a||" },
46
0
    { "a, ",               "a|",        "a||",            "a||" },
47
0
    { ",a",                "a|",        "|a|",            "|a|" },
48
0
    { " ,a",               "a|",        "|a|",            "|a|" },
49
0
    { "aa,bb",             "aa|bb|",    "aa|bb|",         "aa|bb|" },
50
0
    { " a a ,  b b  ",     "a a|b b|",  "a a|b b|",       "a a|b b|" },
51
0
    { " , ,a 1,,  ,b  2,", "a 1|b  2|", "||a 1|||b  2||", "||a 1|||b  2||" }
52
0
  };
53
0
54
0
  for (const auto& test : tests) {
55
0
    nsCString list(test.mList);
56
0
    nsCString out;
57
0
    for (const auto& item : MakeStringListRange(list)) {
58
0
      out += item;
59
0
      out += "|";
60
0
    }
61
0
    EXPECT_STREQ(test.mExpectedSkipEmpties, out.Data());
62
0
    out.SetLength(0);
63
0
64
0
    for (const auto& item :
65
0
         MakeStringListRange<StringListRangeEmptyItems::ProcessAll>(list)) {
66
0
      out += item;
67
0
      out += "|";
68
0
    }
69
0
    EXPECT_STREQ(test.mExpectedProcessAll, out.Data());
70
0
    out.SetLength(0);
71
0
72
0
    for (const auto& item :
73
0
         MakeStringListRange<StringListRangeEmptyItems::ProcessEmptyItems>(list)) {
74
0
      out += item;
75
0
      out += "|";
76
0
    }
77
0
    EXPECT_STREQ(test.mExpectedProcessEmpties, out.Data());
78
0
  }
79
0
}
80
81
TEST(StringListRange, StringListContains)
82
0
{
83
0
  static const struct
84
0
  {
85
0
    const char* mList;
86
0
    const char* mItemToSearch;
87
0
    bool mExpectedSkipEmpties;
88
0
    bool mExpectedProcessAll;
89
0
    bool mExpectedProcessEmpties;
90
0
  } tests[] =
91
0
  { // haystack            needle  skip   all    empties
92
0
    { "",                  "",     false, true,  false },
93
0
    { " ",                 "",     false, true,  true  },
94
0
    { "",                  "a",    false, false, false },
95
0
    { " ",                 "a",    false, false, false },
96
0
    { ",",                 "a",    false, false, false },
97
0
    { " , ",               "",     false, true,  true  },
98
0
    { " , ",               "a",    false, false, false },
99
0
    { "a",                 "a",    true,  true,  true  },
100
0
    { "a",                 "b",    false, false, false },
101
0
    { "  a  ",             "a",    true,  true,  true  },
102
0
    { "aa,bb",             "aa",   true,  true,  true  },
103
0
    { "aa,bb",             "bb",   true,  true,  true  },
104
0
    { "aa,bb",             "cc",   false, false, false },
105
0
    { "aa,bb",             " aa ", false, false, false },
106
0
    { " a a ,  b b  ",     "a a",  true,  true,  true  },
107
0
    { " , ,a 1,,  ,b  2,", "a 1",  true,  true,  true  },
108
0
    { " , ,a 1,,  ,b  2,", "b  2", true,  true,  true  },
109
0
    { " , ,a 1,,  ,b  2,", "",     false, true,  true  },
110
0
    { " , ,a 1,,  ,b  2,", " ",    false, false, false },
111
0
    { " , ,a 1,,  ,b  2,", "A 1",  false, false, false },
112
0
    { " , ,A 1,,  ,b  2,", "a 1",  false, false, false }
113
0
  };
114
0
115
0
  for (const auto& test : tests) {
116
0
    nsCString list(test.mList);
117
0
    nsCString itemToSearch(test.mItemToSearch);
118
0
    EXPECT_EQ(test.mExpectedSkipEmpties, StringListContains(list, itemToSearch))
119
0
      << "trying to find \"" << itemToSearch.Data()
120
0
      << "\" in \"" << list.Data() << "\" (skipping empties)";
121
0
    EXPECT_EQ(test.mExpectedProcessAll,
122
0
              StringListContains<StringListRangeEmptyItems::ProcessAll>
123
0
                                (list, itemToSearch))
124
0
      << "trying to find \"" << itemToSearch.Data()
125
0
      << "\" in \"" << list.Data() << "\" (processing everything)";
126
0
    EXPECT_EQ(test.mExpectedProcessEmpties,
127
0
              StringListContains<StringListRangeEmptyItems::ProcessEmptyItems>
128
0
                                (list, itemToSearch))
129
0
      << "trying to find \"" << itemToSearch.Data()
130
0
      << "\" in \"" << list.Data() << "\" (processing empties)";
131
0
  }
132
0
}