~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to src/GuiException/tests/Controls/TestCodeBox.cs

  • Committer: charliepoole
  • Date: 2008-12-11 03:54:36 UTC
  • Revision ID: vcs-imports@canonical.com-20081211035436-thnyyjdctgmlxvot
Exception Browser - Initial Checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ----------------------------------------------------------------
 
2
// ExceptionBrowser
 
3
// Version 1.0.0
 
4
// Copyright 2008, Irénée HOTTIER,
 
5
// 
 
6
// This is free software licensed under the NUnit license, You may
 
7
// obtain a copy of the license at http://nunit.org/?p=license&r=2.4
 
8
// ----------------------------------------------------------------
 
9
 
 
10
using System;
 
11
using System.Collections.Generic;
 
12
using System.Text;
 
13
using NUnit.Framework;
 
14
using NUnit.UiException;
 
15
using System.Drawing;
 
16
using NUnit.UiException.Controls;
 
17
 
 
18
namespace NUnit.UiException.Tests.Controls
 
19
{
 
20
    [TestFixture]
 
21
    public class TestCodeBox
 
22
    {
 
23
        private InternalCodeBox _empty;
 
24
        private InternalCodeBox _filled;
 
25
 
 
26
        private int _repaintNotification;
 
27
        private int _textChangedNotification;
 
28
 
 
29
        [SetUp]
 
30
        public void SetUp()
 
31
        {
 
32
            _empty = new InternalCodeBox();
 
33
 
 
34
            _filled = new InternalCodeBox();
 
35
            _filled.Text = "111\r\n" +
 
36
                           "222\r\n" +
 
37
                           "333\r\n";
 
38
            _filled.HighlightedLine = 1;
 
39
 
 
40
            _filled.Repainted += new RepaintEventArgs(_filled_Repainted);
 
41
            _filled.TextChanged += new EventHandler(_filled_TextChanged);
 
42
 
 
43
            _repaintNotification = 0;            
 
44
 
 
45
            return;
 
46
        }
 
47
 
 
48
        void _filled_TextChanged(object sender, EventArgs e)
 
49
        {
 
50
            _textChangedNotification++;
 
51
        }
 
52
 
 
53
        void _filled_Repainted(object sender, EventArgs e)
 
54
        {
 
55
            _repaintNotification++;
 
56
        }
 
57
 
 
58
        [Test]
 
59
        public void Test_Default()
 
60
        {
 
61
            Assert.That(_empty.Text, Is.EqualTo(""));
 
62
            Assert.That(_empty.HighlightedLine, Is.EqualTo(0));
 
63
            Assert.That(_empty.Viewport, Is.Not.Null);
 
64
            Assert.That(_empty.FirstLine, Is.EqualTo(""));
 
65
            Assert.That(_empty.CurrentLineNumber, Is.EqualTo(1));
 
66
            Assert.That(_empty.MouseWheelDistance, Is.EqualTo(CodeBox.DEFAULT_MOUSEWHEEL_DISTANCE));
 
67
 
 
68
            Assert.That(_empty.Viewport.CharHeight, Is.GreaterThan(1));
 
69
            Assert.That(_empty.Viewport.CharWidth, Is.GreaterThan(1));
 
70
            Assert.That(_empty.Viewport.Width, Is.GreaterThan(1));
 
71
            Assert.That(_empty.Viewport.Height, Is.GreaterThan(1));
 
72
 
 
73
            return;
 
74
        }
 
75
 
 
76
        [Test]
 
77
        public void Test_Filled()
 
78
        {
 
79
            Assert.That(_filled.Text, Is.EqualTo("111\r\n222\r\n333\r\n"));
 
80
            Assert.That(_filled.HighlightedLine, Is.EqualTo(1));
 
81
            Assert.That(_filled.FirstLine, Is.EqualTo("111"));
 
82
            Assert.That(_filled.CurrentLineNumber, Is.EqualTo(1));
 
83
 
 
84
            return;
 
85
        }
 
86
 
 
87
        [Test]
 
88
        public void Test_Setting_MouseWheelDistance()
 
89
        {
 
90
            _filled.MouseWheelDistance = 4;
 
91
            Assert.That(_filled.MouseWheelDistance, Is.EqualTo(4));
 
92
 
 
93
            _filled.MouseWheelDistance = 6;
 
94
            Assert.That(_filled.MouseWheelDistance, Is.EqualTo(6));
 
95
 
 
96
            return;
 
97
        }
 
98
 
 
99
        [Test]
 
100
        public void Test_Setting_Text()
 
101
        {
 
102
            _filled.Text = "hello world";
 
103
            Assert.That(_repaintNotification, Is.EqualTo(1));
 
104
            Assert.That(_textChangedNotification, Is.EqualTo(1));
 
105
 
 
106
            return;
 
107
        }
 
108
 
 
109
        [Test]
 
110
        public void Test_Setting_Size_Invalidate_Box()
 
111
        {
 
112
            _filled.Width = 200;
 
113
            Assert.That(_repaintNotification, Is.EqualTo(1));
 
114
 
 
115
            _filled.Height = 400;
 
116
            Assert.That(_repaintNotification, Is.EqualTo(2));
 
117
 
 
118
            Assert.That(_filled.Viewport.Width, Is.EqualTo(200));
 
119
            Assert.That(_filled.Viewport.Height, Is.EqualTo(400));
 
120
 
 
121
            return;
 
122
        }
 
123
 
 
124
        [Test]
 
125
        public void Test_Setting_HighlighedLine_Invalidate_Box()
 
126
        {
 
127
            _filled.HighlightedLine = 2;
 
128
            Assert.That(_repaintNotification, Is.EqualTo(1));
 
129
        }
 
130
 
 
131
        [Test]
 
132
        public void Test_Changing_Location_Invalidate_Box()
 
133
        {
 
134
            _filled.Viewport.Location = new PointF(0, 1);
 
135
            Assert.That(_repaintNotification, Is.EqualTo(1));
 
136
        }
 
137
 
 
138
        [Test]
 
139
        public void Test_TranslateView()
 
140
        {
 
141
            _filled.Text = "******\r\n******\r\n******\r\n******\r\n******\r\n";
 
142
            _filled.Viewport.SetCharSize(1, 1);
 
143
            _filled.Viewport.SetViewport(1, 1);
 
144
 
 
145
            _filled.TranslateView(0, 0);
 
146
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 0)));
 
