예제 #1
0
파일: TextBlockTest.cs 프로젝트: ynkbt/moon
        public void LayoutCanvasInTreeWrapTest()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text     = tb.Text = "The truth is Hidden";
            sub.Child       = sub_tb;
            tb.TextWrapping = sub_tb.TextWrapping = TextWrapping.Wrap;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            // Notice that we don't wrap even though the slot is slightly
            // smaller than our actual

            CreateAsyncTest(parent, () => {
                Assert.IsTrue(tb.UseLayoutRounding, "use layout rounding");
                Assert.IsTrue(sub_tb.UseLayoutRounding, "use layout rounding");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are notequal");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Width, sub_tb.ActualWidth, 1, "RenderWidth");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Height, sub_tb.ActualHeight, 1, "RenderHeight");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has no clip");
                Rect slot = LayoutInformation.GetLayoutSlot(sub_tb);
                Assert.IsTrue(Math.Ceiling(sub_tb.ActualWidth) == slot.Width, "slot is rounded up to actual");
            });
        }
예제 #2
0
        public void GetCharacterRect_inTree()
        {
            CreateAsyncTest(rtb,
                            () => {
                Rect r = rtb.ContentStart.GetCharacterRect((LogicalDirection)Int32.MinValue);
                Assert.AreEqual(new Rect(4, 4, 0, 16), r, "#0");

                r = rtb.ContentStart.GetCharacterRect(LogicalDirection.Forward);
                Assert.AreEqual(new Rect(4, 4, 0, 16), r, "#1");
            },
                            () => {
                rtb.Selection.Text = "hi";
                Rect r             = rtb.ContentStart.GetCharacterRect(LogicalDirection.Forward);
                Assert.IsTrue(r.IsEmpty, "#2");
            },
                            () => {
                Rect r = rtb.ContentStart.GetCharacterRect(LogicalDirection.Forward);
                Assert.AreEqual(new Rect(4, 4, 0, 16), r, "#3");

                r = rtb.ContentStart.GetPositionAtOffset(1, LogicalDirection.Forward).GetCharacterRect(LogicalDirection.Forward);
                Assert.AreEqual(new Rect(4, 4, 0, 16), r, "#4");

                r = rtb.ContentStart.GetPositionAtOffset(2, LogicalDirection.Forward).GetCharacterRect(LogicalDirection.Forward);
                Assert.AreEqual(new Rect(4, 4, 0, 16), r, "#5");

                r = rtb.ContentStart.GetPositionAtOffset(3, LogicalDirection.Forward).GetCharacterRect(LogicalDirection.Forward);
                Assert.AreEqualWithDelta(10.960000038147, r.X, 0.001, "#6.x");
                Assert.AreEqualWithDelta(4, r.Y, 0.001, "#6.y");
                Assert.AreEqualWithDelta(0, r.Width, 0.001, "#6.width");
                Assert.AreEqualWithDelta(16, r.Height, 0.001, "#6.height");
            });
        }
예제 #3
0
파일: TextBlockTest.cs 프로젝트: ynkbt/moon
        public void LayoutCanvasInTreeTest()
        {
            var parent = new Canvas();
            var sub    = new Border();
            var tb     = new TextBlock();
            var sub_tb = new TextBlock();

            sub_tb.Text = tb.Text = "The truth is Hidden";
            sub.Child   = sub_tb;

            parent.Children.Add(tb);
            parent.Children.Add(sub);

            CreateAsyncTest(parent, () => {
                Assert.AreEqual(new Size(sub_tb.ActualWidth, sub_tb.ActualHeight), new Size(tb.ActualWidth, tb.ActualHeight), "actual are equal");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Width, sub_tb.ActualWidth, 1, "RenderWidth");
                Assert.AreEqualWithDelta(sub_tb.RenderSize.Height, sub_tb.ActualHeight, 1, "RenderHeight");
                Assert.AreNotEqual(sub_tb.RenderSize, tb.RenderSize, "rendersizes are notequal");
                Assert.AreEqual(new Size(0, 0), tb.RenderSize, "tb 0,0 rendersize");
                Assert.IsNull(LayoutInformation.GetLayoutClip(tb), "tb null clip");
                Assert.IsNull(LayoutInformation.GetLayoutClip(sub_tb), "sub_tb has no clip");
                Rect slot = LayoutInformation.GetLayoutSlot(sub_tb);
                Assert.IsTrue(Math.Ceiling(sub_tb.ActualWidth) == slot.Width, "slot is rounded up to actual");
            });
        }
