Skip to content

Commit

Permalink
Release 5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Release Automat committed Apr 13, 2024
1 parent 585c13c commit 9b91a83
Show file tree
Hide file tree
Showing 42 changed files with 1,452 additions and 14 deletions.
8 changes: 8 additions & 0 deletions Packages/tlp.udonutils/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Packages/tlp.udonutils/Editor/Tests.meta

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.

126 changes: 126 additions & 0 deletions Packages/tlp.udonutils/Editor/Tests/TestWithLogger.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Packages/tlp.udonutils/Editor/Tests/TestWithLogger.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Packages/tlp.udonutils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ The used pattern MAJOR.MINOR.PATCH indicates:

All notable changes to this project will be documented in this file.

### [5.2.0] - 2024-04-13

#### 🚀 Features

- *(testing)* Add base scripts for easy unit testing

### [5.1.0] - 2024-04-11

#### 🚀 Features
Expand Down
8 changes: 8 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockController.cs
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.

39 changes: 39 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockEvent.cs
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
3 changes: 3 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockEvent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockModel.cs
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;
}
}
}
3 changes: 3 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockModel.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockView.cs
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;
}
}
}
3 changes: 3 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/MockView.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Packages/tlp.udonutils/Runtime/EditorOnly/RenderToPng.cs
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
Loading

0 comments on commit 9b91a83

Please sign in to comment.