1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/controls/richtextctrltest.cpp
3 // Purpose: wxRichTextCtrl unit test
4 // Author: Steven Lamerton
6 // Copyright: (c) 2010 Steven Lamerton
7 ///////////////////////////////////////////////////////////////////////////////
21 #include "wx/richtext/richtextctrl.h"
22 #include "wx/richtext/richtextstyles.h"
23 #include "testableframe.h"
24 #include "asserthelper.h"
25 #include "wx/uiaction.h"
27 class RichTextCtrlTestCase
: public CppUnit::TestCase
30 RichTextCtrlTestCase() { }
36 CPPUNIT_TEST_SUITE( RichTextCtrlTestCase
);
37 WXUISIM_TEST( CharacterEvent
);
38 WXUISIM_TEST( DeleteEvent
);
39 WXUISIM_TEST( ReturnEvent
);
40 CPPUNIT_TEST( StyleEvent
);
41 CPPUNIT_TEST( BufferResetEvent
);
42 WXUISIM_TEST( UrlEvent
);
43 WXUISIM_TEST( TextEvent
);
44 CPPUNIT_TEST( CutCopyPaste
);
45 CPPUNIT_TEST( UndoRedo
);
46 CPPUNIT_TEST( CaretPosition
);
47 CPPUNIT_TEST( Selection
);
48 WXUISIM_TEST( Editable
);
49 CPPUNIT_TEST( Range
);
50 CPPUNIT_TEST( Alignment
);
52 CPPUNIT_TEST( Italic
);
53 CPPUNIT_TEST( Underline
);
54 CPPUNIT_TEST( Indent
);
55 CPPUNIT_TEST( LineSpacing
);
56 CPPUNIT_TEST( ParagraphSpacing
);
57 CPPUNIT_TEST( TextColour
);
58 CPPUNIT_TEST( NumberedBullet
);
59 CPPUNIT_TEST( SymbolBullet
);
60 CPPUNIT_TEST( FontSize
);
62 CPPUNIT_TEST( Delete
);
64 CPPUNIT_TEST( Table
);
65 CPPUNIT_TEST_SUITE_END();
67 void CharacterEvent();
71 void BufferResetEvent();
86 void ParagraphSpacing();
88 void NumberedBullet();
96 wxRichTextCtrl
* m_rich
;
98 DECLARE_NO_COPY_CLASS(RichTextCtrlTestCase
)
101 // register in the unnamed registry so that these tests are run by default
102 CPPUNIT_TEST_SUITE_REGISTRATION( RichTextCtrlTestCase
);
104 // also include in its own registry so that these tests can be run alone
105 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RichTextCtrlTestCase
, "RichTextCtrlTestCase" );
107 void RichTextCtrlTestCase::setUp()
109 m_rich
= new wxRichTextCtrl(wxTheApp
->GetTopWindow(), wxID_ANY
, "",
110 wxDefaultPosition
, wxSize(400, 200), wxWANTS_CHARS
);
113 void RichTextCtrlTestCase::tearDown()
118 void RichTextCtrlTestCase::CharacterEvent()
120 #if wxUSE_UIACTIONSIMULATOR
122 // There seems to be an event sequence problem on GTK+ that causes the events
123 // to be disconnected before they're processed, generating spurious errors.
124 #if !defined(__WXGTK__)
125 EventCounter
character(m_rich
, wxEVT_RICHTEXT_CHARACTER
);
126 EventCounter
content(m_rich
, wxEVT_RICHTEXT_CONTENT_INSERTED
);
130 wxUIActionSimulator sim
;
134 CPPUNIT_ASSERT_EQUAL(6, character
.GetCount());
135 CPPUNIT_ASSERT_EQUAL(6, content
.GetCount());
140 //As these are not characters they shouldn't count
141 sim
.Char(WXK_RETURN
);
145 CPPUNIT_ASSERT_EQUAL(0, character
.GetCount());
146 CPPUNIT_ASSERT_EQUAL(1, content
.GetCount());
151 void RichTextCtrlTestCase::DeleteEvent()
153 #if wxUSE_UIACTIONSIMULATOR
154 // There seems to be an event sequence problem on GTK+ that causes the events
155 // to be disconnected before they're processed, generating spurious errors.
156 #if !defined(__WXGTK__)
157 EventCounter
deleteevent(m_rich
, wxEVT_RICHTEXT_DELETE
);
158 EventCounter
contentdelete(m_rich
, wxEVT_RICHTEXT_CONTENT_DELETED
);
162 wxUIActionSimulator sim
;
165 sim
.Char(WXK_DELETE
);
168 CPPUNIT_ASSERT_EQUAL(2, deleteevent
.GetCount());
169 //Only one as the delete doesn't delete anthing
170 CPPUNIT_ASSERT_EQUAL(1, contentdelete
.GetCount());
175 void RichTextCtrlTestCase::ReturnEvent()
177 #if wxUSE_UIACTIONSIMULATOR
178 // There seems to be an event sequence problem on GTK+ that causes the events
179 // to be disconnected before they're processed, generating spurious errors.
180 #if !defined(__WXGTK__)
181 EventCounter
returnevent(m_rich
, wxEVT_RICHTEXT_RETURN
);
185 wxUIActionSimulator sim
;
186 sim
.Char(WXK_RETURN
);
189 CPPUNIT_ASSERT_EQUAL(1, returnevent
.GetCount());
194 void RichTextCtrlTestCase::StyleEvent()
196 EventCounter
stylechanged(m_rich
, wxEVT_RICHTEXT_STYLE_CHANGED
);
198 m_rich
->SetValue("Sometext");
199 m_rich
->SetStyle(0, 8, wxTextAttr(*wxRED
, *wxWHITE
));
201 CPPUNIT_ASSERT_EQUAL(1, stylechanged
.GetCount());
204 void RichTextCtrlTestCase::BufferResetEvent()
206 EventCounter
reset(m_rich
, wxEVT_RICHTEXT_BUFFER_RESET
);
208 m_rich
->AppendText("more text!");
209 m_rich
->SetValue("");
211 CPPUNIT_ASSERT_EQUAL(1, reset
.GetCount());
214 m_rich
->AppendText("more text!");
217 CPPUNIT_ASSERT_EQUAL(1, reset
.GetCount());
221 //We expect a buffer reset here as setvalue clears the existing text
222 m_rich
->SetValue("replace");
223 CPPUNIT_ASSERT_EQUAL(1, reset
.GetCount());
226 void RichTextCtrlTestCase::UrlEvent()
228 #if wxUSE_UIACTIONSIMULATOR
229 // Mouse up event not being caught on GTK+
230 #if !defined(__WXGTK__)
231 EventCounter
url(m_rich
, wxEVT_TEXT_URL
);
233 m_rich
->BeginURL("http://www.wxwidgets.org");
234 m_rich
->WriteText("http://www.wxwidgets.org");
237 wxUIActionSimulator sim
;
238 sim
.MouseMove(m_rich
->ClientToScreen(wxPoint(10, 10)));
244 CPPUNIT_ASSERT_EQUAL(1, url
.GetCount());
249 void RichTextCtrlTestCase::TextEvent()
251 #if wxUSE_UIACTIONSIMULATOR
252 #if !defined(__WXGTK__)
253 EventCounter
updated(m_rich
, wxEVT_TEXT
);
257 wxUIActionSimulator sim
;
261 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich
->GetValue());
262 CPPUNIT_ASSERT_EQUAL(6, updated
.GetCount());
267 void RichTextCtrlTestCase::CutCopyPaste()
270 m_rich
->AppendText("sometext");
273 if(m_rich
->CanCut() && m_rich
->CanPaste())
276 CPPUNIT_ASSERT(m_rich
->IsEmpty());
281 CPPUNIT_ASSERT_EQUAL("sometext", m_rich
->GetValue());
286 if(m_rich
->CanCopy() && m_rich
->CanPaste())
290 CPPUNIT_ASSERT(m_rich
->IsEmpty());
295 CPPUNIT_ASSERT_EQUAL("sometext", m_rich
->GetValue());
300 void RichTextCtrlTestCase::UndoRedo()
302 m_rich
->AppendText("sometext");
304 CPPUNIT_ASSERT(m_rich
->CanUndo());
308 CPPUNIT_ASSERT(m_rich
->IsEmpty());
309 CPPUNIT_ASSERT(m_rich
->CanRedo());
313 CPPUNIT_ASSERT_EQUAL("sometext", m_rich
->GetValue());
315 m_rich
->AppendText("Batch undo");
318 //Also test batch operations
319 m_rich
->BeginBatchUndo("batchtest");
321 m_rich
->ApplyBoldToSelection();
322 m_rich
->ApplyItalicToSelection();
324 m_rich
->EndBatchUndo();
326 CPPUNIT_ASSERT(m_rich
->CanUndo());
330 CPPUNIT_ASSERT(!m_rich
->IsSelectionBold());
331 CPPUNIT_ASSERT(!m_rich
->IsSelectionItalics());
332 CPPUNIT_ASSERT(m_rich
->CanRedo());
336 CPPUNIT_ASSERT(m_rich
->IsSelectionBold());
337 CPPUNIT_ASSERT(m_rich
->IsSelectionItalics());
339 //And surpressing undo
340 m_rich
->BeginSuppressUndo();
342 m_rich
->AppendText("Can't undo this");
344 CPPUNIT_ASSERT(m_rich
->CanUndo());
346 m_rich
->EndSuppressUndo();
349 void RichTextCtrlTestCase::CaretPosition()
351 m_rich
->AddParagraph("This is paragraph one");
352 m_rich
->AddParagraph("Paragraph two\n has \nlots of\n lines");
354 m_rich
->SetInsertionPoint(2);
356 CPPUNIT_ASSERT_EQUAL(1, m_rich
->GetCaretPosition());
358 m_rich
->MoveToParagraphStart();
360 CPPUNIT_ASSERT_EQUAL(0, m_rich
->GetCaretPosition());
363 m_rich
->MoveRight(2);
367 CPPUNIT_ASSERT_EQUAL(2, m_rich
->GetCaretPosition());
369 m_rich
->MoveToParagraphEnd();
371 CPPUNIT_ASSERT_EQUAL(21, m_rich
->GetCaretPosition());
373 m_rich
->MoveToLineStart();
375 CPPUNIT_ASSERT_EQUAL(0, m_rich
->GetCaretPosition());
377 m_rich
->MoveToLineEnd();
379 CPPUNIT_ASSERT_EQUAL(21, m_rich
->GetCaretPosition());
382 void RichTextCtrlTestCase::Selection()
384 m_rich
->SetValue("some more text");
388 CPPUNIT_ASSERT_EQUAL("some more text", m_rich
->GetStringSelection());
390 m_rich
->SelectNone();
392 CPPUNIT_ASSERT_EQUAL("", m_rich
->GetStringSelection());
394 m_rich
->SelectWord(1);
396 CPPUNIT_ASSERT_EQUAL("some", m_rich
->GetStringSelection());
398 m_rich
->SetSelection(5, 14);
400 CPPUNIT_ASSERT_EQUAL("more text", m_rich
->GetStringSelection());
402 wxRichTextRange
range(5, 9);
404 m_rich
->SetSelectionRange(range
);
406 CPPUNIT_ASSERT_EQUAL("more", m_rich
->GetStringSelection());
409 void RichTextCtrlTestCase::Editable()
411 #if wxUSE_UIACTIONSIMULATOR
412 #if !defined(__WXGTK__)
413 EventCounter
updated(m_rich
, wxEVT_TEXT
);
417 wxUIActionSimulator sim
;
421 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich
->GetValue());
422 CPPUNIT_ASSERT_EQUAL(6, updated
.GetCount());
425 m_rich
->SetEditable(false);
429 CPPUNIT_ASSERT_EQUAL("abcdef", m_rich
->GetValue());
430 CPPUNIT_ASSERT_EQUAL(0, updated
.GetCount());
435 void RichTextCtrlTestCase::Range()
437 wxRichTextRange
range(0, 10);
439 CPPUNIT_ASSERT_EQUAL(0, range
.GetStart());
440 CPPUNIT_ASSERT_EQUAL(10, range
.GetEnd());
441 CPPUNIT_ASSERT_EQUAL(11, range
.GetLength());
442 CPPUNIT_ASSERT(range
.Contains(5));
444 wxRichTextRange
outside(12, 14);
446 CPPUNIT_ASSERT(outside
.IsOutside(range
));
448 wxRichTextRange
inside(6, 7);
450 CPPUNIT_ASSERT(inside
.IsWithin(range
));
452 range
.LimitTo(inside
);
454 CPPUNIT_ASSERT(inside
== range
);
455 CPPUNIT_ASSERT(inside
+ range
== outside
);
456 CPPUNIT_ASSERT(outside
- range
== inside
);
461 CPPUNIT_ASSERT_EQUAL(4, range
.GetStart());
462 CPPUNIT_ASSERT_EQUAL(6, range
.GetEnd());
463 CPPUNIT_ASSERT_EQUAL(3, range
.GetLength());
465 inside
.SetRange(6, 4);
468 CPPUNIT_ASSERT(inside
== range
);
471 void RichTextCtrlTestCase::Alignment()
473 m_rich
->SetValue("text to align");
476 m_rich
->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_RIGHT
);
478 CPPUNIT_ASSERT(m_rich
->IsSelectionAligned(wxTEXT_ALIGNMENT_RIGHT
));
480 m_rich
->BeginAlignment(wxTEXT_ALIGNMENT_CENTRE
);
481 m_rich
->AddParagraph("middle aligned");
482 m_rich
->EndAlignment();
484 m_rich
->SetSelection(20, 25);
486 CPPUNIT_ASSERT(m_rich
->IsSelectionAligned(wxTEXT_ALIGNMENT_CENTRE
));
489 void RichTextCtrlTestCase::Bold()
491 m_rich
->SetValue("text to bold");
493 m_rich
->ApplyBoldToSelection();
495 CPPUNIT_ASSERT(m_rich
->IsSelectionBold());
498 m_rich
->AddParagraph("bold paragraph");
500 m_rich
->AddParagraph("not bold paragraph");
502 m_rich
->SetSelection(15, 20);
504 CPPUNIT_ASSERT(m_rich
->IsSelectionBold());
506 m_rich
->SetSelection(30, 35);
508 CPPUNIT_ASSERT(!m_rich
->IsSelectionBold());
511 void RichTextCtrlTestCase::Italic()
513 m_rich
->SetValue("text to italic");
515 m_rich
->ApplyItalicToSelection();
517 CPPUNIT_ASSERT(m_rich
->IsSelectionItalics());
519 m_rich
->BeginItalic();
520 m_rich
->AddParagraph("italic paragraph");
522 m_rich
->AddParagraph("not italic paragraph");
524 m_rich
->SetSelection(20, 25);
526 CPPUNIT_ASSERT(m_rich
->IsSelectionItalics());
528 m_rich
->SetSelection(35, 40);
530 CPPUNIT_ASSERT(!m_rich
->IsSelectionItalics());
533 void RichTextCtrlTestCase::Underline()
535 m_rich
->SetValue("text to underline");
537 m_rich
->ApplyUnderlineToSelection();
539 CPPUNIT_ASSERT(m_rich
->IsSelectionUnderlined());
541 m_rich
->BeginUnderline();
542 m_rich
->AddParagraph("underline paragraph");
543 m_rich
->EndUnderline();
544 m_rich
->AddParagraph("not underline paragraph");
546 m_rich
->SetSelection(20, 25);
548 CPPUNIT_ASSERT(m_rich
->IsSelectionUnderlined());
550 m_rich
->SetSelection(40, 45);
552 CPPUNIT_ASSERT(!m_rich
->IsSelectionUnderlined());
555 void RichTextCtrlTestCase::Indent()
557 m_rich
->BeginLeftIndent(12, -5);
558 m_rich
->BeginRightIndent(14);
559 m_rich
->AddParagraph("A paragraph with indents");
560 m_rich
->EndLeftIndent();
561 m_rich
->EndRightIndent();
562 m_rich
->AddParagraph("No more indent");
565 m_rich
->GetStyle(5, indent
);
567 CPPUNIT_ASSERT_EQUAL(12, indent
.GetLeftIndent());
568 CPPUNIT_ASSERT_EQUAL(-5, indent
.GetLeftSubIndent());
569 CPPUNIT_ASSERT_EQUAL(14, indent
.GetRightIndent());
571 m_rich
->GetStyle(35, indent
);
573 CPPUNIT_ASSERT_EQUAL(0, indent
.GetLeftIndent());
574 CPPUNIT_ASSERT_EQUAL(0, indent
.GetLeftSubIndent());
575 CPPUNIT_ASSERT_EQUAL(0, indent
.GetRightIndent());
578 void RichTextCtrlTestCase::LineSpacing()
580 m_rich
->BeginLineSpacing(20);
581 m_rich
->AddParagraph("double spaced");
582 m_rich
->EndLineSpacing();
583 m_rich
->BeginLineSpacing(wxTEXT_ATTR_LINE_SPACING_HALF
);
584 m_rich
->AddParagraph("1.5 spaced");
585 m_rich
->EndLineSpacing();
586 m_rich
->AddParagraph("normally spaced");
589 m_rich
->GetStyle(5, spacing
);
591 CPPUNIT_ASSERT_EQUAL(20, spacing
.GetLineSpacing());
593 m_rich
->GetStyle(20, spacing
);
595 CPPUNIT_ASSERT_EQUAL(15, spacing
.GetLineSpacing());
597 m_rich
->GetStyle(30, spacing
);
599 CPPUNIT_ASSERT_EQUAL(10, spacing
.GetLineSpacing());
602 void RichTextCtrlTestCase::ParagraphSpacing()
604 m_rich
->BeginParagraphSpacing(15, 20);
605 m_rich
->AddParagraph("spaced paragraph");
606 m_rich
->EndParagraphSpacing();
607 m_rich
->AddParagraph("non-spaced paragraph");
610 m_rich
->GetStyle(5, spacing
);
612 CPPUNIT_ASSERT_EQUAL(15, spacing
.GetParagraphSpacingBefore());
613 CPPUNIT_ASSERT_EQUAL(20, spacing
.GetParagraphSpacingAfter());
615 m_rich
->GetStyle(25, spacing
);
617 //Make sure we test against the defaults
618 CPPUNIT_ASSERT_EQUAL(m_rich
->GetBasicStyle().GetParagraphSpacingBefore(),
619 spacing
.GetParagraphSpacingBefore());
620 CPPUNIT_ASSERT_EQUAL(m_rich
->GetBasicStyle().GetParagraphSpacingAfter(),
621 spacing
.GetParagraphSpacingAfter());
624 void RichTextCtrlTestCase::TextColour()
626 m_rich
->BeginTextColour(*wxRED
);
627 m_rich
->AddParagraph("red paragraph");
628 m_rich
->EndTextColour();
629 m_rich
->AddParagraph("default paragraph");
632 m_rich
->GetStyle(5, colour
);
634 CPPUNIT_ASSERT_EQUAL(*wxRED
, colour
.GetTextColour());
636 m_rich
->GetStyle(25, colour
);
638 CPPUNIT_ASSERT_EQUAL(m_rich
->GetBasicStyle().GetTextColour(),
639 colour
.GetTextColour());
642 void RichTextCtrlTestCase::NumberedBullet()
644 m_rich
->BeginNumberedBullet(1, 15, 20);
645 m_rich
->AddParagraph("bullet one");
646 m_rich
->EndNumberedBullet();
647 m_rich
->BeginNumberedBullet(2, 25, -5);
648 m_rich
->AddParagraph("bullet two");
649 m_rich
->EndNumberedBullet();
652 m_rich
->GetStyle(5, bullet
);
654 CPPUNIT_ASSERT(bullet
.HasBulletStyle());
655 CPPUNIT_ASSERT(bullet
.HasBulletNumber());
656 CPPUNIT_ASSERT_EQUAL(1, bullet
.GetBulletNumber());
657 CPPUNIT_ASSERT_EQUAL(15, bullet
.GetLeftIndent());
658 CPPUNIT_ASSERT_EQUAL(20, bullet
.GetLeftSubIndent());
660 m_rich
->GetStyle(15, bullet
);
662 CPPUNIT_ASSERT(bullet
.HasBulletStyle());
663 CPPUNIT_ASSERT(bullet
.HasBulletNumber());
664 CPPUNIT_ASSERT_EQUAL(2, bullet
.GetBulletNumber());
665 CPPUNIT_ASSERT_EQUAL(25, bullet
.GetLeftIndent());
666 CPPUNIT_ASSERT_EQUAL(-5, bullet
.GetLeftSubIndent());
669 void RichTextCtrlTestCase::SymbolBullet()
671 m_rich
->BeginSymbolBullet("*", 15, 20);
672 m_rich
->AddParagraph("bullet one");
673 m_rich
->EndSymbolBullet();
674 m_rich
->BeginSymbolBullet("%", 25, -5);
675 m_rich
->AddParagraph("bullet two");
676 m_rich
->EndSymbolBullet();
679 m_rich
->GetStyle(5, bullet
);
681 CPPUNIT_ASSERT(bullet
.HasBulletStyle());
682 CPPUNIT_ASSERT(bullet
.HasBulletText());
683 CPPUNIT_ASSERT_EQUAL("*", bullet
.GetBulletText());
684 CPPUNIT_ASSERT_EQUAL(15, bullet
.GetLeftIndent());
685 CPPUNIT_ASSERT_EQUAL(20, bullet
.GetLeftSubIndent());
687 m_rich
->GetStyle(15, bullet
);
689 CPPUNIT_ASSERT(bullet
.HasBulletStyle());
690 CPPUNIT_ASSERT(bullet
.HasBulletText());
691 CPPUNIT_ASSERT_EQUAL("%", bullet
.GetBulletText());
692 CPPUNIT_ASSERT_EQUAL(25, bullet
.GetLeftIndent());
693 CPPUNIT_ASSERT_EQUAL(-5, bullet
.GetLeftSubIndent());
696 void RichTextCtrlTestCase::FontSize()
698 m_rich
->BeginFontSize(24);
699 m_rich
->AddParagraph("Large text");
700 m_rich
->EndFontSize();
703 m_rich
->GetStyle(5, size
);
705 CPPUNIT_ASSERT(size
.HasFontSize());
706 CPPUNIT_ASSERT_EQUAL(24, size
.GetFontSize());
709 void RichTextCtrlTestCase::Font()
711 wxFont
font(14, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
, wxFONTWEIGHT_NORMAL
);
712 m_rich
->BeginFont(font
);
713 m_rich
->AddParagraph("paragraph with font");
716 wxTextAttr fontstyle
;
717 m_rich
->GetStyle(5, fontstyle
);
719 CPPUNIT_ASSERT_EQUAL(font
, fontstyle
.GetFont());
722 void RichTextCtrlTestCase::Delete()
724 m_rich
->AddParagraph("here is a long long line in a paragraph");
725 m_rich
->SetSelection(0, 6);
727 CPPUNIT_ASSERT(m_rich
->CanDeleteSelection());
729 m_rich
->DeleteSelection();
731 CPPUNIT_ASSERT_EQUAL("is a long long line in a paragraph", m_rich
->GetValue());
733 m_rich
->SetSelection(0, 5);
735 CPPUNIT_ASSERT(m_rich
->CanDeleteSelection());
737 m_rich
->DeleteSelectedContent();
739 CPPUNIT_ASSERT_EQUAL("long long line in a paragraph", m_rich
->GetValue());
741 m_rich
->Delete(wxRichTextRange(14, 29));
743 CPPUNIT_ASSERT_EQUAL("long long line", m_rich
->GetValue());
746 void RichTextCtrlTestCase::Url()
748 m_rich
->BeginURL("http://www.wxwidgets.org");
749 m_rich
->WriteText("http://www.wxwidgets.org");
753 m_rich
->GetStyle(5, url
);
755 CPPUNIT_ASSERT(url
.HasURL());
756 CPPUNIT_ASSERT_EQUAL("http://www.wxwidgets.org", url
.GetURL());
759 // Helper function for ::Table()
760 wxRichTextTable
* GetCurrentTableInstance(wxRichTextParagraph
* para
)
762 wxRichTextTable
* table
= wxDynamicCast(para
->FindObjectAtPosition(0), wxRichTextTable
);
763 CPPUNIT_ASSERT(table
);
767 void RichTextCtrlTestCase::Table()
769 m_rich
->BeginSuppressUndo();
770 wxRichTextTable
* table
= m_rich
->WriteTable(1, 1);
771 m_rich
->EndSuppressUndo();
772 CPPUNIT_ASSERT(table
);
773 CPPUNIT_ASSERT(m_rich
->CanUndo() == false);
775 // Run the tests twice: first for the original table, then for a contained one
776 for (int t
= 0; t
< 2; ++t
)
778 size_t n
; // FIXME-VC6: outside of the loops for VC6 only.
780 // Undo() and Redo() switch table instances, so invalidating 'table'
781 // The containing paragraph isn't altered, and so can be used to find the current object
782 wxRichTextParagraph
* para
= wxDynamicCast(table
->GetParent(), wxRichTextParagraph
);
783 CPPUNIT_ASSERT(para
);
785 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
786 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
788 // Test adding columns and rows
789 for (n
= 0; n
< 3; ++n
)
791 m_rich
->BeginBatchUndo("Add col and row");
793 table
->AddColumns(0, 1);
794 table
->AddRows(0, 1);
796 m_rich
->EndBatchUndo();
798 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
799 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
801 // Test deleting columns and rows
802 for (n
= 0; n
< 3; ++n
)
804 m_rich
->BeginBatchUndo("Delete col and row");
806 table
->DeleteColumns(table
->GetColumnCount() - 1, 1);
807 table
->DeleteRows(table
->GetRowCount() - 1, 1);
809 m_rich
->EndBatchUndo();
811 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
812 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
814 // Test undo, first of the deletions...
815 CPPUNIT_ASSERT(m_rich
->CanUndo());
816 for (n
= 0; n
< 3; ++n
)
820 table
= GetCurrentTableInstance(para
);
821 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
822 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
824 // ...then the additions
825 for (n
= 0; n
< 3; ++n
)
829 table
= GetCurrentTableInstance(para
);
830 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
831 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
832 CPPUNIT_ASSERT(m_rich
->CanUndo() == false);
834 // Similarly test redo. Additions:
835 CPPUNIT_ASSERT(m_rich
->CanRedo());
836 for (n
= 0; n
< 3; ++n
)
840 table
= GetCurrentTableInstance(para
);
841 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
842 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
845 for (n
= 0; n
< 3; ++n
)
849 table
= GetCurrentTableInstance(para
);
850 CPPUNIT_ASSERT(table
->GetColumnCount() == 1);
851 CPPUNIT_ASSERT(table
->GetRowCount() == 1);
852 CPPUNIT_ASSERT(m_rich
->CanRedo() == false);
854 // Now test multiple addition and deletion, and also suppression
855 m_rich
->BeginSuppressUndo();
856 table
->AddColumns(0, 3);
857 table
->AddRows(0, 3);
858 CPPUNIT_ASSERT(table
->GetColumnCount() == 4);
859 CPPUNIT_ASSERT(table
->GetRowCount() == 4);
861 // Only delete 2 of these. This makes it easy to be sure we're dealing with the child table when we loop
862 table
->DeleteColumns(0, 2);
863 table
->DeleteRows(0, 2);
864 CPPUNIT_ASSERT(table
->GetColumnCount() == 2);
865 CPPUNIT_ASSERT(table
->GetRowCount() == 2);
866 m_rich
->EndSuppressUndo();
868 m_rich
->GetCommandProcessor()->ClearCommands(); // otherwise the command-history from this loop will cause CPPUNIT_ASSERT failures in the next one
872 // For round 2, re-run the tests on another table inside the last cell of the first one
873 wxRichTextCell
* cell
= table
->GetCell(table
->GetRowCount() - 1, table
->GetColumnCount() - 1);
874 CPPUNIT_ASSERT(cell
);
875 m_rich
->SetFocusObject(cell
);
876 m_rich
->BeginSuppressUndo();
877 table
= m_rich
->WriteTable(1, 1);
878 m_rich
->EndSuppressUndo();
879 CPPUNIT_ASSERT(table
);
885 CPPUNIT_ASSERT_EQUAL(0, table
->GetCells().GetCount());
886 CPPUNIT_ASSERT_EQUAL(0, table
->GetColumnCount());
887 CPPUNIT_ASSERT_EQUAL(0, table
->GetRowCount());
890 m_rich
->SetFocusObject(NULL
);
893 #endif //wxUSE_RICHTEXT