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