Skip to content

Commit 9b91a83

Browse files
author
Release Automat
committed
Release 5.2.0
1 parent 585c13c commit 9b91a83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1452
-14
lines changed

Packages/tlp.udonutils/Editor.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/tlp.udonutils/Editor/Tests.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "TLP.UdonUtils.Tests.Editor",
3+
"references": [
4+
"GUID:5ffc5658c86203349b4ced03f037df1f",
5+
"GUID:3b40974c3b83edb45909671e8bf52bba",
6+
"GUID:857706de0c98e764a98184ca1256e344",
7+
"GUID:0acc523941302664db1f4e527237feb3",
8+
"GUID:27619889b8ba8c24980f49ee34dbb44a",
9+
"GUID:3c1bc1267eab5884ebe7f232c09ee0d9",
10+
"GUID:84265b35cca3905448e623ef3903f0ff",
11+
"GUID:99835874ee819da44948776e0df4ff1d"
12+
],
13+
"includePlatforms": [
14+
"Editor"
15+
],
16+
"excludePlatforms": [],
17+
"allowUnsafeCode": false,
18+
"overrideReferences": false,
19+
"precompiledReferences": [
20+
"VRCSDKBase.dll",
21+
"VRC.Udon.Common.dll",
22+
"nunit.framework.dll"
23+
],
24+
"autoReferenced": true,
25+
"defineConstraints": [
26+
"UNITY_INCLUDE_TESTS"
27+
],
28+
"versionDefines": [],
29+
"noEngineReferences": false
30+
}

