Skip to content

Commit 1771015

Browse files
author
David Kline
authored
Merge pull request #2984 from StephenHodgson/vNEXT-UnitTests
Updated MixedRealityToolkit Unit Tests
2 parents 5f397e5 + 95e12ce commit 1771015

File tree

2 files changed

+34
-89
lines changed

2 files changed

+34
-89
lines changed

Assets/MixedRealityToolkit-Tests/MixedRealityToolkitTests.cs

Lines changed: 20 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void Test03_CreateMixedRealityOrchestrator()
5151

5252
// Create Test Configuration
5353
Assert.AreEqual(0, MixedRealityToolkit.Instance.ActiveProfile.ActiveServices.Count);
54-
Assert.AreEqual(3, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
54+
Assert.AreEqual(0, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
5555
}
5656

5757
[Test]
@@ -66,7 +66,7 @@ public void Test04_CreateMixedRealityInputSystem()
6666
Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile);
6767
Assert.IsNotEmpty(MixedRealityToolkit.Instance.ActiveProfile.ActiveServices);
6868
Assert.AreEqual(1, MixedRealityToolkit.Instance.ActiveProfile.ActiveServices.Count);
69-
Assert.AreEqual(3, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
69+
Assert.AreEqual(0, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
7070
}
7171

7272
[Test]
@@ -117,16 +117,14 @@ public void Test08_CreateMixedRealityComponent()
117117
{
118118
InitializeMixedRealityToolkitScene();
119119

120-
var component = new TestComponent1();
121-
122120
// Add Input System
123121
MixedRealityToolkit.Instance.RegisterService(typeof(IMixedRealityInputSystem), new MixedRealityInputManager());
124122

125123
// Add test component
126-
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent1), component);
124+
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent1), new TestComponent1());
127125

128126
// Tests
129-
Assert.AreEqual(4, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
127+
Assert.AreEqual(1, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
130128
}
131129

132130
[Test]
@@ -157,14 +155,15 @@ public void Test10_TestMixedRealityComponents()
157155

158156
// Add test component
159157
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent1), new TestComponent1());
160-
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent1), new TestComponent1());
161-
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent1), new TestComponent1());
158+
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent2), new TestComponent2());
159+
MixedRealityToolkit.Instance.RegisterService(typeof(IFailComponent), new TestFailComponent());
160+
LogAssert.Expect(LogType.Error, $"Unable to register {typeof(IFailComponent)}. Concrete type does not implement the IMixedRealityExtensionService implementation.");
162161

163-
// Retrieve Component1
164-
var components = MixedRealityToolkit.Instance.GetActiveServices(typeof(ITestComponent1));
162+
// Retrieve all registered IMixedRealityExtensionServices
163+
var components = MixedRealityToolkit.Instance.GetActiveServices(typeof(IMixedRealityExtensionService));
165164

166165
// Tests
167-
Assert.AreEqual(3, components.Count);
166+
Assert.AreEqual(2, components.Count);
168167
}
169168

170169
[Test]
@@ -178,16 +177,9 @@ public void Test11_TestMixedRealityComponent2DoesNotReturn()
178177
// Add test component
179178
MixedRealityToolkit.Instance.RegisterService(typeof(ITestComponent1), new TestComponent1());
180179

181-
try
182-
{
183-
// Validate non-existent component
184-
MixedRealityToolkit.Instance.GetService(typeof(ITestComponent2), "Test2");
185-
Assert.Fail();
186-
}
187-
catch (Exception)
188-
{
189-
// ignored
190-
}
180+
// Validate non-existent component
181+
MixedRealityToolkit.Instance.GetService(typeof(ITestComponent2), "Test2");
182+
LogAssert.Expect(LogType.Error, "Unable to find Test2 Manager.");
191183
}
192184

193185
[Test]
@@ -226,7 +218,7 @@ public void Test13_CreateMixedRealityComponentNameWithInput()
226218
Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile);
227219
Assert.IsNotEmpty(MixedRealityToolkit.Instance.ActiveProfile.ActiveServices);
228220
Assert.AreEqual(1, MixedRealityToolkit.Instance.ActiveProfile.ActiveServices.Count);
229-
Assert.AreEqual(5, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
221+
Assert.AreEqual(2, MixedRealityToolkit.Instance.MixedRealityComponents.Count);
230222
}
231223

232224
[Test]
@@ -300,7 +292,7 @@ public void Test16_GetAllMixedRealityComponents()
300292
var allComponents = MixedRealityToolkit.Instance.MixedRealityComponents;
301293

302294
// Tests
303-
Assert.AreEqual(7, allComponents.Count);
295+
Assert.AreEqual(4, allComponents.Count);
304296
}
305297

306298
[Test]
@@ -334,9 +326,9 @@ private static void InitializeMixedRealityToolkitScene()
334326

335327
#region Test Components
336328

337-
public interface ITestComponent1 : IMixedRealityService { }
329+
public interface ITestComponent1 : IMixedRealityExtensionService { }
338330

