Skip to content

Commit 67be98f

Browse files
Merge pull request #1083 from eluchsinger/master
Added UnitTests for WorldAnchor.
2 parents 210c748 + 5b6da6d commit 67be98f

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using UnityEngine;
2+
using NUnit.Framework;
3+
4+
namespace HoloToolkit.Unity.Tests
5+
{
6+
public class WorldAnchorManagerTests
7+
{
8+
[SetUp]
9+
public void ClearScene()
10+
{
11+
TestUtils.ClearScene();
12+
}
13+
14+
[Test]
15+
public void TestGenerateAnchorNameFromGameObject()
16+
{
17+
const string expected = "AnchorName";
18+
var gameObject = new GameObject(expected);
19+
var result = WorldAnchorManager.GenerateAnchorName(gameObject);
20+
Assert.That(result, Is.EqualTo(expected));
21+
}
22+
23+
[Test]
24+
public void TestGenerateAnchorNameFromParameter()
25+
{
26+
const string expected = "AnchorName";
27+
var gameObject = new GameObject();
28+
var result = WorldAnchorManager.GenerateAnchorName(gameObject, expected);
29+
Assert.That(result, Is.EqualTo(expected));
30+
}
31+
}
32+
}

Assets/HoloToolkit-UnitTests/Editor/Utilities/WorldAnchorManagerTests.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ private void Anchor_OnTrackingChanged(WorldAnchor anchor, bool located)
170170

171171
#endregion // Event Callbacks
172172
#endif
173+
/// <summary>
174+
/// Generates the name for the anchor.
175+
/// If no anchor name was specified, the name of the anchor will be the same as the GameObject's name.
176+
/// </summary>
177+
/// <param name="gameObjectToAnchor">The GameObject to attach the anchor to.</param>
178+
/// <param name="proposedAnchorname">Name of the anchor. If none provided, the name of the GameObject will be used.</param>
179+
/// <returns>The name of the newly attached anchor.</returns>
180+
public static string GenerateAnchorName(GameObject gameObjectToAnchor, string proposedAnchorname = null)
181+
{
182+
return string.IsNullOrEmpty(proposedAnchorname) ? gameObjectToAnchor.name : proposedAnchorname;
183+
}
173184

174185
/// <summary>
175186
/// Attaches an anchor to the GameObject.
@@ -198,7 +209,7 @@ public string AttachAnchor(GameObject gameObjectToAnchor, string anchorName = nu
198209
Debug.LogWarning("[WorldAnchorManager] AttachAnchor called before anchor store is ready.");
199210
}
200211

201-
anchorName = string.IsNullOrEmpty(anchorName) ? gameObjectToAnchor.name : anchorName;
212+
anchorName = GenerateAnchorName(gameObjectToAnchor, anchorName);
202213

203214
LocalAnchorOperations.Enqueue(
204215
new AnchorAttachmentInfo

0 commit comments

Comments
 (0)