]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/richtextctrltest.cpp
Revert "Show the name of the actually tested class in text entry unit tests."
[wxWidgets.git] / tests / controls / richtextctrltest.cpp
CommitLineData
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
28class RichTextCtrlTestCase : public CppUnit::TestCase
29{
30public:
31 RichTextCtrlTestCase() { }
32
33 void setUp();
34 void tearDown();
35
36private:
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 );
31be8400 65 CPPUNIT_TEST( Table );
232fdc63
VZ
66 CPPUNIT_TEST_SUITE_END();
67
68 void CharacterEvent();
69 void DeleteEvent();
70 void ReturnEvent();
71 void StyleEvent();
72 void BufferResetEvent();
73 void UrlEvent();
74 void TextEvent();
75 void CutCopyPaste();
76 void UndoRedo();
77 void CaretPosition();
78 void Selection();
79 void Editable();
80 void Range();
81 void Alignment();
82 void Bold();
83 void Italic();
84 void Underline();
85 void Indent();
86 void LineSpacing();
87 void ParagraphSpacing();
88 void TextColour();
89 void NumberedBullet();
90 void SymbolBullet();
91 void FontSize();
92 void Font();
93 void Delete();
94 void Url();
31be8400 95 void Table();
232fdc63
VZ
96
97 wxRichTextCtrl* m_rich;
98
99 DECLARE_NO_COPY_CLASS(RichTextCtrlTestCase)
100};
101
102// register in the unnamed registry so that these tests are run by default
103CPPUNIT_TEST_SUITE_REGISTRATION( RichTextCtrlTestCase );
104
e3778b4d 105// also include in its own registry so that these tests can be run alone
232fdc63
VZ
106CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RichTextCtrlTestCase, "RichTextCtrlTestCase" );
107
108void RichTextCtrlTestCase::setUp()
109{
110 m_rich = new wxRichTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
39a18da1 111 wxDefaultPosition, wxSize(400, 200), wxWANTS_CHARS);
232fdc63
VZ
112}
113
114void RichTextCtrlTestCase::tearDown()
115{
116 wxDELETE(m_rich);
117}
118
119void RichTextCtrlTestCase::CharacterEvent()
120{
121#if wxUSE_UIACTIONSIMULATOR
9be7f47c
JS
122
123 // There seems to be an event sequence problem on GTK+ that causes the events
124 // to be disconnected before they're processed, generating spurious errors.
125#if !defined(__WXGTK__)
ce7fe42e
VZ
126 EventCounter character(m_rich, wxEVT_RICHTEXT_CHARACTER);
127 EventCounter content(m_rich, wxEVT_RICHTEXT_CONTENT_INSERTED);
232fdc63
VZ
128
129 m_rich->SetFocus();
130
131 wxUIActionSimulator sim;
132 sim.Text("abcdef");
133 wxYield();
134
744d91d4
SL
135 CPPUNIT_ASSERT_EQUAL(6, character.GetCount());
136 CPPUNIT_ASSERT_EQUAL(6, content.GetCount());
137
138 character.Clear();
139 content.Clear();
232fdc63
VZ
140
141 //As these are not characters they shouldn't count
142 sim.Char(WXK_RETURN);
143 sim.Char(WXK_SHIFT);
144 wxYield();
145
744d91d4
SL
146 CPPUNIT_ASSERT_EQUAL(0, character.GetCount());
147 CPPUNIT_ASSERT_EQUAL(1, content.GetCount());
232fdc63 148#endif
9be7f47c 149#endif
232fdc63
VZ
150}
151
152void RichTextCtrlTestCase::DeleteEvent()
153{
154#if wxUSE_UIACTIONSIMULATOR
9be7f47c
JS
155 // There seems to be an event sequence problem on GTK+ that causes the events
156 // to be disconnected before they're processed, generating spurious errors.
157#if !defined(__WXGTK__)
ce7fe42e
VZ
158 EventCounter deleteevent(m_rich, wxEVT_RICHTEXT_DELETE);
159 EventCounter contentdelete(m_rich, wxEVT_RICHTEXT_CONTENT_DELETED);
232fdc63
VZ
160
161 m_rich->SetFocus();
162
163 wxUIActionSimulator sim;
164 sim.Text("abcdef");
165 sim.Char(WXK_BACK);
166 sim.Char(WXK_DELETE);
167 wxYield();
168
744d91d4 169 CPPUNIT_ASSERT_EQUAL(2, deleteevent.GetCount());
232fdc63 170 //Only one as the delete doesn't delete anthing
744d91d4 171 CPPUNIT_ASSERT_EQUAL(1, contentdelete.GetCount());
232fdc63 172#endif
9be7f47c 173#endif
232fdc63
VZ
174}
175
176void RichTextCtrlTestCase::ReturnEvent()
177{
178#if wxUSE_UIACTIONSIMULATOR
9be7f47c
JS
179 // There seems to be an event sequence problem on GTK+ that causes the events
180 // to be disconnected before they're processed, generating spurious errors.
181#if !defined(__WXGTK__)
ce7fe42e 182 EventCounter returnevent(m_rich, wxEVT_RICHTEXT_RETURN);
232fdc63
VZ
183
184 m_rich->SetFocus();
185
186 wxUIActionSimulator sim;
187 sim.Char(WXK_RETURN);
188 wxYield();
189
744d91d4 190 CPPUNIT_ASSERT_EQUAL(1, returnevent.GetCount());
232fdc63 191#endif
9be7f47c 192#endif
232fdc63
VZ
193}
194
195void RichTextCtrlTestCase::StyleEvent()
196{
ce7fe42e 197 EventCounter stylechanged(m_rich, wxEVT_RICHTEXT_STYLE_CHANGED);
232fdc63
VZ
198
199 m_rich->SetValue("Sometext");
200 m_rich->SetStyle(0, 8, wxTextAttr(*wxRED, *wxWHITE));
201
744d91d4 202 CPPUNIT_ASSERT_EQUAL(1, stylechanged.GetCount());
232fdc63
VZ
203}
204
205void RichTextCtrlTestCase::BufferResetEvent()
206{
ce7fe42e 207 EventCounter reset(m_rich, wxEVT_RICHTEXT_BUFFER_RESET);
232fdc63
VZ
208
209 m_rich->AppendText("more text!");
210 m_rich->SetValue("");
211
744d91d4 212 CPPUNIT_ASSERT_EQUAL(1, reset.GetCount());
232fdc63 213
744d91d4 214 reset.Clear();
232fdc63
VZ
215 m_rich->AppendText("more text!");
216 m_rich->Clear();
217
744d91d4
SL
218 CPPUNIT_ASSERT_EQUAL(1, reset.GetCount());
219
220 reset.Clear();
232fdc63
VZ
221
222 //We expect a buffer reset here as setvalue clears the existing text
223 m_rich->SetValue("replace");
744d91d4 224 CPPUNIT_ASSERT_EQUAL(1, reset.GetCount());
232fdc63
VZ
225}
226
227void RichTextCtrlTestCase::UrlEvent()
228{
229#if wxUSE_UIACTIONSIMULATOR
9be7f47c
JS
230 // Mouse up event not being caught on GTK+
231#if !defined(__WXGTK__)
ce7fe42e 232 EventCounter url(m_rich, wxEVT_TEXT_URL);
232fdc63
VZ
233
234 m_rich->BeginURL("http://www.wxwidgets.org");
235 m_rich->WriteText("http://www.wxwidgets.org");
236 m_rich->EndURL();
237
238 wxUIActionSimulator sim;
b083f3e8 239 sim.MouseMove(m_rich->ClientToScreen(wxPoint(10, 10)));
232fdc63
VZ
240 wxYield();
241
242 sim.MouseClick();
243 wxYield();
244
744d91d4 245 CPPUNIT_ASSERT_EQUAL(1, url.GetCount());
232fdc63 246#endif
9be7f47c 247#endif
232fdc63
VZ
248}
249
250void RichTextCtrlTestCase::TextEvent()
251{
252#if wxUSE_UIACTIONSIMULATOR
9be7f47c 253#if !defined(__WXGTK__)
ce7fe42e 254 EventCounter updated(m_rich, wxEVT_TEXT);
232fdc63
VZ
255
256 m_rich->SetFocus();
257
258 wxUIActionSimulator sim;
259 sim.Text("abcdef");
260 wxYield();
261
262 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue());
744d91d4 263 CPPUNIT_ASSERT_EQUAL(6, updated.GetCount());
232fdc63 264#endif
9be7f47c 265#endif
232fdc63
VZ
266}
267
268void RichTextCtrlTestCase::CutCopyPaste()
269{
270#ifndef __WXOSX__
271 m_rich->AppendText("sometext");
272 m_rich->SelectAll();
273
274 if(m_rich->CanCut() && m_rich->CanPaste())
275 {
276 m_rich->Cut();
277 CPPUNIT_ASSERT(m_rich->IsEmpty());
278
279 wxYield();
280
281 m_rich->Paste();
282 CPPUNIT_ASSERT_EQUAL("sometext", m_rich->GetValue());
283 }
284
285 m_rich->SelectAll();
286
287 if(m_rich->CanCopy() && m_rich->CanPaste())
288 {
289 m_rich->Copy();
290 m_rich->Clear();
291 CPPUNIT_ASSERT(m_rich->IsEmpty());
292
293 wxYield();
294
295 m_rich->Paste();
296 CPPUNIT_ASSERT_EQUAL("sometext", m_rich->GetValue());
297 }
298#endif
299}
300
301void RichTextCtrlTestCase::UndoRedo()
302{
303 m_rich->AppendText("sometext");
304
305 CPPUNIT_ASSERT(m_rich->CanUndo());
306
307 m_rich->Undo();
308
309 CPPUNIT_ASSERT(m_rich->IsEmpty());
310 CPPUNIT_ASSERT(m_rich->CanRedo());
311
312 m_rich->Redo();
313
314 CPPUNIT_ASSERT_EQUAL("sometext", m_rich->GetValue());
315
316 m_rich->AppendText("Batch undo");
317 m_rich->SelectAll();
318
319 //Also test batch operations
320 m_rich->BeginBatchUndo("batchtest");
321
322 m_rich->ApplyBoldToSelection();
323 m_rich->ApplyItalicToSelection();
324
325 m_rich->EndBatchUndo();
326
327 CPPUNIT_ASSERT(m_rich->CanUndo());
328
329 m_rich->Undo();
330
331 CPPUNIT_ASSERT(!m_rich->IsSelectionBold());
332 CPPUNIT_ASSERT(!m_rich->IsSelectionItalics());
333 CPPUNIT_ASSERT(m_rich->CanRedo());
334
335 m_rich->Redo();
336
337 CPPUNIT_ASSERT(m_rich->IsSelectionBold());
338 CPPUNIT_ASSERT(m_rich->IsSelectionItalics());
339
340 //And surpressing undo
341 m_rich->BeginSuppressUndo();
342
343 m_rich->AppendText("Can't undo this");
344
345 CPPUNIT_ASSERT(m_rich->CanUndo());
346
347 m_rich->EndSuppressUndo();
348}
349
350void RichTextCtrlTestCase::CaretPosition()
351{
352 m_rich->AddParagraph("This is paragraph one");
353 m_rich->AddParagraph("Paragraph two\n has \nlots of\n lines");
354
04b2b47a 355 m_rich->SetInsertionPoint(2);
232fdc63
VZ
356
357 CPPUNIT_ASSERT_EQUAL(1, m_rich->GetCaretPosition());
358
359 m_rich->MoveToParagraphStart();
360
361 CPPUNIT_ASSERT_EQUAL(0, m_rich->GetCaretPosition());
362
363 m_rich->MoveRight();
364 m_rich->MoveRight(2);
365 m_rich->MoveLeft(1);
366 m_rich->MoveLeft(0);
367
368 CPPUNIT_ASSERT_EQUAL(2, m_rich->GetCaretPosition());
369
370 m_rich->MoveToParagraphEnd();
371
372 CPPUNIT_ASSERT_EQUAL(21, m_rich->GetCaretPosition());
373
374 m_rich->MoveToLineStart();
375
376 CPPUNIT_ASSERT_EQUAL(0, m_rich->GetCaretPosition());
377
378 m_rich->MoveToLineEnd();
379
380 CPPUNIT_ASSERT_EQUAL(21, m_rich->GetCaretPosition());
381}
382
383void RichTextCtrlTestCase::Selection()
384{
385 m_rich->SetValue("some more text");
386
387 m_rich->SelectAll();
388
389 CPPUNIT_ASSERT_EQUAL("some more text", m_rich->GetStringSelection());
390
391 m_rich->SelectNone();
392
393 CPPUNIT_ASSERT_EQUAL("", m_rich->GetStringSelection());
394
395 m_rich->SelectWord(1);
396
397 CPPUNIT_ASSERT_EQUAL("some", m_rich->GetStringSelection());
398
399 m_rich->SetSelection(5, 14);
400
401 CPPUNIT_ASSERT_EQUAL("more text", m_rich->GetStringSelection());
402
403 wxRichTextRange range(5, 9);
404
405 m_rich->SetSelectionRange(range);
406
407 CPPUNIT_ASSERT_EQUAL("more", m_rich->GetStringSelection());
408}
409
410void RichTextCtrlTestCase::Editable()
411{
412#if wxUSE_UIACTIONSIMULATOR
9be7f47c 413#if !defined(__WXGTK__)
ce7fe42e 414 EventCounter updated(m_rich, wxEVT_TEXT);
232fdc63
VZ
415
416 m_rich->SetFocus();
417
418 wxUIActionSimulator sim;
419 sim.Text("abcdef");
420 wxYield();
421
422 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue());
744d91d4
SL
423 CPPUNIT_ASSERT_EQUAL(6, updated.GetCount());
424 updated.Clear();
232fdc63
VZ
425
426 m_rich->SetEditable(false);
427 sim.Text("gh");
428 wxYield();
429
430 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich->GetValue());
744d91d4 431 CPPUNIT_ASSERT_EQUAL(0, updated.GetCount());
232fdc63 432#endif
9be7f47c 433#endif
232fdc63
VZ
434}
435
436void RichTextCtrlTestCase::Range()
437{
438 wxRichTextRange range(0, 10);
439
440 CPPUNIT_ASSERT_EQUAL(0, range.GetStart());
441 CPPUNIT_ASSERT_EQUAL(10, range.GetEnd());
442 CPPUNIT_ASSERT_EQUAL(11, range.GetLength());
443 CPPUNIT_ASSERT(range.Contains(5));
444
445 wxRichTextRange outside(12, 14);
446
447 CPPUNIT_ASSERT(outside.IsOutside(range));
448
449 wxRichTextRange inside(6, 7);
450
451 CPPUNIT_ASSERT(inside.IsWithin(range));
452
453 range.LimitTo(inside);
454
455 CPPUNIT_ASSERT(inside == range);
456 CPPUNIT_ASSERT(inside + range == outside);
457 CPPUNIT_ASSERT(outside - range == inside);
458
459 range.SetStart(4);
460 range.SetEnd(6);
461
462 CPPUNIT_ASSERT_EQUAL(4, range.GetStart());
463 CPPUNIT_ASSERT_EQUAL(6, range.GetEnd());
464 CPPUNIT_ASSERT_EQUAL(3, range.GetLength());
465
466 inside.SetRange(6, 4);
467 inside.Swap();
468
469 CPPUNIT_ASSERT(inside == range);
470}
471
472void RichTextCtrlTestCase::Alignment()
473{
474 m_rich->SetValue("text to align");
475 m_rich->SelectAll();
476
477 m_rich->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_RIGHT);
478
479 CPPUNIT_ASSERT(m_rich->IsSelectionAligned(wxTEXT_ALIGNMENT_RIGHT));
480
481 m_rich->BeginAlignment(wxTEXT_ALIGNMENT_CENTRE);
482 m_rich->AddParagraph("middle aligned");
483 m_rich->EndAlignment();
484
485 m_rich->SetSelection(20, 25);
486
487 CPPUNIT_ASSERT(m_rich->IsSelectionAligned(wxTEXT_ALIGNMENT_CENTRE));
488}
489
490void RichTextCtrlTestCase::Bold()
491{
492 m_rich->SetValue("text to bold");
493 m_rich->SelectAll();
494 m_rich->ApplyBoldToSelection();
495
496 CPPUNIT_ASSERT(m_rich->IsSelectionBold());
497
498 m_rich->BeginBold();
499 m_rich->AddParagraph("bold paragraph");
500 m_rich->EndBold();
501 m_rich->AddParagraph("not bold paragraph");
502
503 m_rich->SetSelection(15, 20);
504
505 CPPUNIT_ASSERT(m_rich->IsSelectionBold());
506
507 m_rich->SetSelection(30, 35);
508
509 CPPUNIT_ASSERT(!m_rich->IsSelectionBold());
510}
511
512void RichTextCtrlTestCase::Italic()
513{
514 m_rich->SetValue("text to italic");
515 m_rich->SelectAll();
516 m_rich->ApplyItalicToSelection();
517
518 CPPUNIT_ASSERT(m_rich->IsSelectionItalics());
519
520 m_rich->BeginItalic();
521 m_rich->AddParagraph("italic paragraph");
522 m_rich->EndItalic();
523 m_rich->AddParagraph("not italic paragraph");
524
525 m_rich->SetSelection(20, 25);
526
527 CPPUNIT_ASSERT(m_rich->IsSelectionItalics());
528
529 m_rich->SetSelection(35, 40);
530
531 CPPUNIT_ASSERT(!m_rich->IsSelectionItalics());
532}
533
534void RichTextCtrlTestCase::Underline()
535{
536 m_rich->SetValue("text to underline");
537 m_rich->SelectAll();
538 m_rich->ApplyUnderlineToSelection();
539
540 CPPUNIT_ASSERT(m_rich->IsSelectionUnderlined());
541
542 m_rich->BeginUnderline();
543 m_rich->AddParagraph("underline paragraph");
544 m_rich->EndUnderline();
545 m_rich->AddParagraph("not underline paragraph");
546
547 m_rich->SetSelection(20, 25);
548
549 CPPUNIT_ASSERT(m_rich->IsSelectionUnderlined());
550
551 m_rich->SetSelection(40, 45);
552
553 CPPUNIT_ASSERT(!m_rich->IsSelectionUnderlined());
554}
555
556void RichTextCtrlTestCase::Indent()
557{
558 m_rich->BeginLeftIndent(12, -5);
559 m_rich->BeginRightIndent(14);
560 m_rich->AddParagraph("A paragraph with indents");
561 m_rich->EndLeftIndent();
562 m_rich->EndRightIndent();
563 m_rich->AddParagraph("No more indent");
564
565 wxTextAttr indent;
566 m_rich->GetStyle(5, indent);
567
568 CPPUNIT_ASSERT_EQUAL(12, indent.GetLeftIndent());
569 CPPUNIT_ASSERT_EQUAL(-5, indent.GetLeftSubIndent());
570 CPPUNIT_ASSERT_EQUAL(14, indent.GetRightIndent());
571
572 m_rich->GetStyle(35, indent);
573
574 CPPUNIT_ASSERT_EQUAL(0, indent.GetLeftIndent());
575 CPPUNIT_ASSERT_EQUAL(0, indent.GetLeftSubIndent());
576 CPPUNIT_ASSERT_EQUAL(0, indent.GetRightIndent());
577}
578
579void RichTextCtrlTestCase::LineSpacing()
580{
581 m_rich->BeginLineSpacing(20);
582 m_rich->AddParagraph("double spaced");
583 m_rich->EndLineSpacing();
584 m_rich->BeginLineSpacing(wxTEXT_ATTR_LINE_SPACING_HALF);
585 m_rich->AddParagraph("1.5 spaced");
586 m_rich->EndLineSpacing();
587 m_rich->AddParagraph("normally spaced");
588
589 wxTextAttr spacing;
590 m_rich->GetStyle(5, spacing);
591
592 CPPUNIT_ASSERT_EQUAL(20, spacing.GetLineSpacing());
593
594 m_rich->GetStyle(20, spacing);
595
596 CPPUNIT_ASSERT_EQUAL(15, spacing.GetLineSpacing());
597
598 m_rich->GetStyle(30, spacing);
599
600 CPPUNIT_ASSERT_EQUAL(10, spacing.GetLineSpacing());
601}
602
603void RichTextCtrlTestCase::ParagraphSpacing()
604{
605 m_rich->BeginParagraphSpacing(15, 20);
606 m_rich->AddParagraph("spaced paragraph");
607 m_rich->EndParagraphSpacing();
608 m_rich->AddParagraph("non-spaced paragraph");
609
610 wxTextAttr spacing;
611 m_rich->GetStyle(5, spacing);
612
613 CPPUNIT_ASSERT_EQUAL(15, spacing.GetParagraphSpacingBefore());
614 CPPUNIT_ASSERT_EQUAL(20, spacing.GetParagraphSpacingAfter());
615
616 m_rich->GetStyle(25, spacing);
617
618 //Make sure we test against the defaults
619 CPPUNIT_ASSERT_EQUAL(m_rich->GetBasicStyle().GetParagraphSpacingBefore(),
620 spacing.GetParagraphSpacingBefore());
621 CPPUNIT_ASSERT_EQUAL(m_rich->GetBasicStyle().GetParagraphSpacingAfter(),
622 spacing.GetParagraphSpacingAfter());
623}
624
625void RichTextCtrlTestCase::TextColour()
626{
627 m_rich->BeginTextColour(*wxRED);
628 m_rich->AddParagraph("red paragraph");
629 m_rich->EndTextColour();
630 m_rich->AddParagraph("default paragraph");
631
632 wxTextAttr colour;
633 m_rich->GetStyle(5, colour);
634
635 CPPUNIT_ASSERT_EQUAL(*wxRED, colour.GetTextColour());
636
637 m_rich->GetStyle(25, colour);
638
639 CPPUNIT_ASSERT_EQUAL(m_rich->GetBasicStyle().GetTextColour(),
640 colour.GetTextColour());
641}
642
643void RichTextCtrlTestCase::NumberedBullet()
644{
645 m_rich->BeginNumberedBullet(1, 15, 20);
646 m_rich->AddParagraph("bullet one");
647 m_rich->EndNumberedBullet();
648 m_rich->BeginNumberedBullet(2, 25, -5);
649 m_rich->AddParagraph("bullet two");
650 m_rich->EndNumberedBullet();
651
652 wxTextAttr bullet;
653 m_rich->GetStyle(5, bullet);
654
655 CPPUNIT_ASSERT(bullet.HasBulletStyle());
656 CPPUNIT_ASSERT(bullet.HasBulletNumber());
657 CPPUNIT_ASSERT_EQUAL(1, bullet.GetBulletNumber());
658 CPPUNIT_ASSERT_EQUAL(15, bullet.GetLeftIndent());
659 CPPUNIT_ASSERT_EQUAL(20, bullet.GetLeftSubIndent());
660
661 m_rich->GetStyle(15, bullet);
662
663 CPPUNIT_ASSERT(bullet.HasBulletStyle());
664 CPPUNIT_ASSERT(bullet.HasBulletNumber());
665 CPPUNIT_ASSERT_EQUAL(2, bullet.GetBulletNumber());
666 CPPUNIT_ASSERT_EQUAL(25, bullet.GetLeftIndent());
667 CPPUNIT_ASSERT_EQUAL(-5, bullet.GetLeftSubIndent());
668}
669
670void RichTextCtrlTestCase::SymbolBullet()
671{
672 m_rich->BeginSymbolBullet("*", 15, 20);
673 m_rich->AddParagraph("bullet one");
674 m_rich->EndSymbolBullet();
675 m_rich->BeginSymbolBullet("%", 25, -5);
676 m_rich->AddParagraph("bullet two");
677 m_rich->EndSymbolBullet();
678
679 wxTextAttr bullet;
680 m_rich->GetStyle(5, bullet);
681
682 CPPUNIT_ASSERT(bullet.HasBulletStyle());
683 CPPUNIT_ASSERT(bullet.HasBulletText());
684 CPPUNIT_ASSERT_EQUAL("*", bullet.GetBulletText());
685 CPPUNIT_ASSERT_EQUAL(15, bullet.GetLeftIndent());
686 CPPUNIT_ASSERT_EQUAL(20, bullet.GetLeftSubIndent());
687
688 m_rich->GetStyle(15, bullet);
689
690 CPPUNIT_ASSERT(bullet.HasBulletStyle());
691 CPPUNIT_ASSERT(bullet.HasBulletText());
692 CPPUNIT_ASSERT_EQUAL("%", bullet.GetBulletText());
693 CPPUNIT_ASSERT_EQUAL(25, bullet.GetLeftIndent());
694 CPPUNIT_ASSERT_EQUAL(-5, bullet.GetLeftSubIndent());
695}
696
697void RichTextCtrlTestCase::FontSize()
698{
699 m_rich->BeginFontSize(24);
700 m_rich->AddParagraph("Large text");
701 m_rich->EndFontSize();
702
703 wxTextAttr size;
704 m_rich->GetStyle(5, size);
705
706 CPPUNIT_ASSERT(size.HasFontSize());
707 CPPUNIT_ASSERT_EQUAL(24, size.GetFontSize());
708}
709
710void RichTextCtrlTestCase::Font()
711{
712 wxFont font(14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
713 m_rich->BeginFont(font);
714 m_rich->AddParagraph("paragraph with font");
715 m_rich->EndFont();
716
717 wxTextAttr fontstyle;
718 m_rich->GetStyle(5, fontstyle);
719
720 CPPUNIT_ASSERT_EQUAL(font, fontstyle.GetFont());
721}
722
723void RichTextCtrlTestCase::Delete()
724{
725 m_rich->AddParagraph("here is a long long line in a paragraph");
726 m_rich->SetSelection(0, 6);
727
728 CPPUNIT_ASSERT(m_rich->CanDeleteSelection());
729
730 m_rich->DeleteSelection();
731
732 CPPUNIT_ASSERT_EQUAL("is a long long line in a paragraph", m_rich->GetValue());
733
734 m_rich->SetSelection(0, 5);
735
736 CPPUNIT_ASSERT(m_rich->CanDeleteSelection());
737
738 m_rich->DeleteSelectedContent();
739
740 CPPUNIT_ASSERT_EQUAL("long long line in a paragraph", m_rich->GetValue());
741
742 m_rich->Delete(wxRichTextRange(14, 29));
743
744 CPPUNIT_ASSERT_EQUAL("long long line", m_rich->GetValue());
745}
746
747void RichTextCtrlTestCase::Url()
748{
749 m_rich->BeginURL("http://www.wxwidgets.org");
750 m_rich->WriteText("http://www.wxwidgets.org");
751 m_rich->EndURL();
752
753 wxTextAttr url;
754 m_rich->GetStyle(5, url);
755
756 CPPUNIT_ASSERT(url.HasURL());
757 CPPUNIT_ASSERT_EQUAL("http://www.wxwidgets.org", url.GetURL());
758}
759
31be8400
JS
760 // Helper function for ::Table()
761wxRichTextTable* GetCurrentTableInstance(wxRichTextParagraph* para)
762{
763 wxRichTextTable* table = wxDynamicCast(para->FindObjectAtPosition(0), wxRichTextTable);
764 CPPUNIT_ASSERT(table);
765 return table;
766}
767
768void RichTextCtrlTestCase::Table()
769{
770 m_rich->BeginSuppressUndo();
771 wxRichTextTable* table = m_rich->WriteTable(1, 1);
772 m_rich->EndSuppressUndo();
773 CPPUNIT_ASSERT(table);
774 CPPUNIT_ASSERT(m_rich->CanUndo() == false);
775
776 // Run the tests twice: first for the original table, then for a contained one
777 for (int t = 0; t < 2; ++t)
65663456
VZ
778 {
779 size_t n; // FIXME-VC6: outside of the loops for VC6 only.
780
31be8400
JS
781 // Undo() and Redo() switch table instances, so invalidating 'table'
782 // The containing paragraph isn't altered, and so can be used to find the current object
783 wxRichTextParagraph* para = wxDynamicCast(table->GetParent(), wxRichTextParagraph);
784 CPPUNIT_ASSERT(para);
785
786 CPPUNIT_ASSERT(table->GetColumnCount() == 1);
787 CPPUNIT_ASSERT(table->GetRowCount() == 1);
788
789 // Test adding columns and rows
65663456 790 for (n = 0; n < 3; ++n)
31be8400
JS
791 {
792 m_rich->BeginBatchUndo("Add col and row");
793
794 table->AddColumns(0, 1);
795 table->AddRows(0, 1);
65663456 796
31be8400
JS
797 m_rich->EndBatchUndo();
798 }
799 CPPUNIT_ASSERT(table->GetColumnCount() == 4);
800 CPPUNIT_ASSERT(table->GetRowCount() == 4);
801
802 // Test deleting columns and rows
65663456 803 for (n = 0; n < 3; ++n)
31be8400
JS
804 {
805 m_rich->BeginBatchUndo("Delete col and row");
806
807 table->DeleteColumns(table->GetColumnCount() - 1, 1);
808 table->DeleteRows(table->GetRowCount() - 1, 1);
65663456 809
31be8400
JS
810 m_rich->EndBatchUndo();
811 }
812 CPPUNIT_ASSERT(table->GetColumnCount() == 1);
813 CPPUNIT_ASSERT(table->GetRowCount() == 1);
814
815 // Test undo, first of the deletions...
816 CPPUNIT_ASSERT(m_rich->CanUndo());
65663456 817 for (n = 0; n < 3; ++n)
31be8400
JS
818 {
819 m_rich->Undo();
820 }
821 table = GetCurrentTableInstance(para);
822 CPPUNIT_ASSERT(table->GetColumnCount() == 4);
823 CPPUNIT_ASSERT(table->GetRowCount() == 4);
824
825 // ...then the additions
65663456 826 for (n = 0; n < 3; ++n)
31be8400
JS
827 {
828 m_rich->Undo();
829 }
830 table = GetCurrentTableInstance(para);
831 CPPUNIT_ASSERT(table->GetColumnCount() == 1);
832 CPPUNIT_ASSERT(table->GetRowCount() == 1);
833 CPPUNIT_ASSERT(m_rich->CanUndo() == false);
834
835 // Similarly test redo. Additions:
836 CPPUNIT_ASSERT(m_rich->CanRedo());
65663456 837 for (n = 0; n < 3; ++n)
31be8400
JS
838 {
839 m_rich->Redo();
840 }
841 table = GetCurrentTableInstance(para);
842 CPPUNIT_ASSERT(table->GetColumnCount() == 4);
843 CPPUNIT_ASSERT(table->GetRowCount() == 4);
844
845 // Deletions:
65663456 846 for (n = 0; n < 3; ++n)
31be8400
JS
847 {
848 m_rich->Redo();
849 }
850 table = GetCurrentTableInstance(para);
851 CPPUNIT_ASSERT(table->GetColumnCount() == 1);
852 CPPUNIT_ASSERT(table->GetRowCount() == 1);
853 CPPUNIT_ASSERT(m_rich->CanRedo() == false);
854
855 // Now test multiple addition and deletion, and also suppression
856 m_rich->BeginSuppressUndo();
857 table->AddColumns(0, 3);
858 table->AddRows(0, 3);
859 CPPUNIT_ASSERT(table->GetColumnCount() == 4);
860 CPPUNIT_ASSERT(table->GetRowCount() == 4);
861
862 // Only delete 2 of these. This makes it easy to be sure we're dealing with the child table when we loop
863 table->DeleteColumns(0, 2);
864 table->DeleteRows(0, 2);
865 CPPUNIT_ASSERT(table->GetColumnCount() == 2);
866 CPPUNIT_ASSERT(table->GetRowCount() == 2);
867 m_rich->EndSuppressUndo();
65663456 868
31be8400
JS
869 m_rich->GetCommandProcessor()->ClearCommands(); // otherwise the command-history from this loop will cause CPPUNIT_ASSERT failures in the next one
870
871 if (t == 0)
872 {
873 // For round 2, re-run the tests on another table inside the last cell of the first one
874 wxRichTextCell* cell = table->GetCell(table->GetRowCount() - 1, table->GetColumnCount() - 1);
875 CPPUNIT_ASSERT(cell);
876 m_rich->SetFocusObject(cell);
877 m_rich->BeginSuppressUndo();
878 table = m_rich->WriteTable(1, 1);
879 m_rich->EndSuppressUndo();
880 CPPUNIT_ASSERT(table);
881 }
882 }
883
884 m_rich->Clear();
885 m_rich->SetFocusObject(NULL);
886}
887
232fdc63 888#endif //wxUSE_RICHTEXT