예제 #4
0
        public void TestDetached()
        {
            int media_opened_counter             = 0;
            int media_ended_counter              = 0;
            int media_failed_counter             = 0;
            int media_buffering_progress_counter = 0;
            int media_download_progress_counter  = 0;
            int media_state_changed_counter      = 0;

            MediaElement mel = new MediaElement();

            TestPanel.Children.Add(mel);

            mel.BufferingProgressChanged += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                Debug.WriteLine("BufferingProgressChanged");
                media_buffering_progress_counter++;
            });
            mel.CurrentStateChanged += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                Debug.WriteLine("CurrentStateChanged");
                media_state_changed_counter++;
            });
            mel.DownloadProgressChanged += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                Debug.WriteLine("DownloadProgressChanged");
                media_download_progress_counter++;
            });
            mel.MediaEnded += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                Debug.WriteLine("MediaEnded");
                media_ended_counter++;
            });
            mel.MediaFailed += new EventHandler <ExceptionRoutedEventArgs> (delegate(object sender, ExceptionRoutedEventArgs e)
            {
                Debug.WriteLine("MediaFailed");
                media_failed_counter++;
            });
            mel.MediaOpened += new RoutedEventHandler(delegate(object sender, RoutedEventArgs e)
            {
                Debug.WriteLine("MediaOpened");
                media_opened_counter++;
            });
            mel.Source = new Uri("/moon-unit;component/timecode-long-with-audio.wmv", UriKind.Relative);

            // set all properties to non-defaults, to check which ones are reset
            mel.AutoPlay      = false;
            mel.Balance       = 0.7;
            mel.BufferingTime = TimeSpan.FromSeconds(3.0);
            mel.IsMuted       = true;
            mel.Volume        = 0.33;

            // wait until media has been opened
            EnqueueConditional(() => media_opened_counter >= 1);

            // check initial values
            Enqueue(delegate()
            {
                Assert.AreEqual(0.0, mel.Position.TotalMilliseconds, "Initial - Position");
            });

            // play
            Enqueue(delegate()
            {
                mel.Play();
            });

            // wait until the media element is playing and has played 1 second
            EnqueueConditional(() => mel.Position.TotalMilliseconds > 1.0);

            // assert attached values
            Enqueue(delegate()
            {
                Assert.AreEqual(1, media_opened_counter, "Attached - MediaOpenedEvent");
                Assert.AreEqual(0, media_ended_counter, "Attached - MediaEndedEvent");
                Assert.AreEqual(0, media_failed_counter, "Attached - MediaFailedEvent");
                Assert.IsGreater(0, media_buffering_progress_counter, "Attached - BufferingProgressChangedEvent");
                Assert.IsGreater(0, media_download_progress_counter, "Attached - DownloadProgressChangedEvent");
                Assert.IsGreater(0, media_state_changed_counter, "Attached - CurrentStateChangedEvent");
                Assert.AreEqual(false, mel.AutoPlay, "Attached - AutoPlay");
                Assert.AreEqualWithDelta(0.7, mel.Balance, 0.0001, "Attached - Balance");
                Assert.AreEqual(1.0, mel.BufferingProgress, "Attached - BufferingProgress");
                Assert.AreEqual(3.0, mel.BufferingTime.TotalSeconds, "Attached - BufferingTime");
                Assert.AreEqual(true, mel.CanPause, "Attached - CanPause");
                Assert.AreEqual(true, mel.CanSeek, "Attached - CanSeek");
                Assert.AreEqual(MediaElementState.Playing, mel.CurrentState, "Attached - CurrentState");
                Assert.AreEqual(true, mel.IsMuted, "Attached - IsMuted");
                Assert.AreEqual(30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Attached - NaturalDuration");
                Assert.IsGreater(1.0, mel.Position.TotalMilliseconds, "Attached - Position");
                Assert.AreEqualWithDelta(0.33, mel.Volume, 0.0001, "Attached - Volume");
            });

            // detach
            Enqueue(delegate()
            {
                media_opened_counter             = 0;
                media_ended_counter              = 0;
                media_failed_counter             = 0;
                media_buffering_progress_counter = 0;
                media_download_progress_counter  = 0;
                media_state_changed_counter      = 0;

                TestPanel.Children.Clear();

                // check what changed immediately
                Assert.AreEqual(0, media_opened_counter, "Detached (immediately) - MediaOpenedEvent");
                Assert.AreEqual(0, media_ended_counter, "Detached (immediately) - MediaEndedEvent");
                Assert.AreEqual(0, media_failed_counter, "Detached (immediately) - MediaFailedEvent");
                Assert.AreEqual(0, media_buffering_progress_counter, "Detached (immediately) - BufferingProgressChangedEvent");
                Assert.AreEqual(0, media_download_progress_counter, "Detached (immediately) - DownloadProgressChangedEvent");
                Assert.AreEqual(0, media_state_changed_counter, "Detached (immediately) - CurrentStateChangedEvent");
                Assert.AreEqual(false, mel.AutoPlay, "Detached (immediately) - AutoPlay");
                Assert.AreEqualWithDelta(0.7, mel.Balance, 0.0001, "Detached (immediately) - Balance");
                Assert.AreEqual(0.0, mel.BufferingProgress, "Detached (immediately) - BufferingProgress");
                Assert.AreEqual(3.0, mel.BufferingTime.TotalSeconds, "Detached (immediately) - BufferingTime");
                Assert.AreEqual(false, mel.CanPause, "Detached (immediately) - CanPause");
                Assert.AreEqual(false, mel.CanSeek, "Detached (immediately) - CanSeek");
                Assert.AreEqual(MediaElementState.Playing, mel.CurrentState, "Detached (immediately) - CurrentState");
                Assert.AreEqual(true, mel.IsMuted, "Detached (immediately) - IsMuted");
                Assert.AreEqual(0.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Detached (immediately) - NaturalDuration");
                Assert.AreEqual(0.0, mel.Position.TotalMilliseconds, "Detached (immediately) - Position");
                Assert.AreEqualWithDelta(0.33, mel.Volume, 0.0001, "Detached (immediately) - Volume");
            });

            // wait a bit
            EnqueueSleep(100);

            // check detached values
            Enqueue(delegate()
            {
                Assert.AreEqual(0, media_opened_counter, "Detached - MediaOpenedEvent");
                Assert.AreEqual(0, media_ended_counter, "Detached - MediaEndedEvent");
                Assert.AreEqual(0, media_failed_counter, "Detached - MediaFailedEvent");
                Assert.AreEqual(0, media_buffering_progress_counter, "Detached - BufferingProgressChangedEvent");
                Assert.AreEqual(0, media_download_progress_counter, "Detached - DownloadProgressChangedEvent");
                Assert.AreEqual(0, media_state_changed_counter, "Detached - CurrentStateChangedEvent");
                Assert.AreEqual(false, mel.AutoPlay, "Detached - AutoPlay");
                Assert.AreEqualWithDelta(0.7, mel.Balance, 0.0001, "Detached - Balance");
                Assert.AreEqual(0.0, mel.BufferingProgress, "Detached - BufferingProgress");
                Assert.AreEqual(3.0, mel.BufferingTime.TotalSeconds, "Detached - BufferingTime");
                Assert.AreEqual(false, mel.CanPause, "Detached - CanPause");
                Assert.AreEqual(false, mel.CanSeek, "Detached - CanSeek");
                Assert.AreEqual(MediaElementState.Playing, mel.CurrentState, "Detached - CurrentState");
                Assert.AreEqual(true, mel.IsMuted, "Detached - IsMuted");
                Assert.AreEqual(0.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Detached - NaturalDuration");
                Assert.AreEqual(0.0, mel.Position.TotalMilliseconds, "Detached - Position");
                Assert.AreEqualWithDelta(0.33, mel.Volume, 0.0001, "Detached - Volume");
            });

            // reattach

            Enqueue(delegate()
            {
                TestPanel.Children.Add(mel);
                // check which properties changed immediately
                Assert.AreEqual(0, media_opened_counter, "Reattached (immediately) - MediaOpenedEvent");
                Assert.AreEqual(0, media_ended_counter, "Reattached (immediately) - MediaEndedEvent");
                Assert.AreEqual(0, media_failed_counter, "Reattached (immediately) - MediaFailedEvent");
                Assert.AreEqual(0, media_buffering_progress_counter, "Reattached (immediately) - BufferingProgressChangedEvent");
                Assert.AreEqual(0, media_download_progress_counter, "Reattached (immediately) - DownloadProgressChangedEvent");
                Assert.AreEqual(0, media_state_changed_counter, "Reattached (immediately) - CurrentStateChangedEvent");
                Assert.AreEqual(false, mel.AutoPlay, "Reattached (immediately) - AutoPlay");
                Assert.AreEqualWithDelta(0.7, mel.Balance, 0.001, "Reattached (immediately) - Balance");
                Assert.AreEqual(1.0, mel.BufferingProgress, "Reattached (immediately) - BufferingProgress");
                Assert.AreEqual(3.0, mel.BufferingTime.TotalSeconds, "Reattached (immediately) - BufferingTime");
                Assert.AreEqual(true, mel.CanPause, "Reattached (immediately) - CanPause");
                Assert.AreEqual(true, mel.CanSeek, "Reattached (immediately) - CanSeek");
                Assert.IsTrue(mel.CurrentState == MediaElementState.Opening || mel.CurrentState == MediaElementState.Playing, "Reattached (immediately) - CurrentState");
                Assert.AreEqual(true, mel.IsMuted, "Reattached (immediately) - IsMuted");
                Assert.AreEqual(0.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Reattached (immediately) - NaturalDuration");
                Assert.AreEqual(0.0, mel.Position.TotalMilliseconds, "Reattached (immediately) - Position");
                Assert.AreEqualWithDelta(0.33, mel.Volume, 0.0001, "Reattached (immediately) - Volume");
            });

            // wait a bit
            EnqueueSleep(200);
            EnqueueConditional(() => media_opened_counter >= 1);

            Enqueue(delegate() {
                Assert.AreEqual(1, media_opened_counter, "Reattached A - MediaOpenedEvent");
                Assert.AreEqual(0, media_ended_counter, "Reattached A - MediaEndedEvent");
                Assert.AreEqual(0, media_failed_counter, "Reattached A - MediaFailedEvent");
                Assert.IsGreater(0, media_buffering_progress_counter, "Reattached A - BufferingProgressChangedEvent");
                Assert.IsGreater(0, media_download_progress_counter, "Reattached A - DownloadProgressChangedEvent");
                Assert.IsGreater(0, media_state_changed_counter, "Reattached A - CurrentStateChangedEvent");
                Assert.AreEqual(false, mel.AutoPlay, "Reattached A - AutoPlay");
                Assert.AreEqualWithDelta(0.7, mel.Balance, 0.001, "Reattached A - Balance");
                Assert.AreEqual(1.0, mel.BufferingProgress, "Reattached A - BufferingProgress");
                Assert.AreEqual(3.0, mel.BufferingTime.TotalSeconds, "Reattached A - BufferingTime");
                Assert.AreEqual(true, mel.CanPause, "Reattached A - CanPause");
                Assert.AreEqual(true, mel.CanSeek, "Reattached A - CanSeek");
                Assert.AreEqual(MediaElementState.Paused, mel.CurrentState, "Reattached A - CurrentState");
                Assert.AreEqual(true, mel.IsMuted, "Reattached A - IsMuted");
                Assert.AreEqual(30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Reattached A - NaturalDuration");
                Assert.AreEqual(0.0, mel.Position.TotalMilliseconds, "Reattached A - Position");
                Assert.AreEqualWithDelta(0.33, mel.Volume, 0.001, "Reattached A - Volume");
            });


            Enqueue(delegate()
            {
                mel.Play();
            });

            // wait until 0.1s have been played. This is to check that when we start playing again
            // we start at the beginning, not the position when the ME was detached.
            EnqueueConditional(() => mel.Position.TotalMilliseconds > 100);

            Enqueue(delegate()
            {
                Assert.AreEqual(1, media_opened_counter, "Reattached B - MediaOpenedEvent");
                Assert.AreEqual(0, media_ended_counter, "Reattached B - MediaEndedEvent");
                Assert.AreEqual(0, media_failed_counter, "Reattached B - MediaFailedEvent");
                Assert.IsGreater(0, media_buffering_progress_counter, "Reattached B - BufferingProgressChangedEvent");
                Assert.IsGreater(0, media_download_progress_counter, "Reattached B - DownloadProgressChangedEvent");
                Assert.IsGreater(0, media_state_changed_counter, "Reattached B - CurrentStateChangedEvent");
                Assert.AreEqual(false, mel.AutoPlay, "Reattached B - AutoPlay");
                Assert.AreEqualWithDelta(0.7, mel.Balance, 0.001, "Reattached B - Balance");
                Assert.AreEqual(1.0, mel.BufferingProgress, "Reattached B - BufferingProgress");
                Assert.AreEqual(3.0, mel.BufferingTime.TotalSeconds, "Reattached B - BufferingTime");
                Assert.AreEqual(true, mel.CanPause, "Reattached B - CanPause");
                Assert.AreEqual(true, mel.CanSeek, "Reattached B - CanSeek");
                Assert.AreEqual(MediaElementState.Playing, mel.CurrentState, "Reattached B - CurrentState");
                Assert.AreEqual(true, mel.IsMuted, "Reattached B - IsMuted");
                Assert.AreEqual(30033.0, mel.NaturalDuration.TimeSpan.TotalMilliseconds, "Reattached B - NaturalDuration");
                Assert.IsBetween(0.100, 0.9, mel.Position.TotalSeconds, "Reattached B - Position");
                Assert.AreEqualWithDelta(0.33, mel.Volume, 0.001, "Reattached B - Volume");
            });

            // detach with AutoPlay = true
            Enqueue(delegate()
            {
                mel.AutoPlay = true;
                TestPanel.Children.Clear();
            });

            // reattach
            Enqueue(delegate()
            {
                TestPanel.Children.Add(mel);
            });

            // wait until we've started playing again
            EnqueueConditional(() => mel.Position.TotalMilliseconds > 0);

            EnqueueTestComplete();
        }