docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class ScrollRectTests

    Inheritance
    object
    ScrollRectTests
    Implements
    IPrebuildSetup
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Global Namespace
    Assembly: UnityEngine.UI.Tests.dll
    Syntax
    public class ScrollRectTests : IPrebuildSetup

    Methods

    CalculateOffsetShouldClamp(bool, bool, int, float, float, float)

    Declaration
    [Test]
    [TestCase(new object[] { true, true, 2, 4, -2, -2 }, TestName = "Should clamp offset")]
    [TestCase(new object[] { false, true, 2, 4, 0, -2 }, TestName = "Vertical should clamp offset on one axis")]
    [TestCase(new object[] { true, false, 2, 4, -2, 0 }, TestName = "Horizontal should clamp offset on one axis")]
    [TestCase(new object[] { false, false, 2, 4, 0, 0 }, TestName = "No axis should not clamp offset")]
    [TestCase(new object[] { true, true, 8, 10, 2, 2 }, TestName = "Should clamp negative offset")]
    [TestCase(new object[] { false, true, 8, 10, 0, 2 }, TestName = "Vertical should clamp negative offset on one axis")]
    [TestCase(new object[] { true, false, 8, 10, 2, 0 }, TestName = "Horizontal should clamp negative offset on one axis")]
    [TestCase(new object[] { false, false, 8, 10, 0, 0 }, TestName = "No axis should not clamp negative offset")]
    public void CalculateOffsetShouldClamp(bool horizontal, bool vertical, int viewX, float viewY, float resX, float resY)
    Parameters
    Type Name Description
    bool horizontal
    bool vertical
    int viewX
    float viewY
    float resX
    float resY

    CalculateOffsetUnrestrictedShouldNotClamp(bool, bool, int, float, float, float)

    Declaration
    [Test]
    [TestCase(new object[] { true, true, 2, 4, -2, -2 }, TestName = "Should clamp offset")]
    [TestCase(new object[] { false, true, 2, 4, 0, -2 }, TestName = "Vertical should clamp offset on one axis")]
    [TestCase(new object[] { true, false, 2, 4, -2, 0 }, TestName = "Horizontal should clamp offset on one axis")]
    [TestCase(new object[] { false, false, 2, 4, 0, 0 }, TestName = "No axis should not clamp offset")]
    [TestCase(new object[] { true, true, 8, 10, 2, 2 }, TestName = "Should clamp negative offset")]
    [TestCase(new object[] { false, true, 8, 10, 0, 2 }, TestName = "Vertical should clamp negative offset on one axis")]
    [TestCase(new object[] { true, false, 8, 10, 2, 0 }, TestName = "Horizontal should clamp negative offset on one axis")]
    [TestCase(new object[] { false, false, 8, 10, 0, 0 }, TestName = "No axis should not clamp negative offset")]
    public void CalculateOffsetUnrestrictedShouldNotClamp(bool horizontal, bool vertical, int viewX, float viewY, float resX, float resY)
    Parameters
    Type Name Description
    bool horizontal
    bool vertical
    int viewX
    float viewY
    float resX
    float resY

    GetBoundsShouldEncapsulateAllCorners()

    Declaration
    [Test]
    public void GetBoundsShouldEncapsulateAllCorners()

    LateUpdateWithElasticNoOffsetShouldZeroVelocity()

    Declaration
    [UnityTest]
    public IEnumerator LateUpdateWithElasticNoOffsetShouldZeroVelocity()
    Returns
    Type Description
    IEnumerator

    LateUpdateWithElasticShouldDecelerate()

    Declaration
    [UnityTest]
    [Ignore("Fails")]
    public IEnumerator LateUpdateWithElasticShouldDecelerate()
    Returns
    Type Description
    IEnumerator

    LateUpdateWithInertiaShouldDecelerate()

    Declaration
    [UnityTest]
    public IEnumerator LateUpdateWithInertiaShouldDecelerate()
    Returns
    Type Description
    IEnumerator

    LateUpdateWithoutInertiaOrElasticShouldZeroVelocity()

    Declaration
    [UnityTest]
    public IEnumerator LateUpdateWithoutInertiaOrElasticShouldZeroVelocity()
    Returns
    Type Description
    IEnumerator

    LeftClickShouldStartDrag(InputButton, bool, bool)

    Declaration
    [Test]
    [TestCase(PointerEventData.InputButton.Left, true, true)]
    [TestCase(PointerEventData.InputButton.Left, false, false)]
    [TestCase(PointerEventData.InputButton.Right, true, false)]
    [TestCase(PointerEventData.InputButton.Middle, true, false)]
    public void LeftClickShouldStartDrag(PointerEventData.InputButton button, bool active, bool expectedIsDragging)
    Parameters
    Type Name Description
    PointerEventData.InputButton button
    bool active
    bool expectedIsDragging

    LeftClickUpShouldEndDrag(InputButton, bool, bool)

    Declaration
    [Test]
    [TestCase(PointerEventData.InputButton.Left, true, false)]
    [TestCase(PointerEventData.InputButton.Left, false, false)]
    [TestCase(PointerEventData.InputButton.Right, false, false)]
    [TestCase(PointerEventData.InputButton.Right, true, true)]
    [TestCase(PointerEventData.InputButton.Middle, true, true)]
    [TestCase(PointerEventData.InputButton.Middle, false, false)]
    public void LeftClickUpShouldEndDrag(PointerEventData.InputButton button, bool active, bool expectedIsDragging)
    Parameters
    Type Name Description
    PointerEventData.InputButton button
    bool active
    bool expectedIsDragging

    OnDisableShouldRemoveListeners(bool)

    Declaration
    [UnityTest]
    [Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-42513")]
    [TestCase(true, ExpectedResult = null)]
    [TestCase(false, ExpectedResult = null)]
    public IEnumerator OnDisableShouldRemoveListeners(bool isHorizontal)
    Parameters
    Type Name Description
    bool isHorizontal
    Returns
    Type Description
    IEnumerator

    OnEnableShouldAddListeners(bool)

    Declaration
    [UnityTest]
    [Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-42513")]
    [TestCase(true, ExpectedResult = null)]
    [TestCase(false, ExpectedResult = null)]
    public IEnumerator OnEnableShouldAddListeners(bool isHorizontal)
    Parameters
    Type Name Description
    bool isHorizontal
    Returns
    Type Description
    IEnumerator

    OnScrollClampedShouldClampContentAnchoredPosition(MovementType, float, float)

    Declaration
    [Test]
    [Ignore("Tests fail without mocking")]
    [TestCase(ScrollRect.MovementType.Clamped, 1, 1)]
    [TestCase(ScrollRect.MovementType.Unrestricted, 150, 150)]
    [TestCase(ScrollRect.MovementType.Elastic, 150, 150)]
    public void OnScrollClampedShouldClampContentAnchoredPosition(ScrollRect.MovementType movementType, float anchoredPosX, float anchoredPosY)
    Parameters
    Type Name Description
    ScrollRect.MovementType movementType
    float anchoredPosX
    float anchoredPosY

    OnScrollClampedShouldMoveContentAnchoredPosition(int, int, bool, bool, int, int)

    Declaration
    [Test]
    [TestCase(new object[] { 1, 1, true, true, 1, -1 }, TestName = "Horizontal and vertical scroll")]
    [TestCase(new object[] { 1, 1, false, true, 0, -1 }, TestName = "Vertical scroll")]
    [TestCase(new object[] { 1, 1, true, false, 1, 0 }, TestName = "Horizontal scroll")]
    public void OnScrollClampedShouldMoveContentAnchoredPosition(int scrollDeltaX, int scrollDeltaY, bool horizontal, bool vertical, int expectedPosX, int expectedPosY)
    Parameters
    Type Name Description
    int scrollDeltaX
    int scrollDeltaY
    bool horizontal
    bool vertical
    int expectedPosX
    int expectedPosY

    OneTimeTearDown()

    Declaration
    [OneTimeTearDown]
    public void OneTimeTearDown()

    PotentialDragNeedsLeftClick(InputButton, bool)

    Declaration
    [Test]
    [TestCase(PointerEventData.InputButton.Left, true)]
    [TestCase(PointerEventData.InputButton.Right, false)]
    [TestCase(PointerEventData.InputButton.Middle, false)]
    public void PotentialDragNeedsLeftClick(PointerEventData.InputButton button, bool expectedEqualsZero)
    Parameters
    Type Name Description
    PointerEventData.InputButton button
    bool expectedEqualsZero

    SetNormalizedPositionShouldSetContentLocalPosition()

    Declaration
    [Test]
    public void SetNormalizedPositionShouldSetContentLocalPosition()

    SettingScrollbarShouldRemoveThenAddListeners(bool)

    Declaration
    [Test]
    [Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-42513")]
    [TestCase(true)]
    [TestCase(false)]
    public void SettingScrollbarShouldRemoveThenAddListeners(bool testHorizontal)
    Parameters
    Type Name Description
    bool testHorizontal

    Setup()

    Implement this method to call actions automatically before the build process.

    Declaration
    public void Setup()
    Examples
      [TestFixture]
                            public class CreateSpriteTest : IPrebuildSetup
                            {
                                Texture2D m_Texture;
                                Sprite m_Sprite;
    
                                public void Setup()
                                {
                                    #if UNITY_EDITOR
                                    var spritePath = "Assets/Resources/Circle.png";
    
                                    var ti = UnityEditor.AssetImporter.GetAtPath(spritePath) as UnityEditor.TextureImporter;
    
                                    ti.textureCompression = UnityEditor.TextureImporterCompression.Uncompressed;
    
                                    ti.SaveAndReimport();
                                    #endif
                                }
    
                                [SetUp]
                                public void SetUpTest()
                                {
                                    m_Texture = Resources.Load<Texture2D>("Circle");
                                }
    
                                [Test]
                                public void WhenNullTextureIsPassed_CreateShouldReturnNullSprite()
                                {
                                    // Check with Valid Texture.
    
                                    LogAssert.Expect(LogType.Log, "Circle Sprite Created");
    
                                    Sprite.Create(m_Texture, new Rect(0, 0, m_Texture.width, m_Texture.height), new Vector2(0.5f, 0.5f));
    
                                    Debug.Log("Circle Sprite Created");
    
                                    // Check with NULL Texture. Should return NULL Sprite.
                                    m_Sprite = Sprite.Create(null, new Rect(0, 0, m_Texture.width, m_Texture.height), new Vector2(0.5f, 0.5f));
    
                                    Assert.That(m_Sprite, Is.Null, "Sprite created with null texture should be null");
                                }
                            }
    
     > **Tip**: Use `#if UNITY_EDITOR` if you want to access Editor only APIs, but the setup/cleanup is inside a **Play Mode** assembly.
    

    TearDown()

    Declaration
    [TearDown]
    public void TearDown()

    TestSetup()

    Declaration
    [SetUp]
    public void TestSetup()

    UpdateBoundsShouldPad()

    Declaration
    [Test]
    public void UpdateBoundsShouldPad()

    Implements

    UnityEngine.TestTools.IPrebuildSetup
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)