initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,224 @@
using UnityEngine;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using UnityEngine.AddressableAssets.Initialization;
namespace AddrRuntimePropertiesTests
{
public class AddrRuntimePropertiesTests
{
[Test]
public void RuntimeProperties_CanAddValue()
{
AddressablesRuntimeProperties.ClearCachedPropertyValues();
AddressablesRuntimeProperties.SetPropertyValue("name", "val");
Assert.AreEqual(1, AddressablesRuntimeProperties.GetCachedValueCount());
}
[Test]
public void RuntimeProperties_CanSetValueMultipleTimes()
{
AddressablesRuntimeProperties.ClearCachedPropertyValues();
AddressablesRuntimeProperties.SetPropertyValue("name", "val");
AddressablesRuntimeProperties.SetPropertyValue("name", "val2");
Assert.AreEqual(1, AddressablesRuntimeProperties.GetCachedValueCount());
}
[Test]
public void RuntimeProperties_ClearCacheClears()
{
AddressablesRuntimeProperties.ClearCachedPropertyValues();
AddressablesRuntimeProperties.SetPropertyValue("name", "val");
AddressablesRuntimeProperties.ClearCachedPropertyValues();
Assert.AreEqual(0, AddressablesRuntimeProperties.GetCachedValueCount());
}
[Test]
public void RuntimeProperties_EvaluatePropertyCanEvaluateSetValue()
{
AddressablesRuntimeProperties.ClearCachedPropertyValues();
string expectedResult = "myVal";
string key = "myName";
AddressablesRuntimeProperties.SetPropertyValue(key, expectedResult);
string actualResult = AddressablesRuntimeProperties.EvaluateProperty(key);
Assert.AreEqual(expectedResult, actualResult);
}
public static string ReflectableStringValue = "myReflectionResult";
[Test]
public void RuntimeProperties_CanEvaluateReflection()
{
AddressablesRuntimeProperties.ClearCachedPropertyValues();
string expectedResult = ReflectableStringValue;
string actualResult = AddressablesRuntimeProperties.EvaluateProperty("AddrRuntimePropertiesTests.AddrRuntimePropertiesTests.ReflectableStringValue");
Assert.AreEqual(expectedResult, actualResult);
}
[Test]
public void RuntimeProperties_EvaluateStringCanParseAutomaticTokens()
{
string tok1 = "cheese";
string tok2 = "cows";
string tok3 = "moo";
string toEval = tok1 + '{' + tok2 + '}' + tok3;
string expectedResult = tok1 + tok2 + tok3;
string actualResult = AddressablesRuntimeProperties.EvaluateString(toEval);
Assert.AreEqual(expectedResult, actualResult);
}
[Test]
public void RuntimeProperties_EvaluateStringCanParseInExplicitOverride()
{
string tok1 = "cheese";
string tok2 = "cows";
string tok3 = "moo";
string replacement = "_parsed_";
char delim = '?';
string toEval = tok1 + delim + tok2 + delim + tok3;
string expectedResult = tok1 + replacement + tok3;
string actualResult = AddressablesRuntimeProperties.EvaluateString(toEval, delim, delim, s => { return replacement; });
Assert.AreEqual(expectedResult, actualResult);
}
[Test]
[Timeout(1000)]
public void RuntimeProperties_CanDetectCyclicLoops()
{
string a = "[B]";
string b = "[A]";
string toEval = "Test_[A]_";
string expectedResult = "Test_#ERROR-CyclicToken#_";
string actualResult = AddressablesRuntimeProperties.EvaluateString(toEval, '[', ']', s =>
{
switch (s)
{
case "A":
return a;
case "B":
return b;
}
return "";
});
Assert.AreEqual(expectedResult, actualResult);
}
[Test]
[Timeout(1000)]
public void RuntimeProperties_CanEvaluateInnerProperties()
{
Dictionary<string, string> stringLookup = new Dictionary<string, string>();
stringLookup.Add("B", "inner");
stringLookup.Add("With_inner", "Success");
string toEval = "Test_[With_[B]]";
string expectedResult = "Test_Success";
string actualResult = AddressablesRuntimeProperties.EvaluateString(toEval, '[', ']', s =>
{
if (stringLookup.TryGetValue(s, out string val))
return val;
return "";
});
Assert.AreEqual(expectedResult, actualResult);
}
[Test]
public void RuntimeProperties_EvaluateString_CreatesLocalStackOnRecursiveCall()
{
string testString = "[{[{correct}]bad}]";
string expectedResult = "CORRECTBAD";
string actualResult = AddressablesRuntimeProperties.EvaluateString(testString, '[', ']', s => { return AddressablesRuntimeProperties.EvaluateString(s, '{', '}', str => str.ToUpper()); });
Assert.AreEqual(expectedResult, actualResult, "EvaluateString does not properly initialize a local stack for recursive/simultaneous calls.");
}
[Test]
public void RuntimeProperties_EvaluateString_CreatesLocalStacksOnDeepRecursiveCall()
{
string testString = "[{([{(correct)}]bad)}]";
string expectedResult = "CORRECTBAD";
string actualResult = AddressablesRuntimeProperties.EvaluateString(testString, '[', ']',
s => { return AddressablesRuntimeProperties.EvaluateString(s, '{', '}', str => { return AddressablesRuntimeProperties.EvaluateString(str, '(', ')', str2 => str2.ToUpper()); }); });
Assert.AreEqual(expectedResult, actualResult, "EvaluateString does not properly initialize a local stack for recursive/simultaneous calls.");
}
[Test]
[Timeout(3000)]
public void RuntimeProperties_EvaluateString_DoesNotLoopInfinitelyOnUnmatchedEndingDelimiter()
{
string testString = "[correct]bad]";
string expectedResult = "#ERROR-" + testString + " contains unmatched delimiters#";
string actualResult = AddressablesRuntimeProperties.EvaluateString(testString, '[', ']', s => s);
Assert.AreEqual(expectedResult, actualResult, "EvaluateString encounters infinite loop with unmatched ending delimiter");
}
[Test]
[Timeout(3000)]
public void RuntimeProperties_EvaluateString_DoesNotLoopInfinitelyOnUnmatchedStartingDelimiter()
{
string testString = "[[correct]bad";
string expectedResult = "[correctbad";
string actualResult = AddressablesRuntimeProperties.EvaluateString(testString, '[', ']', s => s);
Assert.AreEqual(expectedResult, actualResult, "EvaluateString encounters infinite loop with unmatched starting delimiter");
}
[Test]
[Timeout(3000)]
public void RuntimeProperties_EvaluateString_DoesNotLoopInfinitelyOnImproperlyOrderedDelimiters()
{
string testString = "][correct][bad";
string expectedResult = "]correct[bad";
string actualResult = AddressablesRuntimeProperties.EvaluateString(testString, '[', ']', s => s);
Assert.AreEqual(expectedResult, actualResult, "EvaluateString encounters infinite loop on reversed delimiters");
}
[Test]
public void RuntimeProperties_EvaluateStringIgnoresSingleDelim()
{
string tok1 = "cheese";
string tok2 = "cows";
string tok3 = "moo";
string toEval = tok1 + tok2 + '}' + tok3;
string expectedResult = toEval;
string actualResult = AddressablesRuntimeProperties.EvaluateString(toEval);
Assert.AreEqual(expectedResult, actualResult);
toEval = tok1 + '{' + tok2 + tok3;
expectedResult = toEval;
actualResult = AddressablesRuntimeProperties.EvaluateString(toEval);
Assert.AreEqual(expectedResult, actualResult);
string replacement = "_parsed_";
char delim = '?';
toEval = tok1 + tok2 + delim + tok3;
expectedResult = toEval;
actualResult = AddressablesRuntimeProperties.EvaluateString(toEval, delim, delim, s => { return replacement; });
Assert.AreEqual(expectedResult, actualResult);
toEval = tok1 + delim + tok2 + tok3;
expectedResult = toEval;
actualResult = AddressablesRuntimeProperties.EvaluateString(toEval, delim, delim, s => { return replacement; });
Assert.AreEqual(expectedResult, actualResult);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6c1d0b0ab4d44f42a99963de99d60ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,101 @@
using System.IO;
using NUnit.Framework;
using UnityEngine.ResourceManagement;
#if UNITY_EDITOR
using UnityEditor.AddressableAssets.Build.DataBuilders;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
#endif
namespace AddressableTests.FastModeInitTests
{
#if UNITY_EDITOR
public class FastModeInitializationTests : AddressablesTestFixture
{
protected override TestBuildScriptMode BuildScriptMode => TestBuildScriptMode.Fast;
[TestCase(true)]
[TestCase(false)]
public void FastModeInit_EventViewerSetup_InitializesPostProfilerEventsValue(bool sendProfilerEvents)
{
//Setup
bool originalValue = ProjectConfigData.PostProfilerEvents;
ProjectConfigData.PostProfilerEvents = sendProfilerEvents;
var settings = AddressableAssetSettings.Create(Path.Combine(GetGeneratedAssetsPath(), "Settings"), "AddressableAssetSettings.Tests", false, true);
//Test
FastModeInitializationOperation fmInit = new FastModeInitializationOperation(m_Addressables, settings);
fmInit.InvokeExecute();
//Assert
Assert.AreEqual(sendProfilerEvents, m_Addressables.ResourceManager.postProfilerEvents);
//Cleanup
ProjectConfigData.PostProfilerEvents = originalValue;
}
[TestCase(true)]
[TestCase(false)]
public void FastModeInit_EventViewerSetup_InitializesDiagnosticEventCollectorCorrectly(bool sendProfilerEvents)
{
//Setup
bool originalValue = ProjectConfigData.PostProfilerEvents;
ProjectConfigData.PostProfilerEvents = sendProfilerEvents;
var settings = AddressableAssetSettings.Create(Path.Combine(GetGeneratedAssetsPath(), "Settings"), "AddressableAssetSettings.Tests", false, true);
//Test
FastModeInitializationOperation fmInit = new FastModeInitializationOperation(m_Addressables, settings);
fmInit.InvokeExecute();
//Assert
if (sendProfilerEvents)
Assert.IsNotNull(fmInit.m_Diagnostics, "Diagnostic event collector was null when send profiler events was set to true.");
else
Assert.IsNull(fmInit.m_Diagnostics, "Diagnostic event collector was not null when send profiler events was false.");
//Cleanup
ProjectConfigData.PostProfilerEvents = originalValue;
}
[TestCase(true)]
[TestCase(false)]
public void FastModeInitialization_SetsExceptionHandlerToNull_WhenLogRuntimeExceptionsIsOff(bool logRuntimeExceptions)
{
//Setup
var settings = AddressableAssetSettings.Create(Path.Combine(GetGeneratedAssetsPath(), "Settings"), "AddressableAssetSettings.Tests", false, true);
settings.buildSettings.LogResourceManagerExceptions = logRuntimeExceptions;
//Test
FastModeInitializationOperation fmInit = new FastModeInitializationOperation(m_Addressables, settings);
fmInit.InvokeExecute();
//Assert
Assert.AreEqual(logRuntimeExceptions, ResourceManager.ExceptionHandler != null);
}
public class FastModeInitializationTestsBuildScriptFastMode : BuildScriptFastMode
{
}
[Test]
public void FastModeInitialization_GetBuilderOfType_ReturnsDirectAndSubclasses()
{
var settings = base.CreateSettings("AddressableAssetSettings.Tests", Path.Combine(GetGeneratedAssetsPath(), "Settings"));
var db = FastModeInitializationOperation.GetBuilderOfType<BuildScriptFastMode>(settings, true);
// default fast mode should be added on Validate of the settings object
Assert.IsNotNull(db, "Failed to find the FastMode build script");
Assert.AreEqual(db.GetType(), typeof(BuildScriptFastMode), "Fast mode build script expected to be BuildScriptFastMode type");
Assert.IsTrue(settings.AddDataBuilder(settings.CreateScriptAsset<FastModeInitializationTestsBuildScriptFastMode>(), false), "Failed to Add custom buildScript FastMode");
db = FastModeInitializationOperation.GetBuilderOfType<BuildScriptFastMode>(settings, true);
Assert.IsNotNull(db, "Failed to find the FastMode build script");
Assert.AreEqual(db.GetType(), typeof(FastModeInitializationTestsBuildScriptFastMode), "Fast mode build script expected to be FastModeInitializationTestsBuildScriptFastMode type");
db = FastModeInitializationOperation.GetBuilderOfType<BuildScriptFastMode>(settings, false);
Assert.IsNotNull(db, "Failed to find the FastMode build script");
Assert.AreEqual(db.GetType(), typeof(BuildScriptFastMode), "Fast mode build script expected to be BuildScriptFastMode type, where requesting exact type and exists in the settings");
}
}
#endif
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 441d6ab2de7dd3948b7b50882e4370e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: