public void TestContent()
        {
            ResetState();

            // default value
            Assert.AreEqual(null, Content);

            // test parent setting
            var content = new ContentControlTest();
            Assert.DoesNotThrow(()=>Content = content);
            Assert.AreEqual(this, content.Parent);
            Assert.AreEqual(content, Content);

            // unset content
            Assert.DoesNotThrow(()=>Content = null);
            Assert.AreEqual(null, content.Parent);
            Assert.AreEqual(Content, null);
            
            // reset the content
            var contentControl = new ContentControlTest { Content = content };
            Assert.DoesNotThrow(()=>contentControl.Content = content);

            // content reused
            Assert.Throws<InvalidOperationException>(() => Content = content);
        }
Beispiel #2
0
        public void TestContent()
        {
            ResetState();

            // default value
            Assert.AreEqual(null, Content);

            // test parent setting
            var content = new ContentControlTest();

            Assert.DoesNotThrow(() => Content = content);
            Assert.AreEqual(this, content.Parent);
            Assert.AreEqual(content, Content);

            // unset content
            Assert.DoesNotThrow(() => Content = null);
            Assert.AreEqual(null, content.Parent);
            Assert.AreEqual(Content, null);

            // reset the content
            var contentControl = new ContentControlTest {
                Content = content
            };

            Assert.DoesNotThrow(() => contentControl.Content = content);

            // content reused
            Assert.Throws <InvalidOperationException>(() => Content = content);
        }
Beispiel #3
0
        public static void Main()
        {
            var uiElementTest = new UIElementLayeringTests();
            uiElementTest.TestAll();

            var panelTest = new PanelTests();
            panelTest.TestAll();

            var controlTest = new ControlTests();
            controlTest.TestAll();

            var stackPanelTest = new StackPanelTests();
            stackPanelTest.TestAll();

            var canvasTest = new CanvasTests();
            canvasTest.TestAll();

            var contentControlTest = new ContentControlTest();
            contentControlTest.TestAll();

            var eventManagerTest = new EventManagerTests();
            eventManagerTest.TestAll();

            var routedEventArgTest = new RoutedEventArgsTest();
            routedEventArgTest.TestAll();

            var uiElementEventTest = new UIElementEventTests();
            uiElementEventTest.TestAll();

            var gridTest = new GridTests();
            gridTest.TestAll();
        }
Beispiel #4
0
        public void TestCollapseOverride()
        {
            ResetState();

            // create a content
            var child = new ContentControlTest();

            Content = child;

            // set the size of the content
            child.Width  = 100 * rand.NextFloat();
            child.Height = 100 * rand.NextFloat();
            child.Depth  = 150 * rand.NextFloat();

            // arrange and check child render size
            Arrange(1000 * rand.NextVector3(), true);
            Assert.AreEqual(Vector3.Zero, child.RenderSize);
        }
