| Index: media/mp4/avc_unittest.cc
|
| diff --git a/media/mp4/avc_unittest.cc b/media/mp4/avc_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..43451714ebfeff9d68f419bb9d302cf68aa9c6a1
|
| --- /dev/null
|
| +++ b/media/mp4/avc_unittest.cc
|
| @@ -0,0 +1,67 @@
|
| +// Copyright (c) 2012 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 <string.h>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "media/mp4/avc.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/gtest/include/gtest/gtest-param-test.h"
|
| +
|
| +using media::mp4::ConvertAVCCToAnnexB;
|
| +
|
| +const static uint8 kNALU1[] = { 0x01, 0x02, 0x03 };
|
| +const static uint8 kNALU2[] = { 0x04, 0x05, 0x06, 0x07 };
|
| +const static uint8 kExpected[] = {
|
| + 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x03,
|
| + 0x00, 0x00, 0x00, 0x01, 0x04, 0x05, 0x06, 0x07 };
|
| +
|
| +class AVCCConversionTest : public testing::TestWithParam<uint32> {
|
| + protected:
|
| + void MakeInputForLength(uint32 length_size, std::vector<uint8>* buf) {
|
| + buf->clear();
|
| + for (uint32 i = 1; i < length_size; i++) {
|
| + buf->push_back(0);
|
| + }
|
| + buf->push_back(sizeof(kNALU1));
|
| + buf->insert(buf->end(), kNALU1, kNALU1 + sizeof(kNALU1));
|
| +
|
| + for (uint32 i = 1; i < length_size; i++) {
|
| + buf->push_back(0);
|
| + }
|
| + buf->push_back(sizeof(kNALU2));
|
| + buf->insert(buf->end(), kNALU2, kNALU2 + sizeof(kNALU2));
|
| + }
|
| +};
|
| +
|
| +TEST_P(AVCCConversionTest, ParseCorrectly) {
|
| + std::vector<uint8> buf;
|
| + MakeInputForLength(GetParam(), &buf);
|
| + EXPECT_TRUE(ConvertAVCCToAnnexB(GetParam(), &buf));
|
| + ASSERT_EQ(buf.size(), sizeof(kExpected));
|
| + ASSERT_EQ(0, memcmp(kExpected, &buf[0], sizeof(kExpected)));
|
| +}
|
| +
|
| +TEST_P(AVCCConversionTest, ParsePartial) {
|
| + std::vector<uint8> buf;
|
| + MakeInputForLength(GetParam(), &buf);
|
| + buf.pop_back();
|
| + EXPECT_FALSE(ConvertAVCCToAnnexB(GetParam(), &buf));
|
| + // This actually still works for one-byte sizes.
|
| + if (GetParam() != 1) {
|
| + MakeInputForLength(GetParam(), &buf);
|
| + buf.erase(buf.end() - (sizeof(kNALU2) + 1), buf.end());
|
| + EXPECT_FALSE(ConvertAVCCToAnnexB(GetParam(), &buf));
|
| + }
|
| +}
|
| +
|
| +TEST_P(AVCCConversionTest, ParseEmpty) {
|
| + std::vector<uint8> buf;
|
| + EXPECT_TRUE(ConvertAVCCToAnnexB(GetParam(), &buf));
|
| + EXPECT_EQ(0u, buf.size());
|
| +}
|
| +
|
| +INSTANTIATE_TEST_CASE_P(AVCCConversionTestValues,
|
| + AVCCConversionTest,
|
| + ::testing::Values(1, 2, 4));
|
|
|