#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2010 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
#if UNITTEST
using System;
using NUnit.Framework;
using Nuclex.Input;
using Nuclex.Support;
using Nuclex.UserInterface.Input;
namespace Nuclex.UserInterface.Controls.Desktop {
/// Unit Test for the draggable control base class
[TestFixture]
internal class DraggableControlTest {
#region class DummyDraggableControl
/// Dummy implementation of a draggable control
private class DummyDraggableControl : DraggableControl {
/// Initializes a new draggable control
public DummyDraggableControl() : base() { }
/// Initializes a new draggable control
/// Whether the control can obtain the input focus
public DummyDraggableControl(bool canGetFocus) : base(canGetFocus) { }
/// Whether the control can be dragged by the mouse
public new bool EnableDragging {
get { return base.EnableDragging; }
set { base.EnableDragging = value; }
}
}
#endregion // class DummyDraggableControl
///
/// Tests whether the default constructor of the draggable control is working
///
[Test]
public void TestDefaultConstructor() {
DummyDraggableControl dummy = new DummyDraggableControl();
Assert.IsFalse(dummy.AffectsOrdering);
}
///
/// Tests whether the full constructor of the draggable control is working
///
[Test]
public void TestFullConstructor() {
DummyDraggableControl dummy = new DummyDraggableControl(true);
Assert.IsTrue(dummy.AffectsOrdering);
}
/// Tests whether the control can be dragged using the mouse
[Test]
public void TestDragging() {
DummyDraggableControl dummy = new DummyDraggableControl();
dummy.Bounds = new UniRectangle(10, 10, 100, 100);
dummy.ProcessMouseMove(100, 100, 50, 50);
dummy.ProcessMousePress(MouseButtons.Left);
dummy.ProcessMouseMove(100, 100, 60, 50);
Assert.AreEqual(20, dummy.Bounds.Location.X.Offset);
dummy.ProcessMouseMove(100, 100, 40, 40);
Assert.AreEqual(0, dummy.Bounds.Location.X.Offset);
Assert.AreEqual(0, dummy.Bounds.Location.Y.Offset);
dummy.ProcessMouseRelease(MouseButtons.Left);
dummy.ProcessMouseMove(100, 100, 70, 70);
Assert.AreEqual(0, dummy.Bounds.Location.X.Offset);
Assert.AreEqual(0, dummy.Bounds.Location.Y.Offset);
}
///
/// Tests whether the dragging capability can be disabled for a window
///
[Test]
public void DisableDragging() {
DummyDraggableControl dummy = new DummyDraggableControl();
dummy.Bounds = new UniRectangle(10, 10, 100, 100);
// By default, dragging should be enabled
Assert.IsTrue(dummy.EnableDragging);
// Turn it off
dummy.EnableDragging = false;
// Now it should be off ;-)
Assert.IsFalse(dummy.EnableDragging);
// Try to drag the window
dummy.ProcessMouseMove(100, 100, 50, 50);
dummy.ProcessMousePress(MouseButtons.Left);
dummy.ProcessMouseMove(100, 100, 60, 50);
// Make sure the window has not moved
Assert.AreEqual(10, dummy.Bounds.Location.X.Offset);
}
}
} // namespace Nuclex.UserInterface.Controls.Desktop
#endif // UNITTEST