-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "TLP.UdonUtils.Tests.Editor", | ||
"references": [ | ||
"GUID:5ffc5658c86203349b4ced03f037df1f", | ||
"GUID:3b40974c3b83edb45909671e8bf52bba", | ||
"GUID:857706de0c98e764a98184ca1256e344", | ||
"GUID:0acc523941302664db1f4e527237feb3", | ||
"GUID:27619889b8ba8c24980f49ee34dbb44a", | ||
"GUID:3c1bc1267eab5884ebe7f232c09ee0d9", | ||
"GUID:84265b35cca3905448e623ef3903f0ff", | ||
"GUID:99835874ee819da44948776e0df4ff1d" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [ | ||
"VRCSDKBase.dll", | ||
"VRC.Udon.Common.dll", | ||
"nunit.framework.dll" | ||
], | ||
"autoReferenced": true, | ||
"defineConstraints": [ | ||
"UNITY_INCLUDE_TESTS" | ||
], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text.RegularExpressions; | ||
using JetBrains.Annotations; | ||
using NUnit.Framework; | ||
using TLP.UdonUtils.Logger; | ||
using TLP.UdonUtils.Tests.Utils; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
using UnityEngine.TestTools; | ||
using VRC.SDKBase; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace TLP.UdonUtils.Editor.Tests | ||
{ | ||
[TestFixture(Category = "TLP/UdonUtils")] | ||
public abstract class TestWithLogger | ||
{ | ||
[PublicAPI] | ||
protected TlpLogger TlpLogger { get; private set; } | ||
|
||
protected UdonTestUtils.UdonTestEnvironment UdonTestEnvironment; | ||
protected VRCPlayerApi LocalPlayer; | ||
|
||
public void ClearLog() { | ||
var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor)); | ||
var type = assembly.GetType("UnityEditor.LogEntries"); | ||
var method = type.GetMethod("Clear"); | ||
if (method == null) { | ||
Assert.Fail("Editor log clear method not found"); | ||
} | ||
|
||
method.Invoke(new object(), null); | ||
} | ||
|
||
[SetUp] | ||
public virtual void Setup() { | ||
ClearLog(); | ||
Debug.ClearDeveloperConsole(); | ||
Debug.Log("=========== Test Setup start ==========="); | ||
|
||
DestroyGameObjects(SceneManager.GetActiveScene().GetRootGameObjects()); | ||
|
||
UdonTestUtils.UdonTestEnvironment.ResetApiBindings(); | ||
LogAssert.ignoreFailingMessages = false; | ||
TlpLogger = new GameObject(TlpBaseBehaviour.TlpLoggerGameObjectName).AddComponent<TlpLogger>(); | ||
Debug.Log($"Created {TlpBaseBehaviour.TlpLoggerGameObjectName}: {TlpLogger == true}"); | ||
TlpLogger.Severity = ELogLevel.Warning; | ||
|
||
UdonTestEnvironment = new UdonTestUtils.UdonTestEnvironment(); | ||
LocalPlayer = UdonTestEnvironment.CreatePlayer(); | ||
} | ||
|
||
[TearDown] | ||
public virtual void CleanUp() { | ||
Debug.Log("=========== Test TearDown start ==========="); | ||
LogAssert.ignoreFailingMessages = true; | ||
if (UdonTestEnvironment != null) { | ||
UdonTestEnvironment.Deconstruct(); | ||
UdonTestEnvironment = null; | ||
LocalPlayer = null; | ||
} | ||
|
||
if (TlpLogger) { | ||
Object.DestroyImmediate(TlpLogger.gameObject); | ||
TlpLogger = null; | ||
} | ||
|
||
DestroyGameObjects(SceneManager.GetActiveScene().GetRootGameObjects()); | ||
} | ||
|
||
protected static IEnumerator ShowAllGameObjects() { | ||
if (Application.isPlaying) { | ||
foreach (var root in SceneManager.GetActiveScene().GetRootGameObjects()) { | ||
foreach (var componentInChild in root.GetComponentsInChildren<Transform>(true)) { | ||
yield return null; | ||
EditorGUIUtility.PingObject(componentInChild); | ||
} | ||
} | ||
|
||
yield return new WaitForSeconds(10f); | ||
} | ||
} | ||
|
||
protected static void DestroyGameObjects(IEnumerable<GameObject> objectsToCleanup) { | ||
foreach (var objectToCleanUp in objectsToCleanup) { | ||
if (!objectToCleanUp || objectToCleanUp.name == "Code-based tests runner") { | ||
continue; | ||
} | ||
|
||
Debug.Log($"Destroying {objectToCleanUp.name}"); | ||
|
||
Object.DestroyImmediate(objectToCleanUp); | ||
} | ||
} | ||
|
||
protected static void ExpectError(string message) { | ||
LogAssert.Expect(LogType.Error, new Regex(".*" + message + ".*")); | ||
} | ||
|
||
protected static void ExpectWarning(string message) { | ||
LogAssert.Expect(LogType.Warning, new Regex(".*" + message + ".*")); | ||
} | ||
|
||
protected static void ExpectLog(string message) { | ||
LogAssert.Expect(LogType.Log, new Regex(".*" + message + ".*")); | ||
} | ||
|
||
[PublicAPI] | ||
protected static GameObject FindGameObjectIncludingInactive(string goName) { | ||
GameObject gameObject = null; | ||
foreach (var rootGameObject in SceneManager.GetActiveScene().GetRootGameObjects()) { | ||
foreach (var transform in rootGameObject.GetComponentsInChildren<Transform>(true)) { | ||
if (transform.gameObject.name.Equals(goName, StringComparison.InvariantCultureIgnoreCase)) { | ||
gameObject = transform.gameObject; | ||
} | ||
} | ||
} | ||
|
||
return gameObject; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using TLP.UdonUtils.DesignPatterns.MVC; | ||
|
||
namespace TLP.UdonUtils.EditorOnly | ||
{ | ||
public class MockController : Controller | ||
{ | ||
public bool InitResult = true; | ||
public bool DeInitResult = true; | ||
|
||
|
||
protected override bool InitializeInternal() { | ||
return InitResult; | ||
} | ||
|
||
protected override bool DeInitializeInternal() { | ||
return DeInitResult; | ||
} | ||
|
||
public void SetMockHasError(bool error) { | ||
HasError = error; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#if !COMPILER_UDONSHARP && UNITY_EDITOR | ||
using TLP.UdonUtils.Events; | ||
using UnityEngine.Serialization; | ||
using VRC.Udon.Common.Enums; | ||
|
||
namespace TLP.UdonUtils.EditorOnly | ||
{ | ||
public class MockEvent : UdonEvent | ||
{ | ||
public TlpBaseBehaviour Caller; | ||
public TlpBaseBehaviour RaiseOnIdleInstigator { get; private set; } | ||
public int RaiseOnIdleIdleFrames { get; private set; } | ||
public EventTiming RaiseOnIdleEventTiming { get; private set; } | ||
|
||
[FormerlySerializedAs("Raises")] | ||
public int Invocations; | ||
|
||
public override bool Raise(TlpBaseBehaviour instigator) { | ||
DebugLog(nameof(Raise)); | ||
++Invocations; | ||
Caller = instigator; | ||
return true; | ||
} | ||
|
||
public override bool RaiseOnIdle( | ||
TlpBaseBehaviour instigator, | ||
int idleFrames = 1, | ||
EventTiming eventTiming = EventTiming.Update | ||
) { | ||
DebugLog(nameof(RaiseOnIdle)); | ||
RaiseOnIdleEventTiming = eventTiming; | ||
RaiseOnIdleIdleFrames = idleFrames; | ||
RaiseOnIdleInstigator = instigator; | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using TLP.UdonUtils.DesignPatterns.MVC; | ||
|
||
namespace TLP.UdonUtils.EditorOnly | ||
{ | ||
public class MockModel : Model | ||
{ | ||
public bool InitResult = true; | ||
public bool DeInitResult = true; | ||
|
||
|
||
protected override bool InitializeInternal() { | ||
return InitResult; | ||
} | ||
|
||
protected override bool DeInitializeInternal() { | ||
return DeInitResult; | ||
} | ||
|
||
public void SetMockHasError(bool error) { | ||
HasError = error; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using TLP.UdonUtils.DesignPatterns.MVC; | ||
|
||
namespace TLP.UdonUtils.EditorOnly | ||
{ | ||
public class MockView : View | ||
{ | ||
public bool InitResult = true; | ||
public bool DeInitResult = true; | ||
public int ModelChangedInvocations; | ||
|
||
protected override bool InitializeInternal() { | ||
return InitResult; | ||
} | ||
|
||
protected override bool DeInitializeInternal() { | ||
return DeInitResult; | ||
} | ||
|
||
public override void OnModelChanged() { | ||
++ModelChangedInvocations; | ||
} | ||
|
||
public void SetMockHasError(bool error) { | ||
HasError = error; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#if UNITY_EDITOR | ||
using System.IO; | ||
using UnityEngine; | ||
|
||
namespace TLP.UdonUtils.EditorOnly | ||
{ | ||
public class RenderToPng : MonoBehaviour | ||
{ | ||
public void RenderTextureToFile(RenderTexture rt) { | ||
var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false) | ||
{ | ||
hideFlags = HideFlags.DontSave | ||
}; | ||
|
||
|
||
var oldActive = RenderTexture.active; | ||
try { | ||
RenderTexture.active = rt; | ||
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0); | ||
tex.Apply(); | ||
byte[] pngBytes = tex.EncodeToPNG(); | ||
File.WriteAllBytes("Image.png", pngBytes); | ||
} | ||
finally { | ||
RenderTexture.active = oldActive; | ||
Destroy(tex); | ||
} | ||
} | ||
|
||
public RenderTexture rt; | ||
|
||
[ContextMenu("SaveAsFile")] | ||
public void ConvertToPng() { | ||
RenderTextureToFile(rt); | ||
} | ||
} | ||
} | ||
#endif |