1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38

media / base / subsample_entry_unittest.cc [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/base/subsample_entry.h"

#include <limits>

#include "base/numerics/safe_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {

constexpr uint32_t kMax = std::numeric_limits<uint32_t>::max();

TEST(SubsampleEntryTest, NoEntries) {
  EXPECT_TRUE(VerifySubsamplesMatchSize({}, 0));
  EXPECT_FALSE(VerifySubsamplesMatchSize({}, 100));
}

TEST(SubsampleEntryTest, OneEntry) {
  EXPECT_TRUE(VerifySubsamplesMatchSize({{0, 50}}, 50));
  EXPECT_TRUE(VerifySubsamplesMatchSize({{100, 00}}, 100));
  EXPECT_TRUE(VerifySubsamplesMatchSize({{150, 200}}, 350));
}

TEST(SubsampleEntryTest, MultipleEntries) {
  EXPECT_TRUE(VerifySubsamplesMatchSize({{0, 50}, {100, 00}, {150, 200}}, 500));
}

TEST(SubsampleEntryTest, NoOverflow) {
  EXPECT_TRUE(
      VerifySubsamplesMatchSize({{kMax, 0}}, base::strict_cast<size_t>(kMax)));
  EXPECT_TRUE(
      VerifySubsamplesMatchSize({{0, kMax}}, base::strict_cast<size_t>(kMax)));
}

}  // namespace media