Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions com.unity.toon-graphics-test/Editor/UTSGraphicsTestSetup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using Tests;
using System.Linq;
using Unity.ToonShader.GraphicsTest;

namespace UnityEditor.Rendering.Toon
{
Expand Down Expand Up @@ -109,12 +107,12 @@ void SetupScenes(int scneneIndex)
{
Debug.LogError("Unable to Find MainCamera in " + EditorBuildSettings.scenes[scneneIndex].path );
}
UTS_GraphicsTestSettings settings = cameraList[0].gameObject.GetComponent<UTS_GraphicsTestSettings>();
UTSGraphicsTestSettings settings = cameraList[0].gameObject.GetComponent<UTSGraphicsTestSettings>();


if ( settings == null )
{
settings = cameraList[0].gameObject.AddComponent<UTS_GraphicsTestSettings>();
settings = cameraList[0].gameObject.AddComponent<UTSGraphicsTestSettings>();
}
settings.ImageComparisonSettings.ImageResolution = UnityEngine.TestTools.Graphics.ImageComparisonSettings.Resolution.w960h540;
settings.ImageComparisonSettings.PerPixelCorrectnessThreshold = 0.005f;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using UnityEngine.TestTools.Graphics;

namespace Tests
namespace Unity.ToonShader.GraphicsTest
{
public class UTS_GraphicsTestSettings : GraphicsTestSettings
public class UTSGraphicsTestSettings : GraphicsTestSettings
{
public int WaitFrames = 0;
public bool XRCompatible = true;
Expand All @@ -12,7 +12,7 @@ public class UTS_GraphicsTestSettings : GraphicsTestSettings
public bool CheckMemoryAllocation = true;
#endif //#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX

public UTS_GraphicsTestSettings()
public UTSGraphicsTestSettings()
{
ImageComparisonSettings.TargetWidth = 960;
ImageComparisonSettings.TargetHeight = 540;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.TestTools.Graphics;
using UnityEngine.SceneManagement;
using System.IO;
using Unity.ToonShader.GraphicsTest;
using UnityEditor;


namespace Tests
namespace Unity.ToonShader.GraphicsTest
{
#if UNITY_EDITOR
public class UTSGraphicsTestsXR {
Expand Down Expand Up @@ -46,8 +44,7 @@ public IEnumerator Run(GraphicsTestCase testCase) {
Assert.IsTrue(File.Exists(xrImagePath),$"XR Reference image not found at: {xrImagePath}");
testCase.ReferenceImage = AssetDatabase.LoadAssetAtPath<Texture2D>(xrImagePath);

//Unity.ToonShader.GraphicsTest.SetupUTSGraphicsXRTestCases.Setup();
yield return UTS_GraphicsTests.RunInternal(testCase, isXR:true);
yield return UTSGraphicsTests.RunInternal(testCase, isXR:true);

XRUtility.DisableXR();
}
Expand All @@ -61,27 +58,21 @@ public class UTSGraphicsTestsNonXR {
[UseGraphicsTestCases(UTSGraphicsTestConstants.ReferenceImagePath)]
[Timeout(3600000)] //1 hour
public IEnumerator Run(GraphicsTestCase testCase) {
//[TODO-sin: 2025-7-2] Hack for now to disable XR for non-Stereo projects
string projectName = Path.GetFileName(Path.GetDirectoryName(UnityEngine.Application.dataPath));
if (!string.IsNullOrEmpty(projectName) && !projectName.Contains("Stereo")) {
XRUtility.DisableXR();
}

yield return UTS_GraphicsTests.RunInternal(testCase);
yield return UTSGraphicsTests.RunInternal(testCase);
}
}

//----------------------------------------------------------------------------------------------------------------------

public class UTS_GraphicsTests {
public static class UTSGraphicsTests {
internal static IEnumerator RunInternal(GraphicsTestCase testCase, bool isXR = false) {
SceneManager.LoadScene(testCase.ScenePath);

// Always wait one frame for scene load
yield return null;

var cameras = GameObject.FindGameObjectsWithTag("MainCamera").Select(x => x.GetComponent<Camera>());
UTS_GraphicsTestSettings settings = Object.FindFirstObjectByType<UTS_GraphicsTestSettings>();
Camera mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
UTSGraphicsTestSettings settings = Object.FindFirstObjectByType<UTSGraphicsTestSettings>();
Assert.IsNotNull(settings, "Invalid test scene, couldn't find UTS_GraphicsTestSettings");

if (isXR) {
Expand All @@ -94,21 +85,19 @@ internal static IEnumerator RunInternal(GraphicsTestCase testCase, bool isXR = f

int waitFrames = settings.WaitFrames;

if (settings.ImageComparisonSettings.UseBackBuffer && settings.WaitFrames < 1)
{
if (settings.ImageComparisonSettings.UseBackBuffer && settings.WaitFrames < 1) {
waitFrames = 1;
}


for (int i = 0; i < waitFrames; i++)
yield return new WaitForEndOfFrame();

ImageAssert.AreEqual(testCase.ReferenceImage, cameras.Where(x => x != null),
ImageAssert.AreEqual(testCase.ReferenceImage, mainCamera,
settings.ImageComparisonSettings, testCase.ReferenceImagePathLog);

// Does it allocate memory when it renders what's on the main camera?
bool allocatesMemory = false;
var mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();

if (settings == null || settings.CheckMemoryAllocation)
{
Expand All @@ -124,22 +113,6 @@ internal static IEnumerator RunInternal(GraphicsTestCase testCase, bool isXR = f
Assert.Fail("Allocated memory when rendering what is on main camera");
}
}

public static Texture2D LoadPNG(string filePath)
{

Texture2D tex2D = null;
byte[] fileData;

if (File.Exists(filePath))
{
fileData = File.ReadAllBytes(filePath);
tex2D = new Texture2D(2, 2);
tex2D.LoadImage(fileData);
}
return tex2D;
}
}


}