1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/richtextctrltest.cpp
3 // Purpose: wxRichTextCtrl unit test
4 // Author: Steven Lamerton
7 // Copyright: (c) 2010 Steven Lamerton
8 ///////////////////////////////////////////////////////////////////////////////
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"
28 class RichTextCtrlTestCase
: public CppUnit::TestCase
31 RichTextCtrlTestCase() { }
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
);
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
);
63 CPPUNIT_TEST( Delete
);
65 CPPUNIT_TEST( Table
);
66 CPPUNIT_TEST_SUITE_END();
68 void CharacterEvent();
72 void BufferResetEvent();
87 void ParagraphSpacing();
89 void NumberedBullet();
97 wxRichTextCtrl
* m_rich
;
99 DECLARE_NO_COPY_CLASS(RichTextCtrlTestCase
)
102 // register in the unnamed registry so that these tests are run by default
103 CPPUNIT_TEST_SUITE_REGISTRATION( RichTextCtrlTestCase
);
105 // also include in its own registry so that these tests can be run alone
106 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RichTextCtrlTestCase
, "RichTextCtrlTestCase" );
108 void RichTextCtrlTestCase::setUp()
110 m_rich
= new wxRichTextCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
111 wxDefaultPosition
, wxSize(400, 200), wxWANTS_CHARS
);
114 void RichTextCtrlTestCase::tearDown()
119 void RichTextCtrlTestCase::CharacterEvent()
121 #if wxUSE_UIACTIONSIMULATOR
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__)
126 EventCounter
character(m_rich
, wxEVT_RICHTEXT_CHARACTER
);
127 EventCounter
content(m_rich
, wxEVT_RICHTEXT_CONTENT_INSERTED
);
131 wxUIActionSimulator sim
;
135 CPPUNIT_ASSERT_EQUAL(6, character
.GetCount());
136 CPPUNIT_ASSERT_EQUAL(6, content
.GetCount());
141 //As these are not characters they shouldn't count
142 sim
.Char(WXK_RETURN
);
146 CPPUNIT_ASSERT_EQUAL(0, character
.GetCount());
147 CPPUNIT_ASSERT_EQUAL(1, content
.GetCount());
152 void RichTextCtrlTestCase::DeleteEvent()
154 #if wxUSE_UIACTIONSIMULATOR
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__)
158 EventCounter
deleteevent(m_rich
, wxEVT_RICHTEXT_DELETE
);
159 EventCounter
contentdelete(m_rich
, wxEVT_RICHTEXT_CONTENT_DELETED
);
163 wxUIActionSimulator sim
;
166 sim
.Char(WXK_DELETE
);
169 CPPUNIT_ASSERT_EQUAL(2, deleteevent
.GetCount());
170 //Only one as the delete doesn't delete anthing
171 CPPUNIT_ASSERT_EQUAL(1, contentdelete
.GetCount());
176 void RichTextCtrlTestCase::ReturnEvent()
178 #if wxUSE_UIACTIONSIMULATOR
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__)
182 EventCounter
returnevent(m_rich
, wxEVT_RICHTEXT_RETURN
);
186 wxUIActionSimulator sim
;
187 sim
.Char(WXK_RETURN
);
190 CPPUNIT_ASSERT_EQUAL(1, returnevent
.GetCount());
195 void RichTextCtrlTestCase::StyleEvent()
197 EventCounter
stylechanged(m_rich
, wxEVT_RICHTEXT_STYLE_CHANGED
);
199 m_rich
->SetValue("Sometext");
200 m_rich
->SetStyle(0, 8, wxTextAttr(*wxRED
, *wxWHITE
));
202 CPPUNIT_ASSERT_EQUAL(1, stylechanged
.GetCount());
205 void RichTextCtrlTestCase::BufferResetEvent()
207 EventCounter
reset(m_rich
, wxEVT_RICHTEXT_BUFFER_RESET
);
209 m_rich
->AppendText("more text!");
210 m_rich
->SetValue("");
212 CPPUNIT_ASSERT_EQUAL(1, reset
.GetCount());
215 m_rich
->AppendText("more text!");
218 CPPUNIT_ASSERT_EQUAL(1, reset
.GetCount());
222 //We expect a buffer reset here as setvalue clears the existing text
223 m_rich
->SetValue("replace");
224 CPPUNIT_ASSERT_EQUAL(1, reset
.GetCount());
227 void RichTextCtrlTestCase::UrlEvent()
229 #if wxUSE_UIACTIONSIMULATOR
230 // Mouse up event not being caught on GTK+
231 #if !defined(__WXGTK__)
232 EventCounter
url(m_rich
, wxEVT_TEXT_URL
);
234 m_rich
->BeginURL("http://www.wxwidgets.org");
235 m_rich
->WriteText("http://www.wxwidgets.org");
238 wxUIActionSimulator sim
;
239 sim
.MouseMove(m_rich
->ClientToScreen(wxPoint(10, 10)));
245 CPPUNIT_ASSERT_EQUAL(1, url
.GetCount());
250 void RichTextCtrlTestCase::TextEvent()
252 #if wxUSE_UIACTIONSIMULATOR
253 #if !defined(__WXGTK__)
254 EventCounter
updated(m_rich
, wxEVT_TEXT
);
258 wxUIActionSimulator sim
;
262 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich
->GetValue());
263 CPPUNIT_ASSERT_EQUAL(6, updated
.GetCount());
268 void RichTextCtrlTestCase::CutCopyPaste()
271 m_rich
->AppendText("sometext");
274 if(m_rich
->CanCut() && m_rich
->CanPaste())
277 CPPUNIT_ASSERT(m_rich
->IsEmpty());
282 CPPUNIT_ASSERT_EQUAL("sometext", m_rich
->GetValue());
287 if(m_rich
->CanCopy() && m_rich
->CanPaste())
291 CPPUNIT_ASSERT(m_rich
->IsEmpty());
296 CPPUNIT_ASSERT_EQUAL("sometext", m_rich
->GetValue());
301 void RichTextCtrlTestCase::UndoRedo()
303 m_rich
->AppendText("sometext");
305 CPPUNIT_ASSERT(m_rich
->CanUndo());
309 CPPUNIT_ASSERT(m_rich
->IsEmpty());
310 CPPUNIT_ASSERT(m_rich
->CanRedo());
314 CPPUNIT_ASSERT_EQUAL("sometext", m_rich
->GetValue());
316 m_rich
->AppendText("Batch undo");
319 //Also test batch operations
320 m_rich
->BeginBatchUndo("batchtest");
322 m_rich
->ApplyBoldToSelection();
323 m_rich
->ApplyItalicToSelection();
325 m_rich
->EndBatchUndo();
327 CPPUNIT_ASSERT(m_rich
->CanUndo());
331 CPPUNIT_ASSERT(!m_rich
->IsSelectionBold());
332 CPPUNIT_ASSERT(!m_rich
->IsSelectionItalics());
333 CPPUNIT_ASSERT(m_rich
->CanRedo());
337 CPPUNIT_ASSERT(m_rich
->IsSelectionBold());
338 CPPUNIT_ASSERT(m_rich
->IsSelectionItalics());
340 //And surpressing undo
341 m_rich
->BeginSuppressUndo();
343 m_rich
->AppendText("Can't undo this");
345 CPPUNIT_ASSERT(m_rich
->CanUndo());
347 m_rich
->EndSuppressUndo();
350 void RichTextCtrlTestCase::CaretPosition()
352 m_rich
->AddParagraph("This is paragraph one");
353 m_rich
->AddParagraph("Paragraph two\n has \nlots of\n lines");
355 m_rich
->SetInsertionPoint(2);
357 CPPUNIT_ASSERT_EQUAL(1, m_rich
->GetCaretPosition());
359 m_rich
->MoveToParagraphStart();
361 CPPUNIT_ASSERT_EQUAL(0, m_rich
->GetCaretPosition());
364 m_rich
->MoveRight(2);
368 CPPUNIT_ASSERT_EQUAL(2, m_rich
->GetCaretPosition());
370 m_rich
->MoveToParagraphEnd();
372 CPPUNIT_ASSERT_EQUAL(21, m_rich
->GetCaretPosition());
374 m_rich
->MoveToLineStart();
376 CPPUNIT_ASSERT_EQUAL(0, m_rich
->GetCaretPosition());
378 m_rich
->MoveToLineEnd();
380 CPPUNIT_ASSERT_EQUAL(21, m_rich
->GetCaretPosition());
383 void RichTextCtrlTestCase::Selection()
385 m_rich
->SetValue("some more text");
389 CPPUNIT_ASSERT_EQUAL("some more text", m_rich
->GetStringSelection());
391 m_rich
->SelectNone();
393 CPPUNIT_ASSERT_EQUAL("", m_rich
->GetStringSelection());
395 m_rich
->SelectWord(1);
397 CPPUNIT_ASSERT_EQUAL("some", m_rich
->GetStringSelection());
399 m_rich
->SetSelection(5, 14);
401 CPPUNIT_ASSERT_EQUAL("more text", m_rich
->GetStringSelection());
403 wxRichTextRange
range(5, 9);
405 m_rich
->SetSelectionRange(range
);
407 CPPUNIT_ASSERT_EQUAL("more", m_rich
->GetStringSelection());
410 void RichTextCtrlTestCase::Editable()
412 #if wxUSE_UIACTIONSIMULATOR
413 #if !defined(__WXGTK__)
414 EventCounter
updated(m_rich
, wxEVT_TEXT
);
418 wxUIActionSimulator sim
;
422 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich
->GetValue());
423 CPPUNIT_ASSERT_EQUAL(6, updated
.GetCount());
426 m_rich
->SetEditable(false);
430 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich
->GetValue());
431 CPPUNIT_ASSERT_EQUAL(0, updated
.GetCount());
436 void RichTextCtrlTestCase::Range()
438 wxRichTextRange
range(0, 10);
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));
445 wxRichTextRange
outside(12, 14);
447 CPPUNIT_ASSERT(outside
.IsOutside(range
));
449 wxRichTextRange
inside(6, 7);
451 CPPUNIT_ASSERT(inside
.IsWithin(range
));
453 range
.LimitTo(inside
);
455 CPPUNIT_ASSERT(inside
== range
);
456 CPPUNIT_ASSERT(inside
+ range
== outside
);
457 CPPUNIT_ASSERT(outside
- range
== inside
);
462 CPPUNIT_ASSERT_EQUAL(4, range
.GetStart());
463 CPPUNIT_ASSERT_EQUAL(6, range
.GetEnd());
464 CPPUNIT_ASSERT_EQUAL(3, range
.GetLength());
466 inside
.SetRange(6, 4);
469 CPPUNIT_ASSERT(inside
== range
);
472 void RichTextCtrlTestCase::Alignment()
474 m_rich
->SetValue("text to align");
477 m_rich
->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_RIGHT
);
479 CPPUNIT_ASSERT(m_rich
->IsSelectionAligned(wxTEXT_ALIGNMENT_RIGHT
));
481 m_rich
->BeginAlignment(wxTEXT_ALIGNMENT_CENTRE
);
482 m_rich
->AddParagraph("middle aligned");
483 m_rich
->EndAlignment();
485 m_rich
->SetSelection(20, 25);
487 CPPUNIT_ASSERT(m_rich
->IsSelectionAligned(wxTEXT_ALIGNMENT_CENTRE
));
490 void RichTextCtrlTestCase::Bold()
492 m_rich
->SetValue("text to bold");
494 m_rich
->ApplyBoldToSelection();
496 CPPUNIT_ASSERT(m_rich
->IsSelectionBold());
499 m_rich
->AddParagraph("bold paragraph");
501 m_rich
->AddParagraph("not bold paragraph");
503 m_rich
->SetSelection(15, 20);
505 CPPUNIT_ASSERT(m_rich
->IsSelectionBold());
507 m_rich
->SetSelection(30, 35);
509 CPPUNIT_ASSERT(!m_rich
->IsSelectionBold());
512 void RichTextCtrlTestCase::Italic()
514 m_rich
->SetValue("text to italic");
516 m_rich
->ApplyItalicToSelection();
518 CPPUNIT_ASSERT(m_rich
->IsSelectionItalics());
520 m_rich
->BeginItalic();
521 m_rich
->AddParagraph("italic paragraph");
523 m_rich
->AddParagraph("not italic paragraph");
525 m_rich
->SetSelection(20, 25);
527 CPPUNIT_ASSERT(m_rich
->IsSelectionItalics());
529 m_rich
->SetSelection(35, 40);
531 CPPUNIT_ASSERT(!m_rich
->IsSelectionItalics());
534 void RichTextCtrlTestCase::Underline()
536 m_rich
->SetValue("text to underline");
538 m_rich
->ApplyUnderlineToSelection();
540 CPPUNIT_ASSERT(m_rich
->IsSelectionUnderlined());
542 m_rich
->BeginUnderline();
543 m_rich
->AddParagraph("underline paragraph");
544 m_rich
->EndUnderline();
545 m_rich
->AddParagraph("not underline paragraph");
547 m_rich
->SetSelection(20, 25);
549 CPPUNIT_ASSERT(m_rich
->IsSelectionUnderlined());
551 m_rich
->SetSelection(40, 45);
553 CPPUNIT_ASSERT(!m_rich
->IsSelectionUnderlined());
556 void RichTextCtrlTestCase::Indent()
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");
566 m_rich
->GetStyle(5, indent
);
568 CPPUNIT_ASSERT_EQUAL(12, indent
.GetLeftIndent());
569 CPPUNIT_ASSERT_EQUAL(-5, indent
.GetLeftSubIndent());
570 CPPUNIT_ASSERT_EQUAL(14, indent
.GetRightIndent());
572 m_rich
->GetStyle(35, indent
);
574 CPPUNIT_ASSERT_EQUAL(0, indent
.GetLeftIndent());
575 CPPUNIT_ASSERT_EQUAL(0, indent
.GetLeftSubIndent());
576 CPPUNIT_ASSERT_EQUAL(0, indent
.GetRightIndent());
579 void RichTextCtrlTestCase::LineSpacing()
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");
590 m_rich
->GetStyle(5, spacing
);
592 CPPUNIT_ASSERT_EQUAL(20, spacing
.GetLineSpacing());
594 m_rich
->GetStyle(20, spacing
);
596 CPPUNIT_ASSERT_EQUAL(15, spacing
.GetLineSpacing());
598 m_rich
->GetStyle(30, spacing
);
600 CPPUNIT_ASSERT_EQUAL(10, spacing
.GetLineSpacing());
603 void RichTextCtrlTestCase::ParagraphSpacing()
605 m_rich
->BeginParagraphSpacing(15, 20);
606 m_rich
->AddParagraph("spaced paragraph");
607 m_rich
->EndParagraphSpacing();
608 m_rich
->AddParagraph("non-spaced paragraph");
611 m_rich
->GetStyle(5, spacing
);
613 CPPUNIT_ASSERT_EQUAL(15, spacing
.GetParagraphSpacingBefore());
614 CPPUNIT_ASSERT_EQUAL(20, spacing
.GetParagraphSpacingAfter());
616 m_rich
->GetStyle(25, spacing
);
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());
625 void RichTextCtrlTestCase::TextColour()
627 m_rich
->BeginTextColour(*wxRED
);
628 m_rich
->AddParagraph("red paragraph");
629 m_rich
->EndTextColour();
630 m_rich
->AddParagraph("default paragraph");
633 m_rich
->GetStyle(5, colour
);
635 CPPUNIT_ASSERT_EQUAL(*wxRED
, colour
.GetTextColour());
637 m_rich
->GetStyle(25, colour
);
639 CPPUNIT_ASSERT_EQUAL(m_rich
->GetBasicStyle().GetTextColour(),
640 colour
.GetTextColour());
643 void RichTextCtrlTestCase::NumberedBullet()
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();
653 m_rich
->GetStyle(5, bullet
);
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());
661 m_rich
->GetStyle(15, bullet
);
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());
670 void RichTextCtrlTestCase::SymbolBullet()
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();
680 m_rich
->GetStyle(5, bullet
);
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());
688 m_rich
->GetStyle(15, bullet
);
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());
697 void RichTextCtrlTestCase::FontSize()
699 m_rich
->BeginFontSize(24);
700 m_rich
->AddParagraph("Large text");
701 m_rich
->EndFontSize();
704 m_rich
->GetStyle(5, size
);
706 CPPUNIT_ASSERT(size
.HasFontSize());
707 CPPUNIT_ASSERT_EQUAL(24, size
.GetFontSize());
710 void RichTextCtrlTestCase::Font()
712 wxFont
font(14, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
);
713 m_rich
->BeginFont(font
);
714 m_rich
->AddParagraph("paragraph with font");
717 wxTextAttr fontstyle
;
718 m_rich
->GetStyle(5, fontstyle
);
720 CPPUNIT_ASSERT_EQUAL(font
, fontstyle
.GetFont());
723 void RichTextCtrlTestCase::Delete()
725 m_rich
->AddParagraph("here is a long long line in a paragraph");
726 m_rich
->SetSelection(0, 6);
728 CPPUNIT_ASSERT(m_rich
->CanDeleteSelection());
730 m_rich
->DeleteSelection();
732 CPPUNIT_ASSERT_EQUAL("is a long long line in a paragraph", m_rich
->GetValue());
734 m_rich
->SetSelection(0, 5);
736 CPPUNIT_ASSERT(m_rich
->CanDeleteSelection());
738 m_rich
->DeleteSelectedContent();
740 CPPUNIT_ASSERT_EQUAL("long long line in a paragraph", m_rich
->GetValue());
742 m_rich
->Delete(wxRichTextRange(14, 29));
744 CPPUNIT_ASSERT_EQUAL("long long line", m_rich
->GetValue());
747 void RichTextCtrlTestCase::Url()
749 m_rich
->BeginURL("http://www.wxwidgets.org");
750 m_rich
->WriteText("http://www.wxwidgets.org");
754 m_rich
->GetStyle(5, url
);
756 CPPUNIT_ASSERT(url
.HasURL());
757 CPPUNIT_ASSERT_EQUAL("http://www.wxwidgets.org", url
.GetURL());
760 // Helper function for ::Table()
761 wxRichTextTable
* GetCurrentTableInstance(wxRichTextParagraph
* para
)
763 wxRichTextTable
* table
= wxDynamicCast(para
->FindObjectAtPosition(0), wxRichTextTable
);
764 CPPUNIT_ASSERT(table
);
768 void RichTextCtrlTestCase::Table()
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);
776 // Run the tests twice: first for the original table, then for a contained one
777 for (int t
= 0; t
< 2; ++t
)
779 size_t n
; // FIXME-VC6: outside of the loops for VC6 only.
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
);
786 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
787 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
789 // Test adding columns and rows
790 for (n
= 0; n
< 3; ++n
)
792 m_rich
->BeginBatchUndo("Add col and row");
794 table
->AddColumns(0, 1);
795 table
->AddRows(0, 1);
797 m_rich
->EndBatchUndo();
799 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
800 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
802 // Test deleting columns and rows
803 for (n
= 0; n
< 3; ++n
)
805 m_rich
->BeginBatchUndo("Delete col and row");
807 table
->DeleteColumns(table
->GetColumnCount() - 1, 1);
808 table
->DeleteRows(table
->GetRowCount() - 1, 1);
810 m_rich
->EndBatchUndo();
812 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
813 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
815 // Test undo, first of the deletions...
816 CPPUNIT_ASSERT(m_rich
->CanUndo());
817 for (n
= 0; n
< 3; ++n
)
821 table
= GetCurrentTableInstance(para
);
822 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
823 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
825 // ...then the additions
826 for (n
= 0; n
< 3; ++n
)
830 table
= GetCurrentTableInstance(para
);
831 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
832 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
833 CPPUNIT_ASSERT(m_rich
->CanUndo() == false);
835 // Similarly test redo. Additions:
836 CPPUNIT_ASSERT(m_rich
->CanRedo());
837 for (n
= 0; n
< 3; ++n
)
841 table
= GetCurrentTableInstance(para
);
842 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
843 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
846 for (n
= 0; n
< 3; ++n
)
850 table
= GetCurrentTableInstance(para
);
851 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
852 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
853 CPPUNIT_ASSERT(m_rich
->CanRedo() == false);
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);
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();
869 m_rich
->GetCommandProcessor()->ClearCommands(); // otherwise the command-history from this loop will cause CPPUNIT_ASSERT failures in the next one
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
);
885 m_rich
->SetFocusObject(NULL
);
888 #endif //wxUSE_RICHTEXT