Clean up source code
This commit is contained in:
195
vav2/Vav2Player/Vav2UnitTest/tests/VavCoreTest.cpp
Normal file
195
vav2/Vav2Player/Vav2UnitTest/tests/VavCoreTest.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
#include "pch.h"
|
||||
#include "VavCore/VavCore.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace Vav2PlayerUnitTests
|
||||
{
|
||||
TEST_CLASS(VavCoreTest)
|
||||
{
|
||||
public:
|
||||
// Basic API functionality tests
|
||||
TEST_METHOD(VavCore_Initialize_ShouldReturnSuccess)
|
||||
{
|
||||
// Test VavCore library initialization
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
// Cleanup
|
||||
vavcore_cleanup();
|
||||
}
|
||||
|
||||
TEST_METHOD(VavCore_GetVersionString_ShouldReturnValidVersion)
|
||||
{
|
||||
// Test version string retrieval
|
||||
const char* version = vavcore_get_version_string();
|
||||
Assert::IsNotNull(version);
|
||||
Assert::AreNotEqual(0, static_cast<int>(strlen(version)));
|
||||
}
|
||||
|
||||
TEST_METHOD(VavCore_CreateDestroy_Player_ShouldWork)
|
||||
{
|
||||
// Initialize library first
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
// Test player creation
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
Assert::IsNotNull(player);
|
||||
|
||||
// Test player destruction
|
||||
vavcore_destroy_player(player);
|
||||
|
||||
// Cleanup
|
||||
vavcore_cleanup();
|
||||
}
|
||||
|
||||
// SEGFAULT debugging tests - these are designed to isolate the crash point
|
||||
TEST_METHOD(VavCore_OpenFile_WithValidFile_ShouldNotCrash)
|
||||
{
|
||||
// This test isolates file opening functionality
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
Assert::IsNotNull(player);
|
||||
|
||||
// Try to open a test file - this should not crash
|
||||
const char* testFile = "D:\\Project\\video-av1\\oss\\libwebm\\testing\\testdata\\accurate_cluster_duration.webm";
|
||||
result = vavcore_open_file(player, testFile);
|
||||
|
||||
// The result may be success or error, but should not crash
|
||||
// If it crashes here, the issue is in file opening logic
|
||||
Assert::IsTrue(result == VAVCORE_SUCCESS || result != VAVCORE_SUCCESS);
|
||||
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
}
|
||||
|
||||
TEST_METHOD(VavCore_SetQualityMode_AfterOpenFile_ShouldNotCrash)
|
||||
{
|
||||
// This test isolates quality mode setting after file opening
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
Assert::IsNotNull(player);
|
||||
|
||||
const char* testFile = "D:\\Project\\video-av1\\oss\\libwebm\\testing\\testdata\\accurate_cluster_duration.webm";
|
||||
result = vavcore_open_file(player, testFile);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
// Try setting quality mode - this might be where the crash happens
|
||||
result = vavcore_set_quality_mode(player, VAVCORE_QUALITY_CONSERVATIVE);
|
||||
|
||||
// Should not crash here
|
||||
Assert::IsTrue(result == VAVCORE_SUCCESS || result != VAVCORE_SUCCESS);
|
||||
}
|
||||
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
}
|
||||
|
||||
TEST_METHOD(VavCore_Reset_AfterOpenFile_ShouldNotCrash)
|
||||
{
|
||||
// This test isolates the reset functionality
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
Assert::IsNotNull(player);
|
||||
|
||||
const char* testFile = "D:\\Project\\video-av1\\oss\\libwebm\\testing\\testdata\\accurate_cluster_duration.webm";
|
||||
result = vavcore_open_file(player, testFile);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
// Try reset operation - this might be where the crash happens
|
||||
result = vavcore_reset(player);
|
||||
|
||||
// Should not crash here
|
||||
Assert::IsTrue(result == VAVCORE_SUCCESS || result != VAVCORE_SUCCESS);
|
||||
}
|
||||
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
}
|
||||
|
||||
TEST_METHOD(VavCore_SingleFrameDecode_ShouldNotCrash)
|
||||
{
|
||||
// This test isolates the first frame decoding - most likely crash point
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
Assert::IsNotNull(player);
|
||||
|
||||
const char* testFile = "D:\\Project\\video-av1\\oss\\libwebm\\testing\\testdata\\accurate_cluster_duration.webm";
|
||||
result = vavcore_open_file(player, testFile);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
// Set quality mode
|
||||
result = vavcore_set_quality_mode(player, VAVCORE_QUALITY_CONSERVATIVE);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
// Try decoding a single frame - this is the most likely crash point
|
||||
VavCoreVideoFrame frame = {};
|
||||
result = vavcore_decode_next_frame(player, &frame);
|
||||
|
||||
// Should not crash here - this is where segfault likely occurs
|
||||
Assert::IsTrue(result == VAVCORE_SUCCESS || result == VAVCORE_END_OF_STREAM || result != VAVCORE_SUCCESS);
|
||||
|
||||
// Clean up frame memory if decoding succeeded
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
free(frame.y_plane);
|
||||
free(frame.u_plane);
|
||||
free(frame.v_plane);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
}
|
||||
|
||||
// Memory management tests
|
||||
TEST_METHOD(VavCore_FrameMemory_ShouldBeProperlyManaged)
|
||||
{
|
||||
// Test proper memory allocation/deallocation in frame copying
|
||||
VavCoreResult result = vavcore_initialize();
|
||||
Assert::AreEqual(static_cast<int>(VAVCORE_SUCCESS), static_cast<int>(result));
|
||||
|
||||
VavCorePlayer* player = vavcore_create_player();
|
||||
Assert::IsNotNull(player);
|
||||
|
||||
const char* testFile = "D:\\Project\\video-av1\\oss\\libwebm\\testing\\testdata\\accurate_cluster_duration.webm";
|
||||
result = vavcore_open_file(player, testFile);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
result = vavcore_set_quality_mode(player, VAVCORE_QUALITY_CONSERVATIVE);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
// Try multiple frame decodes to test memory management
|
||||
for (int i = 0; i < 3 && result == VAVCORE_SUCCESS; i++) {
|
||||
VavCoreVideoFrame frame = {};
|
||||
result = vavcore_decode_next_frame(player, &frame);
|
||||
|
||||
if (result == VAVCORE_SUCCESS) {
|
||||
// Verify frame data is allocated
|
||||
Assert::IsNotNull(frame.y_plane);
|
||||
Assert::IsNotNull(frame.u_plane);
|
||||
Assert::IsNotNull(frame.v_plane);
|
||||
|
||||
// Clean up
|
||||
free(frame.y_plane);
|
||||
free(frame.u_plane);
|
||||
free(frame.v_plane);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vavcore_destroy_player(player);
|
||||
vavcore_cleanup();
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user