6
6
using UnityEngine . TestTools . Graphics ;
7
7
using UnityEngine . SceneManagement ;
8
8
using System . IO ;
9
+ using Unity . ToonShader . GraphicsTest ;
10
+ using UnityEditor ;
9
11
10
12
11
13
namespace Tests
12
14
{
15
+ #if UNITY_EDITOR
16
+ public class UTSGraphicsTestsXR {
13
17
18
+ [ UnityTest ]
19
+ [ UseGraphicsTestCases ( UTSGraphicsTestConstants . ReferenceImagePath ) ]
20
+ [ Timeout ( 3600000 ) ] //1 hour
21
+ public IEnumerator Run ( GraphicsTestCase testCase ) {
22
+ //[TODO-sin: 2025-7-18] ECS projects were never tested with XR, and currently they don't support XR.
23
+ string projectName = Path . GetFileName ( Path . GetDirectoryName ( UnityEngine . Application . dataPath ) ) ;
24
+ if ( ! string . IsNullOrEmpty ( projectName ) && projectName . Contains ( "ECS" ) ) {
25
+ Assert . Ignore ( ) ;
26
+ }
27
+
28
+ //Enable XR
29
+ XRUtility . EnableXRInEditor ( ) ;
30
+
31
+ //Rendering both eyes in XR requires backbuffer, which depends on the game view resolution
32
+ object gameViewSizeObj = UnityEditor . TestTools . Graphics . GameViewSize . SetCustomSize ( 1920 , 1080 ) ;
33
+ Assert . IsNotNull ( gameViewSizeObj , "Failed to add custom game view size for XR tests." ) ;
34
+ UnityEditor . TestTools . Graphics . GameViewSize . SelectSize ( gameViewSizeObj ) ;
35
+
36
+ string loadedXRDevice = UseGraphicsTestCasesAttribute . LoadedXRDevice ;
37
+
38
+ //Manually load the reference image for XR. Ex: URP/Linear/WindowsEditor/Vulkan/None/AngelRing.png
39
+ Assert . IsNotNull ( testCase . ReferenceImage ) ;
40
+ string imagePath = AssetDatabase . GetAssetPath ( testCase . ReferenceImage ) ;
41
+ string imageFileName = Path . GetFileName ( imagePath ) ;
42
+ string imageFolderName = Path . GetDirectoryName ( Path . GetDirectoryName ( imagePath ) ) ;
43
+ Assert . IsNotNull ( imageFolderName ) ;
44
+ string xrImagePath = Path . Combine ( imageFolderName , loadedXRDevice , imageFileName ) ;
45
+ testCase . ReferenceImagePathLog = xrImagePath ;
46
+ Assert . IsTrue ( File . Exists ( xrImagePath ) , $ "XR Reference image not found at: { xrImagePath } ") ;
47
+ testCase . ReferenceImage = AssetDatabase . LoadAssetAtPath < Texture2D > ( xrImagePath ) ;
48
+
49
+ //Unity.ToonShader.GraphicsTest.SetupUTSGraphicsXRTestCases.Setup();
50
+ yield return UTS_GraphicsTests . RunInternal ( testCase , isXR : true ) ;
51
+
52
+ XRUtility . DisableXR ( ) ;
53
+ }
54
+
55
+ }
14
56
15
- public class UTS_GraphicsTests
16
- {
17
- #if UTS_TEST_USE_HDRP
18
- private const string ReferenceImagePath = "Packages/com.unity.toon-reference-images/HDRP" ;
19
- #elif UTS_TEST_USE_URP
20
- private const string ReferenceImagePath = "Packages/com.unity.toon-reference-images/URP" ;
21
- #else
22
- private const string ReferenceImagePath = "Packages/com.unity.toon-reference-images/Built-In" ;
23
- #endif
24
-
57
+ #endif //UNITY_EDITOR
58
+
59
+ public class UTSGraphicsTestsNonXR {
60
+ [ UnityTest ]
61
+ [ UseGraphicsTestCases ( UTSGraphicsTestConstants . ReferenceImagePath ) ]
62
+ [ Timeout ( 3600000 ) ] //1 hour
63
+ public IEnumerator Run ( GraphicsTestCase testCase ) {
64
+ //[TODO-sin: 2025-7-2] Hack for now to disable XR for non-Stereo projects
65
+ string projectName = Path . GetFileName ( Path . GetDirectoryName ( UnityEngine . Application . dataPath ) ) ;
66
+ if ( ! string . IsNullOrEmpty ( projectName ) && ! projectName . Contains ( "Stereo" ) ) {
67
+ XRUtility . DisableXR ( ) ;
68
+ }
25
69
26
- [ UnityTest ]
27
- [ PrebuildSetup ( typeof ( Unity . ToonShader . GraphicsTest . SetupUTSGraphicsTestCases ) ) ]
28
- [ UseGraphicsTestCases ( ReferenceImagePath ) ]
29
- [ Timeout ( 3600000 ) ] //1 hour
30
- public IEnumerator Run ( GraphicsTestCase testCase )
31
- {
70
+ yield return UTS_GraphicsTests . RunInternal ( testCase ) ;
71
+ }
72
+ }
32
73
74
+ //----------------------------------------------------------------------------------------------------------------------
75
+
76
+ public class UTS_GraphicsTests {
77
+ internal static IEnumerator RunInternal ( GraphicsTestCase testCase , bool isXR = false ) {
33
78
SceneManager . LoadScene ( testCase . ScenePath ) ;
34
79
35
80
// Always wait one frame for scene load
@@ -39,6 +84,13 @@ public IEnumerator Run(GraphicsTestCase testCase)
39
84
UTS_GraphicsTestSettings settings = Object . FindFirstObjectByType < UTS_GraphicsTestSettings > ( ) ;
40
85
Assert . IsNotNull ( settings , "Invalid test scene, couldn't find UTS_GraphicsTestSettings" ) ;
41
86
87
+ if ( isXR ) {
88
+ settings . ImageComparisonSettings . UseBackBuffer = true ; //results using both eyes need backbuffer
89
+
90
+ //[TODO-sin: 2025-7-9] Hack for now. The resolution will be set to this later
91
+ settings . ImageComparisonSettings . ImageResolution = ImageComparisonSettings . Resolution . w1920h1080 ;
92
+ }
93
+
42
94
43
95
int waitFrames = settings . WaitFrames ;
44
96
@@ -51,7 +103,8 @@ public IEnumerator Run(GraphicsTestCase testCase)
51
103
for ( int i = 0 ; i < waitFrames ; i ++ )
52
104
yield return new WaitForEndOfFrame ( ) ;
53
105
54
- ImageAssert . AreEqual ( testCase . ReferenceImage , cameras . Where ( x => x != null ) , settings . ImageComparisonSettings ) ;
106
+ ImageAssert . AreEqual ( testCase . ReferenceImage , cameras . Where ( x => x != null ) ,
107
+ settings . ImageComparisonSettings , testCase . ReferenceImagePathLog ) ;
55
108
56
109
// Does it allocate memory when it renders what's on the main camera?
57
110
bool allocatesMemory = false ;
0 commit comments