TestSettings.cs
6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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);
}
}
}
}