summaryrefslogtreecommitdiffstats
path: root/media/omx/omx_input_buffer_unittest.cc
blob: 50a23028903013e56eb38a5642c3eb4805d57523 (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
// Copyright (c) 2010 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/omx/omx_input_buffer.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const int kSize = 256;

void GenerateData(uint8** data, int size) {
  *data = new uint8[size];
  for (int i = 0; i < size; ++i) {
    (*data)[i] = static_cast<uint8>(i);
  }
}

bool VerifyData(uint8* data, int size, int offset) {
  bool data_mismatch = false;
  for (int i = 0; i < size; ++i) {
    if (data[i] != static_cast<uint8>(offset + i)) {
      data_mismatch = true;
      break;
    }
  }
  return !data_mismatch;
}

}  // namespace

namespace media {

TEST(OmxInputBufferTest, Read) {
  scoped_array<uint8> read_buffer(new uint8[kSize]);
  uint8* data;
  GenerateData(&data, kSize);
  scoped_refptr<OmxInputBuffer> buffer(new OmxInputBuffer(data, kSize));
  EXPECT_FALSE(buffer->Used());

  // Perform the first read.
  EXPECT_EQ(10, buffer->Read(read_buffer.get(), 10));
  EXPECT_FALSE(buffer->Used());
  EXPECT_TRUE(VerifyData(read_buffer.get(), 10, 0));

  // Perform the second read.
  EXPECT_EQ(10, buffer->Read(read_buffer.get(), 10));
  EXPECT_FALSE(buffer->Used());
  EXPECT_TRUE(VerifyData(read_buffer.get(), 10, 10));

  // Perform the last read.
  EXPECT_EQ(kSize - 20, buffer->Read(read_buffer.get(), kSize));
  EXPECT_TRUE(buffer->Used());
  EXPECT_TRUE(VerifyData(read_buffer.get(), kSize - 20, 20));

  // This read will return nothing.
  EXPECT_EQ(0, buffer->Read(read_buffer.get(), kSize));
  EXPECT_TRUE(buffer->Used());
}

TEST(OmxInputBufferTest, EmptyBuffer) {
  scoped_refptr<OmxInputBuffer> buffer(new OmxInputBuffer(NULL, 0));
  EXPECT_TRUE(buffer->IsEndOfStream());
  EXPECT_TRUE(buffer->Used());
}

}  // namespace media