コード例 #1
0
ファイル: TestWeakKey.cs プロジェクト: zparr/ATF
        public void TestWeakKeyHashBehavior()
        {
            var controlA = new TestControlA();
            var controlB = new TestControlA();

            var weakA  = new WeakKey <Control>(controlA);
            var weakA2 = new WeakKey <Control>(controlA);

            Assert.IsTrue(weakA.Equals(weakA));
            Assert.IsTrue(weakA.GetHashCode() == weakA2.GetHashCode());
            Assert.IsTrue(weakA.Equals(weakA2));
            Assert.IsTrue(weakA != weakA2);
            Assert.IsTrue(!weakA.Equals(controlA));
            Assert.IsTrue(!controlA.Equals(weakA));

            var weakB = new WeakKey <Control>(controlB);

            Assert.IsTrue(!weakA.Equals(weakB));
            Assert.IsTrue(weakA.GetHashCode() != weakB.GetHashCode()); //Always true? Not sure, but I hope so!

            var set = new HashSet <WeakKey <Control> >();

            set.Add(weakA);
            Assert.IsTrue(set.Count == 1);
            set.Add(weakA2);
            Assert.IsTrue(set.Count == 1);
            set.Add(weakB);
            Assert.IsTrue(set.Count == 2);

            // Couldn't get this to work.
            //controlA = null;
            //controlB = null;
            //GC.Collect(); //defaults are all generation and 'forced' collection
            //foreach (SkinService.WeakKey<Control> key in set)
            //    Assert.IsTrue(!key.IsAlive);

            // Proves that WeakReference can't do the job!
            //var weakRefA = new WeakReference(controlA);
            //var weakRefA2 = new WeakReference(controlA);
            //var weakRefB = new WeakReference(controlB);

            //var set2 = new HashSet<WeakReference>();
            //set2.Add(weakRefA);
            //Assert.IsTrue(set2.Count == 1);
            //set2.Add(weakRefA2);
            //Assert.IsTrue(set2.Count == 1); //it's 2!
            //set2.Add(weakRefB);
            //Assert.IsTrue(set2.Count == 2); //it's 3!
        }
コード例 #2
0
ファイル: TestWeakKey.cs プロジェクト: Joxx0r/ATF
        public void TestWeakKeyHashBehavior()
        {
            var controlA = new TestControlA();
            var controlB = new TestControlA();

            var weakA = new WeakKey<Control>(controlA);
            var weakA2 = new WeakKey<Control>(controlA);

            Assert.IsTrue(weakA.Equals(weakA));
            Assert.IsTrue(weakA.GetHashCode() == weakA2.GetHashCode());
            Assert.IsTrue(weakA.Equals(weakA2));
            Assert.IsTrue(weakA != weakA2);
            Assert.IsTrue(!weakA.Equals(controlA));
            Assert.IsTrue(!controlA.Equals(weakA));

            var weakB = new WeakKey<Control>(controlB);
            Assert.IsTrue(!weakA.Equals(weakB));
            Assert.IsTrue(weakA.GetHashCode() != weakB.GetHashCode()); //Always true? Not sure, but I hope so!

            var set = new HashSet<WeakKey<Control>>();
            set.Add(weakA);
            Assert.IsTrue(set.Count == 1);
            set.Add(weakA2);
            Assert.IsTrue(set.Count == 1);
            set.Add(weakB);
            Assert.IsTrue(set.Count == 2);

            // Couldn't get this to work.
            //controlA = null;
            //controlB = null;
            //GC.Collect(); //defaults are all generation and 'forced' collection
            //foreach (SkinService.WeakKey<Control> key in set)
            //    Assert.IsTrue(!key.IsAlive);

            // Proves that WeakReference can't do the job!
            //var weakRefA = new WeakReference(controlA);
            //var weakRefA2 = new WeakReference(controlA);
            //var weakRefB = new WeakReference(controlB);

            //var set2 = new HashSet<WeakReference>();
            //set2.Add(weakRefA);
            //Assert.IsTrue(set2.Count == 1);
            //set2.Add(weakRefA2);
            //Assert.IsTrue(set2.Count == 1); //it's 2!
            //set2.Add(weakRefB);
            //Assert.IsTrue(set2.Count == 2); //it's 3!
        }
