]>
Commit | Line | Data |
---|---|---|
232fdc63 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/controls/richtextctrltest.cpp | |
3 | // Purpose: wxRichTextCtrl unit test | |
4 | // Author: Steven Lamerton | |
5 | // Created: 2010-07-07 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2010 Steven Lamerton | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #include "testprec.h" | |
11 | ||
12 | #if wxUSE_RICHTEXT | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/app.h" | |
20 | #endif // WX_PRECOMP | |
21 | ||
22 | #include "wx/richtext/richtextctrl.h" | |
23 | #include "wx/richtext/richtextstyles.h" | |
24 | #include "testableframe.h" | |
25 | #include "asserthelper.h" | |
26 | #include "wx/uiaction.h" | |
27 | ||
28 | class RichTextCtrlTestCase : public CppUnit::TestCase | |
29 | { | |
30 | public: | |
31 | RichTextCtrlTestCase() { } | |
32 | ||
33 | void setUp(); | |
34 | void tearDown(); | |
35 | ||
36 | private: | |
37 | CPPUNIT_TEST_SUITE( RichTextCtrlTestCase ); | |
38 | WXUISIM_TEST( CharacterEvent ); | |
39 | WXUISIM_TEST( DeleteEvent ); | |
40 | WXUISIM_TEST( ReturnEvent ); | |
41 | CPPUNIT_TEST( StyleEvent ); | |
42 | CPPUNIT_TEST( BufferResetEvent ); | |
43 | WXUISIM_TEST( UrlEvent ); | |
44 | WXUISIM_TEST( TextEvent ); | |
45 | CPPUNIT_TEST( CutCopyPaste ); | |
46 | CPPUNIT_TEST( UndoRedo ); | |
300fed48 VZ |
47 | // FIXME: This test is temporarily disabled as it currently fails |
48 | // but it should be reenabled and fixed a.s.a.p. after the | |
49 | // release. | |
50 | #if 0 | |
232fdc63 | 51 | CPPUNIT_TEST( CaretPosition ); |
300fed48 | 52 | #endif |
232fdc63 VZ |
53 | CPPUNIT_TEST( Selection ); |
54 | WXUISIM_TEST( Editable ); | |
55 | CPPUNIT_TEST( Range ); | |
56 | CPPUNIT_TEST( Alignment ); | |
57 | CPPUNIT_TEST( Bold ); | |
58 | CPPUNIT_TEST( Italic ); | |
59 | CPPUNIT_TEST( Underline ); | |
60 | CPPUNIT_TEST( Indent ); | |
61 | CPPUNIT_TEST( LineSpacing ); | |
62 | CPPUNIT_TEST( ParagraphSpacing ); | |
63 | CPPUNIT_TEST( TextColour ); | |
64 | CPPUNIT_TEST( NumberedBullet ); | |
65 | CPPUNIT_TEST( SymbolBullet ); | |
66 | CPPUNIT_TEST( FontSize ); | |
67 | CPPUNIT_TEST( Font ); | |
68 | CPPUNIT_TEST( Delete ); | |
69 | CPPUNIT_TEST( Url ); | |
70 | CPPUNIT_TEST_SUITE_END(); | |
71 | ||
72 | void CharacterEvent(); | |
73 | void DeleteEvent(); | |
74 | void ReturnEvent(); | |
75 | void StyleEvent(); | |
76 | void BufferResetEvent(); | |
77 | void UrlEvent(); | |
78 | void TextEvent(); | |
79 | void CutCopyPaste(); | |
80 | void UndoRedo(); | |
81 | void CaretPosition(); | |
82 | void Selection(); | |
83 | void Editable(); | |
84 | void Range(); | |
85 | void Alignment(); | |
86 | void Bold(); | |
87 | void Italic(); | |
88 | void Underline(); | |
89 | void Indent(); | |
90 | void LineSpacing(); | |
91 | void ParagraphSpacing(); | |
92 | void TextColour(); | |
93 | void NumberedBullet(); | |
94 | void SymbolBullet(); | |
95 | void FontSize(); | |
96 | void Font(); | |
97 | void Delete(); | |
98 | void Url(); | |
99 | ||
100 | wxRichTextCtrl* m_rich; | |
101 | ||
102 | DECLARE_NO_COPY_CLASS(RichTextCtrlTestCase) | |
103 | }; | |
104 | ||
105 | // register in the unnamed registry so that these tests are run by default | |
106 | CPPUNIT_TEST_SUITE_REGISTRATION( RichTextCtrlTestCase ); | |
107 | ||
e3778b4d | 108 | // also include in its own registry so that these tests can be run alone |
232fdc63 VZ |
109 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RichTextCtrlTestCase, "RichTextCtrlTestCase" ); |
110 | ||
111 | void RichTextCtrlTestCase::setUp() | |
112 | { | |
113 | m_rich = new wxRichTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "", | |
114 | wxDefaultPosition, wxSize(400, 200)); | |
115 | } | |
116 | ||
117 | void RichTextCtrlTestCase::tearDown() | |
118 | { | |
119 | wxDELETE(m_rich); | |
120 | } | |
121 | ||
122 | void RichTextCtrlTestCase::CharacterEvent() | |
123 | { | |
124 | #if wxUSE_UIACTIONSIMULATOR | |
9be7f47c JS |
125 | |
126 | // There seems to be an event sequence problem on GTK+ that causes the events | |
127 | // to be disconnected before they're processed, generating spurious errors. | |
128 | #if !defined(__WXGTK__) | |
744d91d4 SL |
129 | EventCounter character(m_rich, wxEVT_COMMAND_RICHTEXT_CHARACTER); |
130 | EventCounter content(m_rich, wxEVT_COMMAND_RICHTEXT_CONTENT_INSERTED); | |
232fdc63 VZ |
131 | |
132 | m_rich->SetFocus(); | |
133 | ||
134 | wxUIActionSimulator sim; | |
135 | sim.Text("abcdef"); | |
136 | wxYield(); | |
137 | ||
744d91d4 SL |
138 | CPPUNIT_ASSERT_EQUAL(6, character.GetCount()); |
139 | CPPUNIT_ASSERT_EQUAL(6, content.GetCount()); | |
140 | ||
141 | character.Clear(); | |
142 | content.Clear(); | |
232fdc63 VZ |
143 | |
144 | //As these are not characters they shouldn't count | |
145 | sim.Char(WXK_RETURN); | |
146 | sim.Char(WXK_SHIFT); | |
147 | wxYield(); | |
148 | ||
744d91d4 SL |
149 | CPPUNIT_ASSERT_EQUAL(0, character.GetCount()); |
150 | CPPUNIT_ASSERT_EQUAL(1, content.GetCount()); | |
232fdc63 | 151 | #endif |
9be7f47c | 152 | #endif |
232fdc63 VZ |
153 | } |
154 | ||
155 | void RichTextCtrlTestCase::DeleteEvent() | |
156 | { | |
157 | #if wxUSE_UIACTIONSIMULATOR | |
9be7f47c JS |
158 | // There seems to be an event sequence problem on GTK+ that causes the events |
159 | // to be disconnected before they're processed, generating spurious errors. | |
160 | #if !defined(__WXGTK__) | |
744d91d4 SL |
161 | EventCounter deleteevent(m_rich, wxEVT_COMMAND_RICHTEXT_DELETE); |
162 | EventCounter contentdelete(m_rich, wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED); | |
232fdc63 VZ |
163 | |
164 | m_rich->SetFocus(); | |
165 | ||
166 | wxUIActionSimulator sim; | |
167 | sim.Text("abcdef"); | |
168 | sim.Char(WXK_BACK); | |
169 | sim.Char(WXK_DELETE); | |
170 | wxYield(); | |
171 | ||
744d91d4 | 172 | CPPUNIT_ASSERT_EQUAL(2, deleteevent.GetCount()); |
232fdc63 | 173 | //Only one as the delete doesn't delete anthing |
744d91d4 | 174 | CPPUNIT_ASSERT_EQUAL(1, contentdelete.GetCount()); |
232fdc63 | 175 | #endif |
9be7f47c | 176 | #endif |
232fdc63 VZ |
177 | } |
178 | ||
179 | void RichTextCtrlTestCase::ReturnEvent() | |
180 | { | |
181 | #if wxUSE_UIACTIONSIMULATOR | |
9be7f47c JS |
182 | // There seems to be an event sequence problem on GTK+ that causes the events |
183 | // to be disconnected before they're processed, generating spurious errors. | |
184 | #if !defined(__WXGTK__) | |
744d91d4 | 185 | EventCounter returnevent(m_rich, wxEVT_COMMAND_RICHTEXT_RETURN); |
232fdc63 VZ |
186 | |
187 | m_rich->SetFocus(); | |
188 | ||
189 | wxUIActionSimulator sim; | |
190 | sim.Char(WXK_RETURN); | |
191 | wxYield(); | |
192 | ||
744d91d4 | 193 | CPPUNIT_ASSERT_EQUAL(1, returnevent.GetCount()); |
232fdc63 | 194 | #endif |
9be7f47c | 195 | #endif |
232fdc63 VZ |
196 | } |
197 | ||
198 | void RichTextCtrlTestCase::StyleEvent() | |
199 | { | |
744d91d4 | 200 | EventCounter stylechanged(m_rich, wxEVT_COMMAND_RICHTEXT_STYLE_CHANGED); |
232fdc63 VZ |
201 | |
202 | m_rich->SetValue("Sometext"); | |
203 | m_rich->SetStyle(0, 8, wxTextAttr(*wxRED, *wxWHITE)); | |
204 | ||
744d91d4 | 205 | CPPUNIT_ASSERT_EQUAL(1, stylechanged.GetCount()); |
232fdc63 VZ |
206 | } |
207 | ||
208 | void RichTextCtrlTestCase::BufferResetEvent() | |
209 | { | |
744d91d4 | 210 | EventCounter reset(m_rich, wxEVT_COMMAND_RICHTEXT_BUFFER_RESET); |
232fdc63 VZ |
211 | |
212 | m_rich->AppendText("more text!"); | |
213 | m_rich->SetValue(""); | |
214 | ||
744d91d4 | 215 | CPPUNIT_ASSERT_EQUAL(1, reset.GetCount()); |
232fdc63 | 216 | |
744d91d4 | 217 | reset.Clear(); |
232fdc63 VZ |
218 | m_rich->AppendText("more text!"); |
219 | m_rich->Clear(); | |
220 | ||
744d91d4 SL |
221 | CPPUNIT_ASSERT_EQUAL(1, reset.GetCount()); |
222 | ||
223 | reset.Clear(); | |
232fdc63 VZ |
224 | |
225 | //We expect a buffer reset here as setvalue clears the existing text | |
226 | m_rich->SetValue("replace"); | |
744d91d4 | 227 | CPPUNIT_ASSERT_EQUAL(1, reset.GetCount()); |
232fdc63 VZ |
228 | } |
229 | ||
230 | void RichTextCtrlTestCase::UrlEvent() | |
231 | { | |
232 | #if wxUSE_UIACTIONSIMULATOR | |
9be7f47c JS |
233 | // Mouse up event not being caught on GTK+ |
234 | #if !defined(__WXGTK__) | |
744d91d4 | 235 | EventCounter url(m_rich, wxEVT_COMMAND_TEXT_URL); |
232fdc63 VZ |
236 | |
237 | m_rich->BeginURL("http://www.wxwidgets.org"); | |
238 | m_rich->WriteText("http://www.wxwidgets.org"); | |
239 | m_rich->EndURL(); | |
240 | ||
241 | wxUIActionSimulator sim; | |
b083f3e8 | 242 | sim.MouseMove(m_rich->ClientToScreen(wxPoint(10, 10))); |
232fdc63 VZ |
243 | wxYield(); |
244 | ||
245 | sim.MouseClick(); | |
246 | wxYield(); | |
247 | ||
744d91d4 | 248 | CPPUNIT_ASSERT_EQUAL(1, url.GetCount()); |
232fdc63 | 249 | #endif |
9be7f47c | 250 | #endif |
232fdc63 VZ |
251 | } |
252 | ||
253 | void RichTextCtrlTestCase::TextEvent() | |
254 | { | |
255 | #if wxUSE_UIACTIONSIMULATOR | |
9be7f47c | 256 | #if !defined(__WXGTK__) |
744d91d4 | 257 | EventCounter updated(m_rich, wxEVT_COMMAND_TEXT_UPDATED); |
232fdc63 VZ |
258 | |
259 | m_rich->SetFocus(); | |
260 | ||
261 | wxUIActionSimulator sim; | |
262 | sim.Text("abcdef"); | |
263 | wxYield(); | |
264 | ||
265 | CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue()); | |
744d91d4 | 266 | CPPUNIT_ASSERT_EQUAL(6, updated.GetCount()); |
232fdc63 | 267 | #endif |
9be7f47c | 268 | #endif |
232fdc63 VZ |
269 | } |
270 | ||
271 | void RichTextCtrlTestCase::CutCopyPaste() | |
272 | { | |
273 | #ifndef __WXOSX__ | |
274 | m_rich->AppendText("sometext"); | |
275 | m_rich->SelectAll(); | |
276 | ||
277 | if(m_rich->CanCut() && m_rich->CanPaste()) | |
278 | { | |
279 | m_rich->Cut(); | |
280 | CPPUNIT_ASSERT(m_rich->IsEmpty()); | |
281 | ||
282 | wxYield(); | |
283 | ||
284 | m_rich->Paste(); | |
285 | CPPUNIT_ASSERT_EQUAL("sometext", m_rich->GetValue()); | |
286 | } | |
287 | ||
288 | m_rich->SelectAll(); | |
289 | ||
290 | if(m_rich->CanCopy() && m_rich->CanPaste()) | |
291 | { | |
292 | m_rich->Copy(); | |
293 | m_rich->Clear(); | |
294 | CPPUNIT_ASSERT(m_rich->IsEmpty()); | |
295 | ||
296 | wxYield(); | |
297 | ||
298 | m_rich->Paste(); | |
299 | CPPUNIT_ASSERT_EQUAL("sometext", m_rich->GetValue()); | |
300 | } | |
301 | #endif | |
302 | } | |
303 | ||
304 | void RichTextCtrlTestCase::UndoRedo() | |
305 | { | |
306 | m_rich->AppendText("sometext"); | |
307 | ||
308 | CPPUNIT_ASSERT(m_rich->CanUndo()); | |
309 | ||
310 | m_rich->Undo(); | |
311 | ||
312 | CPPUNIT_ASSERT(m_rich->IsEmpty()); | |
313 | CPPUNIT_ASSERT(m_rich->CanRedo()); | |
314 | ||
315 | m_rich->Redo(); | |
316 | ||
317 | CPPUNIT_ASSERT_EQUAL("sometext", m_rich->GetValue()); | |
318 | ||
319 | m_rich->AppendText("Batch undo"); | |
320 | m_rich->SelectAll(); | |
321 | ||
322 | //Also test batch operations | |
323 | m_rich->BeginBatchUndo("batchtest"); | |
324 | ||
325 | m_rich->ApplyBoldToSelection(); | |
326 | m_rich->ApplyItalicToSelection(); | |
327 | ||
328 | m_rich->EndBatchUndo(); | |
329 | ||
330 | CPPUNIT_ASSERT(m_rich->CanUndo()); | |
331 | ||
332 | m_rich->Undo(); | |
333 | ||
334 | CPPUNIT_ASSERT(!m_rich->IsSelectionBold()); | |
335 | CPPUNIT_ASSERT(!m_rich->IsSelectionItalics()); | |
336 | CPPUNIT_ASSERT(m_rich->CanRedo()); | |
337 | ||
338 | m_rich->Redo(); | |
339 | ||
340 | CPPUNIT_ASSERT(m_rich->IsSelectionBold()); | |
341 | CPPUNIT_ASSERT(m_rich->IsSelectionItalics()); | |
342 | ||
343 | //And surpressing undo | |
344 | m_rich->BeginSuppressUndo(); | |
345 | ||
346 | m_rich->AppendText("Can't undo this"); | |
347 | ||
348 | CPPUNIT_ASSERT(m_rich->CanUndo()); | |
349 | ||
350 | m_rich->EndSuppressUndo(); | |
351 | } | |
352 | ||
353 | void RichTextCtrlTestCase::CaretPosition() | |
354 | { | |
355 | m_rich->AddParagraph("This is paragraph one"); | |
356 | m_rich->AddParagraph("Paragraph two\n has \nlots of\n lines"); | |
357 | ||
358 | m_rich->MoveCaret(1); | |
359 | ||
360 | CPPUNIT_ASSERT_EQUAL(1, m_rich->GetCaretPosition()); | |
361 | ||
362 | m_rich->MoveToParagraphStart(); | |
363 | ||
364 | CPPUNIT_ASSERT_EQUAL(0, m_rich->GetCaretPosition()); | |
365 | ||
366 | m_rich->MoveRight(); | |
367 | m_rich->MoveRight(2); | |
368 | m_rich->MoveLeft(1); | |
369 | m_rich->MoveLeft(0); | |
370 | ||
371 | CPPUNIT_ASSERT_EQUAL(2, m_rich->GetCaretPosition()); | |
372 | ||
373 | m_rich->MoveToParagraphEnd(); | |
374 | ||
375 | CPPUNIT_ASSERT_EQUAL(21, m_rich->GetCaretPosition()); | |
376 | ||
377 | m_rich->MoveToLineStart(); | |
378 | ||
379 | CPPUNIT_ASSERT_EQUAL(0, m_rich->GetCaretPosition()); | |
380 | ||
381 | m_rich->MoveToLineEnd(); | |
382 | ||
383 | CPPUNIT_ASSERT_EQUAL(21, m_rich->GetCaretPosition()); | |
384 | } | |
385 | ||
386 | void RichTextCtrlTestCase::Selection() | |
387 | { | |
388 | m_rich->SetValue("some more text"); | |
389 | ||
390 | m_rich->SelectAll(); | |
391 | ||
392 | CPPUNIT_ASSERT_EQUAL("some more text", m_rich->GetStringSelection()); | |
393 | ||
394 | m_rich->SelectNone(); | |
395 | ||
396 | CPPUNIT_ASSERT_EQUAL("", m_rich->GetStringSelection()); | |
397 | ||
398 | m_rich->SelectWord(1); | |
399 | ||
400 | CPPUNIT_ASSERT_EQUAL("some", m_rich->GetStringSelection()); | |
401 | ||
402 | m_rich->SetSelection(5, 14); | |
403 | ||
404 | CPPUNIT_ASSERT_EQUAL("more text", m_rich->GetStringSelection()); | |
405 | ||
406 | wxRichTextRange range(5, 9); | |
407 | ||
408 | m_rich->SetSelectionRange(range); | |
409 | ||
410 | CPPUNIT_ASSERT_EQUAL("more", m_rich->GetStringSelection()); | |
411 | } | |
412 | ||
413 | void RichTextCtrlTestCase::Editable() | |
414 | { | |
415 | #if wxUSE_UIACTIONSIMULATOR | |
9be7f47c | 416 | #if !defined(__WXGTK__) |
744d91d4 | 417 | EventCounter updated(m_rich, wxEVT_COMMAND_TEXT_UPDATED); |
232fdc63 VZ |
418 | |
419 | m_rich->SetFocus(); | |
420 | ||
421 | wxUIActionSimulator sim; | |
422 | sim.Text("abcdef"); | |
423 | wxYield(); | |
424 | ||
425 | CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue()); | |
744d91d4 SL |
426 | CPPUNIT_ASSERT_EQUAL(6, updated.GetCount()); |
427 | updated.Clear(); | |
232fdc63 VZ |
428 | |
429 | m_rich->SetEditable(false); | |
430 | sim.Text("gh"); | |
431 | wxYield(); | |
432 | ||
433 | CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue()); | |
744d91d4 | 434 | CPPUNIT_ASSERT_EQUAL(0, updated.GetCount()); |
232fdc63 | 435 | #endif |
9be7f47c | 436 | #endif |
232fdc63 VZ |
437 | } |
438 | ||
439 | void RichTextCtrlTestCase::Range() | |
440 | { | |
441 | wxRichTextRange range(0, 10); | |
442 | ||
443 | CPPUNIT_ASSERT_EQUAL(0, range.GetStart()); | |
444 | CPPUNIT_ASSERT_EQUAL(10, range.GetEnd()); | |
445 | CPPUNIT_ASSERT_EQUAL(11, range.GetLength()); | |
446 | CPPUNIT_ASSERT(range.Contains(5)); | |
447 | ||
448 | wxRichTextRange outside(12, 14); | |
449 | ||
450 | CPPUNIT_ASSERT(outside.IsOutside(range)); | |
451 | ||
452 | wxRichTextRange inside(6, 7); | |
453 | ||
454 | CPPUNIT_ASSERT(inside.IsWithin(range)); | |
455 | ||
456 | range.LimitTo(inside); | |
457 | ||
458 | CPPUNIT_ASSERT(inside == range); | |
459 | CPPUNIT_ASSERT(inside + range == outside); | |
460 | CPPUNIT_ASSERT(outside - range == inside); | |
461 | ||
462 | range.SetStart(4); | |
463 | range.SetEnd(6); | |
464 | ||
465 | CPPUNIT_ASSERT_EQUAL(4, range.GetStart()); | |
466 | CPPUNIT_ASSERT_EQUAL(6, range.GetEnd()); | |
467 | CPPUNIT_ASSERT_EQUAL(3, range.GetLength()); | |
468 | ||
469 | inside.SetRange(6, 4); | |
470 | inside.Swap(); | |
471 | ||
472 | CPPUNIT_ASSERT(inside == range); | |
473 | } | |
474 | ||
475 | void RichTextCtrlTestCase::Alignment() | |
476 | { | |
477 | m_rich->SetValue("text to align"); | |
478 | m_rich->SelectAll(); | |
479 | ||
480 | m_rich->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_RIGHT); | |
481 | ||
482 | CPPUNIT_ASSERT(m_rich->IsSelectionAligned(wxTEXT_ALIGNMENT_RIGHT)); | |
483 | ||
484 | m_rich->BeginAlignment(wxTEXT_ALIGNMENT_CENTRE); | |
485 | m_rich->AddParagraph("middle aligned"); | |
486 | m_rich->EndAlignment(); | |
487 | ||
488 | m_rich->SetSelection(20, 25); | |
489 | ||
490 | CPPUNIT_ASSERT(m_rich->IsSelectionAligned(wxTEXT_ALIGNMENT_CENTRE)); | |
491 | } | |
492 | ||
493 | void RichTextCtrlTestCase::Bold() | |
494 | { | |
495 | m_rich->SetValue("text to bold"); | |
496 | m_rich->SelectAll(); | |
497 | m_rich->ApplyBoldToSelection(); | |
498 | ||
499 | CPPUNIT_ASSERT(m_rich->IsSelectionBold()); | |
500 | ||
501 | m_rich->BeginBold(); | |
502 | m_rich->AddParagraph("bold paragraph"); | |
503 | m_rich->EndBold(); | |
504 | m_rich->AddParagraph("not bold paragraph"); | |
505 | ||
506 | m_rich->SetSelection(15, 20); | |
507 | ||
508 | CPPUNIT_ASSERT(m_rich->IsSelectionBold()); | |
509 | ||
510 | m_rich->SetSelection(30, 35); | |
511 | ||
512 | CPPUNIT_ASSERT(!m_rich->IsSelectionBold()); | |
513 | } | |
514 | ||
515 | void RichTextCtrlTestCase::Italic() | |
516 | { | |
517 | m_rich->SetValue("text to italic"); | |
518 | m_rich->SelectAll(); | |
519 | m_rich->ApplyItalicToSelection(); | |
520 | ||
521 | CPPUNIT_ASSERT(m_rich->IsSelectionItalics()); | |
522 | ||
523 | m_rich->BeginItalic(); | |
524 | m_rich->AddParagraph("italic paragraph"); | |
525 | m_rich->EndItalic(); | |
526 | m_rich->AddParagraph("not italic paragraph"); | |
527 | ||
528 | m_rich->SetSelection(20, 25); | |
529 | ||
530 | CPPUNIT_ASSERT(m_rich->IsSelectionItalics()); | |
531 | ||
532 | m_rich->SetSelection(35, 40); | |
533 | ||
534 | CPPUNIT_ASSERT(!m_rich->IsSelectionItalics()); | |
535 | } | |
536 | ||
537 | void RichTextCtrlTestCase::Underline() | |
538 | { | |
539 | m_rich->SetValue("text to underline"); | |
540 | m_rich->SelectAll(); | |
541 | m_rich->ApplyUnderlineToSelection(); | |
542 | ||
543 | CPPUNIT_ASSERT(m_rich->IsSelectionUnderlined()); | |
544 | ||
545 | m_rich->BeginUnderline(); | |
546 | m_rich->AddParagraph("underline paragraph"); | |
547 | m_rich->EndUnderline(); | |
548 | m_rich->AddParagraph("not underline paragraph"); | |
549 | ||
550 | m_rich->SetSelection(20, 25); | |
551 | ||
552 | CPPUNIT_ASSERT(m_rich->IsSelectionUnderlined()); | |
553 | ||
554 | m_rich->SetSelection(40, 45); | |
555 | ||
556 | CPPUNIT_ASSERT(!m_rich->IsSelectionUnderlined()); | |
557 | } | |
558 | ||
559 | void RichTextCtrlTestCase::Indent() | |
560 | { | |
561 | m_rich->BeginLeftIndent(12, -5); | |
562 | m_rich->BeginRightIndent(14); | |
563 | m_rich->AddParagraph("A paragraph with indents"); | |
564 | m_rich->EndLeftIndent(); | |
565 | m_rich->EndRightIndent(); | |
566 | m_rich->AddParagraph("No more indent"); | |
567 | ||
568 | wxTextAttr indent; | |
569 | m_rich->GetStyle(5, indent); | |
570 | ||
571 | CPPUNIT_ASSERT_EQUAL(12, indent.GetLeftIndent()); | |
572 | CPPUNIT_ASSERT_EQUAL(-5, indent.GetLeftSubIndent()); | |
573 | CPPUNIT_ASSERT_EQUAL(14, indent.GetRightIndent()); | |
574 | ||
575 | m_rich->GetStyle(35, indent); | |
576 | ||
577 | CPPUNIT_ASSERT_EQUAL(0, indent.GetLeftIndent()); | |
578 | CPPUNIT_ASSERT_EQUAL(0, indent.GetLeftSubIndent()); | |
579 | CPPUNIT_ASSERT_EQUAL(0, indent.GetRightIndent()); | |
580 | } | |
581 | ||
582 | void RichTextCtrlTestCase::LineSpacing() | |
583 | { | |
584 | m_rich->BeginLineSpacing(20); | |
585 | m_rich->AddParagraph("double spaced"); | |
586 | m_rich->EndLineSpacing(); | |
587 | m_rich->BeginLineSpacing(wxTEXT_ATTR_LINE_SPACING_HALF); | |
588 | m_rich->AddParagraph("1.5 spaced"); | |
589 | m_rich->EndLineSpacing(); | |
590 | m_rich->AddParagraph("normally spaced"); | |
591 | ||
592 | wxTextAttr spacing; | |
593 | m_rich->GetStyle(5, spacing); | |
594 | ||
595 | CPPUNIT_ASSERT_EQUAL(20, spacing.GetLineSpacing()); | |
596 | ||
597 | m_rich->GetStyle(20, spacing); | |
598 | ||
599 | CPPUNIT_ASSERT_EQUAL(15, spacing.GetLineSpacing()); | |
600 | ||
601 | m_rich->GetStyle(30, spacing); | |
602 | ||
603 | CPPUNIT_ASSERT_EQUAL(10, spacing.GetLineSpacing()); | |
604 | } | |
605 | ||
606 | void RichTextCtrlTestCase::ParagraphSpacing() | |
607 | { | |
608 | m_rich->BeginParagraphSpacing(15, 20); | |
609 | m_rich->AddParagraph("spaced paragraph"); | |
610 | m_rich->EndParagraphSpacing(); | |
611 | m_rich->AddParagraph("non-spaced paragraph"); | |
612 | ||
613 | wxTextAttr spacing; | |
614 | m_rich->GetStyle(5, spacing); | |
615 | ||
616 | CPPUNIT_ASSERT_EQUAL(15, spacing.GetParagraphSpacingBefore()); | |
617 | CPPUNIT_ASSERT_EQUAL(20, spacing.GetParagraphSpacingAfter()); | |
618 | ||
619 | m_rich->GetStyle(25, spacing); | |
620 | ||
621 | //Make sure we test against the defaults | |
622 | CPPUNIT_ASSERT_EQUAL(m_rich->GetBasicStyle().GetParagraphSpacingBefore(), | |
623 | spacing.GetParagraphSpacingBefore()); | |
624 | CPPUNIT_ASSERT_EQUAL(m_rich->GetBasicStyle().GetParagraphSpacingAfter(), | |
625 | spacing.GetParagraphSpacingAfter()); | |
626 | } | |
627 | ||
628 | void RichTextCtrlTestCase::TextColour() | |
629 | { | |
630 | m_rich->BeginTextColour(*wxRED); | |
631 | m_rich->AddParagraph("red paragraph"); | |
632 | m_rich->EndTextColour(); | |
633 | m_rich->AddParagraph("default paragraph"); | |
634 | ||
635 | wxTextAttr colour; | |
636 | m_rich->GetStyle(5, colour); | |
637 | ||
638 | CPPUNIT_ASSERT_EQUAL(*wxRED, colour.GetTextColour()); | |
639 | ||
640 | m_rich->GetStyle(25, colour); | |
641 | ||
642 | CPPUNIT_ASSERT_EQUAL(m_rich->GetBasicStyle().GetTextColour(), | |
643 | colour.GetTextColour()); | |
644 | } | |
645 | ||
646 | void RichTextCtrlTestCase::NumberedBullet() | |
647 | { | |
648 | m_rich->BeginNumberedBullet(1, 15, 20); | |
649 | m_rich->AddParagraph("bullet one"); | |
650 | m_rich->EndNumberedBullet(); | |
651 | m_rich->BeginNumberedBullet(2, 25, -5); | |
652 | m_rich->AddParagraph("bullet two"); | |
653 | m_rich->EndNumberedBullet(); | |
654 | ||
655 | wxTextAttr bullet; | |
656 | m_rich->GetStyle(5, bullet); | |
657 | ||
658 | CPPUNIT_ASSERT(bullet.HasBulletStyle()); | |
659 | CPPUNIT_ASSERT(bullet.HasBulletNumber()); | |
660 | CPPUNIT_ASSERT_EQUAL(1, bullet.GetBulletNumber()); | |
661 | CPPUNIT_ASSERT_EQUAL(15, bullet.GetLeftIndent()); | |
662 | CPPUNIT_ASSERT_EQUAL(20, bullet.GetLeftSubIndent()); | |
663 | ||
664 | m_rich->GetStyle(15, bullet); | |
665 | ||
666 | CPPUNIT_ASSERT(bullet.HasBulletStyle()); | |
667 | CPPUNIT_ASSERT(bullet.HasBulletNumber()); | |
668 | CPPUNIT_ASSERT_EQUAL(2, bullet.GetBulletNumber()); | |
669 | CPPUNIT_ASSERT_EQUAL(25, bullet.GetLeftIndent()); | |
670 | CPPUNIT_ASSERT_EQUAL(-5, bullet.GetLeftSubIndent()); | |
671 | } | |
672 | ||
673 | void RichTextCtrlTestCase::SymbolBullet() | |
674 | { | |
675 | m_rich->BeginSymbolBullet("*", 15, 20); | |
676 | m_rich->AddParagraph("bullet one"); | |
677 | m_rich->EndSymbolBullet(); | |
678 | m_rich->BeginSymbolBullet("%", 25, -5); | |
679 | m_rich->AddParagraph("bullet two"); | |
680 | m_rich->EndSymbolBullet(); | |
681 | ||
682 | wxTextAttr bullet; | |
683 | m_rich->GetStyle(5, bullet); | |
684 | ||
685 | CPPUNIT_ASSERT(bullet.HasBulletStyle()); | |
686 | CPPUNIT_ASSERT(bullet.HasBulletText()); | |
687 | CPPUNIT_ASSERT_EQUAL("*", bullet.GetBulletText()); | |
688 | CPPUNIT_ASSERT_EQUAL(15, bullet.GetLeftIndent()); | |
689 | CPPUNIT_ASSERT_EQUAL(20, bullet.GetLeftSubIndent()); | |
690 | ||
691 | m_rich->GetStyle(15, bullet); | |
692 | ||
693 | CPPUNIT_ASSERT(bullet.HasBulletStyle()); | |
694 | CPPUNIT_ASSERT(bullet.HasBulletText()); | |
695 | CPPUNIT_ASSERT_EQUAL("%", bullet.GetBulletText()); | |
696 | CPPUNIT_ASSERT_EQUAL(25, bullet.GetLeftIndent()); | |
697 | CPPUNIT_ASSERT_EQUAL(-5, bullet.GetLeftSubIndent()); | |
698 | } | |
699 | ||
700 | void RichTextCtrlTestCase::FontSize() | |
701 | { | |
702 | m_rich->BeginFontSize(24); | |
703 | m_rich->AddParagraph("Large text"); | |
704 | m_rich->EndFontSize(); | |
705 | ||
706 | wxTextAttr size; | |
707 | m_rich->GetStyle(5, size); | |
708 | ||
709 | CPPUNIT_ASSERT(size.HasFontSize()); | |
710 | CPPUNIT_ASSERT_EQUAL(24, size.GetFontSize()); | |
711 | } | |
712 | ||
713 | void RichTextCtrlTestCase::Font() | |
714 | { | |
715 | wxFont font(14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); | |
716 | m_rich->BeginFont(font); | |
717 | m_rich->AddParagraph("paragraph with font"); | |
718 | m_rich->EndFont(); | |
719 | ||
720 | wxTextAttr fontstyle; | |
721 | m_rich->GetStyle(5, fontstyle); | |
722 | ||
723 | CPPUNIT_ASSERT_EQUAL(font, fontstyle.GetFont()); | |
724 | } | |
725 | ||
726 | void RichTextCtrlTestCase::Delete() | |
727 | { | |
728 | m_rich->AddParagraph("here is a long long line in a paragraph"); | |
729 | m_rich->SetSelection(0, 6); | |
730 | ||
731 | CPPUNIT_ASSERT(m_rich->CanDeleteSelection()); | |
732 | ||
733 | m_rich->DeleteSelection(); | |
734 | ||
735 | CPPUNIT_ASSERT_EQUAL("is a long long line in a paragraph", m_rich->GetValue()); | |
736 | ||
737 | m_rich->SetSelection(0, 5); | |
738 | ||
739 | CPPUNIT_ASSERT(m_rich->CanDeleteSelection()); | |
740 | ||
741 | m_rich->DeleteSelectedContent(); | |
742 | ||
743 | CPPUNIT_ASSERT_EQUAL("long long line in a paragraph", m_rich->GetValue()); | |
744 | ||
745 | m_rich->Delete(wxRichTextRange(14, 29)); | |
746 | ||
747 | CPPUNIT_ASSERT_EQUAL("long long line", m_rich->GetValue()); | |
748 | } | |
749 | ||
750 | void RichTextCtrlTestCase::Url() | |
751 | { | |
752 | m_rich->BeginURL("http://www.wxwidgets.org"); | |
753 | m_rich->WriteText("http://www.wxwidgets.org"); | |
754 | m_rich->EndURL(); | |
755 | ||
756 | wxTextAttr url; | |
757 | m_rich->GetStyle(5, url); | |
758 | ||
759 | CPPUNIT_ASSERT(url.HasURL()); | |
760 | CPPUNIT_ASSERT_EQUAL("http://www.wxwidgets.org", url.GetURL()); | |
761 | } | |
762 | ||
763 | #endif //wxUSE_RICHTEXT |