2
// TestPositionWindow.cs
5
// Christopher James Halse Rogers <raof@ubuntu.com>
7
// Copyright © 2012 Christopher James Halse Rogers <raof@ubuntu.com>
9
// This library is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as
11
// published by the Free Software Foundation; either version 2.1 of the
12
// License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful, but
15
// WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
using NUnit.Framework;
26
namespace Do.Interface.Linux
29
public class TestPositionWindow
34
Gtk.Application.Init ();
38
public void TestSingleHeadPositionCalc ()
40
var positioner = new PositionWindow (null, null);
41
var calculatePosition = positioner.GetType ().GetMethod ("CalculateBasePosition",
42
System.Reflection.BindingFlags.NonPublic |
43
System.Reflection.BindingFlags.Instance);
44
// Single-head displays have an origin of (0,0)
45
Gdk.Rectangle screen = new Gdk.Rectangle (0, 0, 1024, 768);
46
// We only care about width and height here
47
Gdk.Rectangle window = new Gdk.Rectangle (0, 0, 200, 100);
49
object[] parameters = new object[] {screen, window, new Gdk.Rectangle ()};
50
Gdk.Rectangle result = (Gdk.Rectangle)calculatePosition.Invoke (positioner, parameters);
52
Assert.AreEqual (412, result.X);
53
Assert.AreEqual (267, result.Y);
57
public void TestHorizMultiHeadPositionCalc ()
59
var positioner = new PositionWindow (null, null);
60
var calculatePosition = positioner.GetType ().GetMethod ("CalculateBasePosition",
61
System.Reflection.BindingFlags.NonPublic |
62
System.Reflection.BindingFlags.Instance);
63
// Single-head displays have an origin of (0,0)
64
Gdk.Rectangle screen_one = new Gdk.Rectangle (0, 0, 1024, 768);
65
Gdk.Rectangle screen_two = new Gdk.Rectangle (screen_one.Width, 0, 1024, 768);
66
// We only care about width and height here
67
Gdk.Rectangle window = new Gdk.Rectangle (0, 0, 200, 100);
69
object[] parameters = new object[] {screen_one, window, new Gdk.Rectangle ()};
70
Gdk.Rectangle screen_one_result = (Gdk.Rectangle)calculatePosition.Invoke (positioner, parameters);
71
parameters = new object[] {screen_two, window, new Gdk.Rectangle ()};
72
Gdk.Rectangle screen_two_result = (Gdk.Rectangle)calculatePosition.Invoke (positioner, parameters);
74
Assert.AreEqual (screen_one_result.X + screen_one.Width, screen_two_result.X);
75
Assert.AreEqual (screen_one_result.Y, screen_two_result.Y);
79
public void TestVertMultiHeadPositionCalc ()
81
var positioner = new PositionWindow (null, null);
82
var calculatePosition = positioner.GetType ().GetMethod ("CalculateBasePosition",
83
System.Reflection.BindingFlags.NonPublic |
84
System.Reflection.BindingFlags.Instance);
85
// Single-head displays have an origin of (0,0)
86
Gdk.Rectangle screen_one = new Gdk.Rectangle (0, 0, 1024, 768);
87
Gdk.Rectangle screen_two = new Gdk.Rectangle (0, screen_one.Height, 1024, 768);
88
// We only care about width and height here
89
Gdk.Rectangle window = new Gdk.Rectangle (0, 0, 200, 100);
91
object[] parameters = new object[] {screen_one, window, new Gdk.Rectangle ()};
92
Gdk.Rectangle screen_one_result = (Gdk.Rectangle)calculatePosition.Invoke (positioner, parameters);
93
parameters = new object[] {screen_two, window, new Gdk.Rectangle ()};
94
Gdk.Rectangle screen_two_result = (Gdk.Rectangle)calculatePosition.Invoke (positioner, parameters);
96
Assert.AreEqual (screen_one_result.X, screen_two_result.X);
97
Assert.AreEqual (screen_one_result.Y + screen_one.Height, screen_two_result.Y);
102
public void TestResultsWindowIsBelowMainWindow ()
104
Gtk.Window main = new Gtk.Window ("Test Main Window");
105
Gtk.Window results = new Gtk.Window ("Test Results Window");
107
main.Resize (200, 100);
108
results.Resize (200, 100);
110
Gdk.Rectangle resultsOffset = new Gdk.Rectangle (0, 10, 0, 0);
112
var positioner = new PositionWindow (main, results);
113
positioner.UpdatePosition (10, Pane.First, resultsOffset);
115
// Drain the event loop
116
while (Gtk.Global.EventsPending) {
117
Gtk.Main.Iteration ();
121
int results_x, results_y;
122
main.GetPosition (out main_x, out main_y);
123
results.GetPosition (out results_x, out results_y);
124
Assert.Greater (results_y, main_y + 100);