forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSamplesTest.cs
More file actions
145 lines (127 loc) · 4.63 KB
/
Copy pathSamplesTest.cs
File metadata and controls
145 lines (127 loc) · 4.63 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NUnit.Framework;
using Unity.Entities;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;
using Unity.Physics.Systems;
namespace Unity.Physics.Samples.Test
{
[DisableAutoCreation]
[AlwaysUpdateSystem]
[UpdateBefore(typeof(BuildPhysicsWorld))]
class EnsureSTSimulation : ComponentSystem
{
protected override void OnUpdate()
{
if (HasSingleton<PhysicsStep>())
{
var component = GetSingleton<PhysicsStep>();
if (component.ThreadCountHint != 0)
{
component.ThreadCountHint = 0;
SetSingleton(component);
}
}
else
{
// Invalidate the physics world
var buildPhysicsWorld = World.DefaultGameObjectInjectionWorld.GetOrCreateSystem<BuildPhysicsWorld>();
buildPhysicsWorld.PhysicsWorld.Reset(0, 0, 0);
}
}
}
[TestFixture]
abstract class UnityPhysicsSamplesTest
{
static World DefaultWorld => World.DefaultGameObjectInjectionWorld;
protected static IEnumerable GetScenes()
{
var sceneCount = SceneManager.sceneCountInBuildSettings;
var scenes = new List<string>();
for(int sceneIndex = 0; sceneIndex < sceneCount; ++sceneIndex)
{
var scenePath = SceneUtility.GetScenePathByBuildIndex(sceneIndex);
if (scenePath.Contains("InitTestScene"))
continue;
#if UNITY_ANDROID && !UNITY_64
// Terrain scene needs a lot of memory, skip it on Android armv7
if (scenePath.Contains("/Terrain.unity"))
continue;
#endif
scenes.Add(scenePath);
}
scenes.Sort();
return scenes;
}
[UnityTest]
[Timeout(60000)]
public abstract IEnumerator LoadScenes([ValueSource(nameof(GetScenes))] string scenePath);
[TearDown]
public void TearDown()
{
SwitchWorlds();
}
protected static void SwitchWorlds()
{
var entityManager = DefaultWorld.EntityManager;
var entities = entityManager.GetAllEntities();
entityManager.DestroyEntity(entities);
entities.Dispose();
if (DefaultWorld.IsCreated)
{
var systems = DefaultWorld.Systems;
foreach (var s in systems)
{
s.Enabled = false;
}
DefaultWorld.Dispose();
}
DefaultWorldInitialization.Initialize("Default World", false);
}
}
[TestFixture]
class UnityPhysicsSamplesTestMT : UnityPhysicsSamplesTest
{
[UnityTest]
[Timeout(60000)]
public override IEnumerator LoadScenes([ValueSource(nameof(GetScenes))] string scenePath)
{
// Log scene name in case Unity crashes and test results aren't written out.
Debug.Log("Loading " + scenePath);
LogAssert.Expect(LogType.Log, "Loading " + scenePath);
SceneManager.LoadScene(scenePath);
yield return new WaitForSeconds(1);
SwitchWorlds();
yield return new WaitForFixedUpdate();
LogAssert.NoUnexpectedReceived();
}
}
[TestFixture]
class UnityPhysicsSamplesTestST : UnityPhysicsSamplesTest
{
[UnityTest]
[Timeout(60000)]
public override IEnumerator LoadScenes([ValueSource(nameof(GetScenes))] string scenePath)
{
// Log scene name in case Unity crashes and test results aren't written out.
Debug.Log("Loading " + scenePath);
LogAssert.Expect(LogType.Log, "Loading " + scenePath);
var world = World.DefaultGameObjectInjectionWorld;
// Ensure ST simulation
var stSystem = world.GetExistingSystem<EnsureSTSimulation>();
{
Assert.IsNull(stSystem, "The 'EnsureSTSimulation' system should only be created by the 'SamplesTest.LoadScenes' function!");
stSystem = new EnsureSTSimulation();
world.AddSystem(stSystem);
world.GetExistingSystem<SimulationSystemGroup>().AddSystemToUpdateList(stSystem);
}
SceneManager.LoadScene(scenePath);
yield return new WaitForSeconds(1);
SwitchWorlds();
yield return new WaitForFixedUpdate();
LogAssert.NoUnexpectedReceived();
}
}
}