Skip to content

Commit

Permalink
Fix tests compilation without speech package (MixedRealityToolkit#593) (
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonymous committed Jul 16, 2024
1 parent b7ba49d commit 923f2b3
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public class SeeItSayItLabelEnablerTests : BaseRuntimeInputTests
[UnityTest]
public IEnumerator TestEnableAndSetLabel()
{
GameObject testButton = SetUpButton(true, Control.None);
Transform label = testButton.transform.GetChild(0);

#if MRTK_INPUT_PRESENT && MRTK_SPEECH_PRESENT
SpeechInteractor interactor = FindObjectUtility.FindAnyObjectByType<SpeechInteractor>(true);
interactor.gameObject.SetActive(true);

GameObject testButton = SetUpButton(true, Control.None);
yield return null;
if (Application.isBatchMode)
{
LogAssert.Expect(LogType.Exception, new Regex("Speech recognition is not supported on this machine"));
}

Transform label = testButton.transform.GetChild(0);

Transform sublabel = label.transform.GetChild(0);
Assert.IsTrue(label.gameObject.activeSelf, "Label is enabled");
Assert.IsTrue(!sublabel.gameObject.activeSelf, "Child objects are disabled");
Expand All @@ -56,19 +56,19 @@ public IEnumerator TestEnableAndSetLabel()
[UnityTest]
public IEnumerator TestAutoUpdateLabel()
{
GameObject testButton = SetUpButton(true, Control.None);
Transform label = testButton.transform.GetChild(0);

#if MRTK_INPUT_PRESENT && MRTK_SPEECH_PRESENT
SpeechInteractor interactor = FindObjectUtility.FindAnyObjectByType<SpeechInteractor>(true);
interactor.gameObject.SetActive(true);

GameObject testButton = SetUpButton(true, Control.None);
yield return null;
if (Application.isBatchMode)
{
LogAssert.Expect(LogType.Exception, new Regex("Speech recognition is not supported on this machine"));
}

Transform label = testButton.transform.GetChild(0);

Transform sublabel = label.transform.GetChild(0);
TMP_Text text = label.gameObject.GetComponentInChildren<TMP_Text>(true);
Assert.AreEqual(text.text, "Say 'test'", "Label text was set to voice command keyword.");
Expand Down Expand Up @@ -102,18 +102,19 @@ public IEnumerator TestVoiceCommandsUnavailable()
[UnityTest]
public IEnumerator TestPositionCanvasLabel()
{
GameObject testButton = SetUpButton(true, Control.Canvas);
Transform label = testButton.transform.GetChild(0);

#if MRTK_INPUT_PRESENT && MRTK_SPEECH_PRESENT
SpeechInteractor interactor = FindObjectUtility.FindAnyObjectByType<SpeechInteractor>(true);
interactor.gameObject.SetActive(true);

GameObject testButton = SetUpButton(true, Control.Canvas);
yield return null;
if (Application.isBatchMode)
{
LogAssert.Expect(LogType.Exception, new Regex("Speech recognition is not supported on this machine"));
}

Transform label = testButton.transform.GetChild(0);
RectTransform sublabel = label.transform.GetChild(0) as RectTransform;
Assert.AreEqual(sublabel.anchoredPosition3D, new Vector3(10, -30, -10), "Label is positioned correctly");
#else
Expand All @@ -128,18 +129,19 @@ public IEnumerator TestPositionCanvasLabel()
[UnityTest]
public IEnumerator TestPositionNonCanvasLabel()
{
GameObject testButton = SetUpButton(true, Control.NonCanvas);
Transform label = testButton.transform.GetChild(0);

#if MRTK_INPUT_PRESENT && MRTK_SPEECH_PRESENT
SpeechInteractor interactor = FindObjectUtility.FindAnyObjectByType<SpeechInteractor>(true);
interactor.gameObject.SetActive(true);

GameObject testButton = SetUpButton(true, Control.NonCanvas);
yield return null;
if (Application.isBatchMode)
{
LogAssert.Expect(LogType.Exception, new Regex("Speech recognition is not supported on this machine"));
}

Transform label = testButton.transform.GetChild(0);
Assert.AreEqual(label.transform.localPosition, new Vector3(10f, -.504f, -.004f), "Label is positioned correctly");
#else
Assert.IsTrue(!label.gameObject.activeSelf, "Did not enable label because voice commands unavailable.");
Expand Down

0 comments on commit 923f2b3

Please sign in to comment.