83 lines
2.9 KiB
C++
83 lines
2.9 KiB
C++
#pragma once
|
|
#include <vector>
|
|
#include <string>
|
|
#include <memory>
|
|
|
|
namespace Vav2PlayerUnitTests {
|
|
|
|
// Mock implementation of IWebMFileReader for unit testing
|
|
// Provides controllable test data without actual file I/O
|
|
class MockWebMFileReader : public VavCore::IWebMFileReader {
|
|
public:
|
|
MockWebMFileReader();
|
|
virtual ~MockWebMFileReader() = default;
|
|
|
|
// IWebMFileReader interface implementation
|
|
bool OpenFile(const std::string& file_path) override;
|
|
void CloseFile() override;
|
|
bool IsFileOpen() const override;
|
|
|
|
const VavCore::VideoMetadata& GetVideoMetadata() const override;
|
|
std::string GetFilePath() const override;
|
|
|
|
std::vector<VavCore::VideoTrackInfo> GetVideoTracks() const override;
|
|
bool SelectVideoTrack(uint64_t track_number) override;
|
|
uint64_t GetSelectedTrackNumber() const override;
|
|
|
|
bool ReadNextPacket(VavCore::VideoPacket& packet) override;
|
|
bool SeekToFrame(uint64_t frame_index) override;
|
|
bool SeekToTime(double timestamp_seconds) override;
|
|
|
|
uint64_t GetCurrentFrameIndex() const override;
|
|
double GetCurrentTimestamp() const override;
|
|
bool IsEndOfFile() const override;
|
|
|
|
bool Reset() override;
|
|
uint64_t GetTotalFrames() const override;
|
|
double GetDuration() const override;
|
|
|
|
VavCore::WebMErrorCode GetLastError() const override;
|
|
std::string GetLastErrorString() const override;
|
|
|
|
// Mock-specific control methods for testing
|
|
void SetMockVideoMetadata(const VavCore::VideoMetadata& metadata);
|
|
void SetMockVideoTracks(const std::vector<VavCore::VideoTrackInfo>& tracks);
|
|
void SetMockPackets(const std::vector<std::vector<uint8_t>>& packets);
|
|
void SetMockError(VavCore::WebMErrorCode error, const std::string& message = "");
|
|
void SetOpenFileResult(bool success);
|
|
void SetEndOfFileAtFrame(uint64_t frame_index);
|
|
|
|
// Test verification methods
|
|
uint32_t GetOpenFileCallCount() const { return m_openFileCallCount; }
|
|
uint32_t GetReadPacketCallCount() const { return m_readPacketCallCount; }
|
|
std::string GetLastOpenedFile() const { return m_lastOpenedFile; }
|
|
|
|
private:
|
|
// Mock state
|
|
bool m_isOpen = false;
|
|
bool m_openFileResult = true;
|
|
std::string m_currentFilePath;
|
|
std::string m_lastOpenedFile;
|
|
uint64_t m_selectedTrack = 0;
|
|
uint64_t m_currentFrame = 0;
|
|
uint64_t m_endOfFileFrame = UINT64_MAX;
|
|
|
|
// Mock data
|
|
VavCore::VideoMetadata m_mockMetadata;
|
|
std::vector<VavCore::VideoTrackInfo> m_mockTracks;
|
|
std::vector<std::vector<uint8_t>> m_mockPackets;
|
|
|
|
// Error simulation
|
|
VavCore::WebMErrorCode m_mockError = VavCore::WebMErrorCode::Success;
|
|
std::string m_mockErrorMessage;
|
|
|
|
// Call tracking for test verification
|
|
mutable uint32_t m_openFileCallCount = 0;
|
|
mutable uint32_t m_readPacketCallCount = 0;
|
|
|
|
// Helper methods
|
|
void CreateDefaultMockData();
|
|
std::vector<uint8_t> CreateMockAV1Packet(uint64_t frame_index);
|
|
};
|
|
|
|
} // namespace Vav2PlayerUnitTests
|