1
// ----------------------------------------------------------------
4
// Copyright 2008, Irénée HOTTIER,
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
// ----------------------------------------------------------------
11
using System.Collections.Generic;
13
using NUnit.Framework;
14
using NUnit.UiException;
16
using NUnit.UiException.Controls;
18
namespace NUnit.UiException.Tests.Controls
21
public class TestCodeBox
23
private InternalCodeBox _empty;
24
private InternalCodeBox _filled;
26
private int _repaintNotification;
27
private int _textChangedNotification;
32
_empty = new InternalCodeBox();
34
_filled = new InternalCodeBox();
35
_filled.Text = "111\r\n" +
38
_filled.HighlightedLine = 1;
40
_filled.Repainted += new RepaintEventArgs(_filled_Repainted);
41
_filled.TextChanged += new EventHandler(_filled_TextChanged);
43
_repaintNotification = 0;
48
void _filled_TextChanged(object sender, EventArgs e)
50
_textChangedNotification++;
53
void _filled_Repainted(object sender, EventArgs e)
55
_repaintNotification++;
59
public void Test_Default()
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));
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));
77
public void Test_Filled()
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));
88
public void Test_Setting_MouseWheelDistance()
90
_filled.MouseWheelDistance = 4;
91
Assert.That(_filled.MouseWheelDistance, Is.EqualTo(4));
93
_filled.MouseWheelDistance = 6;
94
Assert.That(_filled.MouseWheelDistance, Is.EqualTo(6));
100
public void Test_Setting_Text()
102
_filled.Text = "hello world";
103
Assert.That(_repaintNotification, Is.EqualTo(1));
104
Assert.That(_textChangedNotification, Is.EqualTo(1));
110
public void Test_Setting_Size_Invalidate_Box()
113
Assert.That(_repaintNotification, Is.EqualTo(1));
115
_filled.Height = 400;
116
Assert.That(_repaintNotification, Is.EqualTo(2));
118
Assert.That(_filled.Viewport.Width, Is.EqualTo(200));
119
Assert.That(_filled.Viewport.Height, Is.EqualTo(400));
125
public void Test_Setting_HighlighedLine_Invalidate_Box()
127
_filled.HighlightedLine = 2;
128
Assert.That(_repaintNotification, Is.EqualTo(1));
132
public void Test_Changing_Location_Invalidate_Box()
134
_filled.Viewport.Location = new PointF(0, 1);
135
Assert.That(_repaintNotification, Is.EqualTo(1));
139
public void Test_TranslateView()
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);
145
_filled.TranslateView(0, 0);
146
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 0)));
148
_filled.TranslateView(2, 1);
149
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(2, 1)));
151
_filled.TranslateView(3, 1);
152
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(5, 2)));
158
public void Test_CurrentLineNumber()
160
_filled.Viewport.SetViewport(1, 1);
161
_filled.Viewport.SetCharSize(1, 1);
163
Assert.That(_filled.CurrentLineNumber, Is.EqualTo(1));
165
_filled.TranslateView(0, 1000);
167
Assert.That(_filled.CurrentLineNumber,
168
Is.EqualTo(_filled.Viewport.TextSource.LineCount));
170
_filled.TranslateView(0, -2000);
171
Assert.That(_filled.CurrentLineNumber, Is.EqualTo(1));
177
public void Test_MouseWheel_Up()
179
_filled.Viewport.SetViewport(1, 1);
180
_filled.Viewport.SetCharSize(1, 1);
182
_filled.Viewport.SetPosition(0, 2);
184
_filled.MouseWheelDistance = 1;
186
_filled.HandleMouseWheelUp();
187
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 1)));
189
_filled.HandleMouseWheelUp();
190
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 0)));
196
public void Test_MouseWheel_Down()
198
_filled.Viewport.SetViewport(1, 1);
199
_filled.Viewport.SetCharSize(1, 1);
201
_filled.Viewport.SetPosition(0, 0);
203
_filled.MouseWheelDistance = 1;
205
_filled.HandleMouseWheelDown();
206
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 1)));
208
_filled.HandleMouseWheelDown();
209
Assert.That(_filled.Viewport.Location, Is.EqualTo(new PointF(0, 2)));
214
#region InternalCodeBox
216
delegate void RepaintEventArgs(object sender, EventArgs e);
218
class InternalCodeBox :
221
public event RepaintEventArgs Repainted;
223
protected override void Repaint()
227
if (Repainted != null)
228
Repainted(this, new EventArgs());
233
public new void HandleMouseWheelUp()
235
base.HandleMouseWheelUp();
238
public new void HandleMouseWheelDown()
240
base.HandleMouseWheelDown();