StandaloneSubsystemTests.cs
3.44 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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
using Unity.Subsystem.Registration;
using UnityEngine;
using UnityEngine.TestTools;
#if !UNITY_2019_2_OR_NEWER
using UnityEngine.Experimental;
#endif
namespace Unity.Subsystem.Registration
{
[TestFixture]
public class StandaloneSubsystemTestFixture
{
public class TestSubsystemDescriptor : SubsystemDescriptor<TestSubsystem>
{
public bool holdsThings { get; set; }
}
public abstract class TestSubsystem : Subsystem<TestSubsystemDescriptor>
{
public bool StartCalled { get; set; }
public bool StopCalled { get; set; }
public bool DestroyCalled { get; set; }
public bool IsRunning { get; set; }
public abstract int GetNumThings();
}
public class ConcreteTestSubsystem : TestSubsystem
{
#if UNITY_2019_3_OR_NEWER
protected override void OnDestroy() { DestroyCalled = true; }
#else
public override void Destroy() { DestroyCalled = true; }
#endif
public override void Start() { StartCalled = true; IsRunning = true; }
public override void Stop() { StopCalled = true; IsRunning = false; }
#if UNITY_2019_2_OR_NEWER
public override bool running { get { return IsRunning; } }
#else
public bool running { get { return IsRunning; } }
#endif
public override int GetNumThings()
{
return 66;
}
}
[Test, Order(2)]
public void UseSubsystemTest()
{
List<TestSubsystemDescriptor> descriptors = new List<TestSubsystemDescriptor>();
SubsystemManager.GetSubsystemDescriptors<TestSubsystemDescriptor>(descriptors);
Assert.That(1 == descriptors.Count, "TestSubsystemDescriptor not registered.");
Assert.That("RuntimeTestSubsystem" == descriptors[0].id, "Subsystem ID doesn't match registered ID.");
TestSubsystem subsystem = descriptors[0].Create();
Assert.That(null != subsystem, "Create() failed in test subsystem descriptor.");
// Method call works
Assert.That(66 == subsystem.GetNumThings(), "Test method on TestSubsystem failed.");
}
[Test, Order(1)]
public void RegisterSubsystemTest()
{
TestSubsystemDescriptor descriptor = new TestSubsystemDescriptor();
List<TestSubsystemDescriptor> descriptors = new List<TestSubsystemDescriptor>();
SubsystemManager.GetSubsystemDescriptors<TestSubsystemDescriptor>(descriptors);
Assert.That(0 == descriptors.Count, "TestSubsystemDescriptor already registered.");
// Populate the descriptor object
descriptor.holdsThings = true;
descriptor.id = "RuntimeTestSubsystem";
descriptor.subsystemImplementationType = typeof(ConcreteTestSubsystem);
// Register the descriptor
Assert.That(true == SubsystemRegistration.CreateDescriptor(descriptor), "Descriptor not added.");
Assert.That(false == SubsystemRegistration.CreateDescriptor(descriptor), "Descriptor added twice.");
SubsystemManager.GetSubsystemDescriptors<TestSubsystemDescriptor>(descriptors);
Assert.That(1 == descriptors.Count, "TestSubsystemDescriptor not registered.");
}
}
}