summaryrefslogtreecommitdiffstats
path: root/media/formats/mp4/sample_to_group_iterator_unittest.cc
blob: e94b5ffb8a73e1dd1bcec70820697ab7a97102d5 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/formats/mp4/sample_to_group_iterator.h"

#include <stddef.h>
#include <stdint.h>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {
namespace mp4 {

namespace {
const SampleToGroupEntry kCompactSampleToGroupTable[] =
    {{10, 8}, {9, 5}, {25, 7}, {48, 63}, {8, 2}};
}  // namespace

class SampleToGroupIteratorTest : public testing::Test {
 public:
  SampleToGroupIteratorTest() {
    // Build sample group description index table from kSampleToGroupTable.
    for (size_t i = 0; i < arraysize(kCompactSampleToGroupTable); ++i) {
      for (uint32_t j = 0; j < kCompactSampleToGroupTable[i].sample_count;
           ++j) {
        sample_to_group_table_.push_back(
            kCompactSampleToGroupTable[i].group_description_index);
      }
    }

    sample_to_group_.entries.assign(
        kCompactSampleToGroupTable,
        kCompactSampleToGroupTable + arraysize(kCompactSampleToGroupTable));
    sample_to_group_iterator_.reset(
        new SampleToGroupIterator(sample_to_group_));
  }

 protected:
  std::vector<uint32_t> sample_to_group_table_;
  SampleToGroup sample_to_group_;
  scoped_ptr<SampleToGroupIterator> sample_to_group_iterator_;

 private:
  DISALLOW_COPY_AND_ASSIGN(SampleToGroupIteratorTest);
};

TEST_F(SampleToGroupIteratorTest, EmptyTable) {
  SampleToGroup sample_to_group;
  SampleToGroupIterator iterator(sample_to_group);
  EXPECT_FALSE(iterator.IsValid());
}

TEST_F(SampleToGroupIteratorTest, Advance) {
  ASSERT_EQ(sample_to_group_table_[0],
            sample_to_group_iterator_->group_description_index());
  for (uint32_t sample = 1; sample < sample_to_group_table_.size(); ++sample) {
    ASSERT_TRUE(sample_to_group_iterator_->Advance());
    ASSERT_EQ(sample_to_group_table_[sample],
              sample_to_group_iterator_->group_description_index());
    ASSERT_TRUE(sample_to_group_iterator_->IsValid());
  }
  ASSERT_FALSE(sample_to_group_iterator_->Advance());
  ASSERT_FALSE(sample_to_group_iterator_->IsValid());
}

}  // namespace mp4
}  // namespace media