Clean up source code
This commit is contained in:
213
vav2/Vav2Player/Vav2UnitTest/tests/AV1DecoderTest.cpp
Normal file
213
vav2/Vav2Player/Vav2UnitTest/tests/AV1DecoderTest.cpp
Normal file
@@ -0,0 +1,213 @@
|
||||
#include "pch.h"
|
||||
#include "MockWebMFileReader.h"
|
||||
#include "../../VavCore/src/Decoder/AV1Decoder.h"
|
||||
#include "../../VavCore/src/Decoder/VideoDecoderFactory.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
using namespace Vav2PlayerUnitTests;
|
||||
|
||||
namespace Vav2PlayerUnitTests
|
||||
{
|
||||
TEST_CLASS(AV1DecoderTest)
|
||||
{
|
||||
public:
|
||||
TEST_METHOD(AV1Decoder_Initialize_ValidMetadata_ShouldReturnTrue)
|
||||
{
|
||||
// Arrange
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
VideoMetadata metadata;
|
||||
metadata.width = 1920;
|
||||
metadata.height = 1080;
|
||||
metadata.codec_type = VideoCodecType::AV1;
|
||||
metadata.frame_rate = 30.0;
|
||||
|
||||
// Act
|
||||
bool result = decoder->Initialize(metadata);
|
||||
|
||||
// Assert
|
||||
Assert::IsTrue(result);
|
||||
Assert::IsTrue(decoder->IsInitialized());
|
||||
}
|
||||
|
||||
TEST_METHOD(AV1Decoder_Initialize_InvalidMetadata_ShouldReturnFalse)
|
||||
{
|
||||
// Arrange
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
VideoMetadata metadata;
|
||||
metadata.width = 0; // Invalid width
|
||||
metadata.height = 1080;
|
||||
metadata.codec_type = VideoCodecType::AV1;
|
||||
|
||||
// Act
|
||||
bool result = decoder->Initialize(metadata);
|
||||
|
||||
// Assert
|
||||
Assert::IsFalse(result);
|
||||
Assert::IsFalse(decoder->IsInitialized());
|
||||
}
|
||||
|
||||
TEST_METHOD(VideoDecoderFactory_CreateAV1Decoder_ShouldReturnValidDecoder)
|
||||
{
|
||||
// Act
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
// Assert
|
||||
Assert::IsNotNull(decoder.get());
|
||||
Assert::IsFalse(decoder->IsInitialized()); // Should not be initialized until Initialize() is called
|
||||
}
|
||||
|
||||
TEST_METHOD(VideoDecoderFactory_CreateAutoDecoder_ShouldReturnValidDecoder)
|
||||
{
|
||||
// Act
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::AUTO);
|
||||
|
||||
// Assert
|
||||
Assert::IsNotNull(decoder.get());
|
||||
Assert::IsFalse(decoder->IsInitialized());
|
||||
}
|
||||
|
||||
TEST_METHOD(AV1Decoder_Reset_AfterInitialization_ShouldSucceed)
|
||||
{
|
||||
// Arrange
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
VideoMetadata metadata;
|
||||
metadata.width = 1920;
|
||||
metadata.height = 1080;
|
||||
metadata.codec_type = VideoCodecType::AV1;
|
||||
metadata.frame_rate = 30.0;
|
||||
|
||||
decoder->Initialize(metadata);
|
||||
|
||||
// Act
|
||||
bool result = decoder->Reset();
|
||||
|
||||
// Assert
|
||||
Assert::IsTrue(result);
|
||||
Assert::IsTrue(decoder->IsInitialized()); // Should remain initialized after reset
|
||||
}
|
||||
|
||||
TEST_METHOD(AV1Decoder_Cleanup_ShouldSetNotInitialized)
|
||||
{
|
||||
// Arrange
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
VideoMetadata metadata;
|
||||
metadata.width = 1920;
|
||||
metadata.height = 1080;
|
||||
metadata.codec_type = VideoCodecType::AV1;
|
||||
metadata.frame_rate = 30.0;
|
||||
|
||||
decoder->Initialize(metadata);
|
||||
Assert::IsTrue(decoder->IsInitialized());
|
||||
|
||||
// Act
|
||||
decoder->Cleanup();
|
||||
|
||||
// Assert
|
||||
Assert::IsFalse(decoder->IsInitialized());
|
||||
}
|
||||
|
||||
// Note: GetSupportedFormats and GetAvailableDecoders methods don't exist yet
|
||||
// Commenting out until these methods are implemented
|
||||
/*
|
||||
TEST_METHOD(AV1Decoder_GetSupportedFormats_ShouldReturnAV1)
|
||||
{
|
||||
// Arrange
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
// Act
|
||||
auto formats = decoder->GetSupportedFormats();
|
||||
|
||||
// Assert
|
||||
Assert::IsTrue(formats.size() > 0);
|
||||
|
||||
// Check if AV1 is in the supported formats
|
||||
bool foundAV1 = false;
|
||||
for (const auto& format : formats) {
|
||||
if (format == VideoCodecType::AV1) {
|
||||
foundAV1 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert::IsTrue(foundAV1);
|
||||
}
|
||||
|
||||
TEST_METHOD(VideoDecoderFactory_GetAvailableDecoders_ShouldIncludeAV1)
|
||||
{
|
||||
// Act
|
||||
auto decoders = VideoDecoderFactory::GetAvailableDecoders();
|
||||
|
||||
// Assert
|
||||
Assert::IsTrue(decoders.size() > 0);
|
||||
|
||||
// Check if AV1 decoder info is present
|
||||
bool foundAV1 = false;
|
||||
for (const auto& decoderInfo : decoders) {
|
||||
if (decoderInfo.codec_type == VideoCodecType::AV1) {
|
||||
foundAV1 = true;
|
||||
Assert::IsFalse(decoderInfo.name.empty());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert::IsTrue(foundAV1);
|
||||
}
|
||||
*/
|
||||
|
||||
TEST_METHOD(AV1Decoder_HardwareDecoder_CreationTest)
|
||||
{
|
||||
// Act - Try to create hardware decoder (may fail on systems without hardware support)
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::MEDIA_FOUNDATION);
|
||||
|
||||
// Assert - Should either succeed or return nullptr (graceful failure)
|
||||
// This test mainly verifies that factory doesn't crash
|
||||
if (decoder) {
|
||||
// If hardware decoder is available, test basic functionality
|
||||
VideoMetadata metadata;
|
||||
metadata.width = 1920;
|
||||
metadata.height = 1080;
|
||||
metadata.codec_type = VideoCodecType::AV1;
|
||||
metadata.frame_rate = 30.0;
|
||||
|
||||
// Hardware decoder may fail initialization on systems without support
|
||||
// This is expected behavior, not a test failure
|
||||
decoder->Initialize(metadata);
|
||||
}
|
||||
|
||||
// Test passes if we reach here without crashing
|
||||
Assert::IsTrue(true);
|
||||
}
|
||||
|
||||
TEST_METHOD(AV1Decoder_Integration_WithMockReader)
|
||||
{
|
||||
// Arrange
|
||||
MockWebMFileReader mockReader;
|
||||
auto decoder = VideoDecoderFactory::CreateDecoder(VideoCodecType::AV1, VideoDecoderFactory::DecoderType::DAV1D);
|
||||
|
||||
mockReader.OpenFile("test.webm");
|
||||
mockReader.SelectVideoTrack(1);
|
||||
|
||||
const auto& metadata = mockReader.GetVideoMetadata();
|
||||
decoder->Initialize(metadata);
|
||||
|
||||
// Act - Try to decode first packet
|
||||
VideoPacket packet;
|
||||
bool readResult = mockReader.ReadNextPacket(packet);
|
||||
|
||||
VideoFrame frame;
|
||||
bool decodeResult = false;
|
||||
if (readResult && packet.data && packet.size > 0) {
|
||||
// Note: This will likely fail with mock data since it's not real AV1
|
||||
// But the test verifies the integration doesn't crash
|
||||
decodeResult = decoder->DecodeFrame(packet, frame);
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert::IsTrue(readResult); // Mock reader should succeed
|
||||
Assert::IsTrue(decoder->IsInitialized());
|
||||
// decodeResult may be false since mock data isn't real AV1 - this is expected
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user