chromium/third_party/blink/renderer/platform/image-decoders/segment_stream_test.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/image-decoders/segment_stream.h"

#include "base/memory/scoped_refptr.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/image-decoders/segment_reader.h"
#include "third_party/blink/renderer/platform/wtf/shared_buffer.h"

// SegmentStream has 4 accessors which do not alter state:
// - isCleared()
// - isAtEnd()
// - getPosition()
// - getLength()
//
// For every operation which changes state we can test:
// - the operation completed as expected,
// - the accessors did not change, and/or
// - the accessors changed in the way we expected.
//
// There are actually 2 more accessors:
// - hasPosition()
// - hasLength()
// but these should always return true to indicate that we can call getLength()
// for example. So let's not add them to every state changing operation and add
// needless complexity.

namespace blink {

namespace {

constexpr size_t kBufferAllocationSize =;
constexpr size_t kInsideBufferPosition =;
constexpr size_t kPastEndOfBufferPosition =;

::testing::AssertionResult IsCleared(const SegmentStream&);
::testing::AssertionResult IsAtEnd(const SegmentStream&);
::testing::AssertionResult PositionIsZero(const SegmentStream&);
::testing::AssertionResult PositionIsInsideBuffer(const SegmentStream&);
::testing::AssertionResult PositionIsAtEndOfBuffer(const SegmentStream&);
::testing::AssertionResult LengthIsZero(const SegmentStream&);
::testing::AssertionResult LengthIsAllocationSize(const SegmentStream&);

// Many of these tests require a SegmentStream with populated data.
//
// This function creates a buffer of size |kBufferAllocationSize| and prepares
// a SegmentStream with that buffer.
// This also populates other properties such as the length, cleared state, etc.
SegmentStream CreatePopulatedSegmentStream();

// This function creates a buffer of size |kBufferAllocationSize| to be used
// when populating a SegmentStream.
scoped_refptr<SegmentReader> CreateSegmentReader();

size_t ReadFromSegmentStream(SegmentStream&,
                             size_t amount_to_read = kInsideBufferPosition);
size_t PeekIntoSegmentStream(SegmentStream&,
                             size_t amount_to_peek = kInsideBufferPosition);

}  // namespace

TEST(SegmentStreamTest, DefaultConstructorShouldSetIsCleared) {}

TEST(SegmentStreamTest, DefaultConstructorShouldSetIsAtEnd) {}

TEST(SegmentStreamTest, DefaultContructorShouldClearPosition) {}

TEST(SegmentStreamTest, DefaultConstructorShouldHaveZeroLength) {}

TEST(SegmentStreamTest, MoveConstructorShouldSetIsClearedWhenRhsIsCleared) {}

TEST(SegmentStreamTest,
     MoveConstructorShouldUnsetIsClearedWhenRhsIsNotCleared) {}

TEST(SegmentStreamTest, MoveConstructorShouldSetIsAtEndWhenRhsIsAtEnd) {}

TEST(SegmentStreamTest, MoveConstructorShouldUnsetIsAtEndWhenRhsIsNotAtEnd) {}

TEST(SegmentStreamTest, MoveContructorShouldCopyRhsPosition) {}

TEST(SegmentStreamTest, MoveConstructorShouldCopyRhsLength) {}

TEST(SegmentStreamTest,
     MoveAssignmentOperatorShouldSetIsClearedWhenRhsIsCleared) {}

TEST(SegmentStreamTest,
     MoveAssignmentOperatorShouldUnsetIsClearedWhenRhsIsNotCleared) {}

TEST(SegmentStreamTest, MoveAssignmentOperatorShouldSetIsAtEndWhenRhsIsAtEnd) {}

TEST(SegmentStreamTest,
     MoveAssignmentOperatorShouldUnsetIsAtEndWhenRhsIsNotAtEnd) {}

TEST(SegmentStreamTest, MoveAssignmentOperatorShouldCopyRhsPosition) {}

TEST(SegmentStreamTest, MoveAssignmentOperatorShouldCopyRhsLength) {}

TEST(SegmentStreamTest, SetReaderShouldUnsetIsCleared) {}

TEST(SegmentStreamTest, SetReaderShouldUnsetIsAtEnd) {}

TEST(SegmentStreamTest, SetReaderShouldNotChangePosition) {}

TEST(SegmentStreamTest, SetReaderShouldUpdateLength) {}

TEST(SegmentStreamTest, SetReaderShouldSetIsClearedWhenSetToNull) {}

TEST(SegmentStreamTest, SetReaderShouldSetIsClearedWhenReaderSizeNotBigEnough) {}

TEST(SegmentStreamTest, SetReaderShouldSetIsAtEndWhenReaderSizeNotBigEnough) {}

TEST(SegmentStreamTest,
     SetReaderShouldNotChangePositionWhenReaderSizeNotBigEnough) {}

TEST(SegmentStreamTest, SetReaderShouldChangeLengthWhenReaderSizeNotBigEnough) {}

TEST(SegmentStreamTest, SetReaderShouldSetIsAtEndWhenSetToNull) {}

TEST(SegmentStreamTest, SetReaderShouldNotChangePositionWhenSetToNull) {}

TEST(SegmentStreamTest, SetReaderShouldClearLengthWhenSetToNull) {}

TEST(SegmentStreamTest, ReadShouldConsumeBuffer) {}

TEST(SegmentStreamTest, ReadShouldNotClear) {}

TEST(SegmentStreamTest, ReadShouldUpdateIsAtEnd) {}

TEST(SegmentStreamTest, ReadShouldUpdatePosition) {}

TEST(SegmentStreamTest, ReadShouldNotChangeLength) {}

TEST(SegmentStreamTest, ReadShouldConsumeBufferWithoutGoingPastTheEnd) {}

TEST(SegmentStreamTest, ReadShouldSetIsAtEndWhenPastEnd) {}

TEST(SegmentStreamTest, ReadShouldTruncatePositionWhenPastEnd) {}

TEST(SegmentStreamTest, PeekShouldConsumeBuffer) {}

TEST(SegmentStreamTest, PeekShouldNotClear) {}

TEST(SegmentStreamTest, PeekShouldNotUpdateIsAtEnd) {}

TEST(SegmentStreamTest, PeekShouldNotUpdatePosition) {}

TEST(SegmentStreamTest, PeekShouldNotChangeLength) {}

TEST(SegmentStreamTest, PeekShouldConsumeBufferWithoutGoingPastTheEnd) {}

TEST(SegmentStreamTest, PeekShouldNotSetIsAtEndWhenPastEnd) {}

TEST(SegmentStreamTest, PeekShouldNotTruncatePositionWhenPastEnd) {}

TEST(SegmentStreamTest, RewindShouldNotClear) {}

TEST(SegmentStreamTest, RewindShouldNotSetAtEnd) {}

TEST(SegmentStreamTest, RewindShouldResetPosition) {}

TEST(SegmentStreamTest, RewindShouldNotChangeLength) {}

TEST(SegmentStreamTest, HasPositionShouldBeSupported) {}

TEST(SegmentStreamTest, SeekShouldNotSetIsCleared) {}

TEST(SegmentStreamTest, SeekShouldNotSetIsAtEndWhenSeekingInsideTheBuffer) {}

TEST(SegmentStreamTest, SeekShouldSetIsAtEndWhenSeekingToTheEndOfTheBuffer) {}

TEST(SegmentStreamTest, SeekShouldUpdatePosition) {}

TEST(SegmentStreamTest, SeekShouldNotTruncatePositionWhenPastEnd) {}

TEST(SegmentStreamTest, SeekShouldNotUpdateLength) {}

TEST(SegmentStreamTest, MoveShouldNotSetCleared) {}

TEST(SegmentStreamTest, MoveShouldUpdatePosition) {}

TEST(SegmentStreamTest, MoveShouldNotTruncatePositionWhenPastEnd) {}

TEST(SegmentStreamTest, MoveShouldNotChangeLength) {}

TEST(SegmentStreamTest, HasLengthShouldBeSupported) {}

namespace {

::testing::AssertionResult IsCleared(const SegmentStream& segment_stream) {}

::testing::AssertionResult IsAtEnd(const SegmentStream& segment_stream) {}

::testing::AssertionResult PositionIsZero(const SegmentStream& segment_stream) {}

::testing::AssertionResult PositionIsInsideBuffer(
    const SegmentStream& segment_stream) {}

::testing::AssertionResult PositionIsAtEndOfBuffer(
    const SegmentStream& segment_stream) {}

::testing::AssertionResult LengthIsZero(const SegmentStream& segment_stream) {}

::testing::AssertionResult LengthIsAllocationSize(
    const SegmentStream& segment_stream) {}

SegmentStream CreatePopulatedSegmentStream() {}

scoped_refptr<SegmentReader> CreateSegmentReader() {}

size_t ReadFromSegmentStream(SegmentStream& segment_stream,
                             size_t amount_to_read) {}

size_t PeekIntoSegmentStream(SegmentStream& segment_stream,
                             size_t amount_to_peek) {}

}  // namespace
}  // namespace blink