コード例 #3
0
ファイル: TestSkinService.cs プロジェクト: Joxx0r/ATF
        public void TestSkinApplying()
        {
            var skinService = new SkinService();

            var earlyControl = new TestControlA();
            Color originalBackColor = earlyControl.BackColor;
            SkinService.ApplyActiveSkin(earlyControl);

            skinService.OpenSkinFile(".\\Resources\\TestSkin.xml");

            // The new value should not be applied yet.
            Assert.IsTrue(earlyControl.BackColor == originalBackColor);

            skinService.ApplyActiveSkin();

            // The new color should be applied now. http://tracker.ship.scea.com/jira/browse/WWSATF-1028
            Assert.IsTrue((uint)earlyControl.BackColor.ToArgb() == 0xff00000a);

            var controlA = new TestControlA();
            SkinService.ApplyActiveSkin(controlA);
            Assert.IsTrue((uint)controlA.BackColor.ToArgb() == 0xff00000a);
            Assert.IsTrue(string.Equals(controlA.StringA, "TestSkinValueA"));

            var controlB = new TestControlB();
            SkinService.ApplyActiveSkin(controlB);
            Assert.IsTrue((uint)controlB.BackColor.ToArgb() == 0xff00000b);
            Assert.IsTrue(string.Equals(controlB.StringA, "TestSkinValueA"));
            Assert.IsTrue(string.Equals(controlB.StringB, "TestSkinValueB"));

            var controlC = new TestControlC();
            SkinService.ApplyActiveSkin(controlC);
            Assert.IsTrue((uint)controlC.BackColor.ToArgb() == 0xff00000c);
            Assert.IsTrue(string.Equals(controlC.StringA, "TestSkinValueA"));
            Assert.IsTrue(string.Equals(controlC.StringB, "TestSkinValueB"));
            Assert.IsTrue(string.Equals(controlC.StringC, "TestSkinValueC"));

            var controlX = new TestControlX();
            SkinService.ApplyActiveSkin(controlX);
            Assert.IsTrue(string.Equals(controlX.StringA, "TestSkinValueX"));

            var controlY = new TestControlY();
            SkinService.ApplyActiveSkin(controlY);
            Assert.IsTrue(string.Equals(controlY.StringA, "TestSkinValueY"));

            var controlZ = new TestControlZ();
            SkinService.ApplyActiveSkin(controlZ);
            Assert.IsTrue(string.Equals(controlZ.StringA, "TestSkinValueZ"));

            //DerivedUndefinedControl derives from TestControlC, so should receive C's style
            var undefinedControl = new DerivedUndefinedControl();
            SkinService.ApplyActiveSkin(undefinedControl);
            Assert.IsTrue((uint)undefinedControl.BackColor.ToArgb() == 0xff00000c);
            Assert.IsTrue(string.Equals(undefinedControl.StringA, "TestSkinValueA"));
            Assert.IsTrue(string.Equals(undefinedControl.StringB, "TestSkinValueB"));
            Assert.IsTrue(string.Equals(undefinedControl.StringC, "TestSkinValueC"));

            // Make sure that the skins are reset correctly.
            skinService.ResetSkin(); //sets the active skin to null
            Assert.IsTrue(controlA.BackColor == originalBackColor);
            Assert.IsTrue(controlA.StringA == null);

            Assert.IsTrue(controlB.BackColor == originalBackColor);
            Assert.IsTrue(controlB.StringA == null);
            Assert.IsTrue(controlB.StringB == null);

            Assert.IsTrue(controlC.BackColor == originalBackColor);
            Assert.IsTrue(controlC.StringA == null);
            Assert.IsTrue(controlC.StringB == null);
            Assert.IsTrue(controlC.StringC == null);

            Assert.IsTrue(undefinedControl.BackColor == originalBackColor);
            Assert.IsTrue(undefinedControl.StringA == null);
            Assert.IsTrue(undefinedControl.StringB == null);
            Assert.IsTrue(undefinedControl.StringC == null);

            // Apply the skin again, this time with new original values.
            // To-do: it's kind of odd that we have to reload the xml file. What if clients wanted to rapidly
            //  switch back and forth programmatically?
            controlA.StringA = "OriginalA";
            controlB.StringB = "OriginalB";
            controlC.StringC = "OriginalC";
            undefinedControl.StringC = "OriginalC";
            skinService.OpenSkinFile(".\\Resources\\TestSkin.xml");
            skinService.ApplyActiveSkin();
            SkinService.ApplyActiveSkin(controlA);
            SkinService.ApplyActiveSkin(controlB);
            SkinService.ApplyActiveSkin(controlC);
            SkinService.ApplyActiveSkin(undefinedControl);
            skinService.ResetSkin();
            Assert.IsTrue(controlA.StringA == "OriginalA");
            Assert.IsTrue(controlB.StringB == "OriginalB");
            Assert.IsTrue(controlC.StringC == "OriginalC");
            Assert.IsTrue(undefinedControl.StringC == "OriginalC");
        }
