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