Chromium Code Reviews| 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..c21c72ae49fa9da1d6b56ae068231d61ff51c477 |
| --- /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 "base/basictypes.h" |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Group w/ other base includes
strobe_
2012/06/07 16:33:54
Done.
|
| + |
| +#include "string.h" |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Use <> & place before all other includes.
strobe_
2012/06/07 16:33:54
Done.
|
| +#include "base/logging.h" |
| +#include "media/mp4/avc.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using media::mp4::ConvertAVCCToAnnexB; |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Remove and put tests in media::mp4 namespace
strobe_
2012/06/07 22:04:22
Done.
|
| + |
| +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> { |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
Use int here and various other places below.
strobe_
2012/06/07 22:04:22
Done.
|
| + protected: |
| + void MakeInputForLength(uint32 length_size, std::vector<uint8>* buf) { |
| + buf->clear(); |
| + for (uint32 i = 1; i < length_size; i++) { |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: remove {}
strobe_
2012/06/07 22:04:22
Done.
|
| + 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++) { |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
nit: remove {}
strobe_
2012/06/07 22:04:22
Done.
|
| + 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. |
|
acolwell GONE FROM CHROMIUM
2012/06/06 17:32:39
I'm not sure what this comment is trying to tell m
strobe_
2012/06/07 22:04:22
Done.
|
| + 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)); |