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. 4 5 #include "media/ffmpeg/ffmpeg_common.h" 6 #include "media/filters/in_memory_url_protocol.h" 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 namespace media { 10 11 static const uint8 kData[] = { 0x01, 0x02, 0x03, 0x04 }; 12 13 TEST(InMemoryUrlProtocolTest, ReadFromLargeBuffer) { 14 InMemoryUrlProtocol protocol(kData, std::numeric_limits<int64>::max(), false); 15 16 uint8 out[sizeof(kData)]; 17 EXPECT_EQ(4, protocol.Read(sizeof(out), out)); 18 EXPECT_EQ(0, memcmp(out, kData, sizeof(out))); 19 } 20 21 TEST(InMemoryUrlProtocolTest, ReadWithNegativeSize) { 22 InMemoryUrlProtocol protocol(kData, sizeof(kData), false); 23 24 uint8 out[sizeof(kData)]; 25 EXPECT_EQ(AVERROR(EIO), protocol.Read(-2, out)); 26 } 27 28 TEST(InMemoryUrlProtocolTest, ReadWithZeroSize) { 29 InMemoryUrlProtocol protocol(kData, sizeof(kData), false); 30 31 uint8 out; 32 EXPECT_EQ(0, protocol.Read(0, &out)); 33 } 34 35 TEST(InMemoryUrlProtocolTest, SetPosition) { 36 InMemoryUrlProtocol protocol(kData, sizeof(kData), false); 37 38 EXPECT_FALSE(protocol.SetPosition(-1)); 39 EXPECT_FALSE(protocol.SetPosition(sizeof(kData) + 1)); 40 41 uint8 out; 42 EXPECT_TRUE(protocol.SetPosition(sizeof(kData))); 43 EXPECT_EQ(0, protocol.Read(1, &out)); 44 45 int i = sizeof(kData) / 2; 46 EXPECT_TRUE(protocol.SetPosition(i)); 47 EXPECT_EQ(1, protocol.Read(1, &out)); 48 EXPECT_EQ(kData[i], out); 49 } 50 51 } // namespace media 52