Beispiel #5
0
        public void TestUpdateWorldMatrix()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // set the panel size to 1
            Arrange(Vector3.One, false);

            // test that the world matrix of the panel is correctly updated.
            var localMatrix = Matrix.Scaling(0.1f, 0.5f, 1f);
            var worldMatrix = Matrix.Scaling(1f, 0.8f, 0.4f);

            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(new Matrix(0.1f, 0, 0, 0, 0, 0.4f, 0, 0, 0, 0, 0.4f, 0, 0.5f, 0.4f, 0.2f, 1), WorldMatrix);

            // add a child and set its local matrix
            var child = new ContentControlTest {
                DepthAlignment = DepthAlignment.Stretch
            };
            var childArrangementMatrix = Matrix.Translation(10, 20, 30);
            var childLocalMatrix       = new Matrix(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

            child.LocalMatrix = childLocalMatrix;
            Content           = child;

            // set the child's panel arrangement matrix
            VisualContent.DependencyProperties.Set(ContentArrangeMatrixPropertyKey, childArrangementMatrix);

            // arrange the child (set its size to 1)
            child.Arrange(Vector3.One, false);

            // check that the value of the world matrix of the child is correctly updated too
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(new Matrix(0, -0.4f, 0, 0, 0.1f, 0, 0, 0, 0, 0, 0.4f, 0, 1.55f, 8.6f, 12.4f, 1), child.WorldMatrix);
        }
        public void TestCollapseOverride()
        {
            ResetState();

            // create a content
            var child = new ContentControlTest();
            Content = child;

            // set the size of the content
            child.Width = 100 * rand.NextFloat();
            child.Height = 100 * rand.NextFloat();
            child.Depth = 150 * rand.NextFloat();

            // arrange and check child render size
            Arrange(1000 * rand.NextVector3(), true);
            Assert.AreEqual(Vector3.Zero, child.RenderSize);
        }
        public void TestUpdateWorldMatrix()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // set the panel size to 1
            Arrange(Vector3.One, false);

            // test that the world matrix of the panel is correctly updated.
            var localMatrix = Matrix.Scaling(0.1f, 0.5f, 1f);
            var worldMatrix = Matrix.Scaling(1f, 0.8f, 0.4f);
            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(new Matrix(0.1f, 0, 0, 0, 0, 0.4f, 0, 0, 0, 0, 0.4f, 0, 0.5f, 0.4f, 0.2f, 1), WorldMatrix);

            // add a child and set its local matrix
            var child = new ContentControlTest { DepthAlignment = DepthAlignment.Stretch };
            var childArrangementMatrix = Matrix.Translation(10, 20, 30);
            var childLocalMatrix = new Matrix(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
            child.LocalMatrix = childLocalMatrix;
            Content = child;

            // set the child's panel arrangement matrix
            VisualContent.DependencyProperties.Set(ContentArrangeMatrixPropertyKey, childArrangementMatrix);

            // arrange the child (set its size to 1)
            child.Arrange(Vector3.One, false);

            // check that the value of the world matrix of the child is correctly updated too
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.AreEqual(new Matrix(0, -0.4f, 0, 0, 0.1f, 0, 0, 0, 0, 0, 0.4f, 0, 1.55f, 8.6f, 12.4f, 1), child.WorldMatrix);
        }