Packages/tlp.udonutils/Editor/Tests/TLP.UdonUtils.Tests.Editor.asmdef.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Reflection;
5+
using System.Text.RegularExpressions;
6+
using JetBrains.Annotations;
7+
using NUnit.Framework;
8+
using TLP.UdonUtils.Logger;
9+
using TLP.UdonUtils.Tests.Utils;
10+
using UnityEditor;
11+
using UnityEngine;
12+
using UnityEngine.SceneManagement;
13+
using UnityEngine.TestTools;
14+
using VRC.SDKBase;
15+
using Object = UnityEngine.Object;
16+
17+
namespace TLP.UdonUtils.Editor.Tests
18+
{
19+
[TestFixture(Category = "TLP/UdonUtils")]
20+
public abstract class TestWithLogger
21+
{
22+
[PublicAPI]
23+
protected TlpLogger TlpLogger { get; private set; }
24+
25+
protected UdonTestUtils.UdonTestEnvironment UdonTestEnvironment;
26+
protected VRCPlayerApi LocalPlayer;
27+
28+
public void ClearLog() {
29+
var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor));
30+
var type = assembly.GetType("UnityEditor.LogEntries");
31+
var method = type.GetMethod("Clear");
32+
if (method == null) {
33+
Assert.Fail("Editor log clear method not found");
34+
}
35+
36+
method.Invoke(new object(), null);
37+
}
38+
39+
[SetUp]
40+
public virtual void Setup() {
41+
ClearLog();
42+
Debug.ClearDeveloperConsole();
43+
Debug.Log("=========== Test Setup start ===========");
44+
45+
DestroyGameObjects(SceneManager.GetActiveScene().GetRootGameObjects());
46+
47+
UdonTestUtils.UdonTestEnvironment.ResetApiBindings();
48+
LogAssert.ignoreFailingMessages = false;
49+
TlpLogger = new GameObject(TlpBaseBehaviour.TlpLoggerGameObjectName).AddComponent<TlpLogger>();
50+
Debug.Log($"Created {TlpBaseBehaviour.TlpLoggerGameObjectName}: {TlpLogger == true}");
51+
TlpLogger.Severity = ELogLevel.Warning;
52+
53+
UdonTestEnvironment = new UdonTestUtils.UdonTestEnvironment();
54+
LocalPlayer = UdonTestEnvironment.CreatePlayer();
55+
}
56+
57+
[TearDown]
58+
public virtual void CleanUp() {
59+
Debug.Log("=========== Test TearDown start ===========");
60+
LogAssert.ignoreFailingMessages = true;
61+
if (UdonTestEnvironment != null) {
62+
UdonTestEnvironment.Deconstruct();
63+
UdonTestEnvironment = null;
64+
LocalPlayer = null;
65+
}
66+
67+
if (TlpLogger) {
68+
Object.DestroyImmediate(TlpLogger.gameObject);
69+
TlpLogger = null;
70+
}
71+
72+
DestroyGameObjects(SceneManager.GetActiveScene().GetRootGameObjects());
73+
}
74+
75+
protected static IEnumerator ShowAllGameObjects() {
76+
if (Application.isPlaying) {
77+
foreach (var root in SceneManager.GetActiveScene().GetRootGameObjects()) {
78+
foreach (var componentInChild in root.GetComponentsInChildren<Transform>(true)) {
79+
yield return null;
80+
EditorGUIUtility.PingObject(componentInChild);
81+
}
82+
}
83+
84+
yield return new WaitForSeconds(10f);
85+
}
86+
}
87+
88+
protected static void DestroyGameObjects(IEnumerable<GameObject> objectsToCleanup) {
89+
foreach (var objectToCleanUp in objectsToCleanup) {
90+
if (!objectToCleanUp || objectToCleanUp.name == "Code-based tests runner") {
91+
continue;
92+
}
93+
94+
Debug.Log($"Destroying {objectToCleanUp.name}");
95+
96+
Object.DestroyImmediate(objectToCleanUp);
97+
}
98+
}
99+
100+
protected static void ExpectError(string message) {
101+
LogAssert.Expect(LogType.Error, new Regex(".*" + message + ".*"));
102+
}
103+
104+
protected static void ExpectWarning(string message) {
105+
LogAssert.Expect(LogType.Warning, new Regex(".*" + message + ".*"));
106+
}
107+
108+
protected static void ExpectLog(string message) {
109+
LogAssert.Expect(LogType.Log, new Regex(".*" + message + ".*"));
110+
}
111+
112+
[PublicAPI]
113+
protected static GameObject FindGameObjectIncludingInactive(string goName) {
114+
GameObject gameObject = null;
115+
foreach (var rootGameObject in SceneManager.GetActiveScene().GetRootGameObjects()) {
116+
foreach (var transform in rootGameObject.GetComponentsInChildren<Transform>(true)) {
117+
if (transform.gameObject.name.Equals(goName, StringComparison.InvariantCultureIgnoreCase)) {
118+
gameObject = transform.gameObject;
119+
}
120+
}
121+
}
122+
123+
return gameObject;
124+
}
125+
}
126+
}

Packages/tlp.udonutils/Editor/Tests/TestWithLogger.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/tlp.udonutils/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ The used pattern MAJOR.MINOR.PATCH indicates:
3030

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

33+
### [5.2.0] - 2024-04-13
34+
35+
#### 🚀 Features
36+
37+
- *(testing)* Add base scripts for easy unit testing
38+
3339
### [5.1.0] - 2024-04-11
3440

3541
#### 🚀 Features

Packages/tlp.udonutils/Runtime/EditorOnly.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using TLP.UdonUtils.DesignPatterns.MVC;
2+
3+
namespace TLP.UdonUtils.EditorOnly
4+
{
5+
public class MockController : Controller
6+
{
7+
public bool InitResult = true;
8+
public bool DeInitResult = true;
9+
10+
11+
protected override bool InitializeInternal() {
12+
return InitResult;
13+
}
14+
15+
protected override bool DeInitializeInternal() {
16+
return DeInitResult;
17+
}
18+
19+
public void SetMockHasError(bool error) {
20+
HasError = error;
21+
}
22+
}
23+
}

