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