MediaPlane/test/test_viewport.mel

359 lines
9.4 KiB
Plaintext

// Maya Image Plane Node Plugin - Viewport 2.0 Test Script
// This MEL script tests the viewport display functionality
// Usage: In Maya GUI, go to Script Editor and source this file
// Test Results Storage
global string $gTestResults = "";
// Helper function to log test results
proc logTest(string $testName, int $passed, string $message) {
if ($passed) {
print("[PASS] " + $testName + "\n");
} else {
print("[FAIL] " + $testName + ": " + $message + "\n");
}
}
// Test 1: Load Plugin
proc int testLoadPlugin() {
print("\n=== TEST 1: Plugin Loading ===\n");
string $pluginPath = "C:/workspace/MediaPlane/maya/2023/plug-ins/MayaImagePlaneNode.mll";
// Check if plugin file exists
if (!`file -q -ex $pluginPath`) {
logTest("Plugin file exists", false, "File not found: " + $pluginPath);
return 0;
}
// Load plugin
loadPlugin($pluginPath);
// Check if plugin is loaded
string $plugins[] = `pluginInfo -q -listPlugins`;
int $loaded = 0;
for ($p in $plugins) {
if ($p == "MayaImagePlaneNode") {
$loaded = 1;
break;
}
}
logTest("Load Plugin", $loaded, "");
return $loaded;
}
// Test 2: Create Node
proc int testCreateNode() {
print("\n=== TEST 2: Create Node ===\n");
// Create imagePlaneVideo node
string $node = `createNode imagePlaneVideo`;
int $created = ($node != "");
logTest("Create imagePlaneVideo node", $created, "Node: " + $node);
return $created;
}
// Test 3: Set Video File
proc int testSetVideoFile() {
print("\n=== TEST 3: Set Video File ===\n");
string $node = "imagePlaneVideo1";
string $videoPath = "C:/workspace/MediaPlane/test/test_video.mp4";
// Check if node exists
if (!`objExists $node`) {
logTest("Set videoFile", false, "Node does not exist");
return 0;
}
// Set video file
setAttr ($node + ".videoFile") -type "string" $videoPath;
// Get video file
string $videoFile = `getAttr ($node + ".videoFile")`;
int $match = ($videoFile == $videoPath);
logTest("Set videoFile attribute", $match, "Expected: " + $videoPath + ", Got: " + $videoFile);
return $match;
}
// Test 4: Test Frame Navigation
proc int testFrameNavigation() {
print("\n=== TEST 4: Frame Navigation ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Frame navigation", false, "Node does not exist");
return 0;
}
// Set current time
setAttr ($node + ".currentTime") 1.0;
float $time = `getAttr ($node + ".currentTime")`;
int $match = ($time == 1.0);
logTest("Set currentTime", $match, "Time: " + $time);
return $match;
}
// Test 5: Test Frame Rate
proc int testFrameRate() {
print("\n=== TEST 5: Frame Rate ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Frame rate", false, "Node does not exist");
return 0;
}
// Set frame rate
setAttr ($node + ".frameRate") 30.0;
float $frameRate = `getAttr ($node + ".frameRate")`;
int $match = ($frameRate == 30.0);
logTest("Set frameRate", $match, "Frame rate: " + $frameRate);
return $match;
}
// Test 6: Test Playback Rate
proc int testPlaybackRate() {
print("\n=== TEST 6: Playback Rate ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Playback rate", false, "Node does not exist");
return 0;
}
// Test different playback rates
float $rates[] = {0.25, 0.5, 1.0, 2.0, 4.0};
int $allPassed = 1;
for ($rate in $rates) {
setAttr ($node + ".playbackRate") $rate;
float $actualRate = `getAttr ($node + ".playbackRate")`;
int $match = (abs($actualRate - $rate) < 0.01);
if (!$match) {
logTest("Set playbackRate=" + $rate, false, "Actual: " + $actualRate);
$allPassed = 0;
}
}
logTest("Test playback rates (0.25x to 4.0x)", $allPassed, "");
return $allPassed;
}
// Test 7: Test Post Effects - Crop
proc int testPostEffectCrop() {
print("\n=== TEST 7: Post Effect - Crop ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Post effect crop", false, "Node does not exist");
return 0;
}
// Set crop values
setAttr -type "doubleArray" ($node + ".postEffectCrop") 4 10 20 30 40;
double $crop[] = `getAttr ($node + ".postEffectCrop")`;
// Check values
int $match = (size($crop) == 4 && $crop[0] == 10 && $crop[1] == 20 && $crop[2] == 30 && $crop[3] == 40);
logTest("Set postEffectCrop", $match, "Values: " + $crop[0] + " " + $crop[1] + " " + $crop[2] + " " + $crop[3]);
return $match;
}
// Test 8: Test Post Effects - Resize
proc int testPostEffectResize() {
print("\n=== TEST 8: Post Effect - Resize ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Post effect resize", false, "Node does not exist");
return 0;
}
// Set resize values
setAttr -type "doubleArray" ($node + ".postEffectResize") 2 800 600;
double $resize[] = `getAttr ($node + ".postEffectResize")`;
// Check values
int $match = (size($resize) == 2 && $resize[0] == 800 && $resize[1] == 600);
logTest("Set postEffectResize", $match, "Values: " + $resize[0] + " " + $resize[1]);
return $match;
}
// Test 9: Test Post Effects - Flip
proc int testPostEffectFlip() {
print("\n=== TEST 9: Post Effect - Flip ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Post effect flip", false, "Node does not exist");
return 0;
}
// Set flip values (horizontal flip)
setAttr -type "doubleArray" ($node + ".postEffectFlip") 2 1 0;
double $flip[] = `getAttr ($node + ".postEffectFlip")`;
// Check values
int $match = (size($flip) == 2 && $flip[0] == 1 && $flip[1] == 0);
logTest("Set postEffectFlip", $match, "Values: " + $flip[0] + " " + $flip[1]);
return $match;
}
// Test 10: Test Cache Settings
proc int testCacheSettings() {
print("\n=== TEST 10: Cache Settings ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Cache settings", false, "Node does not exist");
return 0;
}
// Set cache size
setAttr ($node + ".cacheSize") 100;
int $cacheSize = `getAttr ($node + ".cacheSize")`;
int $match = ($cacheSize == 100);
logTest("Set cacheSize", $match, "Cache size: " + $cacheSize);
return $match;
}
// Test 11: Viewport Display Test
proc int testViewportDisplay() {
print("\n=== TEST 11: Viewport 2.0 Display ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Viewport display", false, "Node does not exist");
return 0;
}
// Check if the node is visible in viewport
// This is a basic check - actual viewport rendering needs manual verification
int $visibility = `getAttr ($node + ".visibility")`;
logTest("Node visibility in viewport", $visibility, "Visibility: " + $visibility);
return $visibility;
}
// Test 12: Output Attributes
proc int testOutputAttributes() {
print("\n=== TEST 12: Output Attributes ===\n");
string $node = "imagePlaneVideo1";
if (!`objExists $node`) {
logTest("Output attributes", false, "Node does not exist");
return 0;
}
// Trigger computation by getting output attributes
int $width = `getAttr ($node + ".outFrameWidth")`;
int $height = `getAttr ($node + ".outFrameHeight")`;
int $isValid = `getAttr ($node + ".outIsValid")`;
print(" outFrameWidth: " + $width + "\n");
print(" outFrameHeight: " + $height + "\n");
print(" outIsValid: " + $isValid + "\n");
// Check if values are reasonable (not 0 if video is loaded)
int $passed = ($width > 0 && $height > 0);
logTest("Output attributes accessible", $passed, "");
return $passed;
}
// Main Test Function
proc runAllTests() {
print("========================================\n");
print("Maya Image Plane Node - Viewport Tests\n");
print("========================================\n");
int $allPassed = 1;
// Run tests
if (!testLoadPlugin()) {
$allPassed = 0;
}
if (!testCreateNode()) {
$allPassed = 0;
}
if (!testSetVideoFile()) {
$allPassed = 0;
}
if (!testFrameNavigation()) {
$allPassed = 0;
}
if (!testFrameRate()) {
$allPassed = 0;
}
if (!testPlaybackRate()) {
$allPassed = 0;
}
if (!testPostEffectCrop()) {
$allPassed = 0;
}
if (!testPostEffectResize()) {
$allPassed = 0;
}
if (!testPostEffectFlip()) {
$allPassed = 0;
}
if (!testCacheSettings()) {
$allPassed = 0;
}
if (!testViewportDisplay()) {
$allPassed = 0;
}
if (!testOutputAttributes()) {
$allPassed = 0;
}
print("\n========================================\n");
if ($allPassed) {
print("All tests PASSED!\n");
} else {
print("Some tests FAILED!\n");
}
print("========================================\n");
}
// Run the tests
runAllTests();