chromium/media/formats/hls/media_playlist_test_builder.h

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

#ifndef MEDIA_FORMATS_HLS_MEDIA_PLAYLIST_TEST_BUILDER_H_
#define MEDIA_FORMATS_HLS_MEDIA_PLAYLIST_TEST_BUILDER_H_

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "media/formats/hls/media_playlist.h"
#include "media/formats/hls/media_segment.h"
#include "media/formats/hls/playlist_test_builder.h"
#include "media/formats/hls/test_util.h"
#include "media/formats/hls/types.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace media::hls {

class MultivariantPlaylist;

// Helper for building media playlist test cases that allows writing assertions
// next to the playlist lines they check, as well as "forking" test cases via
// copying the builder.
class MediaPlaylistTestBuilder : public PlaylistTestBuilder<MediaPlaylist> {};

// Checks that the media playlist has the given type (or `std::nullopt`).
inline void HasType(std::optional<PlaylistType> type,
                    const base::Location& from,
                    const MediaPlaylist& playlist) {}

// Checks that the media playlist has the given Target Duration.
inline void HasTargetDuration(base::TimeDelta value,
                              const base::Location& from,
                              const MediaPlaylist& playlist) {}

// Checks that the value of `GetComputedDuration()` matches the given value.
inline void HasComputedDuration(base::TimeDelta value,
                                const base::Location& from,
                                const MediaPlaylist& playlist) {}

// Checks that the value of `GetPartialSegmentInfo()` matches the given value.
inline void HasPartialSegmentInfo(
    std::optional<MediaPlaylist::PartialSegmentInfo> partial_segment_info,
    const base::Location& from,
    const MediaPlaylist& playlist) {}

// Checks the media playlist's `HasMediaSequenceTag` property against
// the given value.
inline void HasMediaSequenceTag(bool value,
                                const base::Location& from,
                                const MediaPlaylist& playlist) {}

// Checks that the value of `GetSkipBoundary()` matches the given value.
inline void HasSkipBoundary(std::optional<base::TimeDelta> value,
                            const base::Location& from,
                            const MediaPlaylist& playlist) {}

// Checks that the value of `CanSkipDateRanges()` matches the given value.
inline void CanSkipDateRanges(bool value,
                              const base::Location& from,
                              const MediaPlaylist& playlist) {}

// Checks that the value of `GetHoldBackDistance()` matches the given value.
inline void HasHoldBackDistance(base::TimeDelta value,
                                const base::Location& from,
                                const MediaPlaylist& playlist) {}

// Checks that the value of `GetPartHoldBackDistance()` matches the given value.
inline void HasPartHoldBackDistance(std::optional<base::TimeDelta> value,
                                    const base::Location& from,
                                    const MediaPlaylist& playlist) {}

// Checks that the value of `CanBlockReload()` matches the given value.
inline void CanBlockReload(bool value,
                           const base::Location& from,
                           const MediaPlaylist& playlist) {}

// Checks that the latest media segment has the given duration.
inline void HasDuration(base::TimeDelta duration,
                        const base::Location& from,
                        const MediaSegment& segment) {}

// Checks that the latest media segment has the given media sequence number.
inline void HasMediaSequenceNumber(types::DecimalInteger number,
                                   const base::Location& from,
                                   const MediaSegment& segment) {}

// Checks that the latest media segment has the given media sequence number.
inline void HasEncryptionData(
    std::optional<std::tuple<GURL,
                             XKeyTagMethod,
                             XKeyTagKeyFormat,
                             MediaSegment::EncryptionData::IVContainer>> pack,
    const base::Location& from,
    const MediaSegment& segment) {}

// Checks that the latest media segment has the given discontinuity sequence
// number.
inline void HasDiscontinuitySequenceNumber(types::DecimalInteger number,
                                           const base::Location& from,
                                           const MediaSegment& segment) {}

// Checks that the latest media segment has the given URI.
inline void HasUri(GURL uri,
                   const base::Location& from,
                   const MediaSegment& segment) {}

// Checks that the latest media segment's media initialization segment is
// equivalent to the given value.
inline void HasInitializationSegment(
    scoped_refptr<MediaSegment::InitializationSegment> expected,
    const base::Location& from,
    const MediaSegment& segment) {}

// Checks that the latest media segment has the given byte range.
inline void HasByteRange(std::optional<types::ByteRange> range,
                         const base::Location& from,
                         const MediaSegment& segment) {}

// Checks the latest media segment's `GetBitRate` property against the given
// value.
inline void HasBitRate(std::optional<types::DecimalInteger> bitrate,
                       const base::Location& from,
                       const MediaSegment& segment) {}

// Checks the latest media segment's `HasDiscontinuity` property against the
// given value.
inline void HasDiscontinuity(bool value,
                             const base::Location& from,
                             const MediaSegment& segment) {}

// Checks the latest media segment's `IsGap` property against the given value.
inline void IsGap(bool value,
                  const base::Location& from,
                  const MediaSegment& segment) {}

// Checks the value of `IsEndList` against the given value.
inline void IsEndList(bool value,
                      const base::Location& from,
                      const MediaPlaylist& playlist) {}

// Checks the value of `IsIFramesOnly` against the given value.
inline void IsIFramesOnly(bool value,
                          const base::Location& from,
                          const MediaPlaylist& playlist) {}

}  // namespace media::hls

#endif  // MEDIA_FORMATS_HLS_MEDIA_PLAYLIST_TEST_BUILDER_H_