Roll ANGLE e754fb8..6ffeb74
[chromium-blink-merge.git] / media / formats / mp4 / sample_to_group_iterator_unittest.cc
blob3e8148c127e6bb3d3b2dce49e89976afecb1ef77
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/formats/mp4/sample_to_group_iterator.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
11 namespace mp4 {
13 namespace {
14 const SampleToGroupEntry kCompactSampleToGroupTable[] =
15 {{10, 8}, {9, 5}, {25, 7}, {48, 63}, {8, 2}};
16 } // namespace
18 class SampleToGroupIteratorTest : public testing::Test {
19 public:
20 SampleToGroupIteratorTest() {
21 // Build sample group description index table from kSampleToGroupTable.
22 for (size_t i = 0; i < arraysize(kCompactSampleToGroupTable); ++i) {
23 for (uint32 j = 0; j < kCompactSampleToGroupTable[i].sample_count; ++j) {
24 sample_to_group_table_.push_back(
25 kCompactSampleToGroupTable[i].group_description_index);
29 sample_to_group_.entries.assign(
30 kCompactSampleToGroupTable,
31 kCompactSampleToGroupTable + arraysize(kCompactSampleToGroupTable));
32 sample_to_group_iterator_.reset(
33 new SampleToGroupIterator(sample_to_group_));
36 protected:
37 std::vector<uint32> sample_to_group_table_;
38 SampleToGroup sample_to_group_;
39 scoped_ptr<SampleToGroupIterator> sample_to_group_iterator_;
41 private:
42 DISALLOW_COPY_AND_ASSIGN(SampleToGroupIteratorTest);
45 TEST_F(SampleToGroupIteratorTest, EmptyTable) {
46 SampleToGroup sample_to_group;
47 SampleToGroupIterator iterator(sample_to_group);
48 EXPECT_FALSE(iterator.IsValid());
51 TEST_F(SampleToGroupIteratorTest, Advance) {
52 ASSERT_EQ(sample_to_group_table_[0],
53 sample_to_group_iterator_->group_description_index());
54 for (uint32 sample = 1; sample < sample_to_group_table_.size(); ++sample) {
55 ASSERT_TRUE(sample_to_group_iterator_->Advance());
56 ASSERT_EQ(sample_to_group_table_[sample],
57 sample_to_group_iterator_->group_description_index());
58 ASSERT_TRUE(sample_to_group_iterator_->IsValid());
60 ASSERT_FALSE(sample_to_group_iterator_->Advance());
61 ASSERT_FALSE(sample_to_group_iterator_->IsValid());
64 } // namespace mp4
65 } // namespace media