Packages/tlp.udonutils/Runtime/EditorOnly/MockController.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#if !COMPILER_UDONSHARP && UNITY_EDITOR
2+
using TLP.UdonUtils.Events;
3+
using UnityEngine.Serialization;
4+
using VRC.Udon.Common.Enums;
5+
6+
namespace TLP.UdonUtils.EditorOnly
7+
{
8+
public class MockEvent : UdonEvent
9+
{
10+
public TlpBaseBehaviour Caller;
11+
public TlpBaseBehaviour RaiseOnIdleInstigator { get; private set; }
12+
public int RaiseOnIdleIdleFrames { get; private set; }
13+
public EventTiming RaiseOnIdleEventTiming { get; private set; }
14+
15+
[FormerlySerializedAs("Raises")]
16+
public int Invocations;
17+
18+
public override bool Raise(TlpBaseBehaviour instigator) {
19+
DebugLog(nameof(Raise));
20+
++Invocations;
21+
Caller = instigator;
22+
return true;
23+
}
24+
25+
public override bool RaiseOnIdle(
26+
TlpBaseBehaviour instigator,
27+
int idleFrames = 1,
28+
EventTiming eventTiming = EventTiming.Update
29+
) {
30+
DebugLog(nameof(RaiseOnIdle));
31+
RaiseOnIdleEventTiming = eventTiming;
32+
RaiseOnIdleIdleFrames = idleFrames;
33+
RaiseOnIdleInstigator = instigator;
34+
35+
return true;
36+
}
37+
}
38+
}
39+
#endif

Packages/tlp.udonutils/Runtime/EditorOnly/MockEvent.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using TLP.UdonUtils.DesignPatterns.MVC;
2+
3+
namespace TLP.UdonUtils.EditorOnly
4+
{
5+
public class MockModel : Model
6+
{
7+
public bool InitResult = true;
8+
public bool DeInitResult = true;
9+
10+
11+
protected override bool InitializeInternal() {
12+
return InitResult;
13+
}
14+
15+
protected override bool DeInitializeInternal() {
16+
return DeInitResult;
17+
}
18+
19+
public void SetMockHasError(bool error) {
20+
HasError = error;
21+
}
22+
}
23+
}

Packages/tlp.udonutils/Runtime/EditorOnly/MockModel.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using TLP.UdonUtils.DesignPatterns.MVC;
2+
3+
namespace TLP.UdonUtils.EditorOnly
4+
{
5+
public class MockView : View
6+
{
7+
public bool InitResult = true;
8+
public bool DeInitResult = true;
9+
public int ModelChangedInvocations;
10+
11+
protected override bool InitializeInternal() {
12+
return InitResult;
13+
}
14+
15+
protected override bool DeInitializeInternal() {
16+
return DeInitResult;
17+
}
18+
19+
public override void OnModelChanged() {
20+
++ModelChangedInvocations;
21+
}
22+
23+
public void SetMockHasError(bool error) {
24+
HasError = error;
25+
}
26+
}
27+
}

Packages/tlp.udonutils/Runtime/EditorOnly/MockView.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#if UNITY_EDITOR
2+
using System.IO;
3+
using UnityEngine;
4+
5+
namespace TLP.UdonUtils.EditorOnly
6+
{
7+
public class RenderToPng : MonoBehaviour
8+
{
9+
public void RenderTextureToFile(RenderTexture rt) {
10+
var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false)
11+
{
12+
hideFlags = HideFlags.DontSave
13+
};
14+
15+
16+
var oldActive = RenderTexture.active;
17+
try {
18+
RenderTexture.active = rt;
19+
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
20+
tex.Apply();
21+
byte[] pngBytes = tex.EncodeToPNG();
22+
File.WriteAllBytes("Image.png", pngBytes);
23+
}
24+
finally {
25+
RenderTexture.active = oldActive;
26+
Destroy(tex);
27+
}
28+
}
29+
30+
public RenderTexture rt;
31+
32+
[ContextMenu("SaveAsFile")]
33+
public void ConvertToPng() {
34+
RenderTextureToFile(rt);
35+
}
36+
}
37+
}
38+
#endif

0 commit comments

Comments
 (0)