Ejemplo n.º 1
0
        public void AssignPasses()
        {
            var info  = new LayoutInfo();
            var other = new LayoutInfo();

            other.LayoutSize = Vector3.one * 100f;
            other.SetMinMaxSize(Vector3.one * 10f, Vector3.one * 200f);
            other.IgnoreLayoutGroup = true;
            other.SizeGrowInGroup   = 2f;
            other.OrderInGroup      = 10;

            info.Assign(other);

            AssertionUtils.AreNearlyEqual(other.LayoutSize, info.LayoutSize);
            AssertionUtils.AreNearlyEqual(other.MinSize, info.MinSize);
            AssertionUtils.AreNearlyEqual(other.MaxSize, info.MaxSize);
            Assert.AreEqual(other.IgnoreLayoutGroup, info.IgnoreLayoutGroup);
            AssertionUtils.AreNearlyEqual(other.SizeGrowInGroup, info.SizeGrowInGroup);
            Assert.AreEqual(other.OrderInGroup, info.OrderInGroup);
        }
Ejemplo n.º 2
0
        public void OnChangedValue_InAssignPasses()
        {
            var info  = new LayoutInfo();
            var other = new LayoutInfo();

            info.MaxSize = other.MaxSize = Vector3.one * 100f; // Callbackの呼び出しのみをテストするので、MinSizeより下回らないようにしています。

            var callCounter = 0;

            (LayoutInfo self, LayoutInfo.ValueKind kinds, LayoutInfo.OnChangedValueParam prevInfo)recievedValues = default;
            info.OnChangedValue.Add((_self, _kinds, _prev) => {
                callCounter++;
                recievedValues = (_self, _kinds, _prev);
            });
            //例外が発生しても他のコールバックは実行されるようにしてください。
            info.OnChangedValue.Add((_, __, ___) => throw new System.Exception());

            var flagCombination = IndexCombinationEnumerable.GetFlagEnumCombination(
                System.Enum.GetValues(typeof(LayoutInfo.ValueKind)).OfType <LayoutInfo.ValueKind>()
                );

            foreach (var kinds in flagCombination)
            {
                var prev         = new LayoutInfo(info);
                var errorMessage = $"Fail test... kinds={kinds}";
                if (0 != (kinds & LayoutInfo.ValueKind.LayoutSize))
                {
                    other.LayoutSize = other.LayoutSize + Vector3.one;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.MinSize))
                {
                    other.MinSize = other.MinSize + Vector3.one;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.MaxSize))
                {
                    other.MaxSize = other.MaxSize + Vector3.one;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.IgnoreLayoutGroup))
                {
                    other.IgnoreLayoutGroup = !other.IgnoreLayoutGroup;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.SizeGrowInGroup))
                {
                    other.SizeGrowInGroup = other.SizeGrowInGroup + 1f;
                }
                if (0 != (kinds & LayoutInfo.ValueKind.OrderInGroup))
                {
                    other.OrderInGroup = other.OrderInGroup + 1;
                }

                callCounter    = 0;
                recievedValues = default;

                info.Assign(other); //test point

                Assert.AreSame(info, recievedValues.self, errorMessage);
                Assert.AreEqual(kinds, recievedValues.kinds, errorMessage);

                Assert.AreNotSame(info, recievedValues.prevInfo);
                Assert.AreEqual(prev.LayoutSize, recievedValues.prevInfo.LayoutSize);
                Assert.AreEqual(prev.MinSize, recievedValues.prevInfo.MinSize);
                Assert.AreEqual(prev.MaxSize, recievedValues.prevInfo.MaxSize);
                Assert.AreEqual(prev.IgnoreLayoutGroup, recievedValues.prevInfo.IgnoreLayoutGroup);
                Assert.AreEqual(prev.SizeGrowInGroup, recievedValues.prevInfo.SizeGrowInGroup);
                Assert.AreEqual(prev.OrderInGroup, recievedValues.prevInfo.OrderInGroup);
            }
        }