[Ktutorial-commits] SF.net SVN: ktutorial:[207] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-29 03:59:47
|
Revision: 207
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=207&view=rev
Author: danxuliu
Date: 2010-03-29 03:59:41 +0000 (Mon, 29 Mar 2010)
Log Message:
-----------
Ensure that no unnecessary commands are created to set a WaitFor
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2010-03-29 03:15:38 UTC (rev 206)
+++ trunk/ktutorial/ktutorial-editor/src/view/ReactionWidget.cpp 2010-03-29 03:59:41 UTC (rev 207)
@@ -86,8 +86,10 @@
commands.append(reactionCommands.setOptionName(optionName, parent));
}
- if (!mReaction->waitFor() || !mWaitForWidget->waitFor() ||
- *mReaction->waitFor() != *mWaitForWidget->waitFor()) {
+ if ((!mReaction->waitFor() && mWaitForWidget->waitFor()) ||
+ (mReaction->waitFor() && !mWaitForWidget->waitFor()) ||
+ (mReaction->waitFor() && mWaitForWidget->waitFor() &&
+ *mReaction->waitFor() != *mWaitForWidget->waitFor())) {
commands.append(reactionCommands.setWaitFor(mWaitForWidget->waitFor(),
parent));
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2010-03-29 03:15:38 UTC (rev 206)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/ReactionWidgetTest.cpp 2010-03-29 03:59:41 UTC (rev 207)
@@ -22,6 +22,7 @@
#include <QRadioButton>
#include <QTreeView>
+#include <QUndoStack>
#include <KComboBox>
#include <KDialog>
@@ -48,7 +49,10 @@
void testSelectResponseTypeCustomCode();
void testSaveChanges();
- void testSaveChangesWithNoWaitFor();
+ void testSaveChangesAddRootWaitFor();
+ void testSaveChangesRemoveRootWaitFor();
+ void testSaveChangesNoOldWaitForAndNoNewWaitFor();
+ void testSaveChangesEqualWaitFor();
private:
@@ -63,6 +67,7 @@
void addWaitForSignal(ReactionWidget* widget);
void addWaitForSignalToRootWaitFor(ReactionWidget* widget);
+ void removeRootWaitFor(ReactionWidget* widget);
};
@@ -180,21 +185,61 @@
QCOMPARE(reaction.customCode(), QString("The custom code"));
}
-void ReactionWidgetTest::testSaveChangesWithNoWaitFor() {
+void ReactionWidgetTest::testSaveChangesAddRootWaitFor() {
Reaction reaction;
reaction.setTriggerType(Reaction::ConditionMet);
ReactionWidget widget(&reaction);
+ addWaitForSignal(&widget);
widget.saveChanges();
+ QVERIFY(reaction.waitFor() != 0);
+ QVERIFY(qobject_cast<WaitForSignal*>(reaction.waitFor()));
+}
+
+void ReactionWidgetTest::testSaveChangesRemoveRootWaitFor() {
+ Reaction reaction;
+ reaction.setTriggerType(Reaction::ConditionMet);
+ reaction.setWaitFor(new WaitForSignal());
+
+ ReactionWidget widget(&reaction);
+
+ removeRootWaitFor(&widget);
+ widget.saveChanges();
+
QCOMPARE(reaction.waitFor(), (WaitFor*)0);
+}
+void ReactionWidgetTest::testSaveChangesNoOldWaitForAndNoNewWaitFor() {
+ Reaction reaction;
+
+ ReactionWidget widget(&reaction);
+
+ QUndoStack undoStack;
+ widget.setUndoStack(&undoStack);
+
+ widget.saveChanges();
+
+ QCOMPARE(undoStack.count(), 0);
+ QCOMPARE(reaction.waitFor(), (WaitFor*)0);
+}
+
+void ReactionWidgetTest::testSaveChangesEqualWaitFor() {
+ Reaction reaction;
+ WaitForSignal* waitFor = new WaitForSignal();
+ reaction.setWaitFor(waitFor);
+
+ ReactionWidget widget(&reaction);
+
+ QUndoStack undoStack;
+ widget.setUndoStack(&undoStack);
+
addWaitForSignal(&widget);
widget.saveChanges();
- QVERIFY(reaction.waitFor() != 0);
- QVERIFY(qobject_cast<WaitForSignal*>(reaction.waitFor()));
+ QCOMPARE(undoStack.count(), 0);
+ QCOMPARE(reaction.waitFor(), waitFor);
}
/////////////////////////////////// Helpers ////////////////////////////////////
@@ -286,6 +331,14 @@
addWaitForSignal(widget);
}
+void ReactionWidgetTest::removeRootWaitFor(ReactionWidget* widget) {
+ QTreeView* tree = widget->findChild<QTreeView*>("waitForTreeView");
+ QModelIndex index = tree->model()->index(0, 0);
+ tree->selectionModel()->select(index, QItemSelectionModel::SelectCurrent);
+
+ widget->findChild<KPushButton*>("removeButton")->click();
+}
+
QTEST_MAIN(ReactionWidgetTest)
#include "ReactionWidgetTest.moc"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|