Skip to content

Commit

Permalink
Merge pull request #1083 from eluchsinger/master
Browse files Browse the repository at this point in the history
Added UnitTests for WorldAnchor.
  • Loading branch information
StephenHodgson authored Oct 6, 2017
2 parents 210c748 + 5b6da6d commit 67be98f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using UnityEngine;
using NUnit.Framework;

namespace HoloToolkit.Unity.Tests
{
public class WorldAnchorManagerTests
{
[SetUp]
public void ClearScene()
{
TestUtils.ClearScene();
}

[Test]
public void TestGenerateAnchorNameFromGameObject()
{
const string expected = "AnchorName";
var gameObject = new GameObject(expected);
var result = WorldAnchorManager.GenerateAnchorName(gameObject);
Assert.That(result, Is.EqualTo(expected));
}

[Test]
public void TestGenerateAnchorNameFromParameter()
{
const string expected = "AnchorName";
var gameObject = new GameObject();
var result = WorldAnchorManager.GenerateAnchorName(gameObject, expected);
Assert.That(result, Is.EqualTo(expected));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Assets/HoloToolkit/Utilities/Scripts/WorldAnchorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ private void Anchor_OnTrackingChanged(WorldAnchor anchor, bool located)

#endregion // Event Callbacks
#endif
/// <summary>
/// Generates the name for the anchor.
/// If no anchor name was specified, the name of the anchor will be the same as the GameObject's name.
/// </summary>
/// <param name="gameObjectToAnchor">The GameObject to attach the anchor to.</param>
/// <param name="proposedAnchorname">Name of the anchor. If none provided, the name of the GameObject will be used.</param>
/// <returns>The name of the newly attached anchor.</returns>
public static string GenerateAnchorName(GameObject gameObjectToAnchor, string proposedAnchorname = null)
{
return string.IsNullOrEmpty(proposedAnchorname) ? gameObjectToAnchor.name : proposedAnchorname;
}

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

anchorName = string.IsNullOrEmpty(anchorName) ? gameObjectToAnchor.name : anchorName;
anchorName = GenerateAnchorName(gameObjectToAnchor, anchorName);

LocalAnchorOperations.Enqueue(
new AnchorAttachmentInfo
Expand Down

0 comments on commit 67be98f

Please sign in to comment.