initial project folder
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal interface ITestSettings : IDisposable
|
||||
{
|
||||
ScriptingImplementation? scriptingBackend { get; set; }
|
||||
|
||||
string Architecture { get; set; }
|
||||
|
||||
ApiCompatibilityLevel? apiProfile { get; set; }
|
||||
|
||||
bool? appleEnableAutomaticSigning { get; set; }
|
||||
string appleDeveloperTeamID { get; set; }
|
||||
ProvisioningProfileType? iOSManualProvisioningProfileType { get; set; }
|
||||
string iOSManualProvisioningProfileID { get; set; }
|
||||
ProvisioningProfileType? tvOSManualProvisioningProfileType { get; set; }
|
||||
string tvOSManualProvisioningProfileID { get; set; }
|
||||
|
||||
void SetupProjectParameters();
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83eda34b7da01e04aa894f268158b0c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,7 @@
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
interface ITestSettingsDeserializer
|
||||
{
|
||||
ITestSettings GetSettingsFromJsonFile(string jsonFilePath);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d208a1684f8aa6a40ad91d6aa9600c14
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,160 @@
|
||||
using System;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
internal class TestSettings : ITestSettings
|
||||
{
|
||||
private readonly TestSetting[] m_Settings =
|
||||
{
|
||||
new TestSetting<ScriptingImplementation?>(
|
||||
settings => settings.scriptingBackend,
|
||||
() => PlayerSettings.GetScriptingBackend(EditorUserBuildSettings.activeBuildTargetGroup),
|
||||
implementation => PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.activeBuildTargetGroup, implementation.Value)),
|
||||
new TestSetting<string>(
|
||||
settings => settings.Architecture,
|
||||
() => EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android ? PlayerSettings.Android.targetArchitectures.ToString() : null,
|
||||
architecture =>
|
||||
{
|
||||
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(architecture))
|
||||
{
|
||||
var targetArchitectures = (AndroidArchitecture)Enum.Parse(typeof(AndroidArchitecture), architecture, true);
|
||||
PlayerSettings.Android.targetArchitectures = targetArchitectures;
|
||||
}
|
||||
}
|
||||
}),
|
||||
new TestSetting<ApiCompatibilityLevel?>(
|
||||
settings => settings.apiProfile,
|
||||
() => PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup),
|
||||
implementation =>
|
||||
{
|
||||
if (Enum.IsDefined(typeof(ApiCompatibilityLevel), implementation.Value))
|
||||
{
|
||||
PlayerSettings.SetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup,
|
||||
implementation.Value);
|
||||
}
|
||||
}),
|
||||
new TestSetting<bool?>(
|
||||
settings => settings.appleEnableAutomaticSigning,
|
||||
() => PlayerSettings.iOS.appleEnableAutomaticSigning,
|
||||
enableAutomaticSigning =>
|
||||
{
|
||||
if (enableAutomaticSigning != null)
|
||||
PlayerSettings.iOS.appleEnableAutomaticSigning = enableAutomaticSigning.Value;
|
||||
}),
|
||||
new TestSetting<string>(
|
||||
settings => settings.appleDeveloperTeamID,
|
||||
() => PlayerSettings.iOS.appleDeveloperTeamID,
|
||||
developerTeam =>
|
||||
{
|
||||
if (developerTeam != null)
|
||||
PlayerSettings.iOS.appleDeveloperTeamID = developerTeam;
|
||||
}),
|
||||
new TestSetting<ProvisioningProfileType?>(
|
||||
settings => settings.iOSManualProvisioningProfileType,
|
||||
() => PlayerSettings.iOS.iOSManualProvisioningProfileType,
|
||||
profileType =>
|
||||
{
|
||||
if (profileType != null)
|
||||
PlayerSettings.iOS.iOSManualProvisioningProfileType = profileType.Value;
|
||||
}),
|
||||
new TestSetting<string>(
|
||||
settings => settings.iOSManualProvisioningProfileID,
|
||||
() => PlayerSettings.iOS.iOSManualProvisioningProfileID,
|
||||
provisioningUUID =>
|
||||
{
|
||||
if (provisioningUUID != null)
|
||||
PlayerSettings.iOS.iOSManualProvisioningProfileID = provisioningUUID;
|
||||
}),
|
||||
new TestSetting<ProvisioningProfileType?>(
|
||||
settings => settings.tvOSManualProvisioningProfileType,
|
||||
() => PlayerSettings.iOS.tvOSManualProvisioningProfileType,
|
||||
profileType =>
|
||||
{
|
||||
if (profileType != null)
|
||||
PlayerSettings.iOS.tvOSManualProvisioningProfileType = profileType.Value;
|
||||
}),
|
||||
new TestSetting<string>(
|
||||
settings => settings.tvOSManualProvisioningProfileID,
|
||||
() => PlayerSettings.iOS.tvOSManualProvisioningProfileID,
|
||||
provisioningUUID =>
|
||||
{
|
||||
if (provisioningUUID != null)
|
||||
PlayerSettings.iOS.tvOSManualProvisioningProfileID = provisioningUUID;
|
||||
}),
|
||||
};
|
||||
|
||||
private bool m_Disposed;
|
||||
|
||||
public ScriptingImplementation? scriptingBackend { get; set; }
|
||||
|
||||
public string Architecture { get; set; }
|
||||
|
||||
public ApiCompatibilityLevel? apiProfile { get; set; }
|
||||
|
||||
public bool? appleEnableAutomaticSigning { get; set; }
|
||||
public string appleDeveloperTeamID { get; set; }
|
||||
public ProvisioningProfileType? iOSManualProvisioningProfileType { get; set; }
|
||||
public string iOSManualProvisioningProfileID { get; set; }
|
||||
public ProvisioningProfileType? tvOSManualProvisioningProfileType { get; set; }
|
||||
public string tvOSManualProvisioningProfileID { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!m_Disposed)
|
||||
{
|
||||
foreach (var testSetting in m_Settings)
|
||||
{
|
||||
testSetting.Cleanup();
|
||||
}
|
||||
|
||||
m_Disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupProjectParameters()
|
||||
{
|
||||
foreach (var testSetting in m_Settings)
|
||||
{
|
||||
testSetting.Setup(this);
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class TestSetting
|
||||
{
|
||||
public abstract void Setup(TestSettings settings);
|
||||
public abstract void Cleanup();
|
||||
}
|
||||
|
||||
private class TestSetting<T> : TestSetting
|
||||
{
|
||||
private T m_ValueBeforeSetup;
|
||||
private Func<TestSettings, T> m_GetFromSettings;
|
||||
private Func<T> m_GetCurrentValue;
|
||||
private Action<T> m_SetValue;
|
||||
|
||||
public TestSetting(Func<TestSettings, T> getFromSettings, Func<T> getCurrentValue, Action<T> setValue)
|
||||
{
|
||||
m_GetFromSettings = getFromSettings;
|
||||
m_GetCurrentValue = getCurrentValue;
|
||||
m_SetValue = setValue;
|
||||
}
|
||||
|
||||
public override void Setup(TestSettings settings)
|
||||
{
|
||||
m_ValueBeforeSetup = m_GetCurrentValue();
|
||||
var newValue = m_GetFromSettings(settings);
|
||||
if (newValue != null)
|
||||
{
|
||||
m_SetValue(newValue);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Cleanup()
|
||||
{
|
||||
m_SetValue(m_ValueBeforeSetup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b32b6725087a0d4bb1670818d26996e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.TestTools.TestRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles deserialization of TestSettings from a provided json file path.
|
||||
/// </summary>
|
||||
internal class TestSettingsDeserializer : ITestSettingsDeserializer
|
||||
{
|
||||
private static readonly SettingsMap[] s_SettingsMapping =
|
||||
{
|
||||
new SettingsMap<ScriptingImplementation>("scriptingBackend", (settings, value) => settings.scriptingBackend = value),
|
||||
new SettingsMap<string>("architecture", (settings, value) => settings.Architecture = value),
|
||||
new SettingsMap<ApiCompatibilityLevel>("apiProfile", (settings, value) => settings.apiProfile = value),
|
||||
new SettingsMap<bool>("appleEnableAutomaticSigning", (settings, value) => settings.appleEnableAutomaticSigning = value),
|
||||
new SettingsMap<string>("appleDeveloperTeamID", (settings, value) => settings.appleDeveloperTeamID = value),
|
||||
new SettingsMap<ProvisioningProfileType>("iOSManualProvisioningProfileType", (settings, value) => settings.iOSManualProvisioningProfileType = value),
|
||||
new SettingsMap<string>("iOSManualProvisioningProfileID", (settings, value) => settings.iOSManualProvisioningProfileID = value),
|
||||
new SettingsMap<ProvisioningProfileType>("tvOSManualProvisioningProfileType", (settings, value) => settings.tvOSManualProvisioningProfileType = value),
|
||||
new SettingsMap<string>("tvOSManualProvisioningProfileID", (settings, value) => settings.tvOSManualProvisioningProfileID = value),
|
||||
};
|
||||
|
||||
private readonly Func<ITestSettings> m_TestSettingsFactory;
|
||||
public TestSettingsDeserializer(Func<ITestSettings> testSettingsFactory)
|
||||
{
|
||||
m_TestSettingsFactory = testSettingsFactory;
|
||||
}
|
||||
|
||||
public ITestSettings GetSettingsFromJsonFile(string jsonFilePath)
|
||||
{
|
||||
var text = File.ReadAllText(jsonFilePath);
|
||||
var settingsDictionary = Json.Deserialize(text) as Dictionary<string, object>;
|
||||
|
||||
var testSettings = m_TestSettingsFactory();
|
||||
if (settingsDictionary == null)
|
||||
{
|
||||
return testSettings;
|
||||
}
|
||||
|
||||
foreach (var settingsMap in s_SettingsMapping)
|
||||
{
|
||||
if (!settingsDictionary.ContainsKey(settingsMap.Key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (settingsMap.Type.IsEnum)
|
||||
{
|
||||
SetEnumValue(settingsMap.Key, settingsDictionary[settingsMap.Key], settingsMap.Type, value => settingsMap.ApplyToSettings(testSettings, value));
|
||||
}
|
||||
else
|
||||
{
|
||||
SetValue(settingsMap.Key, settingsDictionary[settingsMap.Key], settingsMap.Type, value => settingsMap.ApplyToSettings(testSettings, value));
|
||||
}
|
||||
}
|
||||
|
||||
return testSettings;
|
||||
}
|
||||
|
||||
private abstract class SettingsMap
|
||||
{
|
||||
public string Key { get; }
|
||||
public Type Type { get; }
|
||||
protected SettingsMap(string key, Type type)
|
||||
{
|
||||
Key = key;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public abstract void ApplyToSettings(ITestSettings settings, object value);
|
||||
}
|
||||
|
||||
private class SettingsMap<T> : SettingsMap
|
||||
{
|
||||
private Action<ITestSettings, T> m_Setter;
|
||||
public SettingsMap(string key, Action<ITestSettings, T> setter) : base(key, typeof(T))
|
||||
{
|
||||
m_Setter = setter;
|
||||
}
|
||||
|
||||
public override void ApplyToSettings(ITestSettings settings, object value)
|
||||
{
|
||||
m_Setter(settings, (T)value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetEnumValue(string key, object value, Type type, Action<object> setter)
|
||||
{
|
||||
object enumValue;
|
||||
if (TryGetEnum(value as string, type, out enumValue))
|
||||
{
|
||||
setter(enumValue);
|
||||
return;
|
||||
}
|
||||
|
||||
var acceptedValues = string.Join(", ", Enum.GetValues(type).OfType<object>().Select(val => val.ToString()).ToArray());
|
||||
|
||||
Debug.LogFormat("Could not convert '{0}' argument '{1}' to a valid {2}. Accepted values: {3}.", key, value, type.Name, acceptedValues);
|
||||
}
|
||||
|
||||
private static bool TryGetEnum(string value, Type type, out object enumValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
enumValue = Enum.Parse(type, value, true);
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
enumValue = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetValue(string key, object value, Type type, Action<object> setter)
|
||||
{
|
||||
if (type.IsInstanceOfType(value))
|
||||
{
|
||||
setter(value);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogFormat("Could not convert '{0}' argument '{1}' to a valid {2}.", key, value, type.Name);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75e7d7a9a57458841a85fe42d9c9141f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user