Beispiel #8
0
        public void TestPropagateEvent()
        {
            // create a hierarchy of UIElements
            //               (00)
            //                | 
            //               (10)
            //             /     \
            //          (20)      (21)
            //            |       /  \
            //          (30)    (31)  (32)
            var element00 = new ContentControlTest();
            var element10 = new StackPanel();
            var element20 = new ContentControlTest();
            var element21 = new StackPanel();
            var element30 = new UIElementLayeringTests();
            var element31 = new UIElementLayeringTests();
            var element32 = new UIElementLayeringTests();
            element00.Content = element10;
            element10.Children.Add(element20);
            element10.Children.Add(element21);
            element20.Content = element30;
            element21.Children.Add(element31);
            element21.Children.Add(element32);
            var elements = new List<UIElement> { element00, element10, element20, element21, element30, element31, element32 };

            // create routed events
            var tunnelingEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestTuneling", RoutingStrategy.Tunnel, typeof(UIElementLayeringTests));
            var bubblingEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestBubbling", RoutingStrategy.Bubble, typeof(UIElementLayeringTests));
            var directEvent = EventManager.RegisterRoutedEvent<RoutedEventArgs>("TestDirect", RoutingStrategy.Direct, typeof(UIElementLayeringTests));

            // test propagation direction, propagation bounds and sender values
            foreach (var uiElement in elements)
            {
                uiElement.AddHandler(tunnelingEvent, TestAddSenderToList);
                uiElement.AddHandler(bubblingEvent, TestAddSenderToList);
                uiElement.AddHandler(directEvent, TestAddSenderToList);
            }

            // tunneling test 1
            senderList.Clear();
            element20.RaiseEvent(new RoutedEventArgs(tunnelingEvent));
            Assert.AreEqual(3, senderList.Count);
            Assert.AreEqual(element00, senderList[0]);
            Assert.AreEqual(element10, senderList[1]);
            Assert.AreEqual(element20, senderList[2]);

            // tunneling test 2
            senderList.Clear();
            element31.RaiseEvent(new RoutedEventArgs(tunnelingEvent));
            Assert.AreEqual(4, senderList.Count);
            Assert.AreEqual(element00, senderList[0]);
            Assert.AreEqual(element10, senderList[1]);
            Assert.AreEqual(element21, senderList[2]);
            Assert.AreEqual(element31, senderList[3]);

            // direct test
            senderList.Clear();
            element10.RaiseEvent(new RoutedEventArgs(directEvent));
            Assert.AreEqual(1, senderList.Count);
            Assert.AreEqual(element10, senderList[0]);

            // tunneling test 1
            senderList.Clear();
            element30.RaiseEvent(new RoutedEventArgs(bubblingEvent));
            Assert.AreEqual(4, senderList.Count);
            Assert.AreEqual(element30, senderList[0]);
            Assert.AreEqual(element20, senderList[1]);
            Assert.AreEqual(element10, senderList[2]);
            Assert.AreEqual(element00, senderList[3]);

            // tunneling test 2
            senderList.Clear();
            element20.RaiseEvent(new RoutedEventArgs(bubblingEvent));
            Assert.AreEqual(3, senderList.Count);
            Assert.AreEqual(element20, senderList[0]);
            Assert.AreEqual(element10, senderList[1]);
            Assert.AreEqual(element00, senderList[2]);

            // test with another type of handler
            var eventMyTestHandler = EventManager.RegisterRoutedEvent<MyTestRoutedEventArgs>("TestMyTestHandler", RoutingStrategy.Direct, typeof(UIElementLayeringTests));
            AddHandler(eventMyTestHandler, TestMyTestHandler);
            RaiseEvent(new MyTestRoutedEventArgs(eventMyTestHandler));
            Assert.AreEqual(true, testMyTestHandlerCalled);

            // test Handled and EventHandledToo
            foreach (var uiElement in elements)
            {
                uiElement.RemoveHandler(bubblingEvent, TestAddSenderToList);
                uiElement.AddHandler(bubblingEvent, TestHandledHandler);
            }
            senderList.Clear();
            element00.AddHandler(bubblingEvent, TestEventHandledHandler, true);
            element32.RaiseEvent(new RoutedEventArgs(bubblingEvent));
            Assert.AreEqual(1, senderList.Count);
            Assert.AreEqual(element32, senderList[0]);
            Assert.AreEqual(true, testEventHandledTooCalled);

            // test class handlers basic working
            foreach (var uiElement in elements)
                uiElement.RemoveHandler(bubblingEvent, TestHandledHandler);
            EventManager.RegisterClassHandler(typeof(ContentControl), bubblingEvent, TestAddSenderToClassHandlerList);
            element30.RaiseEvent(new RoutedEventArgs(bubblingEvent));
            Assert.AreEqual(2, classHandlerSenderList.Count);
            Assert.AreEqual(element20, classHandlerSenderList[0]);
            Assert.AreEqual(element00, classHandlerSenderList[1]);

            // test that class handlers are called before instance handlers + test handledEventToo for class handlers
            senderList.Clear();
            classHandlerSenderList.Clear();
            EventManager.RegisterClassHandler(typeof(ContentControl), bubblingEvent, TestClassHandlerHandled);
            EventManager.RegisterClassHandler(typeof(StackPanel), bubblingEvent, TestClassHandlerEventHandled, true);
            foreach (var uiElement in elements)
                uiElement.AddHandler(bubblingEvent, TestAddSenderToList);
            element20.RaiseEvent(new RoutedEventArgs(bubblingEvent));
            Assert.AreEqual(1, classHandlerSenderList.Count);
            Assert.AreEqual(element20, classHandlerSenderList[0]);
            Assert.AreEqual(0, senderList.Count);
            Assert.AreEqual(true, testClassHandlerEventHandledTooCalled);
        }