~ubuntu-branches/ubuntu/trusty/gnome-do/trusty

« back to all changes in this revision

Viewing changes to Do.Interface.Linux/src/Do.Interface/Tests/TestPositionWindow.cs

  • Committer: Package Import Robot
  • Author(s): Christopher James Halse Rogers
  • Date: 2012-03-26 11:12:21 UTC
  • mfrom: (0.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120326111221-1jk143fy37zxi3e4
Tags: 0.9-1
* New upstream version no longer uses deprecated internal glib headers.
  (Closes: #665537)
* [59fa37b9] Fix watch file
* [63486516] Imported Upstream version 0.9
* [8c636d84] Disable testsuite for now; requires running dbus and gconf daemons
* [e46de4b9] Remove inaccurate README.Source
* [4591d677] Add git-buildpackage configuration to default to pristine-tar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
//  TestPositionWindow.cs
 
3
//  
 
4
//  Author:
 
5
//       Christopher James Halse Rogers <raof@ubuntu.com>
 
6
// 
 
7
//  Copyright © 2012 Christopher James Halse Rogers <raof@ubuntu.com>
 
8
// 
 
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.
 
13
// 
 
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.
 
18
// 
 
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
 
22
 
 
23
using System;
 
24
using NUnit.Framework;
 
25
 
 
26
namespace Do.Interface.Linux
 
27
{
 
28
        [TestFixture()]
 
29
        public class TestPositionWindow
 
30
        {
 
31
                [SetUp]
 
32
                public void Setup()
 
33
                {
 
34
                        Gtk.Application.Init ();
 
35
                }
 
36
                
 
37
                [Test()]
 
38
                public void TestSingleHeadPositionCalc ()
 
39
                {
 
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);
 
48
 
 
49
                        object[] parameters = new object[] {screen, window, new Gdk.Rectangle ()};
 
50
                        Gdk.Rectangle result = (Gdk.Rectangle)calculatePosition.Invoke (positioner, parameters);
 
51
 
 
52
                        Assert.AreEqual (412, result.X);
 
53
                        Assert.AreEqual (267, result.Y);
 
54
                }
 
55
 
 
56
                [Test]
 
57
                public void TestHorizMultiHeadPositionCalc ()
 
58
                {
 
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);
 
68
 
 
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);
 
73
 
 
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);
 
76
                }
 
77
 
 
78
                [Test]
 
79
                public void TestVertMultiHeadPositionCalc ()
 
80
                {
 
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);
 
90
 
 
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);
 
95
 
 
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);
 
98
                }
 
99
                
 
100
                [Test]
 
101
                [Timeout (500)]
 
102
                public void TestResultsWindowIsBelowMainWindow ()
 
103
                {
 
104
                        Gtk.Window main = new Gtk.Window ("Test Main Window");
 
105
                        Gtk.Window results = new Gtk.Window ("Test Results Window");
 
106
                        
 
107
                        main.Resize (200, 100);
 
108
                        results.Resize (200, 100);
 
109
                        
 
110
                        Gdk.Rectangle resultsOffset = new Gdk.Rectangle (0, 10, 0, 0);
 
111
                        
 
112
                        var positioner = new PositionWindow (main, results);
 
113
                        positioner.UpdatePosition (10, Pane.First, resultsOffset);
 
114
                        
 
115
                        // Drain the event loop
 
116
                        while (Gtk.Global.EventsPending) {
 
117
                                Gtk.Main.Iteration ();  
 
118
                        }
 
119
                        
 
120
                        int main_x, main_y;
 
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);
 
125
                }
 
126
        }
 
127
}
 
128