339-
public interface ITestComponent2 : IMixedRealityService { }
331+
public interface ITestComponent2 : IMixedRealityExtensionService { }
340332

341333
internal class TestComponent1 : BaseService, ITestComponent1
342334
{
@@ -350,30 +342,6 @@ public override void Initialize()
350342
{
351343
InputSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityInputSystem>();
352344
}
353-
354-
/// <summary>
355-
/// Optional Update function to perform per-frame updates of the service
356-
/// </summary>
357-
public override void Update()
358-
{
359-
// TODO Update stuff
360-
}
361-
362-
/// <summary>
363-
/// Optional ProfileUpdate function to allow reconfiguration when the active configuration profile of the Mixed Reality Toolkit is replaced
364-
/// </summary>
365-
public override void Reset()
366-
{
367-
// TODO React to profile change
368-
}
369-
370-
/// <summary>
371-
/// Optional Destroy function to perform cleanup of the service before the Mixed Reality Toolkit is destroyed
372-
/// </summary>
373-
public override void Destroy()
374-
{
375-
// TODO Destroy stuff
376-
}
377345
}
378346

379347
internal class TestComponent2 : BaseService, ITestComponent2
@@ -388,31 +356,11 @@ public override void Initialize()
388356
{
389357
InputSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityInputSystem>();
390358
}
359+
}
391360

392-
/// <summary>
393-
/// Optional Update function to perform per-frame updates of the service
394-
/// </summary>
395-
public override void Update()
396-
{
397-
// TODO Update stuff
398-
}
399-
400-
/// <summary>
401-
/// Optional ProfileUpdate function to allow reconfiguration when the active configuration profile of the Mixed Reality Toolkit is replaced
402-
/// </summary>
403-
public override void Reset()
404-
{
405-
// TODO React to profile change
406-
}
361+
internal interface IFailComponent : IMixedRealityService { }
407362

408-
/// <summary>
409-
/// Optional Destroy function to perform cleanup of the service before the Mixed Reality Toolkit is destroyed
410-
/// </summary>
411-
public override void Destroy()
412-
{
413-
// TODO Destroy stuff
414-
}
415-
}
363+
internal class TestFailComponent : BaseService, IFailComponent { }
416364

417365
#endregion Test Components
418366
}

Assets/MixedRealityToolkit/_Core/Services/MixedRealityToolkit.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void Initialize()
227227
{
228228
if (configuration.ComponentType.Type != null)
229229
{
230-
if(!RegisterService(typeof(IMixedRealityExtensionService), Activator.CreateInstance(configuration.ComponentType, configuration.ComponentName, configuration.Priority) as IMixedRealityExtensionService))
230+
if (!RegisterService(typeof(IMixedRealityExtensionService), Activator.CreateInstance(configuration.ComponentType, configuration.ComponentName, configuration.Priority) as IMixedRealityExtensionService))
231231
{
232232
Debug.LogError($"Failed to register the {configuration.ComponentType.Type} Extension Service!");
233233
}
@@ -501,6 +501,7 @@ public bool RegisterService(Type type, IMixedRealityService service)
501501
Debug.LogWarning("Unable to add a manager of type null.");
502502
return false;
503503
}
504+
504505
if (service == null)
505506
{
506507
Debug.LogWarning("Unable to add a manager with a null instance.");
@@ -518,25 +519,21 @@ public bool RegisterService(Type type, IMixedRealityService service)
518519
ActiveProfile.ActiveServices.Add(type, service);
519520
return true;
520521
}
521-
else
522-
{
523-
Debug.LogError($"There's already a {type.Name} registered.");
524-
return false;
525-
}
522+
523+
Debug.LogError($"There's already a {type.Name} registered.");
524+
return false;
526525
}
527-
else
528-
{
529-
if (!typeof(IMixedRealityExtensionService).IsAssignableFrom(type))
530-
{
531-
Debug.LogError($"Unable to register {service}. Concrete type does not implement the IMixedRealityExtensionService implementation.");
532-
return false;
533-
}
534526

535-
MixedRealityComponents.Add(new Tuple<Type, IMixedRealityExtensionService>(type, (IMixedRealityExtensionService)service));
536-
if (!isInitializing) { service.Initialize(); }
537-
mixedRealityComponentsCount = MixedRealityComponents.Count;
538-
return true;
527+
if (!typeof(IMixedRealityExtensionService).IsAssignableFrom(type))
528+
{
529+
Debug.LogError($"Unable to register {type}. Concrete type does not implement the IMixedRealityExtensionService implementation.");
530+
return false;
539531
}
532+
533+
MixedRealityComponents.Add(new Tuple<Type, IMixedRealityExtensionService>(type, (IMixedRealityExtensionService)service));
534+
if (!isInitializing) { service.Initialize(); }
535+
mixedRealityComponentsCount = MixedRealityComponents.Count;
536+
return true;
540537
}
541538

542539
/// <summary>

0 commit comments

Comments
 (0)