|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 #include <QAction> |
|
45 #include <QUndoStack> |
|
46 |
|
47 //TESTED_CLASS= |
|
48 //TESTED_FILES= |
|
49 |
|
50 /****************************************************************************** |
|
51 ** Commands |
|
52 */ |
|
53 |
|
54 class InsertCommand : public QUndoCommand |
|
55 { |
|
56 public: |
|
57 InsertCommand(QString *str, int idx, const QString &text, |
|
58 QUndoCommand *parent = 0); |
|
59 |
|
60 virtual void undo(); |
|
61 virtual void redo(); |
|
62 |
|
63 private: |
|
64 QString *m_str; |
|
65 int m_idx; |
|
66 QString m_text; |
|
67 }; |
|
68 |
|
69 class RemoveCommand : public QUndoCommand |
|
70 { |
|
71 public: |
|
72 RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent = 0); |
|
73 |
|
74 virtual void undo(); |
|
75 virtual void redo(); |
|
76 |
|
77 private: |
|
78 QString *m_str; |
|
79 int m_idx; |
|
80 QString m_text; |
|
81 }; |
|
82 |
|
83 class AppendCommand : public QUndoCommand |
|
84 { |
|
85 public: |
|
86 AppendCommand(QString *str, const QString &text, bool _fail_merge = false, |
|
87 QUndoCommand *parent = 0); |
|
88 ~AppendCommand(); |
|
89 |
|
90 virtual void undo(); |
|
91 virtual void redo(); |
|
92 virtual int id() const; |
|
93 virtual bool mergeWith(const QUndoCommand *other); |
|
94 |
|
95 bool merged; |
|
96 bool fail_merge; |
|
97 static int delete_cnt; |
|
98 |
|
99 private: |
|
100 QString *m_str; |
|
101 QString m_text; |
|
102 }; |
|
103 |
|
104 InsertCommand::InsertCommand(QString *str, int idx, const QString &text, |
|
105 QUndoCommand *parent) |
|
106 : QUndoCommand(parent) |
|
107 { |
|
108 QVERIFY(str->length() >= idx); |
|
109 |
|
110 setText("insert"); |
|
111 |
|
112 m_str = str; |
|
113 m_idx = idx; |
|
114 m_text = text; |
|
115 } |
|
116 |
|
117 void InsertCommand::redo() |
|
118 { |
|
119 QVERIFY(m_str->length() >= m_idx); |
|
120 |
|
121 m_str->insert(m_idx, m_text); |
|
122 } |
|
123 |
|
124 void InsertCommand::undo() |
|
125 { |
|
126 QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); |
|
127 |
|
128 m_str->remove(m_idx, m_text.length()); |
|
129 } |
|
130 |
|
131 RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent) |
|
132 : QUndoCommand(parent) |
|
133 { |
|
134 QVERIFY(str->length() >= idx + len); |
|
135 |
|
136 setText("remove"); |
|
137 |
|
138 m_str = str; |
|
139 m_idx = idx; |
|
140 m_text = m_str->mid(m_idx, len); |
|
141 } |
|
142 |
|
143 void RemoveCommand::redo() |
|
144 { |
|
145 QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); |
|
146 |
|
147 m_str->remove(m_idx, m_text.length()); |
|
148 } |
|
149 |
|
150 void RemoveCommand::undo() |
|
151 { |
|
152 QVERIFY(m_str->length() >= m_idx); |
|
153 |
|
154 m_str->insert(m_idx, m_text); |
|
155 } |
|
156 |
|
157 int AppendCommand::delete_cnt = 0; |
|
158 |
|
159 AppendCommand::AppendCommand(QString *str, const QString &text, bool _fail_merge, |
|
160 QUndoCommand *parent) |
|
161 : QUndoCommand(parent) |
|
162 { |
|
163 setText("append"); |
|
164 |
|
165 m_str = str; |
|
166 m_text = text; |
|
167 merged = false; |
|
168 fail_merge = _fail_merge; |
|
169 } |
|
170 |
|
171 AppendCommand::~AppendCommand() |
|
172 { |
|
173 ++delete_cnt; |
|
174 } |
|
175 |
|
176 void AppendCommand::redo() |
|
177 { |
|
178 m_str->append(m_text); |
|
179 } |
|
180 |
|
181 void AppendCommand::undo() |
|
182 { |
|
183 QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text); |
|
184 |
|
185 m_str->truncate(m_str->length() - m_text.length()); |
|
186 } |
|
187 |
|
188 int AppendCommand::id() const |
|
189 { |
|
190 return 1; |
|
191 } |
|
192 |
|
193 bool AppendCommand::mergeWith(const QUndoCommand *other) |
|
194 { |
|
195 if (other->id() != id()) |
|
196 return false; |
|
197 if (fail_merge) |
|
198 return false; |
|
199 m_text += static_cast<const AppendCommand*>(other)->m_text; |
|
200 merged = true; |
|
201 return true; |
|
202 } |
|
203 |
|
204 /****************************************************************************** |
|
205 ** tst_QUndoStack |
|
206 */ |
|
207 |
|
208 class tst_QUndoStack : public QObject |
|
209 { |
|
210 Q_OBJECT |
|
211 public: |
|
212 tst_QUndoStack(); |
|
213 |
|
214 private slots: |
|
215 void undoRedo(); |
|
216 void setIndex(); |
|
217 void setClean(); |
|
218 void clear(); |
|
219 void childCommand(); |
|
220 void macroBeginEnd(); |
|
221 void compression(); |
|
222 void undoLimit(); |
|
223 }; |
|
224 |
|
225 tst_QUndoStack::tst_QUndoStack() |
|
226 { |
|
227 } |
|
228 |
|
229 static QString glue(const QString &s1, const QString &s2) |
|
230 { |
|
231 QString result; |
|
232 |
|
233 result.append(s1); |
|
234 if (!s1.isEmpty() && !s2.isEmpty()) |
|
235 result.append(' '); |
|
236 result.append(s2); |
|
237 |
|
238 return result; |
|
239 } |
|
240 |
|
241 static void checkState(QSignalSpy &redoTextChangedSpy, |
|
242 QSignalSpy &canRedoChangedSpy, |
|
243 QSignalSpy &undoTextChangedSpy, |
|
244 QAction *const redoAction, |
|
245 QAction *const undoAction, |
|
246 QSignalSpy &canUndoChangedSpy, |
|
247 QSignalSpy &cleanChangedSpy, |
|
248 QSignalSpy &indexChangedSpy, |
|
249 QUndoStack &stack, |
|
250 const bool _clean, |
|
251 const int _count, |
|
252 const int _index, |
|
253 const bool _canUndo, |
|
254 const QString &_undoText, |
|
255 const bool _canRedo, |
|
256 const QString &_redoText, |
|
257 const bool _cleanChanged, |
|
258 const bool _indexChanged, |
|
259 const bool _undoChanged, |
|
260 const bool _redoChanged) |
|
261 { |
|
262 QCOMPARE(stack.count(), _count); |
|
263 QCOMPARE(stack.isClean(), _clean); |
|
264 QCOMPARE(stack.index(), _index); |
|
265 QCOMPARE(stack.canUndo(), _canUndo); |
|
266 QCOMPARE(stack.undoText(), QString(_undoText)); |
|
267 QCOMPARE(stack.canRedo(), _canRedo); |
|
268 QCOMPARE(stack.redoText(), QString(_redoText)); |
|
269 if (_indexChanged) { |
|
270 QCOMPARE(indexChangedSpy.count(), 1); |
|
271 QCOMPARE(indexChangedSpy.at(0).at(0).toInt(), _index); |
|
272 indexChangedSpy.clear(); |
|
273 } else { |
|
274 QCOMPARE(indexChangedSpy.count(), 0); |
|
275 } |
|
276 if (_cleanChanged) { |
|
277 QCOMPARE(cleanChangedSpy.count(), 1); |
|
278 QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean); |
|
279 cleanChangedSpy.clear(); |
|
280 } else { |
|
281 QCOMPARE(cleanChangedSpy.count(), 0); |
|
282 } |
|
283 if (_undoChanged) { |
|
284 QCOMPARE(canUndoChangedSpy.count(), 1); |
|
285 QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo); |
|
286 QCOMPARE(undoAction->isEnabled(), _canUndo); |
|
287 QCOMPARE(undoTextChangedSpy.count(), 1); |
|
288 QCOMPARE(undoTextChangedSpy.at(0).at(0).toString(), QString(_undoText)); |
|
289 QCOMPARE(undoAction->text(), glue("foo", _undoText)); |
|
290 canUndoChangedSpy.clear(); |
|
291 undoTextChangedSpy.clear(); |
|
292 } else { |
|
293 QCOMPARE(canUndoChangedSpy.count(), 0); |
|
294 QCOMPARE(undoTextChangedSpy.count(), 0); |
|
295 } |
|
296 if (_redoChanged) { |
|
297 QCOMPARE(canRedoChangedSpy.count(), 1); |
|
298 QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo); |
|
299 QCOMPARE(redoAction->isEnabled(), _canRedo); |
|
300 QCOMPARE(redoTextChangedSpy.count(), 1); |
|
301 QCOMPARE(redoTextChangedSpy.at(0).at(0).toString(), QString(_redoText)); |
|
302 QCOMPARE(redoAction->text(), glue("bar", _redoText)); |
|
303 canRedoChangedSpy.clear(); |
|
304 redoTextChangedSpy.clear(); |
|
305 } else { |
|
306 QCOMPARE(canRedoChangedSpy.count(), 0); |
|
307 QCOMPARE(redoTextChangedSpy.count(), 0); |
|
308 } |
|
309 } |
|
310 |
|
311 void tst_QUndoStack::undoRedo() |
|
312 { |
|
313 QUndoStack stack; |
|
314 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
315 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
316 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
317 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
318 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
319 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
320 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
321 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
322 QString str; |
|
323 |
|
324 // push, undo, redo |
|
325 |
|
326 checkState(redoTextChangedSpy, |
|
327 canRedoChangedSpy, |
|
328 undoTextChangedSpy, |
|
329 redoAction, |
|
330 undoAction, |
|
331 canUndoChangedSpy, |
|
332 cleanChangedSpy, |
|
333 indexChangedSpy, |
|
334 stack, |
|
335 true, // clean |
|
336 0, // count |
|
337 0, // index |
|
338 false, // canUndo |
|
339 "", // undoText |
|
340 false, // canRedo |
|
341 "", // redoText |
|
342 false, // cleanChanged |
|
343 false, // indexChanged |
|
344 false, // undoChanged |
|
345 false); // redoChanged |
|
346 |
|
347 stack.undo(); // nothing to undo |
|
348 QCOMPARE(str, QString()); |
|
349 checkState(redoTextChangedSpy, |
|
350 canRedoChangedSpy, |
|
351 undoTextChangedSpy, |
|
352 redoAction, |
|
353 undoAction, |
|
354 canUndoChangedSpy, |
|
355 cleanChangedSpy, |
|
356 indexChangedSpy, |
|
357 stack, |
|
358 true, // clean |
|
359 0, // count |
|
360 0, // index |
|
361 false, // canUndo |
|
362 "", // undoText |
|
363 false, // canRedo |
|
364 "", // redoText |
|
365 false, // cleanChanged |
|
366 false, // indexChanged |
|
367 false, // undoChanged |
|
368 false); // redoChanged |
|
369 |
|
370 stack.push(new InsertCommand(&str, 0, "hello")); |
|
371 QCOMPARE(str, QString("hello")); |
|
372 checkState(redoTextChangedSpy, |
|
373 canRedoChangedSpy, |
|
374 undoTextChangedSpy, |
|
375 redoAction, |
|
376 undoAction, |
|
377 canUndoChangedSpy, |
|
378 cleanChangedSpy, |
|
379 indexChangedSpy, |
|
380 stack, |
|
381 false, // clean |
|
382 1, // count |
|
383 1, // index |
|
384 true, // canUndo |
|
385 "insert", // undoText |
|
386 false, // canRedo |
|
387 "", // redoText |
|
388 true, // cleanChanged |
|
389 true, // indexChanged |
|
390 true, // undoChanged |
|
391 true); // redoChanged |
|
392 |
|
393 stack.push(new InsertCommand(&str, 2, "123")); |
|
394 QCOMPARE(str, QString("he123llo")); |
|
395 checkState(redoTextChangedSpy, |
|
396 canRedoChangedSpy, |
|
397 undoTextChangedSpy, |
|
398 redoAction, |
|
399 undoAction, |
|
400 canUndoChangedSpy, |
|
401 cleanChangedSpy, |
|
402 indexChangedSpy, |
|
403 stack, |
|
404 false, // clean |
|
405 2, // count |
|
406 2, // index |
|
407 true, // canUndo |
|
408 "insert", // undoText |
|
409 false, // canRedo |
|
410 "", // redoText |
|
411 false, // cleanChanged |
|
412 true, // indexChanged |
|
413 true, // undoChanged |
|
414 true); // redoChanged |
|
415 |
|
416 |
|
417 stack.undo(); |
|
418 QCOMPARE(str, QString("hello")); |
|
419 checkState(redoTextChangedSpy, |
|
420 canRedoChangedSpy, |
|
421 undoTextChangedSpy, |
|
422 redoAction, |
|
423 undoAction, |
|
424 canUndoChangedSpy, |
|
425 cleanChangedSpy, |
|
426 indexChangedSpy, |
|
427 stack, |
|
428 false, // clean |
|
429 2, // count |
|
430 1, // index |
|
431 true, // canUndo |
|
432 "insert", // undoText |
|
433 true, // canRedo |
|
434 "insert", // redoText |
|
435 false, // cleanChanged |
|
436 true, // indexChanged |
|
437 true, // undoChanged |
|
438 true); // redoChanged |
|
439 |
|
440 stack.redo(); |
|
441 QCOMPARE(str, QString("he123llo")); |
|
442 checkState(redoTextChangedSpy, |
|
443 canRedoChangedSpy, |
|
444 undoTextChangedSpy, |
|
445 redoAction, |
|
446 undoAction, |
|
447 canUndoChangedSpy, |
|
448 cleanChangedSpy, |
|
449 indexChangedSpy, |
|
450 stack, |
|
451 false, // clean |
|
452 2, // count |
|
453 2, // index |
|
454 true, // canUndo |
|
455 "insert", // undoText |
|
456 false, // canRedo |
|
457 "", // redoText |
|
458 false, // cleanChanged |
|
459 true, // indexChanged |
|
460 true, // undoChanged |
|
461 true); // redoChanged |
|
462 |
|
463 stack.redo(); // nothing to redo |
|
464 QCOMPARE(str, QString("he123llo")); |
|
465 checkState(redoTextChangedSpy, |
|
466 canRedoChangedSpy, |
|
467 undoTextChangedSpy, |
|
468 redoAction, |
|
469 undoAction, |
|
470 canUndoChangedSpy, |
|
471 cleanChangedSpy, |
|
472 indexChangedSpy, |
|
473 stack, |
|
474 false, // clean |
|
475 2, // count |
|
476 2, // index |
|
477 true, // canUndo |
|
478 "insert", // undoText |
|
479 false, // canRedo |
|
480 "", // redoText |
|
481 false, // cleanChanged |
|
482 false, // indexChanged |
|
483 false, // undoChanged |
|
484 false); // redoChanged |
|
485 |
|
486 stack.undo(); |
|
487 QCOMPARE(str, QString("hello")); |
|
488 checkState(redoTextChangedSpy, |
|
489 canRedoChangedSpy, |
|
490 undoTextChangedSpy, |
|
491 redoAction, |
|
492 undoAction, |
|
493 canUndoChangedSpy, |
|
494 cleanChangedSpy, |
|
495 indexChangedSpy, |
|
496 stack, |
|
497 false, // clean |
|
498 2, // count |
|
499 1, // index |
|
500 true, // canUndo |
|
501 "insert", // undoText |
|
502 true, // canRedo |
|
503 "insert", // redoText |
|
504 false, // cleanChanged |
|
505 true, // indexChanged |
|
506 true, // undoChanged |
|
507 true); // redoChanged |
|
508 |
|
509 stack.undo(); |
|
510 QCOMPARE(str, QString()); |
|
511 checkState(redoTextChangedSpy, |
|
512 canRedoChangedSpy, |
|
513 undoTextChangedSpy, |
|
514 redoAction, |
|
515 undoAction, |
|
516 canUndoChangedSpy, |
|
517 cleanChangedSpy, |
|
518 indexChangedSpy, |
|
519 stack, |
|
520 true, // clean |
|
521 2, // count |
|
522 0, // index |
|
523 false, // canUndo |
|
524 "", // undoText |
|
525 true, // canRedo |
|
526 "insert", // redoText |
|
527 true, // cleanChanged |
|
528 true, // indexChanged |
|
529 true, // undoChanged |
|
530 true); // redoChanged |
|
531 |
|
532 stack.undo(); // nothing to undo |
|
533 QCOMPARE(str, QString()); |
|
534 checkState(redoTextChangedSpy, |
|
535 canRedoChangedSpy, |
|
536 undoTextChangedSpy, |
|
537 redoAction, |
|
538 undoAction, |
|
539 canUndoChangedSpy, |
|
540 cleanChangedSpy, |
|
541 indexChangedSpy, |
|
542 stack, |
|
543 true, // clean |
|
544 2, // count |
|
545 0, // index |
|
546 false, // canUndo |
|
547 "", // undoText |
|
548 true, // canRedo |
|
549 "insert", // redoText |
|
550 false, // cleanChanged |
|
551 false, // indexChanged |
|
552 false, // undoChanged |
|
553 false); // redoChanged |
|
554 |
|
555 // push after undo - check that undone commands get deleted |
|
556 |
|
557 stack.redo(); |
|
558 checkState(redoTextChangedSpy, |
|
559 canRedoChangedSpy, |
|
560 undoTextChangedSpy, |
|
561 redoAction, |
|
562 undoAction, |
|
563 canUndoChangedSpy, |
|
564 cleanChangedSpy, |
|
565 indexChangedSpy, |
|
566 stack, |
|
567 false, // clean |
|
568 2, // count |
|
569 1, // index |
|
570 true, // canUndo |
|
571 "insert", // undoText |
|
572 true, // canRedo |
|
573 "insert", // redoText |
|
574 true, // cleanChanged |
|
575 true, // indexChanged |
|
576 true, // undoChanged |
|
577 true); // redoChanged |
|
578 |
|
579 stack.push(new RemoveCommand(&str, 2, 2)); |
|
580 QCOMPARE(str, QString("heo")); |
|
581 checkState(redoTextChangedSpy, |
|
582 canRedoChangedSpy, |
|
583 undoTextChangedSpy, |
|
584 redoAction, |
|
585 undoAction, |
|
586 canUndoChangedSpy, |
|
587 cleanChangedSpy, |
|
588 indexChangedSpy, |
|
589 stack, |
|
590 false, // clean |
|
591 2, // count - still 2, last command got deleted |
|
592 2, // index |
|
593 true, // canUndo |
|
594 "remove", // undoText |
|
595 false, // canRedo |
|
596 "", // redoText |
|
597 false, // cleanChanged |
|
598 true, // indexChanged |
|
599 true, // undoChanged |
|
600 true); // redoChanged |
|
601 |
|
602 stack.undo(); |
|
603 QCOMPARE(str, QString("hello")); |
|
604 checkState(redoTextChangedSpy, |
|
605 canRedoChangedSpy, |
|
606 undoTextChangedSpy, |
|
607 redoAction, |
|
608 undoAction, |
|
609 canUndoChangedSpy, |
|
610 cleanChangedSpy, |
|
611 indexChangedSpy, |
|
612 stack, |
|
613 false, // clean |
|
614 2, // count |
|
615 1, // index |
|
616 true, // canUndo |
|
617 "insert", // undoText |
|
618 true, // canRedo |
|
619 "remove", // redoText |
|
620 false, // cleanChanged |
|
621 true, // indexChanged |
|
622 true, // undoChanged |
|
623 true); // redoChanged |
|
624 |
|
625 stack.undo(); |
|
626 QCOMPARE(str, QString()); |
|
627 checkState(redoTextChangedSpy, |
|
628 canRedoChangedSpy, |
|
629 undoTextChangedSpy, |
|
630 redoAction, |
|
631 undoAction, |
|
632 canUndoChangedSpy, |
|
633 cleanChangedSpy, |
|
634 indexChangedSpy, |
|
635 stack, |
|
636 true, // clean |
|
637 2, // count |
|
638 0, // index |
|
639 false, // canUndo |
|
640 "", // undoText |
|
641 true, // canRedo |
|
642 "insert", // redoText |
|
643 true, // cleanChanged |
|
644 true, // indexChanged |
|
645 true, // undoChanged |
|
646 true); // redoChanged |
|
647 |
|
648 stack.push(new InsertCommand(&str, 0, "goodbye")); |
|
649 QCOMPARE(str, QString("goodbye")); |
|
650 checkState(redoTextChangedSpy, |
|
651 canRedoChangedSpy, |
|
652 undoTextChangedSpy, |
|
653 redoAction, |
|
654 undoAction, |
|
655 canUndoChangedSpy, |
|
656 cleanChangedSpy, |
|
657 indexChangedSpy, |
|
658 stack, |
|
659 false, // clean |
|
660 1, // count - two commands got deleted |
|
661 1, // index |
|
662 true, // canUndo |
|
663 "insert", // undoText |
|
664 false, // canRedo |
|
665 "", // redoText |
|
666 true, // cleanChanged |
|
667 true, // indexChanged |
|
668 true, // undoChanged |
|
669 true); // redoChanged |
|
670 } |
|
671 |
|
672 void tst_QUndoStack::setIndex() |
|
673 { |
|
674 QUndoStack stack; |
|
675 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
676 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
677 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
678 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
679 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
680 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
681 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
682 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
683 QString str; |
|
684 |
|
685 stack.setIndex(10); // should do nothing |
|
686 checkState(redoTextChangedSpy, |
|
687 canRedoChangedSpy, |
|
688 undoTextChangedSpy, |
|
689 redoAction, |
|
690 undoAction, |
|
691 canUndoChangedSpy, |
|
692 cleanChangedSpy, |
|
693 indexChangedSpy, |
|
694 stack, |
|
695 true, // clean |
|
696 0, // count |
|
697 0, // index |
|
698 false, // canUndo |
|
699 "", // undoText |
|
700 false, // canRedo |
|
701 "", // redoText |
|
702 false, // cleanChanged |
|
703 false, // indexChanged |
|
704 false, // undoChanged |
|
705 false); // redoChanged |
|
706 |
|
707 stack.setIndex(0); // should do nothing |
|
708 checkState(redoTextChangedSpy, |
|
709 canRedoChangedSpy, |
|
710 undoTextChangedSpy, |
|
711 redoAction, |
|
712 undoAction, |
|
713 canUndoChangedSpy, |
|
714 cleanChangedSpy, |
|
715 indexChangedSpy, |
|
716 stack, |
|
717 true, // clean |
|
718 0, // count |
|
719 0, // index |
|
720 false, // canUndo |
|
721 "", // undoText |
|
722 false, // canRedo |
|
723 "", // redoText |
|
724 false, // cleanChanged |
|
725 false, // indexChanged |
|
726 false, // undoChanged |
|
727 false); // redoChanged |
|
728 |
|
729 stack.setIndex(-10); // should do nothing |
|
730 checkState(redoTextChangedSpy, |
|
731 canRedoChangedSpy, |
|
732 undoTextChangedSpy, |
|
733 redoAction, |
|
734 undoAction, |
|
735 canUndoChangedSpy, |
|
736 cleanChangedSpy, |
|
737 indexChangedSpy, |
|
738 stack, |
|
739 true, // clean |
|
740 0, // count |
|
741 0, // index |
|
742 false, // canUndo |
|
743 "", // undoText |
|
744 false, // canRedo |
|
745 "", // redoText |
|
746 false, // cleanChanged |
|
747 false, // indexChanged |
|
748 false, // undoChanged |
|
749 false); // redoChanged |
|
750 |
|
751 stack.push(new InsertCommand(&str, 0, "hello")); |
|
752 QCOMPARE(str, QString("hello")); |
|
753 checkState(redoTextChangedSpy, |
|
754 canRedoChangedSpy, |
|
755 undoTextChangedSpy, |
|
756 redoAction, |
|
757 undoAction, |
|
758 canUndoChangedSpy, |
|
759 cleanChangedSpy, |
|
760 indexChangedSpy, |
|
761 stack, |
|
762 false, // clean |
|
763 1, // count |
|
764 1, // index |
|
765 true, // canUndo |
|
766 "insert", // undoText |
|
767 false, // canRedo |
|
768 "", // redoText |
|
769 true, // cleanChanged |
|
770 true, // indexChanged |
|
771 true, // undoChanged |
|
772 true); // redoChanged |
|
773 |
|
774 stack.push(new InsertCommand(&str, 2, "123")); |
|
775 QCOMPARE(str, QString("he123llo")); |
|
776 checkState(redoTextChangedSpy, |
|
777 canRedoChangedSpy, |
|
778 undoTextChangedSpy, |
|
779 redoAction, |
|
780 undoAction, |
|
781 canUndoChangedSpy, |
|
782 cleanChangedSpy, |
|
783 indexChangedSpy, |
|
784 stack, |
|
785 false, // clean |
|
786 2, // count |
|
787 2, // index |
|
788 true, // canUndo |
|
789 "insert", // undoText |
|
790 false, // canRedo |
|
791 "", // redoText |
|
792 false, // cleanChanged |
|
793 true, // indexChanged |
|
794 true, // undoChanged |
|
795 true); // redoChanged |
|
796 |
|
797 stack.setIndex(2); |
|
798 QCOMPARE(str, QString("he123llo")); |
|
799 checkState(redoTextChangedSpy, |
|
800 canRedoChangedSpy, |
|
801 undoTextChangedSpy, |
|
802 redoAction, |
|
803 undoAction, |
|
804 canUndoChangedSpy, |
|
805 cleanChangedSpy, |
|
806 indexChangedSpy, |
|
807 stack, |
|
808 false, // clean |
|
809 2, // count |
|
810 2, // index |
|
811 true, // canUndo |
|
812 "insert", // undoText |
|
813 false, // canRedo |
|
814 "", // redoText |
|
815 false, // cleanChanged |
|
816 false, // indexChanged |
|
817 false, // undoChanged |
|
818 false); // redoChanged |
|
819 |
|
820 stack.setIndex(0); |
|
821 QCOMPARE(str, QString()); |
|
822 checkState(redoTextChangedSpy, |
|
823 canRedoChangedSpy, |
|
824 undoTextChangedSpy, |
|
825 redoAction, |
|
826 undoAction, |
|
827 canUndoChangedSpy, |
|
828 cleanChangedSpy, |
|
829 indexChangedSpy, |
|
830 stack, |
|
831 true, // clean |
|
832 2, // count |
|
833 0, // index |
|
834 false, // canUndo |
|
835 "", // undoText |
|
836 true, // canRedo |
|
837 "insert", // redoText |
|
838 true, // cleanChanged |
|
839 true, // indexChanged |
|
840 true, // undoChanged |
|
841 true); // redoChanged |
|
842 |
|
843 stack.setIndex(10); // should set index to 2 |
|
844 QCOMPARE(str, QString("he123llo")); |
|
845 checkState(redoTextChangedSpy, |
|
846 canRedoChangedSpy, |
|
847 undoTextChangedSpy, |
|
848 redoAction, |
|
849 undoAction, |
|
850 canUndoChangedSpy, |
|
851 cleanChangedSpy, |
|
852 indexChangedSpy, |
|
853 stack, |
|
854 false, // clean |
|
855 2, // count |
|
856 2, // index |
|
857 true, // canUndo |
|
858 "insert", // undoText |
|
859 false, // canRedo |
|
860 "", // redoText |
|
861 true, // cleanChanged |
|
862 true, // indexChanged |
|
863 true, // undoChanged |
|
864 true); // redoChanged |
|
865 |
|
866 stack.setIndex(-10); // should set index to 0 |
|
867 QCOMPARE(str, QString()); |
|
868 checkState(redoTextChangedSpy, |
|
869 canRedoChangedSpy, |
|
870 undoTextChangedSpy, |
|
871 redoAction, |
|
872 undoAction, |
|
873 canUndoChangedSpy, |
|
874 cleanChangedSpy, |
|
875 indexChangedSpy, |
|
876 stack, |
|
877 true, // clean |
|
878 2, // count |
|
879 0, // index |
|
880 false, // canUndo |
|
881 "", // undoText |
|
882 true, // canRedo |
|
883 "insert", // redoText |
|
884 true, // cleanChanged |
|
885 true, // indexChanged |
|
886 true, // undoChanged |
|
887 true); // redoChanged |
|
888 |
|
889 stack.setIndex(1); |
|
890 QCOMPARE(str, QString("hello")); |
|
891 checkState(redoTextChangedSpy, |
|
892 canRedoChangedSpy, |
|
893 undoTextChangedSpy, |
|
894 redoAction, |
|
895 undoAction, |
|
896 canUndoChangedSpy, |
|
897 cleanChangedSpy, |
|
898 indexChangedSpy, |
|
899 stack, |
|
900 false, // clean |
|
901 2, // count |
|
902 1, // index |
|
903 true, // canUndo |
|
904 "insert", // undoText |
|
905 true, // canRedo |
|
906 "insert", // redoText |
|
907 true, // cleanChanged |
|
908 true, // indexChanged |
|
909 true, // undoChanged |
|
910 true); // redoChanged |
|
911 |
|
912 stack.setIndex(2); |
|
913 QCOMPARE(str, QString("he123llo")); |
|
914 checkState(redoTextChangedSpy, |
|
915 canRedoChangedSpy, |
|
916 undoTextChangedSpy, |
|
917 redoAction, |
|
918 undoAction, |
|
919 canUndoChangedSpy, |
|
920 cleanChangedSpy, |
|
921 indexChangedSpy, |
|
922 stack, |
|
923 false, // clean |
|
924 2, // count |
|
925 2, // index |
|
926 true, // canUndo |
|
927 "insert", // undoText |
|
928 false, // canRedo |
|
929 "", // redoText |
|
930 false, // cleanChanged |
|
931 true, // indexChanged |
|
932 true, // undoChanged |
|
933 true); // redoChanged |
|
934 } |
|
935 |
|
936 void tst_QUndoStack::setClean() |
|
937 { |
|
938 QUndoStack stack; |
|
939 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
940 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
941 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
942 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
943 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
944 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
945 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
946 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
947 QString str; |
|
948 |
|
949 QCOMPARE(stack.cleanIndex(), 0); |
|
950 stack.setClean(); |
|
951 checkState(redoTextChangedSpy, |
|
952 canRedoChangedSpy, |
|
953 undoTextChangedSpy, |
|
954 redoAction, |
|
955 undoAction, |
|
956 canUndoChangedSpy, |
|
957 cleanChangedSpy, |
|
958 indexChangedSpy, |
|
959 stack, |
|
960 true, // clean |
|
961 0, // count |
|
962 0, // index |
|
963 false, // canUndo |
|
964 "", // undoText |
|
965 false, // canRedo |
|
966 "", // redoText |
|
967 false, // cleanChanged |
|
968 false, // indexChanged |
|
969 false, // undoChanged |
|
970 false); // redoChanged |
|
971 QCOMPARE(stack.cleanIndex(), 0); |
|
972 |
|
973 stack.push(new InsertCommand(&str, 0, "goodbye")); |
|
974 checkState(redoTextChangedSpy, |
|
975 canRedoChangedSpy, |
|
976 undoTextChangedSpy, |
|
977 redoAction, |
|
978 undoAction, |
|
979 canUndoChangedSpy, |
|
980 cleanChangedSpy, |
|
981 indexChangedSpy, |
|
982 stack, |
|
983 false, // clean |
|
984 1, // count |
|
985 1, // index |
|
986 true, // canUndo |
|
987 "insert", // undoText |
|
988 false, // canRedo |
|
989 "", // redoText |
|
990 true, // cleanChanged |
|
991 true, // indexChanged |
|
992 true, // undoChanged |
|
993 true); // redoChanged |
|
994 QCOMPARE(stack.cleanIndex(), 0); |
|
995 |
|
996 stack.setClean(); |
|
997 QCOMPARE(str, QString("goodbye")); |
|
998 checkState(redoTextChangedSpy, |
|
999 canRedoChangedSpy, |
|
1000 undoTextChangedSpy, |
|
1001 redoAction, |
|
1002 undoAction, |
|
1003 canUndoChangedSpy, |
|
1004 cleanChangedSpy, |
|
1005 indexChangedSpy, |
|
1006 stack, |
|
1007 true, // clean |
|
1008 1, // count |
|
1009 1, // index |
|
1010 true, // canUndo |
|
1011 "insert", // undoText |
|
1012 false, // canRedo |
|
1013 "", // redoText |
|
1014 true, // cleanChanged |
|
1015 false, // indexChanged |
|
1016 false, // undoChanged |
|
1017 false); // redoChanged |
|
1018 QCOMPARE(stack.cleanIndex(), 1); |
|
1019 |
|
1020 stack.push(new AppendCommand(&str, " cowboy")); |
|
1021 QCOMPARE(str, QString("goodbye cowboy")); |
|
1022 checkState(redoTextChangedSpy, |
|
1023 canRedoChangedSpy, |
|
1024 undoTextChangedSpy, |
|
1025 redoAction, |
|
1026 undoAction, |
|
1027 canUndoChangedSpy, |
|
1028 cleanChangedSpy, |
|
1029 indexChangedSpy, |
|
1030 stack, |
|
1031 false, // clean |
|
1032 2, // count |
|
1033 2, // index |
|
1034 true, // canUndo |
|
1035 "append", // undoText |
|
1036 false, // canRedo |
|
1037 "", // redoText |
|
1038 true, // cleanChanged |
|
1039 true, // indexChanged |
|
1040 true, // undoChanged |
|
1041 true); // redoChanged |
|
1042 QCOMPARE(stack.cleanIndex(), 1); |
|
1043 |
|
1044 stack.undo(); // reaching clean state from above |
|
1045 QCOMPARE(str, QString("goodbye")); |
|
1046 checkState(redoTextChangedSpy, |
|
1047 canRedoChangedSpy, |
|
1048 undoTextChangedSpy, |
|
1049 redoAction, |
|
1050 undoAction, |
|
1051 canUndoChangedSpy, |
|
1052 cleanChangedSpy, |
|
1053 indexChangedSpy, |
|
1054 stack, |
|
1055 true, // clean |
|
1056 2, // count |
|
1057 1, // index |
|
1058 true, // canUndo |
|
1059 "insert", // undoText |
|
1060 true, // canRedo |
|
1061 "append", // redoText |
|
1062 true, // cleanChanged |
|
1063 true, // indexChanged |
|
1064 true, // undoChanged |
|
1065 true); // redoChanged |
|
1066 QCOMPARE(stack.cleanIndex(), 1); |
|
1067 |
|
1068 stack.undo(); |
|
1069 QCOMPARE(str, QString()); |
|
1070 checkState(redoTextChangedSpy, |
|
1071 canRedoChangedSpy, |
|
1072 undoTextChangedSpy, |
|
1073 redoAction, |
|
1074 undoAction, |
|
1075 canUndoChangedSpy, |
|
1076 cleanChangedSpy, |
|
1077 indexChangedSpy, |
|
1078 stack, |
|
1079 false, // clean |
|
1080 2, // count |
|
1081 0, // index |
|
1082 false, // canUndo |
|
1083 "", // undoText |
|
1084 true, // canRedo |
|
1085 "insert", // redoText |
|
1086 true, // cleanChanged |
|
1087 true, // indexChanged |
|
1088 true, // undoChanged |
|
1089 true); // redoChanged |
|
1090 QCOMPARE(stack.cleanIndex(), 1); |
|
1091 |
|
1092 stack.redo(); // reaching clean state from below |
|
1093 QCOMPARE(str, QString("goodbye")); |
|
1094 checkState(redoTextChangedSpy, |
|
1095 canRedoChangedSpy, |
|
1096 undoTextChangedSpy, |
|
1097 redoAction, |
|
1098 undoAction, |
|
1099 canUndoChangedSpy, |
|
1100 cleanChangedSpy, |
|
1101 indexChangedSpy, |
|
1102 stack, |
|
1103 true, // clean |
|
1104 2, // count |
|
1105 1, // index |
|
1106 true, // canUndo |
|
1107 "insert", // undoText |
|
1108 true, // canRedo |
|
1109 "append", // redoText |
|
1110 true, // cleanChanged |
|
1111 true, // indexChanged |
|
1112 true, // undoChanged |
|
1113 true); // redoChanged |
|
1114 QCOMPARE(stack.cleanIndex(), 1); |
|
1115 |
|
1116 stack.undo(); |
|
1117 QCOMPARE(str, QString()); |
|
1118 checkState(redoTextChangedSpy, |
|
1119 canRedoChangedSpy, |
|
1120 undoTextChangedSpy, |
|
1121 redoAction, |
|
1122 undoAction, |
|
1123 canUndoChangedSpy, |
|
1124 cleanChangedSpy, |
|
1125 indexChangedSpy, |
|
1126 stack, |
|
1127 false, // clean |
|
1128 2, // count |
|
1129 0, // index |
|
1130 false, // canUndo |
|
1131 "", // undoText |
|
1132 true, // canRedo |
|
1133 "insert", // redoText |
|
1134 true, // cleanChanged |
|
1135 true, // indexChanged |
|
1136 true, // undoChanged |
|
1137 true); // redoChanged |
|
1138 QCOMPARE(stack.cleanIndex(), 1); |
|
1139 |
|
1140 stack.push(new InsertCommand(&str, 0, "foo")); // the clean state gets deleted! |
|
1141 QCOMPARE(str, QString("foo")); |
|
1142 checkState(redoTextChangedSpy, |
|
1143 canRedoChangedSpy, |
|
1144 undoTextChangedSpy, |
|
1145 redoAction, |
|
1146 undoAction, |
|
1147 canUndoChangedSpy, |
|
1148 cleanChangedSpy, |
|
1149 indexChangedSpy, |
|
1150 stack, |
|
1151 false, // clean |
|
1152 1, // count |
|
1153 1, // index |
|
1154 true, // canUndo |
|
1155 "insert", // undoText |
|
1156 false, // canRedo |
|
1157 "", // redoText |
|
1158 false, // cleanChanged |
|
1159 true, // indexChanged |
|
1160 true, // undoChanged |
|
1161 true); // redoChanged |
|
1162 QCOMPARE(stack.cleanIndex(), -1); |
|
1163 |
|
1164 stack.undo(); |
|
1165 QCOMPARE(str, QString()); |
|
1166 checkState(redoTextChangedSpy, |
|
1167 canRedoChangedSpy, |
|
1168 undoTextChangedSpy, |
|
1169 redoAction, |
|
1170 undoAction, |
|
1171 canUndoChangedSpy, |
|
1172 cleanChangedSpy, |
|
1173 indexChangedSpy, |
|
1174 stack, |
|
1175 false, // clean |
|
1176 1, // count |
|
1177 0, // index |
|
1178 false, // canUndo |
|
1179 "", // undoText |
|
1180 true, // canRedo |
|
1181 "insert", // redoText |
|
1182 false, // cleanChanged |
|
1183 true, // indexChanged |
|
1184 true, // undoChanged |
|
1185 true); // redoChanged |
|
1186 QCOMPARE(stack.cleanIndex(), -1); |
|
1187 } |
|
1188 |
|
1189 void tst_QUndoStack::clear() |
|
1190 { |
|
1191 QUndoStack stack; |
|
1192 QAction *undoAction = stack.createUndoAction(this, QString("foo")); |
|
1193 QAction *redoAction = stack.createRedoAction(this, QString("bar")); |
|
1194 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
1195 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
1196 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
1197 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
1198 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
1199 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
1200 QString str; |
|
1201 |
|
1202 stack.clear(); |
|
1203 checkState(redoTextChangedSpy, |
|
1204 canRedoChangedSpy, |
|
1205 undoTextChangedSpy, |
|
1206 redoAction, |
|
1207 undoAction, |
|
1208 canUndoChangedSpy, |
|
1209 cleanChangedSpy, |
|
1210 indexChangedSpy, |
|
1211 stack, |
|
1212 true, // clean |
|
1213 0, // count |
|
1214 0, // index |
|
1215 false, // canUndo |
|
1216 "", // undoText |
|
1217 false, // canRedo |
|
1218 "", // redoText |
|
1219 false, // cleanChanged |
|
1220 false, // indexChanged |
|
1221 false, // undoChanged |
|
1222 false); // redoChanged |
|
1223 |
|
1224 stack.push(new InsertCommand(&str, 0, "hello")); |
|
1225 QCOMPARE(str, QString("hello")); |
|
1226 checkState(redoTextChangedSpy, |
|
1227 canRedoChangedSpy, |
|
1228 undoTextChangedSpy, |
|
1229 redoAction, |
|
1230 undoAction, |
|
1231 canUndoChangedSpy, |
|
1232 cleanChangedSpy, |
|
1233 indexChangedSpy, |
|
1234 stack, |
|
1235 false, // clean |
|
1236 1, // count |
|
1237 1, // index |
|
1238 true, // canUndo |
|
1239 "insert", // undoText |
|
1240 false, // canRedo |
|
1241 "", // redoText |
|
1242 true, // cleanChanged |
|
1243 true, // indexChanged |
|
1244 true, // undoChanged |
|
1245 true); // redoChanged |
|
1246 |
|
1247 stack.push(new InsertCommand(&str, 2, "123")); |
|
1248 QCOMPARE(str, QString("he123llo")); |
|
1249 checkState(redoTextChangedSpy, |
|
1250 canRedoChangedSpy, |
|
1251 undoTextChangedSpy, |
|
1252 redoAction, |
|
1253 undoAction, |
|
1254 canUndoChangedSpy, |
|
1255 cleanChangedSpy, |
|
1256 indexChangedSpy, |
|
1257 stack, |
|
1258 false, // clean |
|
1259 2, // count |
|
1260 2, // index |
|
1261 true, // canUndo |
|
1262 "insert", // undoText |
|
1263 false, // canRedo |
|
1264 "", // redoText |
|
1265 false, // cleanChanged |
|
1266 true, // indexChanged |
|
1267 true, // undoChanged |
|
1268 true); // redoChanged |
|
1269 |
|
1270 stack.clear(); |
|
1271 QCOMPARE(str, QString("he123llo")); |
|
1272 checkState(redoTextChangedSpy, |
|
1273 canRedoChangedSpy, |
|
1274 undoTextChangedSpy, |
|
1275 redoAction, |
|
1276 undoAction, |
|
1277 canUndoChangedSpy, |
|
1278 cleanChangedSpy, |
|
1279 indexChangedSpy, |
|
1280 stack, |
|
1281 true, // clean |
|
1282 0, // count |
|
1283 0, // index |
|
1284 false, // canUndo |
|
1285 "", // undoText |
|
1286 false, // canRedo |
|
1287 "", // redoText |
|
1288 true, // cleanChanged |
|
1289 true, // indexChanged |
|
1290 true, // undoChanged |
|
1291 true); // redoChanged |
|
1292 |
|
1293 str.clear(); |
|
1294 stack.push(new InsertCommand(&str, 0, "hello")); |
|
1295 QCOMPARE(str, QString("hello")); |
|
1296 checkState(redoTextChangedSpy, |
|
1297 canRedoChangedSpy, |
|
1298 undoTextChangedSpy, |
|
1299 redoAction, |
|
1300 undoAction, |
|
1301 canUndoChangedSpy, |
|
1302 cleanChangedSpy, |
|
1303 indexChangedSpy, |
|
1304 stack, |
|
1305 false, // clean |
|
1306 1, // count |
|
1307 1, // index |
|
1308 true, // canUndo |
|
1309 "insert", // undoText |
|
1310 false, // canRedo |
|
1311 "", // redoText |
|
1312 true, // cleanChanged |
|
1313 true, // indexChanged |
|
1314 true, // undoChanged |
|
1315 true); // redoChanged |
|
1316 |
|
1317 stack.push(new InsertCommand(&str, 2, "123")); |
|
1318 QCOMPARE(str, QString("he123llo")); |
|
1319 checkState(redoTextChangedSpy, |
|
1320 canRedoChangedSpy, |
|
1321 undoTextChangedSpy, |
|
1322 redoAction, |
|
1323 undoAction, |
|
1324 canUndoChangedSpy, |
|
1325 cleanChangedSpy, |
|
1326 indexChangedSpy, |
|
1327 stack, |
|
1328 false, // clean |
|
1329 2, // count |
|
1330 2, // index |
|
1331 true, // canUndo |
|
1332 "insert", // undoText |
|
1333 false, // canRedo |
|
1334 "", // redoText |
|
1335 false, // cleanChanged |
|
1336 true, // indexChanged |
|
1337 true, // undoChanged |
|
1338 true); // redoChanged |
|
1339 |
|
1340 stack.setIndex(0); |
|
1341 QCOMPARE(str, QString()); |
|
1342 checkState(redoTextChangedSpy, |
|
1343 canRedoChangedSpy, |
|
1344 undoTextChangedSpy, |
|
1345 redoAction, |
|
1346 undoAction, |
|
1347 canUndoChangedSpy, |
|
1348 cleanChangedSpy, |
|
1349 indexChangedSpy, |
|
1350 stack, |
|
1351 true, // clean |
|
1352 2, // count |
|
1353 0, // index |
|
1354 false, // canUndo |
|
1355 "", // undoText |
|
1356 true, // canRedo |
|
1357 "insert", // redoText |
|
1358 true, // cleanChanged |
|
1359 true, // indexChanged |
|
1360 true, // undoChanged |
|
1361 true); // redoChanged |
|
1362 |
|
1363 stack.clear(); |
|
1364 QCOMPARE(str, QString()); |
|
1365 checkState(redoTextChangedSpy, |
|
1366 canRedoChangedSpy, |
|
1367 undoTextChangedSpy, |
|
1368 redoAction, |
|
1369 undoAction, |
|
1370 canUndoChangedSpy, |
|
1371 cleanChangedSpy, |
|
1372 indexChangedSpy, |
|
1373 stack, |
|
1374 true, // clean |
|
1375 0, // count |
|
1376 0, // index |
|
1377 false, // canUndo |
|
1378 "", // undoText |
|
1379 false, // canRedo |
|
1380 "", // redoText |
|
1381 false, // cleanChanged |
|
1382 true, // indexChanged |
|
1383 true, // undoChanged |
|
1384 true); // redoChanged |
|
1385 } |
|
1386 |
|
1387 void tst_QUndoStack::childCommand() |
|
1388 { |
|
1389 QUndoStack stack; |
|
1390 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
1391 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
1392 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
1393 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
1394 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
1395 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
1396 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
1397 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
1398 QString str; |
|
1399 |
|
1400 stack.push(new InsertCommand(&str, 0, "hello")); |
|
1401 QCOMPARE(str, QString("hello")); |
|
1402 checkState(redoTextChangedSpy, |
|
1403 canRedoChangedSpy, |
|
1404 undoTextChangedSpy, |
|
1405 redoAction, |
|
1406 undoAction, |
|
1407 canUndoChangedSpy, |
|
1408 cleanChangedSpy, |
|
1409 indexChangedSpy, |
|
1410 stack, |
|
1411 false, // clean |
|
1412 1, // count |
|
1413 1, // index |
|
1414 true, // canUndo |
|
1415 "insert", // undoText |
|
1416 false, // canRedo |
|
1417 "", // redoText |
|
1418 true, // cleanChanged |
|
1419 true, // indexChanged |
|
1420 true, // undoChanged |
|
1421 true); // redoChanged |
|
1422 |
|
1423 QUndoCommand *cmd = new QUndoCommand(); |
|
1424 cmd->setText("ding"); |
|
1425 new InsertCommand(&str, 5, "world", cmd); |
|
1426 new RemoveCommand(&str, 4, 1, cmd); |
|
1427 stack.push(cmd); |
|
1428 QCOMPARE(str, QString("hellworld")); |
|
1429 checkState(redoTextChangedSpy, |
|
1430 canRedoChangedSpy, |
|
1431 undoTextChangedSpy, |
|
1432 redoAction, |
|
1433 undoAction, |
|
1434 canUndoChangedSpy, |
|
1435 cleanChangedSpy, |
|
1436 indexChangedSpy, |
|
1437 stack, |
|
1438 false, // clean |
|
1439 2, // count |
|
1440 2, // index |
|
1441 true, // canUndo |
|
1442 "ding", // undoText |
|
1443 false, // canRedo |
|
1444 "", // redoText |
|
1445 false, // cleanChanged |
|
1446 true, // indexChanged |
|
1447 true, // undoChanged |
|
1448 true); // redoChanged |
|
1449 |
|
1450 stack.undo(); |
|
1451 QCOMPARE(str, QString("hello")); |
|
1452 checkState(redoTextChangedSpy, |
|
1453 canRedoChangedSpy, |
|
1454 undoTextChangedSpy, |
|
1455 redoAction, |
|
1456 undoAction, |
|
1457 canUndoChangedSpy, |
|
1458 cleanChangedSpy, |
|
1459 indexChangedSpy, |
|
1460 stack, |
|
1461 false, // clean |
|
1462 2, // count |
|
1463 1, // index |
|
1464 true, // canUndo |
|
1465 "insert", // undoText |
|
1466 true, // canRedo |
|
1467 "ding", // redoText |
|
1468 false, // cleanChanged |
|
1469 true, // indexChanged |
|
1470 true, // undoChanged |
|
1471 true); // redoChanged |
|
1472 |
|
1473 stack.redo(); |
|
1474 QCOMPARE(str, QString("hellworld")); |
|
1475 checkState(redoTextChangedSpy, |
|
1476 canRedoChangedSpy, |
|
1477 undoTextChangedSpy, |
|
1478 redoAction, |
|
1479 undoAction, |
|
1480 canUndoChangedSpy, |
|
1481 cleanChangedSpy, |
|
1482 indexChangedSpy, |
|
1483 stack, |
|
1484 false, // clean |
|
1485 2, // count |
|
1486 2, // index |
|
1487 true, // canUndo |
|
1488 "ding", // undoText |
|
1489 false, // canRedo |
|
1490 "", // redoText |
|
1491 false, // cleanChanged |
|
1492 true, // indexChanged |
|
1493 true, // undoChanged |
|
1494 true); // redoChanged |
|
1495 |
|
1496 delete undoAction; |
|
1497 delete redoAction; |
|
1498 } |
|
1499 |
|
1500 void tst_QUndoStack::macroBeginEnd() |
|
1501 { |
|
1502 QUndoStack stack; |
|
1503 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
1504 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
1505 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
1506 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
1507 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
1508 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
1509 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
1510 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
1511 QString str; |
|
1512 |
|
1513 stack.beginMacro("ding"); |
|
1514 checkState(redoTextChangedSpy, |
|
1515 canRedoChangedSpy, |
|
1516 undoTextChangedSpy, |
|
1517 redoAction, |
|
1518 undoAction, |
|
1519 canUndoChangedSpy, |
|
1520 cleanChangedSpy, |
|
1521 indexChangedSpy, |
|
1522 stack, |
|
1523 false, // clean |
|
1524 1, // count |
|
1525 0, // index |
|
1526 false, // canUndo |
|
1527 "", // undoText |
|
1528 false, // canRedo |
|
1529 "", // redoText |
|
1530 false, // cleanChanged |
|
1531 false, // indexChanged |
|
1532 true, // undoChanged |
|
1533 true); // redoChanged |
|
1534 |
|
1535 stack.setClean(); // should do nothing |
|
1536 checkState(redoTextChangedSpy, |
|
1537 canRedoChangedSpy, |
|
1538 undoTextChangedSpy, |
|
1539 redoAction, |
|
1540 undoAction, |
|
1541 canUndoChangedSpy, |
|
1542 cleanChangedSpy, |
|
1543 indexChangedSpy, |
|
1544 stack, |
|
1545 false, // clean |
|
1546 1, // count |
|
1547 0, // index |
|
1548 false, // canUndo |
|
1549 "", // undoText |
|
1550 false, // canRedo |
|
1551 "", // redoText |
|
1552 false, // cleanChanged |
|
1553 false, // indexChanged |
|
1554 false, // undoChanged |
|
1555 false); // redoChanged |
|
1556 |
|
1557 stack.undo(); // should do nothing |
|
1558 checkState(redoTextChangedSpy, |
|
1559 canRedoChangedSpy, |
|
1560 undoTextChangedSpy, |
|
1561 redoAction, |
|
1562 undoAction, |
|
1563 canUndoChangedSpy, |
|
1564 cleanChangedSpy, |
|
1565 indexChangedSpy, |
|
1566 stack, |
|
1567 false, // clean |
|
1568 1, // count |
|
1569 0, // index |
|
1570 false, // canUndo |
|
1571 "", // undoText |
|
1572 false, // canRedo |
|
1573 "", // redoText |
|
1574 false, // cleanChanged |
|
1575 false, // indexChanged |
|
1576 false, // undoChanged |
|
1577 false); // redoChanged |
|
1578 |
|
1579 stack.redo(); // should do nothing |
|
1580 checkState(redoTextChangedSpy, |
|
1581 canRedoChangedSpy, |
|
1582 undoTextChangedSpy, |
|
1583 redoAction, |
|
1584 undoAction, |
|
1585 canUndoChangedSpy, |
|
1586 cleanChangedSpy, |
|
1587 indexChangedSpy, |
|
1588 stack, |
|
1589 false, // clean |
|
1590 1, // count |
|
1591 0, // index |
|
1592 false, // canUndo |
|
1593 "", // undoText |
|
1594 false, // canRedo |
|
1595 "", // redoText |
|
1596 false, // cleanChanged |
|
1597 false, // indexChanged |
|
1598 false, // undoChanged |
|
1599 false); // redoChanged |
|
1600 |
|
1601 stack.setIndex(0); // should do nothing |
|
1602 checkState(redoTextChangedSpy, |
|
1603 canRedoChangedSpy, |
|
1604 undoTextChangedSpy, |
|
1605 redoAction, |
|
1606 undoAction, |
|
1607 canUndoChangedSpy, |
|
1608 cleanChangedSpy, |
|
1609 indexChangedSpy, |
|
1610 stack, |
|
1611 false, // clean |
|
1612 1, // count |
|
1613 0, // index |
|
1614 false, // canUndo |
|
1615 "", // undoText |
|
1616 false, // canRedo |
|
1617 "", // redoText |
|
1618 false, // cleanChanged |
|
1619 false, // indexChanged |
|
1620 false, // undoChanged |
|
1621 false); // redoChanged |
|
1622 |
|
1623 stack.endMacro(); |
|
1624 checkState(redoTextChangedSpy, |
|
1625 canRedoChangedSpy, |
|
1626 undoTextChangedSpy, |
|
1627 redoAction, |
|
1628 undoAction, |
|
1629 canUndoChangedSpy, |
|
1630 cleanChangedSpy, |
|
1631 indexChangedSpy, |
|
1632 stack, |
|
1633 false, // clean |
|
1634 1, // count |
|
1635 1, // index - endMacro() increments index |
|
1636 true, // canUndo |
|
1637 "ding", // undoText |
|
1638 false, // canRedo |
|
1639 "", // redoText |
|
1640 true, // cleanChanged |
|
1641 true, // indexChanged |
|
1642 true, // undoChanged |
|
1643 true); // redoChanged |
|
1644 |
|
1645 stack.push(new InsertCommand(&str, 0, "h")); |
|
1646 QCOMPARE(str, QString("h")); |
|
1647 checkState(redoTextChangedSpy, |
|
1648 canRedoChangedSpy, |
|
1649 undoTextChangedSpy, |
|
1650 redoAction, |
|
1651 undoAction, |
|
1652 canUndoChangedSpy, |
|
1653 cleanChangedSpy, |
|
1654 indexChangedSpy, |
|
1655 stack, |
|
1656 false, // clean |
|
1657 2, // count |
|
1658 2, // index |
|
1659 true, // canUndo |
|
1660 "insert", // undoText |
|
1661 false, // canRedo |
|
1662 "", // redoText |
|
1663 false, // cleanChanged |
|
1664 true, // indexChanged |
|
1665 true, // undoChanged |
|
1666 true); // redoChanged |
|
1667 |
|
1668 stack.push(new InsertCommand(&str, 1, "owdy")); |
|
1669 QCOMPARE(str, QString("howdy")); |
|
1670 checkState(redoTextChangedSpy, |
|
1671 canRedoChangedSpy, |
|
1672 undoTextChangedSpy, |
|
1673 redoAction, |
|
1674 undoAction, |
|
1675 canUndoChangedSpy, |
|
1676 cleanChangedSpy, |
|
1677 indexChangedSpy, |
|
1678 stack, |
|
1679 false, // clean |
|
1680 3, // count |
|
1681 3, // index |
|
1682 true, // canUndo |
|
1683 "insert", // undoText |
|
1684 false, // canRedo |
|
1685 "", // redoText |
|
1686 false, // cleanChanged |
|
1687 true, // indexChanged |
|
1688 true, // undoChanged |
|
1689 true); // redoChanged |
|
1690 |
|
1691 stack.setIndex(2); |
|
1692 QCOMPARE(str, QString("h")); |
|
1693 checkState(redoTextChangedSpy, |
|
1694 canRedoChangedSpy, |
|
1695 undoTextChangedSpy, |
|
1696 redoAction, |
|
1697 undoAction, |
|
1698 canUndoChangedSpy, |
|
1699 cleanChangedSpy, |
|
1700 indexChangedSpy, |
|
1701 stack, |
|
1702 false, // clean |
|
1703 3, // count |
|
1704 2, // index |
|
1705 true, // canUndo |
|
1706 "insert", // undoText |
|
1707 true, // canRedo |
|
1708 "insert", // redoText |
|
1709 false, // cleanChanged |
|
1710 true, // indexChanged |
|
1711 true, // undoChanged |
|
1712 true); // redoChanged |
|
1713 |
|
1714 stack.beginMacro("dong"); // the "owdy" command gets deleted |
|
1715 checkState(redoTextChangedSpy, |
|
1716 canRedoChangedSpy, |
|
1717 undoTextChangedSpy, |
|
1718 redoAction, |
|
1719 undoAction, |
|
1720 canUndoChangedSpy, |
|
1721 cleanChangedSpy, |
|
1722 indexChangedSpy, |
|
1723 stack, |
|
1724 false, // clean |
|
1725 3, // count |
|
1726 2, // index |
|
1727 false, // canUndo |
|
1728 "", // undoText |
|
1729 false, // canRedo |
|
1730 "", // redoText |
|
1731 false, // cleanChanged |
|
1732 false, // indexChanged |
|
1733 true, // undoChanged |
|
1734 true); // redoChanged |
|
1735 |
|
1736 stack.push(new InsertCommand(&str, 1, "ello")); |
|
1737 QCOMPARE(str, QString("hello")); |
|
1738 checkState(redoTextChangedSpy, |
|
1739 canRedoChangedSpy, |
|
1740 undoTextChangedSpy, |
|
1741 redoAction, |
|
1742 undoAction, |
|
1743 canUndoChangedSpy, |
|
1744 cleanChangedSpy, |
|
1745 indexChangedSpy, |
|
1746 stack, |
|
1747 false, // clean |
|
1748 3, // count |
|
1749 2, // index |
|
1750 false, // canUndo |
|
1751 "", // undoText |
|
1752 false, // canRedo |
|
1753 "", // redoText |
|
1754 false, // cleanChanged |
|
1755 false, // indexChanged |
|
1756 false, // undoChanged |
|
1757 false); // redoChanged |
|
1758 |
|
1759 stack.push(new RemoveCommand(&str, 1, 2)); |
|
1760 QCOMPARE(str, QString("hlo")); |
|
1761 checkState(redoTextChangedSpy, |
|
1762 canRedoChangedSpy, |
|
1763 undoTextChangedSpy, |
|
1764 redoAction, |
|
1765 undoAction, |
|
1766 canUndoChangedSpy, |
|
1767 cleanChangedSpy, |
|
1768 indexChangedSpy, |
|
1769 stack, |
|
1770 false, // clean |
|
1771 3, // count |
|
1772 2, // index |
|
1773 false, // canUndo |
|
1774 "", // undoText |
|
1775 false, // canRedo |
|
1776 "", // redoText |
|
1777 false, // cleanChanged |
|
1778 false, // indexChanged |
|
1779 false, // undoChanged |
|
1780 false); // redoChanged |
|
1781 |
|
1782 stack.beginMacro("dong2"); |
|
1783 QCOMPARE(str, QString("hlo")); |
|
1784 checkState(redoTextChangedSpy, |
|
1785 canRedoChangedSpy, |
|
1786 undoTextChangedSpy, |
|
1787 redoAction, |
|
1788 undoAction, |
|
1789 canUndoChangedSpy, |
|
1790 cleanChangedSpy, |
|
1791 indexChangedSpy, |
|
1792 stack, |
|
1793 false, // clean |
|
1794 3, // count |
|
1795 2, // index |
|
1796 false, // canUndo |
|
1797 "", // undoText |
|
1798 false, // canRedo |
|
1799 "", // redoText |
|
1800 false, // cleanChanged |
|
1801 false, // indexChanged |
|
1802 false, // undoChanged |
|
1803 false); // redoChanged |
|
1804 |
|
1805 stack.push(new RemoveCommand(&str, 1, 1)); |
|
1806 QCOMPARE(str, QString("ho")); |
|
1807 checkState(redoTextChangedSpy, |
|
1808 canRedoChangedSpy, |
|
1809 undoTextChangedSpy, |
|
1810 redoAction, |
|
1811 undoAction, |
|
1812 canUndoChangedSpy, |
|
1813 cleanChangedSpy, |
|
1814 indexChangedSpy, |
|
1815 stack, |
|
1816 false, // clean |
|
1817 3, // count |
|
1818 2, // index |
|
1819 false, // canUndo |
|
1820 "", // undoText |
|
1821 false, // canRedo |
|
1822 "", // redoText |
|
1823 false, // cleanChanged |
|
1824 false, // indexChanged |
|
1825 false, // undoChanged |
|
1826 false); // redoChanged |
|
1827 |
|
1828 stack.endMacro(); |
|
1829 QCOMPARE(str, QString("ho")); |
|
1830 checkState(redoTextChangedSpy, |
|
1831 canRedoChangedSpy, |
|
1832 undoTextChangedSpy, |
|
1833 redoAction, |
|
1834 undoAction, |
|
1835 canUndoChangedSpy, |
|
1836 cleanChangedSpy, |
|
1837 indexChangedSpy, |
|
1838 stack, |
|
1839 false, // clean |
|
1840 3, // count |
|
1841 2, // index |
|
1842 false, // canUndo |
|
1843 "", // undoText |
|
1844 false, // canRedo |
|
1845 "", // redoText |
|
1846 false, // cleanChanged |
|
1847 false, // indexChanged |
|
1848 false, // undoChanged |
|
1849 false); // redoChanged |
|
1850 |
|
1851 stack.endMacro(); |
|
1852 QCOMPARE(str, QString("ho")); |
|
1853 checkState(redoTextChangedSpy, |
|
1854 canRedoChangedSpy, |
|
1855 undoTextChangedSpy, |
|
1856 redoAction, |
|
1857 undoAction, |
|
1858 canUndoChangedSpy, |
|
1859 cleanChangedSpy, |
|
1860 indexChangedSpy, |
|
1861 stack, |
|
1862 false, // clean |
|
1863 3, // count |
|
1864 3, // index |
|
1865 true, // canUndo |
|
1866 "dong", // undoText |
|
1867 false, // canRedo |
|
1868 "", // redoText |
|
1869 false, // cleanChanged |
|
1870 true, // indexChanged |
|
1871 true, // undoChanged |
|
1872 true); // redoChanged |
|
1873 |
|
1874 stack.undo(); |
|
1875 QCOMPARE(str, QString("h")); |
|
1876 checkState(redoTextChangedSpy, |
|
1877 canRedoChangedSpy, |
|
1878 undoTextChangedSpy, |
|
1879 redoAction, |
|
1880 undoAction, |
|
1881 canUndoChangedSpy, |
|
1882 cleanChangedSpy, |
|
1883 indexChangedSpy, |
|
1884 stack, |
|
1885 false, // clean |
|
1886 3, // count |
|
1887 2, // index |
|
1888 true, // canUndo |
|
1889 "insert", // undoText |
|
1890 true, // canRedo |
|
1891 "dong", // redoText |
|
1892 false, // cleanChanged |
|
1893 true, // indexChanged |
|
1894 true, // undoChanged |
|
1895 true); // redoChanged |
|
1896 |
|
1897 stack.undo(); |
|
1898 QCOMPARE(str, QString("")); |
|
1899 checkState(redoTextChangedSpy, |
|
1900 canRedoChangedSpy, |
|
1901 undoTextChangedSpy, |
|
1902 redoAction, |
|
1903 undoAction, |
|
1904 canUndoChangedSpy, |
|
1905 cleanChangedSpy, |
|
1906 indexChangedSpy, |
|
1907 stack, |
|
1908 false, // clean |
|
1909 3, // count |
|
1910 1, // index |
|
1911 true, // canUndo |
|
1912 "ding", // undoText |
|
1913 true, // canRedo |
|
1914 "insert", // redoText |
|
1915 false, // cleanChanged |
|
1916 true, // indexChanged |
|
1917 true, // undoChanged |
|
1918 true); // redoChanged |
|
1919 |
|
1920 stack.setIndex(3); |
|
1921 QCOMPARE(str, QString("ho")); |
|
1922 checkState(redoTextChangedSpy, |
|
1923 canRedoChangedSpy, |
|
1924 undoTextChangedSpy, |
|
1925 redoAction, |
|
1926 undoAction, |
|
1927 canUndoChangedSpy, |
|
1928 cleanChangedSpy, |
|
1929 indexChangedSpy, |
|
1930 stack, |
|
1931 false, // clean |
|
1932 3, // count |
|
1933 3, // index |
|
1934 true, // canUndo |
|
1935 "dong", // undoText |
|
1936 false, // canRedo |
|
1937 "", // redoText |
|
1938 false, // cleanChanged |
|
1939 true, // indexChanged |
|
1940 true, // undoChanged |
|
1941 true); // redoChanged |
|
1942 |
|
1943 stack.setIndex(1); |
|
1944 QCOMPARE(str, QString()); |
|
1945 checkState(redoTextChangedSpy, |
|
1946 canRedoChangedSpy, |
|
1947 undoTextChangedSpy, |
|
1948 redoAction, |
|
1949 undoAction, |
|
1950 canUndoChangedSpy, |
|
1951 cleanChangedSpy, |
|
1952 indexChangedSpy, |
|
1953 stack, |
|
1954 false, // clean |
|
1955 3, // count |
|
1956 1, // index |
|
1957 true, // canUndo |
|
1958 "ding", // undoText |
|
1959 true, // canRedo |
|
1960 "insert", // redoText |
|
1961 false, // cleanChanged |
|
1962 true, // indexChanged |
|
1963 true, // undoChanged |
|
1964 true); // redoChanged |
|
1965 |
|
1966 delete undoAction; |
|
1967 delete redoAction; |
|
1968 } |
|
1969 |
|
1970 void tst_QUndoStack::compression() |
|
1971 { |
|
1972 QUndoStack stack; |
|
1973 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
1974 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
1975 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
1976 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
1977 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
1978 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
1979 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
1980 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
1981 QString str; |
|
1982 |
|
1983 AppendCommand::delete_cnt = 0; |
|
1984 |
|
1985 stack.push(new InsertCommand(&str, 0, "ene")); |
|
1986 QCOMPARE(str, QString("ene")); |
|
1987 checkState(redoTextChangedSpy, |
|
1988 canRedoChangedSpy, |
|
1989 undoTextChangedSpy, |
|
1990 redoAction, |
|
1991 undoAction, |
|
1992 canUndoChangedSpy, |
|
1993 cleanChangedSpy, |
|
1994 indexChangedSpy, |
|
1995 stack, |
|
1996 false, // clean |
|
1997 1, // count |
|
1998 1, // index |
|
1999 true, // canUndo |
|
2000 "insert", // undoText |
|
2001 false, // canRedo |
|
2002 "", // redoText |
|
2003 true, // cleanChanged |
|
2004 true, // indexChanged |
|
2005 true, // undoChanged |
|
2006 true); // redoChanged |
|
2007 |
|
2008 stack.push(new AppendCommand(&str, " due")); // #1 |
|
2009 QCOMPARE(str, QString("ene due")); |
|
2010 checkState(redoTextChangedSpy, |
|
2011 canRedoChangedSpy, |
|
2012 undoTextChangedSpy, |
|
2013 redoAction, |
|
2014 undoAction, |
|
2015 canUndoChangedSpy, |
|
2016 cleanChangedSpy, |
|
2017 indexChangedSpy, |
|
2018 stack, |
|
2019 false, // clean |
|
2020 2, // count |
|
2021 2, // index |
|
2022 true, // canUndo |
|
2023 "append", // undoText |
|
2024 false, // canRedo |
|
2025 "", // redoText |
|
2026 false, // cleanChanged |
|
2027 true, // indexChanged |
|
2028 true, // undoChanged |
|
2029 true); // redoChanged |
|
2030 |
|
2031 stack.push(new AppendCommand(&str, " rike")); // #2 should merge |
|
2032 QCOMPARE(str, QString("ene due rike")); |
|
2033 QCOMPARE(AppendCommand::delete_cnt, 1); // #2 should be deleted |
|
2034 checkState(redoTextChangedSpy, |
|
2035 canRedoChangedSpy, |
|
2036 undoTextChangedSpy, |
|
2037 redoAction, |
|
2038 undoAction, |
|
2039 canUndoChangedSpy, |
|
2040 cleanChangedSpy, |
|
2041 indexChangedSpy, |
|
2042 stack, |
|
2043 false, // clean |
|
2044 2, // count |
|
2045 2, // index |
|
2046 true, // canUndo |
|
2047 "append", // undoText |
|
2048 false, // canRedo |
|
2049 "", // redoText |
|
2050 false, // cleanChanged |
|
2051 true, // indexChanged |
|
2052 true, // undoChanged |
|
2053 true); // redoChanged |
|
2054 |
|
2055 stack.setClean(); |
|
2056 checkState(redoTextChangedSpy, |
|
2057 canRedoChangedSpy, |
|
2058 undoTextChangedSpy, |
|
2059 redoAction, |
|
2060 undoAction, |
|
2061 canUndoChangedSpy, |
|
2062 cleanChangedSpy, |
|
2063 indexChangedSpy, |
|
2064 stack, |
|
2065 true, // clean |
|
2066 2, // count |
|
2067 2, // index |
|
2068 true, // canUndo |
|
2069 "append", // undoText |
|
2070 false, // canRedo |
|
2071 "", // redoText |
|
2072 true, // cleanChanged |
|
2073 false, // indexChanged |
|
2074 false, // undoChanged |
|
2075 false); // redoChanged |
|
2076 |
|
2077 stack.push(new AppendCommand(&str, " fake")); // #3 should NOT merge, since the stack was clean |
|
2078 QCOMPARE(str, QString("ene due rike fake")); // and we want to be able to return to this state |
|
2079 QCOMPARE(AppendCommand::delete_cnt, 1); // #3 should not be deleted |
|
2080 checkState(redoTextChangedSpy, |
|
2081 canRedoChangedSpy, |
|
2082 undoTextChangedSpy, |
|
2083 redoAction, |
|
2084 undoAction, |
|
2085 canUndoChangedSpy, |
|
2086 cleanChangedSpy, |
|
2087 indexChangedSpy, |
|
2088 stack, |
|
2089 false, // clean |
|
2090 3, // count |
|
2091 3, // index |
|
2092 true, // canUndo |
|
2093 "append", // undoText |
|
2094 false, // canRedo |
|
2095 "", // redoText |
|
2096 true, // cleanChanged |
|
2097 true, // indexChanged |
|
2098 true, // undoChanged |
|
2099 true); // redoChanged |
|
2100 |
|
2101 stack.undo(); |
|
2102 QCOMPARE(str, QString("ene due rike")); |
|
2103 checkState(redoTextChangedSpy, |
|
2104 canRedoChangedSpy, |
|
2105 undoTextChangedSpy, |
|
2106 redoAction, |
|
2107 undoAction, |
|
2108 canUndoChangedSpy, |
|
2109 cleanChangedSpy, |
|
2110 indexChangedSpy, |
|
2111 stack, |
|
2112 true, // clean |
|
2113 3, // count |
|
2114 2, // index |
|
2115 true, // canUndo |
|
2116 "append", // undoText |
|
2117 true, // canRedo |
|
2118 "append", // redoText |
|
2119 true, // cleanChanged |
|
2120 true, // indexChanged |
|
2121 true, // undoChanged |
|
2122 true); // redoChanged |
|
2123 |
|
2124 stack.undo(); |
|
2125 QCOMPARE(str, QString("ene")); |
|
2126 checkState(redoTextChangedSpy, |
|
2127 canRedoChangedSpy, |
|
2128 undoTextChangedSpy, |
|
2129 redoAction, |
|
2130 undoAction, |
|
2131 canUndoChangedSpy, |
|
2132 cleanChangedSpy, |
|
2133 indexChangedSpy, |
|
2134 stack, |
|
2135 false, // clean |
|
2136 3, // count |
|
2137 1, // index |
|
2138 true, // canUndo |
|
2139 "insert", // undoText |
|
2140 true, // canRedo |
|
2141 "append", // redoText |
|
2142 true, // cleanChanged |
|
2143 true, // indexChanged |
|
2144 true, // undoChanged |
|
2145 true); // redoChanged |
|
2146 |
|
2147 stack.push(new AppendCommand(&str, "ma", true)); // #4 clean state gets deleted! |
|
2148 QCOMPARE(str, QString("enema")); |
|
2149 QCOMPARE(AppendCommand::delete_cnt, 3); // #1 got deleted |
|
2150 checkState(redoTextChangedSpy, |
|
2151 canRedoChangedSpy, |
|
2152 undoTextChangedSpy, |
|
2153 redoAction, |
|
2154 undoAction, |
|
2155 canUndoChangedSpy, |
|
2156 cleanChangedSpy, |
|
2157 indexChangedSpy, |
|
2158 stack, |
|
2159 false, // clean |
|
2160 2, // count |
|
2161 2, // index |
|
2162 true, // canUndo |
|
2163 "append", // undoText |
|
2164 false, // canRedo |
|
2165 "", // redoText |
|
2166 false, // cleanChanged |
|
2167 true, // indexChanged |
|
2168 true, // undoChanged |
|
2169 true); // redoChanged |
|
2170 |
|
2171 stack.push(new AppendCommand(&str, "trix")); // #5 should NOT merge |
|
2172 QCOMPARE(str, QString("enematrix")); |
|
2173 QCOMPARE(AppendCommand::delete_cnt, 3); |
|
2174 checkState(redoTextChangedSpy, |
|
2175 canRedoChangedSpy, |
|
2176 undoTextChangedSpy, |
|
2177 redoAction, |
|
2178 undoAction, |
|
2179 canUndoChangedSpy, |
|
2180 cleanChangedSpy, |
|
2181 indexChangedSpy, |
|
2182 stack, |
|
2183 false, // clean |
|
2184 3, // count |
|
2185 3, // index |
|
2186 true, // canUndo |
|
2187 "append", // undoText |
|
2188 false, // canRedo |
|
2189 "", // redoText |
|
2190 false, // cleanChanged |
|
2191 true, // indexChanged |
|
2192 true, // undoChanged |
|
2193 true); // redoChanged |
|
2194 |
|
2195 stack.undo(); |
|
2196 QCOMPARE(str, QString("enema")); |
|
2197 checkState(redoTextChangedSpy, |
|
2198 canRedoChangedSpy, |
|
2199 undoTextChangedSpy, |
|
2200 redoAction, |
|
2201 undoAction, |
|
2202 canUndoChangedSpy, |
|
2203 cleanChangedSpy, |
|
2204 indexChangedSpy, |
|
2205 stack, |
|
2206 false, // clean |
|
2207 3, // count |
|
2208 2, // index |
|
2209 true, // canUndo |
|
2210 "append", // undoText |
|
2211 true, // canRedo |
|
2212 "append", // redoText |
|
2213 false, // cleanChanged |
|
2214 true, // indexChanged |
|
2215 true, // undoChanged |
|
2216 true); // redoChanged |
|
2217 |
|
2218 // and now for command compression inside macros |
|
2219 |
|
2220 stack.setClean(); |
|
2221 QCOMPARE(str, QString("enema")); |
|
2222 checkState(redoTextChangedSpy, |
|
2223 canRedoChangedSpy, |
|
2224 undoTextChangedSpy, |
|
2225 redoAction, |
|
2226 undoAction, |
|
2227 canUndoChangedSpy, |
|
2228 cleanChangedSpy, |
|
2229 indexChangedSpy, |
|
2230 stack, |
|
2231 true, // clean |
|
2232 3, // count |
|
2233 2, // index |
|
2234 true, // canUndo |
|
2235 "append", // undoText |
|
2236 true, // canRedo |
|
2237 "append", // redoText |
|
2238 true, // cleanChanged |
|
2239 false, // indexChanged |
|
2240 false, // undoChanged |
|
2241 false); // redoChanged |
|
2242 |
|
2243 stack.beginMacro("ding"); |
|
2244 QCOMPARE(str, QString("enema")); |
|
2245 QCOMPARE(AppendCommand::delete_cnt, 4); // #5 gets deleted |
|
2246 checkState(redoTextChangedSpy, |
|
2247 canRedoChangedSpy, |
|
2248 undoTextChangedSpy, |
|
2249 redoAction, |
|
2250 undoAction, |
|
2251 canUndoChangedSpy, |
|
2252 cleanChangedSpy, |
|
2253 indexChangedSpy, |
|
2254 stack, |
|
2255 false, // clean |
|
2256 3, // count |
|
2257 2, // index |
|
2258 false, // canUndo |
|
2259 "", // undoText |
|
2260 false, // canRedo |
|
2261 "", // redoText |
|
2262 false, // cleanChanged |
|
2263 false, // indexChanged |
|
2264 true, // undoChanged |
|
2265 true); // redoChanged |
|
2266 |
|
2267 AppendCommand *merge_cmd = new AppendCommand(&str, "top"); |
|
2268 stack.push(merge_cmd); // #6 |
|
2269 QCOMPARE(merge_cmd->merged, false); |
|
2270 QCOMPARE(str, QString("enematop")); |
|
2271 checkState(redoTextChangedSpy, |
|
2272 canRedoChangedSpy, |
|
2273 undoTextChangedSpy, |
|
2274 redoAction, |
|
2275 undoAction, |
|
2276 canUndoChangedSpy, |
|
2277 cleanChangedSpy, |
|
2278 indexChangedSpy, |
|
2279 stack, |
|
2280 false, // clean |
|
2281 3, // count |
|
2282 2, // index |
|
2283 false, // canUndo |
|
2284 "", // undoText |
|
2285 false, // canRedo |
|
2286 "", // redoText |
|
2287 false, // cleanChanged |
|
2288 false, // indexChanged |
|
2289 false, // undoChanged |
|
2290 false); // redoChanged |
|
2291 |
|
2292 stack.push(new AppendCommand(&str, "eja")); // #7 should merge |
|
2293 QCOMPARE(str, QString("enematopeja")); |
|
2294 QCOMPARE(merge_cmd->merged, true); |
|
2295 QCOMPARE(AppendCommand::delete_cnt, 5); // #7 gets deleted |
|
2296 checkState(redoTextChangedSpy, |
|
2297 canRedoChangedSpy, |
|
2298 undoTextChangedSpy, |
|
2299 redoAction, |
|
2300 undoAction, |
|
2301 canUndoChangedSpy, |
|
2302 cleanChangedSpy, |
|
2303 indexChangedSpy, |
|
2304 stack, |
|
2305 false, // clean |
|
2306 3, // count |
|
2307 2, // index |
|
2308 false, // canUndo |
|
2309 "", // undoText |
|
2310 false, // canRedo |
|
2311 "", // redoText |
|
2312 false, // cleanChanged |
|
2313 false, // indexChanged |
|
2314 false, // undoChanged |
|
2315 false); // redoChanged |
|
2316 merge_cmd->merged = false; |
|
2317 |
|
2318 stack.push(new InsertCommand(&str, 2, "123")); // should not merge |
|
2319 QCOMPARE(str, QString("en123ematopeja")); |
|
2320 QCOMPARE(merge_cmd->merged, false); |
|
2321 checkState(redoTextChangedSpy, |
|
2322 canRedoChangedSpy, |
|
2323 undoTextChangedSpy, |
|
2324 redoAction, |
|
2325 undoAction, |
|
2326 canUndoChangedSpy, |
|
2327 cleanChangedSpy, |
|
2328 indexChangedSpy, |
|
2329 stack, |
|
2330 false, // clean |
|
2331 3, // count |
|
2332 2, // index |
|
2333 false, // canUndo |
|
2334 "", // undoText |
|
2335 false, // canRedo |
|
2336 "", // redoText |
|
2337 false, // cleanChanged |
|
2338 false, // indexChanged |
|
2339 false, // undoChanged |
|
2340 false); // redoChanged |
|
2341 |
|
2342 stack.endMacro(); |
|
2343 QCOMPARE(str, QString("en123ematopeja")); |
|
2344 checkState(redoTextChangedSpy, |
|
2345 canRedoChangedSpy, |
|
2346 undoTextChangedSpy, |
|
2347 redoAction, |
|
2348 undoAction, |
|
2349 canUndoChangedSpy, |
|
2350 cleanChangedSpy, |
|
2351 indexChangedSpy, |
|
2352 stack, |
|
2353 false, // clean |
|
2354 3, // count |
|
2355 3, // index |
|
2356 true, // canUndo |
|
2357 "ding", // undoText |
|
2358 false, // canRedo |
|
2359 "", // redoText |
|
2360 true, // cleanChanged |
|
2361 true, // indexChanged |
|
2362 true, // undoChanged |
|
2363 true); // redoChanged |
|
2364 |
|
2365 stack.undo(); |
|
2366 QCOMPARE(str, QString("enema")); |
|
2367 checkState(redoTextChangedSpy, |
|
2368 canRedoChangedSpy, |
|
2369 undoTextChangedSpy, |
|
2370 redoAction, |
|
2371 undoAction, |
|
2372 canUndoChangedSpy, |
|
2373 cleanChangedSpy, |
|
2374 indexChangedSpy, |
|
2375 stack, |
|
2376 true, // clean |
|
2377 3, // count |
|
2378 2, // index |
|
2379 true, // canUndo |
|
2380 "append", // undoText |
|
2381 true, // canRedo |
|
2382 "ding", // redoText |
|
2383 true, // cleanChanged |
|
2384 true, // indexChanged |
|
2385 true, // undoChanged |
|
2386 true); // redoChanged |
|
2387 |
|
2388 stack.redo(); |
|
2389 QCOMPARE(str, QString("en123ematopeja")); |
|
2390 checkState(redoTextChangedSpy, |
|
2391 canRedoChangedSpy, |
|
2392 undoTextChangedSpy, |
|
2393 redoAction, |
|
2394 undoAction, |
|
2395 canUndoChangedSpy, |
|
2396 cleanChangedSpy, |
|
2397 indexChangedSpy, |
|
2398 stack, |
|
2399 false, // clean |
|
2400 3, // count |
|
2401 3, // index |
|
2402 true, // canUndo |
|
2403 "ding", // undoText |
|
2404 false, // canRedo |
|
2405 "", // redoText |
|
2406 true, // cleanChanged |
|
2407 true, // indexChanged |
|
2408 true, // undoChanged |
|
2409 true); // redoChanged |
|
2410 |
|
2411 delete undoAction; |
|
2412 delete redoAction; |
|
2413 } |
|
2414 |
|
2415 void tst_QUndoStack::undoLimit() |
|
2416 { |
|
2417 QUndoStack stack; |
|
2418 QAction *undoAction = stack.createUndoAction(0, QString("foo")); |
|
2419 QAction *redoAction = stack.createRedoAction(0, QString("bar")); |
|
2420 QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); |
|
2421 QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); |
|
2422 QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); |
|
2423 QSignalSpy undoTextChangedSpy(&stack, SIGNAL(undoTextChanged(QString))); |
|
2424 QSignalSpy canRedoChangedSpy(&stack, SIGNAL(canRedoChanged(bool))); |
|
2425 QSignalSpy redoTextChangedSpy(&stack, SIGNAL(redoTextChanged(QString))); |
|
2426 AppendCommand::delete_cnt = 0; |
|
2427 QString str; |
|
2428 |
|
2429 QCOMPARE(stack.undoLimit(), 0); |
|
2430 stack.setUndoLimit(2); |
|
2431 QCOMPARE(stack.undoLimit(), 2); |
|
2432 |
|
2433 stack.push(new AppendCommand(&str, "1", true)); |
|
2434 QCOMPARE(str, QString("1")); |
|
2435 QCOMPARE(AppendCommand::delete_cnt, 0); |
|
2436 checkState(redoTextChangedSpy, |
|
2437 canRedoChangedSpy, |
|
2438 undoTextChangedSpy, |
|
2439 redoAction, |
|
2440 undoAction, |
|
2441 canUndoChangedSpy, |
|
2442 cleanChangedSpy, |
|
2443 indexChangedSpy, |
|
2444 stack, |
|
2445 false, // clean |
|
2446 1, // count |
|
2447 1, // index |
|
2448 true, // canUndo |
|
2449 "append", // undoText |
|
2450 false, // canRedo |
|
2451 "", // redoText |
|
2452 true, // cleanChanged |
|
2453 true, // indexChanged |
|
2454 true, // undoChanged |
|
2455 true); // redoChanged |
|
2456 |
|
2457 stack.push(new AppendCommand(&str, "2", true)); |
|
2458 QCOMPARE(str, QString("12")); |
|
2459 QCOMPARE(AppendCommand::delete_cnt, 0); |
|
2460 checkState(redoTextChangedSpy, |
|
2461 canRedoChangedSpy, |
|
2462 undoTextChangedSpy, |
|
2463 redoAction, |
|
2464 undoAction, |
|
2465 canUndoChangedSpy, |
|
2466 cleanChangedSpy, |
|
2467 indexChangedSpy, |
|
2468 stack, |
|
2469 false, // clean |
|
2470 2, // count |
|
2471 2, // index |
|
2472 true, // canUndo |
|
2473 "append", // undoText |
|
2474 false, // canRedo |
|
2475 "", // redoText |
|
2476 false, // cleanChanged |
|
2477 true, // indexChanged |
|
2478 true, // undoChanged |
|
2479 true); // redoChanged |
|
2480 |
|
2481 stack.setClean(); |
|
2482 QCOMPARE(str, QString("12")); |
|
2483 QCOMPARE(AppendCommand::delete_cnt, 0); |
|
2484 checkState(redoTextChangedSpy, |
|
2485 canRedoChangedSpy, |
|
2486 undoTextChangedSpy, |
|
2487 redoAction, |
|
2488 undoAction, |
|
2489 canUndoChangedSpy, |
|
2490 cleanChangedSpy, |
|
2491 indexChangedSpy, |
|
2492 stack, |
|
2493 true, // clean |
|
2494 2, // count |
|
2495 2, // index |
|
2496 true, // canUndo |
|
2497 "append", // undoText |
|
2498 false, // canRedo |
|
2499 "", // redoText |
|
2500 true, // cleanChanged |
|
2501 false, // indexChanged |
|
2502 false, // undoChanged |
|
2503 false); // redoChanged |
|
2504 |
|
2505 stack.push(new AppendCommand(&str, "3", true)); |
|
2506 QCOMPARE(str, QString("123")); |
|
2507 QCOMPARE(AppendCommand::delete_cnt, 1); |
|
2508 checkState(redoTextChangedSpy, |
|
2509 canRedoChangedSpy, |
|
2510 undoTextChangedSpy, |
|
2511 redoAction, |
|
2512 undoAction, |
|
2513 canUndoChangedSpy, |
|
2514 cleanChangedSpy, |
|
2515 indexChangedSpy, |
|
2516 stack, |
|
2517 false, // clean |
|
2518 2, // count |
|
2519 2, // index |
|
2520 true, // canUndo |
|
2521 "append", // undoText |
|
2522 false, // canRedo |
|
2523 "", // redoText |
|
2524 true, // cleanChanged |
|
2525 true, // indexChanged |
|
2526 true, // undoChanged |
|
2527 true); // redoChanged |
|
2528 |
|
2529 stack.push(new AppendCommand(&str, "4", true)); |
|
2530 QCOMPARE(str, QString("1234")); |
|
2531 QCOMPARE(AppendCommand::delete_cnt, 2); |
|
2532 checkState(redoTextChangedSpy, |
|
2533 canRedoChangedSpy, |
|
2534 undoTextChangedSpy, |
|
2535 redoAction, |
|
2536 undoAction, |
|
2537 canUndoChangedSpy, |
|
2538 cleanChangedSpy, |
|
2539 indexChangedSpy, |
|
2540 stack, |
|
2541 false, // clean |
|
2542 2, // count |
|
2543 2, // index |
|
2544 true, // canUndo |
|
2545 "append", // undoText |
|
2546 false, // canRedo |
|
2547 "", // redoText |
|
2548 false, // cleanChanged |
|
2549 true, // indexChanged |
|
2550 true, // undoChanged |
|
2551 true); // redoChanged |
|
2552 |
|
2553 stack.undo(); |
|
2554 QCOMPARE(str, QString("123")); |
|
2555 QCOMPARE(AppendCommand::delete_cnt, 2); |
|
2556 checkState(redoTextChangedSpy, |
|
2557 canRedoChangedSpy, |
|
2558 undoTextChangedSpy, |
|
2559 redoAction, |
|
2560 undoAction, |
|
2561 canUndoChangedSpy, |
|
2562 cleanChangedSpy, |
|
2563 indexChangedSpy, |
|
2564 stack, |
|
2565 false, // clean |
|
2566 2, // count |
|
2567 1, // index |
|
2568 true, // canUndo |
|
2569 "append", // undoText |
|
2570 true, // canRedo |
|
2571 "append", // redoText |
|
2572 false, // cleanChanged |
|
2573 true, // indexChanged |
|
2574 true, // undoChanged |
|
2575 true); // redoChanged |
|
2576 |
|
2577 stack.undo(); |
|
2578 QCOMPARE(str, QString("12")); |
|
2579 QCOMPARE(AppendCommand::delete_cnt, 2); |
|
2580 checkState(redoTextChangedSpy, |
|
2581 canRedoChangedSpy, |
|
2582 undoTextChangedSpy, |
|
2583 redoAction, |
|
2584 undoAction, |
|
2585 canUndoChangedSpy, |
|
2586 cleanChangedSpy, |
|
2587 indexChangedSpy, |
|
2588 stack, |
|
2589 true, // clean |
|
2590 2, // count |
|
2591 0, // index |
|
2592 false, // canUndo |
|
2593 "", // undoText |
|
2594 true, // canRedo |
|
2595 "append", // redoText |
|
2596 true, // cleanChanged |
|
2597 true, // indexChanged |
|
2598 true, // undoChanged |
|
2599 true); // redoChanged |
|
2600 |
|
2601 stack.push(new AppendCommand(&str, "3", true)); |
|
2602 QCOMPARE(str, QString("123")); |
|
2603 QCOMPARE(AppendCommand::delete_cnt, 4); |
|
2604 checkState(redoTextChangedSpy, |
|
2605 canRedoChangedSpy, |
|
2606 undoTextChangedSpy, |
|
2607 redoAction, |
|
2608 undoAction, |
|
2609 canUndoChangedSpy, |
|
2610 cleanChangedSpy, |
|
2611 indexChangedSpy, |
|
2612 stack, |
|
2613 false, // clean |
|
2614 1, // count |
|
2615 1, // index |
|
2616 true, // canUndo |
|
2617 "append", // undoText |
|
2618 false, // canRedo |
|
2619 "", // redoText |
|
2620 true, // cleanChanged |
|
2621 true, // indexChanged |
|
2622 true, // undoChanged |
|
2623 true); // redoChanged |
|
2624 |
|
2625 stack.push(new AppendCommand(&str, "4", true)); |
|
2626 QCOMPARE(str, QString("1234")); |
|
2627 QCOMPARE(AppendCommand::delete_cnt, 4); |
|
2628 checkState(redoTextChangedSpy, |
|
2629 canRedoChangedSpy, |
|
2630 undoTextChangedSpy, |
|
2631 redoAction, |
|
2632 undoAction, |
|
2633 canUndoChangedSpy, |
|
2634 cleanChangedSpy, |
|
2635 indexChangedSpy, |
|
2636 stack, |
|
2637 false, // clean |
|
2638 2, // count |
|
2639 2, // index |
|
2640 true, // canUndo |
|
2641 "append", // undoText |
|
2642 false, // canRedo |
|
2643 "", // redoText |
|
2644 false, // cleanChanged |
|
2645 true, // indexChanged |
|
2646 true, // undoChanged |
|
2647 true); // redoChanged |
|
2648 |
|
2649 stack.push(new AppendCommand(&str, "5", true)); |
|
2650 QCOMPARE(str, QString("12345")); |
|
2651 QCOMPARE(AppendCommand::delete_cnt, 5); |
|
2652 checkState(redoTextChangedSpy, |
|
2653 canRedoChangedSpy, |
|
2654 undoTextChangedSpy, |
|
2655 redoAction, |
|
2656 undoAction, |
|
2657 canUndoChangedSpy, |
|
2658 cleanChangedSpy, |
|
2659 indexChangedSpy, |
|
2660 stack, |
|
2661 false, // clean |
|
2662 2, // count |
|
2663 2, // index |
|
2664 true, // canUndo |
|
2665 "append", // undoText |
|
2666 false, // canRedo |
|
2667 "", // redoText |
|
2668 false, // cleanChanged |
|
2669 true, // indexChanged |
|
2670 true, // undoChanged |
|
2671 true); // redoChanged |
|
2672 |
|
2673 stack.undo(); |
|
2674 QCOMPARE(str, QString("1234")); |
|
2675 QCOMPARE(AppendCommand::delete_cnt, 5); |
|
2676 checkState(redoTextChangedSpy, |
|
2677 canRedoChangedSpy, |
|
2678 undoTextChangedSpy, |
|
2679 redoAction, |
|
2680 undoAction, |
|
2681 canUndoChangedSpy, |
|
2682 cleanChangedSpy, |
|
2683 indexChangedSpy, |
|
2684 stack, |
|
2685 false, // clean |
|
2686 2, // count |
|
2687 1, // index |
|
2688 true, // canUndo |
|
2689 "append", // undoText |
|
2690 true, // canRedo |
|
2691 "append", // redoText |
|
2692 false, // cleanChanged |
|
2693 true, // indexChanged |
|
2694 true, // undoChanged |
|
2695 true); // redoChanged |
|
2696 |
|
2697 stack.undo(); |
|
2698 QCOMPARE(str, QString("123")); |
|
2699 QCOMPARE(AppendCommand::delete_cnt, 5); |
|
2700 checkState(redoTextChangedSpy, |
|
2701 canRedoChangedSpy, |
|
2702 undoTextChangedSpy, |
|
2703 redoAction, |
|
2704 undoAction, |
|
2705 canUndoChangedSpy, |
|
2706 cleanChangedSpy, |
|
2707 indexChangedSpy, |
|
2708 stack, |
|
2709 false, // clean |
|
2710 2, // count |
|
2711 0, // index |
|
2712 false, // canUndo |
|
2713 "", // undoText |
|
2714 true, // canRedo |
|
2715 "append", // redoText |
|
2716 false, // cleanChanged |
|
2717 true, // indexChanged |
|
2718 true, // undoChanged |
|
2719 true); // redoChanged |
|
2720 |
|
2721 stack.push(new AppendCommand(&str, "4", true)); |
|
2722 QCOMPARE(str, QString("1234")); |
|
2723 QCOMPARE(AppendCommand::delete_cnt, 7); |
|
2724 checkState(redoTextChangedSpy, |
|
2725 canRedoChangedSpy, |
|
2726 undoTextChangedSpy, |
|
2727 redoAction, |
|
2728 undoAction, |
|
2729 canUndoChangedSpy, |
|
2730 cleanChangedSpy, |
|
2731 indexChangedSpy, |
|
2732 stack, |
|
2733 false, // clean |
|
2734 1, // count |
|
2735 1, // index |
|
2736 true, // canUndo |
|
2737 "append", // undoText |
|
2738 false, // canRedo |
|
2739 "", // redoText |
|
2740 false, // cleanChanged |
|
2741 true, // indexChanged |
|
2742 true, // undoChanged |
|
2743 true); // redoChanged |
|
2744 |
|
2745 stack.push(new AppendCommand(&str, "5")); |
|
2746 QCOMPARE(str, QString("12345")); |
|
2747 QCOMPARE(AppendCommand::delete_cnt, 7); |
|
2748 checkState(redoTextChangedSpy, |
|
2749 canRedoChangedSpy, |
|
2750 undoTextChangedSpy, |
|
2751 redoAction, |
|
2752 undoAction, |
|
2753 canUndoChangedSpy, |
|
2754 cleanChangedSpy, |
|
2755 indexChangedSpy, |
|
2756 stack, |
|
2757 false, // clean |
|
2758 2, // count |
|
2759 2, // index |
|
2760 true, // canUndo |
|
2761 "append", // undoText |
|
2762 false, // canRedo |
|
2763 "", // redoText |
|
2764 false, // cleanChanged |
|
2765 true, // indexChanged |
|
2766 true, // undoChanged |
|
2767 true); // redoChanged |
|
2768 |
|
2769 stack.push(new AppendCommand(&str, "6", true)); // should be merged |
|
2770 QCOMPARE(str, QString("123456")); |
|
2771 QCOMPARE(AppendCommand::delete_cnt, 8); |
|
2772 checkState(redoTextChangedSpy, |
|
2773 canRedoChangedSpy, |
|
2774 undoTextChangedSpy, |
|
2775 redoAction, |
|
2776 undoAction, |
|
2777 canUndoChangedSpy, |
|
2778 cleanChangedSpy, |
|
2779 indexChangedSpy, |
|
2780 stack, |
|
2781 false, // clean |
|
2782 2, // count |
|
2783 2, // index |
|
2784 true, // canUndo |
|
2785 "append", // undoText |
|
2786 false, // canRedo |
|
2787 "", // redoText |
|
2788 false, // cleanChanged |
|
2789 true, // indexChanged |
|
2790 true, // undoChanged |
|
2791 true); // redoChanged |
|
2792 |
|
2793 stack.beginMacro("foo"); |
|
2794 QCOMPARE(str, QString("123456")); |
|
2795 QCOMPARE(AppendCommand::delete_cnt, 8); |
|
2796 checkState(redoTextChangedSpy, |
|
2797 canRedoChangedSpy, |
|
2798 undoTextChangedSpy, |
|
2799 redoAction, |
|
2800 undoAction, |
|
2801 canUndoChangedSpy, |
|
2802 cleanChangedSpy, |
|
2803 indexChangedSpy, |
|
2804 stack, |
|
2805 false, // clean |
|
2806 3, // count |
|
2807 2, // index |
|
2808 false, // canUndo |
|
2809 "", // undoText |
|
2810 false, // canRedo |
|
2811 "", // redoText |
|
2812 false, // cleanChanged |
|
2813 false, // indexChanged |
|
2814 true, // undoChanged |
|
2815 true); // redoChanged |
|
2816 |
|
2817 stack.push(new AppendCommand(&str, "7", true)); |
|
2818 QCOMPARE(str, QString("1234567")); |
|
2819 QCOMPARE(AppendCommand::delete_cnt, 8); |
|
2820 checkState(redoTextChangedSpy, |
|
2821 canRedoChangedSpy, |
|
2822 undoTextChangedSpy, |
|
2823 redoAction, |
|
2824 undoAction, |
|
2825 canUndoChangedSpy, |
|
2826 cleanChangedSpy, |
|
2827 indexChangedSpy, |
|
2828 stack, |
|
2829 false, // clean |
|
2830 3, // count |
|
2831 2, // index |
|
2832 false, // canUndo |
|
2833 "", // undoText |
|
2834 false, // canRedo |
|
2835 "", // redoText |
|
2836 false, // cleanChanged |
|
2837 false, // indexChanged |
|
2838 false, // undoChanged |
|
2839 false); // redoChanged |
|
2840 |
|
2841 stack.push(new AppendCommand(&str, "8")); |
|
2842 QCOMPARE(str, QString("12345678")); |
|
2843 QCOMPARE(AppendCommand::delete_cnt, 8); |
|
2844 checkState(redoTextChangedSpy, |
|
2845 canRedoChangedSpy, |
|
2846 undoTextChangedSpy, |
|
2847 redoAction, |
|
2848 undoAction, |
|
2849 canUndoChangedSpy, |
|
2850 cleanChangedSpy, |
|
2851 indexChangedSpy, |
|
2852 stack, |
|
2853 false, // clean |
|
2854 3, // count |
|
2855 2, // index |
|
2856 false, // canUndo |
|
2857 "", // undoText |
|
2858 false, // canRedo |
|
2859 "", // redoText |
|
2860 false, // cleanChanged |
|
2861 false, // indexChanged |
|
2862 false, // undoChanged |
|
2863 false); // redoChanged |
|
2864 |
|
2865 stack.endMacro(); |
|
2866 QCOMPARE(str, QString("12345678")); |
|
2867 QCOMPARE(AppendCommand::delete_cnt, 9); |
|
2868 checkState(redoTextChangedSpy, |
|
2869 canRedoChangedSpy, |
|
2870 undoTextChangedSpy, |
|
2871 redoAction, |
|
2872 undoAction, |
|
2873 canUndoChangedSpy, |
|
2874 cleanChangedSpy, |
|
2875 indexChangedSpy, |
|
2876 stack, |
|
2877 false, // clean |
|
2878 2, // count |
|
2879 2, // index |
|
2880 true, // canUndo |
|
2881 "foo", // undoText |
|
2882 false, // canRedo |
|
2883 "", // redoText |
|
2884 false, // cleanChanged |
|
2885 true, // indexChanged |
|
2886 true, // undoChanged |
|
2887 true); // redoChanged |
|
2888 |
|
2889 stack.undo(); |
|
2890 QCOMPARE(str, QString("123456")); |
|
2891 QCOMPARE(AppendCommand::delete_cnt, 9); |
|
2892 checkState(redoTextChangedSpy, |
|
2893 canRedoChangedSpy, |
|
2894 undoTextChangedSpy, |
|
2895 redoAction, |
|
2896 undoAction, |
|
2897 canUndoChangedSpy, |
|
2898 cleanChangedSpy, |
|
2899 indexChangedSpy, |
|
2900 stack, |
|
2901 false, // clean |
|
2902 2, // count |
|
2903 1, // index |
|
2904 true, // canUndo |
|
2905 "append", // undoText |
|
2906 true, // canRedo |
|
2907 "foo", // redoText |
|
2908 false, // cleanChanged |
|
2909 true, // indexChanged |
|
2910 true, // undoChanged |
|
2911 true); // redoChanged |
|
2912 |
|
2913 stack.undo(); |
|
2914 QCOMPARE(str, QString("1234")); |
|
2915 QCOMPARE(AppendCommand::delete_cnt, 9); |
|
2916 checkState(redoTextChangedSpy, |
|
2917 canRedoChangedSpy, |
|
2918 undoTextChangedSpy, |
|
2919 redoAction, |
|
2920 undoAction, |
|
2921 canUndoChangedSpy, |
|
2922 cleanChangedSpy, |
|
2923 indexChangedSpy, |
|
2924 stack, |
|
2925 false, // clean |
|
2926 2, // count |
|
2927 0, // index |
|
2928 false, // canUndo |
|
2929 "", // undoText |
|
2930 true, // canRedo |
|
2931 "append", // redoText |
|
2932 false, // cleanChanged |
|
2933 true, // indexChanged |
|
2934 true, // undoChanged |
|
2935 true); // redoChanged |
|
2936 } |
|
2937 |
|
2938 QTEST_MAIN(tst_QUndoStack) |
|
2939 |
|
2940 #include "tst_qundostack.moc" |