コード例 #4
0
ファイル: TestSkinService.cs プロジェクト: zparr/ATF
        public void TestSkinApplying()
        {
            var skinService = new SkinService();

            var   earlyControl      = new TestControlA();
            Color originalBackColor = earlyControl.BackColor;

            SkinService.ApplyActiveSkin(earlyControl);

            skinService.OpenSkinFile(".\\Resources\\TestSkin.xml");

            // The new value should not be applied yet.
            Assert.IsTrue(earlyControl.BackColor == originalBackColor);

            skinService.ApplyActiveSkin();

            // The new color should be applied now. http://tracker.ship.scea.com/jira/browse/WWSATF-1028
            Assert.IsTrue((uint)earlyControl.BackColor.ToArgb() == 0xff00000a);

            var controlA = new TestControlA();

            SkinService.ApplyActiveSkin(controlA);
            Assert.IsTrue((uint)controlA.BackColor.ToArgb() == 0xff00000a);
            Assert.IsTrue(string.Equals(controlA.StringA, "TestSkinValueA"));

            var controlB = new TestControlB();

            SkinService.ApplyActiveSkin(controlB);
            Assert.IsTrue((uint)controlB.BackColor.ToArgb() == 0xff00000b);
            Assert.IsTrue(string.Equals(controlB.StringA, "TestSkinValueA"));
            Assert.IsTrue(string.Equals(controlB.StringB, "TestSkinValueB"));

            var controlC = new TestControlC();

            SkinService.ApplyActiveSkin(controlC);
            Assert.IsTrue((uint)controlC.BackColor.ToArgb() == 0xff00000c);
            Assert.IsTrue(string.Equals(controlC.StringA, "TestSkinValueA"));
            Assert.IsTrue(string.Equals(controlC.StringB, "TestSkinValueB"));
            Assert.IsTrue(string.Equals(controlC.StringC, "TestSkinValueC"));

            var controlX = new TestControlX();

            SkinService.ApplyActiveSkin(controlX);
            Assert.IsTrue(string.Equals(controlX.StringA, "TestSkinValueX"));

            var controlY = new TestControlY();

            SkinService.ApplyActiveSkin(controlY);
            Assert.IsTrue(string.Equals(controlY.StringA, "TestSkinValueY"));

            var controlZ = new TestControlZ();

            SkinService.ApplyActiveSkin(controlZ);
            Assert.IsTrue(string.Equals(controlZ.StringA, "TestSkinValueZ"));

            //DerivedUndefinedControl derives from TestControlC, so should receive C's style
            var undefinedControl = new DerivedUndefinedControl();

            SkinService.ApplyActiveSkin(undefinedControl);
            Assert.IsTrue((uint)undefinedControl.BackColor.ToArgb() == 0xff00000c);
            Assert.IsTrue(string.Equals(undefinedControl.StringA, "TestSkinValueA"));
            Assert.IsTrue(string.Equals(undefinedControl.StringB, "TestSkinValueB"));
            Assert.IsTrue(string.Equals(undefinedControl.StringC, "TestSkinValueC"));

            // Make sure that the skins are reset correctly.
            skinService.ResetSkin(); //sets the active skin to null
            Assert.IsTrue(controlA.BackColor == originalBackColor);
            Assert.IsTrue(controlA.StringA == null);

            Assert.IsTrue(controlB.BackColor == originalBackColor);
            Assert.IsTrue(controlB.StringA == null);
            Assert.IsTrue(controlB.StringB == null);

            Assert.IsTrue(controlC.BackColor == originalBackColor);
            Assert.IsTrue(controlC.StringA == null);
            Assert.IsTrue(controlC.StringB == null);
            Assert.IsTrue(controlC.StringC == null);

            Assert.IsTrue(undefinedControl.BackColor == originalBackColor);
            Assert.IsTrue(undefinedControl.StringA == null);
            Assert.IsTrue(undefinedControl.StringB == null);
            Assert.IsTrue(undefinedControl.StringC == null);

            // Apply the skin again, this time with new original values.
            // To-do: it's kind of odd that we have to reload the xml file. What if clients wanted to rapidly
            //  switch back and forth programmatically?
            controlA.StringA         = "OriginalA";
            controlB.StringB         = "OriginalB";
            controlC.StringC         = "OriginalC";
            undefinedControl.StringC = "OriginalC";
            skinService.OpenSkinFile(".\\Resources\\TestSkin.xml");
            skinService.ApplyActiveSkin();
            SkinService.ApplyActiveSkin(controlA);
            SkinService.ApplyActiveSkin(controlB);
            SkinService.ApplyActiveSkin(controlC);
            SkinService.ApplyActiveSkin(undefinedControl);
            skinService.ResetSkin();
            Assert.IsTrue(controlA.StringA == "OriginalA");
            Assert.IsTrue(controlB.StringB == "OriginalB");
            Assert.IsTrue(controlC.StringC == "OriginalC");
            Assert.IsTrue(undefinedControl.StringC == "OriginalC");
        }