147
 
 
148
            _filled.TranslateView(2, 1);
 
149
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(2, 1)));
 
150
 
 
151
            _filled.TranslateView(3, 1);
 
152
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(5, 2)));
 
153
 
 
154
            return;
 
155
        }
 
156
 
 
157
        [Test]
 
158
        public void Test_CurrentLineNumber()
 
159
        {
 
160
            _filled.Viewport.SetViewport(1, 1);
 
161
            _filled.Viewport.SetCharSize(1, 1);
 
162
 
 
163
            Assert.That(_filled.CurrentLineNumber, Is.EqualTo(1));
 
164
 
 
165
            _filled.TranslateView(0, 1000);
 
166
 
 
167
            Assert.That(_filled.CurrentLineNumber,
 
168
                Is.EqualTo(_filled.Viewport.TextSource.LineCount));
 
169
 
 
170
            _filled.TranslateView(0, -2000);
 
171
            Assert.That(_filled.CurrentLineNumber, Is.EqualTo(1));
 
172
 
 
173
            return;
 
174
        }
 
175
 
 
176
        [Test]
 
177
        public void Test_MouseWheel_Up()
 
178
        {
 
179
            _filled.Viewport.SetViewport(1, 1);
 
180
            _filled.Viewport.SetCharSize(1, 1);
 
181
 
 
182
            _filled.Viewport.SetPosition(0, 2);
 
183
 
 
184
            _filled.MouseWheelDistance = 1;           
 
185
 
 
186
            _filled.HandleMouseWheelUp();
 
187
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 1)));
 
188
 
 
189
            _filled.HandleMouseWheelUp();
 
190
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 0)));
 
191
 
 
192
            return;
 
193
        }
 
194
 
 
195
        [Test]
 
196
        public void Test_MouseWheel_Down()
 
197
        {
 
198
            _filled.Viewport.SetViewport(1, 1);
 
199
            _filled.Viewport.SetCharSize(1, 1);
 
200
 
 
201
            _filled.Viewport.SetPosition(0, 0);
 
202
 
 
203
            _filled.MouseWheelDistance = 1;
 
204
 
 
205
            _filled.HandleMouseWheelDown();
 
206
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 1)));
 
207
 
 
208
            _filled.HandleMouseWheelDown();
 
209
            Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 2)));
 
210
 
 
211
            return;
 
212
        }
 
213
 
 
214
        #region InternalCodeBox
 
215
 
 
216
        delegate void RepaintEventArgs(object sender, EventArgs e);
 
217
 
 
218
        class InternalCodeBox :
 
219
            CodeBox
 
220
        {
 
221
            public event RepaintEventArgs Repainted;
 
222
 
 
223
            protected override void Repaint()
 
224
            {
 
225
                base.Repaint();
 
226
 
 
227
                if (Repainted != null)
 
228
                    Repainted(this, new EventArgs());
 
229
 
 
230
                return;
 
231
            }
 
232
 
 
233
            public new void HandleMouseWheelUp()
 
234
            {
 
235
                base.HandleMouseWheelUp();
 
236
            }
 
237
 
 
238
            public new void HandleMouseWheelDown()
 
239
            {
 
240
                base.HandleMouseWheelDown();
 
241
            }
 
242
        }
 
243
 
 
244
        #endregion
 
245
    }
 
246
}