[Ktutorial-commits] SF.net SVN: ktutorial:[120] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2010-03-07 22:50:22
|
Revision: 120
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=120&view=rev
Author: danxuliu
Date: 2010-03-07 22:50:16 +0000 (Sun, 07 Mar 2010)
Log Message:
-----------
Include a list of steps in tutorial.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp
trunk/ktutorial/ktutorial-editor/src/Tutorial.h
trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp
trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h
trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp
trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h
trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp
trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp
Modified: trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/src/Tutorial.cpp 2010-03-07 22:50:16 UTC (rev 120)
@@ -20,11 +20,17 @@
#include <QStringList>
+#include "Step.h"
+
//public:
Tutorial::Tutorial(QObject* parent) {
}
+Tutorial::~Tutorial() {
+ qDeleteAll(mSteps);
+}
+
QString Tutorial::id() const {
return toLowerCamelCase(mName);
}
@@ -79,6 +85,26 @@
emit dataChanged(this);
}
+void Tutorial::addStep(Step* step) {
+ Q_ASSERT(!mSteps.contains(step));
+
+ mSteps.append(step);
+
+ emit stepAdded(step);
+}
+
+QList<Step*> Tutorial::steps() const {
+ return mSteps;
+}
+
+void Tutorial::removeStep(Step* step) {
+ Q_ASSERT(mSteps.contains(step));
+
+ mSteps.removeOne(step);
+
+ emit stepRemoved(step);
+}
+
//private:
QString Tutorial::toLowerCamelCase(const QString& text) const {
Modified: trunk/ktutorial/ktutorial-editor/src/Tutorial.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/Tutorial.h 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/src/Tutorial.h 2010-03-07 22:50:16 UTC (rev 120)
@@ -19,8 +19,11 @@
#ifndef TUTORIAL_H
#define TUTORIAL_H
+#include <QList>
#include <QObject>
+class Step;
+
/**
* Container for tutorial data.
* It stores the data used in KTutorial tutorials, but it has nothing to do with
@@ -28,6 +31,8 @@
* generate the code to create a true KTutorial::Tutorial.
*
* When any attribute is modified, dataChanged(Tutorial*) signal is emitted.
+ * When steps are added or removed, stepAdded(Step*) and stepRemoved(Step*) are
+ * emitted.
*/
class Tutorial: public QObject {
Q_OBJECT
@@ -36,6 +41,11 @@
Tutorial(QObject* parent = 0);
/**
+ * Destroys this Tutorial and all its steps.
+ */
+ virtual ~Tutorial();
+
+ /**
* Returns the id of this Tutorial.
* The id is a lowerCamelCase version of the name.
*
@@ -58,6 +68,24 @@
QString customTearDownCode() const;
void setCustomTearDownCode(const QString& code);
+ /**
+ * Adds a new step to this Tutorial.
+ * The Tutorial gets ownership of the Step, so it is deleted when the
+ * Tutorial is deleted.
+ *
+ * @param step The step to add.
+ */
+ void addStep(Step* step);
+ QList<Step*> steps() const;
+
+ /**
+ * Removes a step from this Tutorial.
+ * The Step must be deleted explicitly.
+ *
+ * @param step The step to remove.
+ */
+ void removeStep(Step* step);
+
Q_SIGNALS:
/**
@@ -67,6 +95,20 @@
*/
void dataChanged(Tutorial* tutorial);
+ /**
+ * Emitted when the step is added to the tutorial.
+ *
+ * @param step The step added.
+ */
+ void stepAdded(Step* step);
+
+ /**
+ * Emitted when the step is removed from the tutorial.
+ *
+ * @param step The step removed.
+ */
+ void stepRemoved(Step* step);
+
private:
QString mName;
@@ -74,6 +116,7 @@
QString mLicenseText;
QString mCustomSetupCode;
QString mCustomTearDownCode;
+ QList<Step*> mSteps;
/**
* Returns the lowerCamelCase version of the given text.
Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.cpp 2010-03-07 22:50:16 UTC (rev 120)
@@ -27,7 +27,8 @@
//public:
StepTreeItem::StepTreeItem(Step* step, TreeItem* parent):
- TreeItem(parent) {
+ TreeItem(parent),
+ mStep(step) {
Q_ASSERT(step);
mTextItem = 0;
@@ -47,6 +48,10 @@
return i18nc("@item", "Step %1", mStepId);
}
+Step* StepTreeItem::step() const {
+ return mStep;
+}
+
//private slots:
void StepTreeItem::update(Step* step) {
Modified: trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/src/view/StepTreeItem.h 2010-03-07 22:50:16 UTC (rev 120)
@@ -70,9 +70,21 @@
*/
virtual QString text() const;
+ /**
+ * Returns the Step.
+ *
+ * @return The Step.
+ */
+ Step* step() const;
+
private:
/**
+ * The Step.
+ */
+ Step* mStep;
+
+ /**
* The id of the step.
*/
QString mStepId;
Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.cpp 2010-03-07 22:50:16 UTC (rev 120)
@@ -20,6 +20,7 @@
#include <KLocalizedString>
+#include "StepTreeItem.h"
#include "TextTreeItem.h"
#include "TreeItemUtil.h"
#include "../Tutorial.h"
@@ -39,6 +40,14 @@
update(tutorial);
connect(tutorial, SIGNAL(dataChanged(Tutorial*)),
this, SLOT(update(Tutorial*)));
+
+ foreach(Step* step, tutorial->steps()) {
+ addStep(step);
+ }
+ connect(tutorial, SIGNAL(stepAdded(Step*)),
+ this, SLOT(addStep(Step*)));
+ connect(tutorial, SIGNAL(stepRemoved(Step*)),
+ this, SLOT(removeStep(Step*)));
}
QString TutorialTreeItem::text() const {
@@ -49,6 +58,18 @@
return i18nc("@item", "Tutorial %1", mTutorialId);
}
+//private:
+
+StepTreeItem* TutorialTreeItem::stepTreeItemForStep(Step* step) {
+ foreach (StepTreeItem* stepTreeItem, mStepTreeItems) {
+ if (stepTreeItem->step() == step) {
+ return stepTreeItem;
+ }
+ }
+
+ return 0;
+}
+
//private slots:
void TutorialTreeItem::update(Tutorial* tutorial) {
@@ -111,3 +132,35 @@
childIndex++;
}
}
+
+void TutorialTreeItem::addStep(Step* step) {
+ TreeItem* rootStepItem;
+
+ if (mStepTreeItems.isEmpty()) {
+ TextTreeItem* textRootStepItem = new TextTreeItem(this);
+ textRootStepItem->setText(i18nc("@item", "Steps:"));
+ appendChild(textRootStepItem);
+
+ rootStepItem = textRootStepItem;
+ } else {
+ rootStepItem = mStepTreeItems.at(0)->parent();
+ }
+
+ StepTreeItem* stepTreeItem = new StepTreeItem(step, rootStepItem);
+ rootStepItem->appendChild(stepTreeItem);
+ mStepTreeItems.append(stepTreeItem);
+}
+
+void TutorialTreeItem::removeStep(Step* step) {
+ StepTreeItem* stepTreeItem = stepTreeItemForStep(step);
+ TreeItem* rootStepItem = stepTreeItem->parent();
+
+ rootStepItem->removeChild(stepTreeItem);
+ mStepTreeItems.removeOne(stepTreeItem);
+ delete stepTreeItem;
+
+ if (mStepTreeItems.isEmpty()) {
+ removeChild(rootStepItem);
+ delete rootStepItem;
+ }
+}
Modified: trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h
===================================================================
--- trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/src/view/TutorialTreeItem.h 2010-03-07 22:50:16 UTC (rev 120)
@@ -21,6 +21,8 @@
#include "TreeItem.h"
+class Step;
+class StepTreeItem;
class TextTreeItem;
class Tutorial;
@@ -34,8 +36,14 @@
* | -The license text
* |-Setup:
* | -The custom setup code
- * --Tear down:
- * -The custom tear down code
+ * |-Tear down:
+ * | -The custom tear down code
+ * --Steps:
+ * -Step first step added
+ * ...
+ * -Step second step added
+ * ...
+ * ...
*
* The items only appear if they have some data to show. For example, if only
* the name of the Tutorial is set, its representation is:
@@ -51,6 +59,8 @@
* Also note that the order of the child elements is always the same. Even if,
* for example, the setup code is set first and then the name, the name item
* will appear first and then the setup code item.
+ *
+ * @see StepTreeItem
*/
class TutorialTreeItem: public TreeItem {
Q_OBJECT
@@ -111,6 +121,19 @@
*/
TextTreeItem* mTearDownItem;
+ /**
+ * The StepTreeItems for each Step in the Tutorial.
+ */
+ QList<StepTreeItem*> mStepTreeItems;
+
+ /**
+ * Returns the StepTreeItem for the given Step.
+ *
+ * @param step The Step to get its StepTreeItem.
+ * @return The StepTreeItem.
+ */
+ StepTreeItem* stepTreeItemForStep(Step* step);
+
private Q_SLOTS:
/**
@@ -125,6 +148,22 @@
*/
void update(Tutorial* tutorial);
+ /**
+ * Adds a new StepTreeItem when a Step is added in the tutorial.
+ * If there were no other steps yet, the parent "Steps:" item is also added.
+ *
+ * @param step The Step added in the Tutorial.
+ */
+ void addStep(Step* step);
+
+ /**
+ * Removes the StepTreeItem for the Step removed in the tutorial.
+ * If there are no other steps, the parent "Steps:" item is also removed.
+ *
+ * @param step The Step removed in the Tutorial.
+ */
+ void removeStep(Step* step);
+
};
#endif
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/TutorialTest.cpp 2010-03-07 22:50:16 UTC (rev 120)
@@ -19,12 +19,15 @@
#include <QtTest>
#include "Tutorial.h"
+#include "Step.h"
class TutorialTest: public QObject {
Q_OBJECT
private slots:
+ void initTestCase();
+
void testId();
void testIdWithEmptyName();
void testIdWithSpaceName();
@@ -39,8 +42,22 @@
void testSetCustomTearDownCode();
+ void testAddStep();
+ void testRemoveStep();
+
+private:
+
+ int mStepStarType;
+
+ void assertStepSignal(const QSignalSpy& spy, int index, Step* step);
+
};
+void TutorialTest::initTestCase() {
+ //Step* must be registered in order to be used with QSignalSpy
+ mStepStarType = qRegisterMetaType<Tutorial*>("Step*");
+}
+
void TutorialTest::testId() {
Tutorial tutorial;
tutorial.setName("ThE name of a tutoRial");
@@ -145,6 +162,74 @@
QCOMPARE(qvariant_cast<Tutorial*>(argument), &tutorial);
}
+//Step* must be declared as a metatype to be used in qvariant_cast
+Q_DECLARE_METATYPE(Step*);
+
+void TutorialTest::testAddStep() {
+ Tutorial tutorial;
+ Step* step1 = new Step();
+ Step* step2 = new Step();
+ Step* step3 = new Step();
+
+ QSignalSpy stepAddedSpy(&tutorial, SIGNAL(stepAdded(Step*)));
+
+ tutorial.addStep(step1);
+ tutorial.addStep(step2);
+ tutorial.addStep(step3);
+
+ QCOMPARE(tutorial.steps().count(), 3);
+ QCOMPARE(tutorial.steps()[0], step1);
+ QCOMPARE(tutorial.steps()[1], step2);
+ QCOMPARE(tutorial.steps()[2], step3);
+ QCOMPARE(stepAddedSpy.count(), 3);
+ assertStepSignal(stepAddedSpy, 0, step1);
+ assertStepSignal(stepAddedSpy, 1, step2);
+ assertStepSignal(stepAddedSpy, 2, step3);
+}
+
+void TutorialTest::testRemoveStep() {
+ Tutorial tutorial;
+
+ //They will be removed and not deleted by the Tutorial, so they are created
+ //in stack
+ Step step1;
+ Step step2;
+ Step step3;
+
+ tutorial.addStep(&step1);
+ tutorial.addStep(&step2);
+ tutorial.addStep(&step3);
+
+ QSignalSpy stepRemovedSpy(&tutorial, SIGNAL(stepRemoved(Step*)));
+
+ tutorial.removeStep(&step2);
+
+ QCOMPARE(tutorial.steps().count(), 2);
+ QCOMPARE(tutorial.steps()[0], &step1);
+ QCOMPARE(tutorial.steps()[1], &step3);
+ QCOMPARE(stepRemovedSpy.count(), 1);
+ assertStepSignal(stepRemovedSpy, 0, &step2);
+
+ tutorial.removeStep(&step1);
+ tutorial.removeStep(&step3);
+
+ QCOMPARE(tutorial.steps().count(), 0);
+ QCOMPARE(stepRemovedSpy.count(), 3);
+ assertStepSignal(stepRemovedSpy, 1, &step1);
+ assertStepSignal(stepRemovedSpy, 2, &step3);
+}
+
+/////////////////////////////////// Helpers ////////////////////////////////////
+
+void TutorialTest::assertStepSignal(const QSignalSpy& spy, int index,
+ Step* step) {
+ QCOMPARE(spy.at(index).count(), 1);
+
+ QVariant argument = spy.at(index).at(0);
+ QCOMPARE(argument.userType(), mStepStarType);
+ QCOMPARE(qvariant_cast<Step*>(argument), step);
+}
+
QTEST_MAIN(TutorialTest)
#include "TutorialTest.moc"
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/StepTreeItemTest.cpp 2010-03-07 22:50:16 UTC (rev 120)
@@ -87,6 +87,7 @@
QCOMPARE(item.parent(), &parent);
QCOMPARE(item.text(), i18nc("@item", "Step"));
+ QCOMPARE(item.step(), &step);
QCOMPARE(item.childCount(), 0);
}
@@ -102,6 +103,7 @@
QCOMPARE(item.parent(), &parent);
QCOMPARE(item.text(), i18nc("@item", "Step %1", "The id"));
+ QCOMPARE(item.step(), &step);
QCOMPARE(item.childCount(), 3);
assertText(item.child(0), "The text");
assertCustomSetupCode(item.child(1), "The setup code");
Modified: trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-07 18:50:37 UTC (rev 119)
+++ trunk/ktutorial/ktutorial-editor/tests/unit/view/TutorialTreeItemTest.cpp 2010-03-07 22:50:16 UTC (rev 120)
@@ -22,6 +22,8 @@
#include <KLocalizedString>
+#include "StepTreeItem.h"
+#include "../Step.h"
#include "../Tutorial.h"
class TutorialTreeItemTest: public QObject {
@@ -54,6 +56,10 @@
void testTutorialSetCustomTearDownCodeChange();
void testTutorialSetCustomTearDownCodeEmpty();
+ void testTutorialAddStep();
+
+ void testTutorialRemoveStep();
+
void testChildOrderWhenSettingDataInTutorial();
void testChildOrderWhenUnsettingDataInTutorial();
@@ -69,6 +75,8 @@
void assertCustomSetupCode(TreeItem* setupItem, const QString& code) const;
void assertCustomTearDownCode(TreeItem* tearDownItem,
const QString& code) const;
+ void assertStep(TreeItem* rootStepItem, int index,
+ const QString& stepId) const;
void assertDataChanged(const QSignalSpy& spy, int index,
TreeItem* item) const;
@@ -106,17 +114,28 @@
tutorial.setCustomSetupCode("The setup code");
tutorial.setCustomTearDownCode("The tear down code");
+ Step* step1 = new Step();
+ step1->setId("First step");
+ tutorial.addStep(step1);
+
+ Step* step2 = new Step();
+ step2->setId("Second step");
+ tutorial.addStep(step2);
+
StubTreeItem parent;
TutorialTreeItem item(&tutorial, &parent);
QCOMPARE(item.parent(), &parent);
QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName"));
- QCOMPARE(item.childCount(), 5);
+ QCOMPARE(item.childCount(), 6);
assertName(item.child(0), "The name");
assertDescription(item.child(1), "The description");
assertLicenseText(item.child(2), "The license text");
assertCustomSetupCode(item.child(3), "The setup code");
assertCustomTearDownCode(item.child(4), "The tear down code");
+ QCOMPARE(item.child(5)->childCount(), 2);
+ assertStep(item.child(5), 0, "First step");
+ assertStep(item.child(5), 1, "Second step");
}
//TreeItem* must be declared as a metatype to be used in qvariant_cast
@@ -322,6 +341,30 @@
QCOMPARE(item.childCount(), 0);
}
+void TutorialTreeItemTest::testTutorialAddStep() {
+ Tutorial tutorial;
+ TutorialTreeItem item(&tutorial);
+
+ Step* step = new Step();
+ step->setId("Step id");
+ tutorial.addStep(step);
+
+ QCOMPARE(item.childCount(), 1);
+ assertStep(item.child(0), 0, "Step id");
+}
+
+void TutorialTreeItemTest::testTutorialRemoveStep() {
+ Tutorial tutorial;
+ TutorialTreeItem item(&tutorial);
+
+ Step* step = new Step();
+ step->setId("Step id");
+ tutorial.addStep(step);
+ tutorial.removeStep(step);
+
+ QCOMPARE(item.childCount(), 0);
+}
+
void TutorialTreeItemTest::testChildOrderWhenSettingDataInTutorial() {
Tutorial tutorial;
TutorialTreeItem item(&tutorial);
@@ -347,24 +390,55 @@
assertCustomSetupCode(item.child(1), "The setup code");
assertCustomTearDownCode(item.child(2), "The tear down code");
+ Step* step1 = new Step();
+ step1->setId("First step");
+ tutorial.addStep(step1);
+
+ QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
+ QCOMPARE(item.childCount(), 4);
+ assertDescription(item.child(0), "The description");
+ assertCustomSetupCode(item.child(1), "The setup code");
+ assertCustomTearDownCode(item.child(2), "The tear down code");
+ QCOMPARE(item.child(3)->childCount(), 1);
+ assertStep(item.child(3), 0, "First step");
+
tutorial.setName("The name");
QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName"));
- QCOMPARE(item.childCount(), 4);
+ QCOMPARE(item.childCount(), 5);
assertName(item.child(0), "The name");
assertDescription(item.child(1), "The description");
assertCustomSetupCode(item.child(2), "The setup code");
assertCustomTearDownCode(item.child(3), "The tear down code");
+ QCOMPARE(item.child(4)->childCount(), 1);
+ assertStep(item.child(4), 0, "First step");
- tutorial.setLicenseText("The license text");
+ Step* step2 = new Step();
+ step2->setId("Second step");
+ tutorial.addStep(step2);
QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName"));
QCOMPARE(item.childCount(), 5);
assertName(item.child(0), "The name");
assertDescription(item.child(1), "The description");
+ assertCustomSetupCode(item.child(2), "The setup code");
+ assertCustomTearDownCode(item.child(3), "The tear down code");
+ QCOMPARE(item.child(4)->childCount(), 2);
+ assertStep(item.child(4), 0, "First step");
+ assertStep(item.child(4), 1, "Second step");
+
+ tutorial.setLicenseText("The license text");
+
+ QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName"));
+ QCOMPARE(item.childCount(), 6);
+ assertName(item.child(0), "The name");
+ assertDescription(item.child(1), "The description");
assertLicenseText(item.child(2), "The license text");
assertCustomSetupCode(item.child(3), "The setup code");
assertCustomTearDownCode(item.child(4), "The tear down code");
+ QCOMPARE(item.child(5)->childCount(), 2);
+ assertStep(item.child(5), 0, "First step");
+ assertStep(item.child(5), 1, "Second step");
}
void TutorialTreeItemTest::testChildOrderWhenUnsettingDataInTutorial() {
@@ -375,41 +449,78 @@
tutorial.setCustomSetupCode("The setup code");
tutorial.setCustomTearDownCode("The tear down code");
+ //They will be removed and not deleted by the Tutorial, so they are created
+ //in stack
+ Step step1;
+ step1.setId("First step");
+ tutorial.addStep(&step1);
+
+ Step step2;
+ step2.setId("Second step");
+ tutorial.addStep(&step2);
+
TutorialTreeItem item(&tutorial);
tutorial.setLicenseText("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial %1", "theName"));
- QCOMPARE(item.childCount(), 4);
+ QCOMPARE(item.childCount(), 5);
assertName(item.child(0), "The name");
assertDescription(item.child(1), "The description");
assertCustomSetupCode(item.child(2), "The setup code");
assertCustomTearDownCode(item.child(3), "The tear down code");
+ QCOMPARE(item.child(4)->childCount(), 2);
+ assertStep(item.child(4), 0, "First step");
+ assertStep(item.child(4), 1, "Second step");
tutorial.setName("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 3);
+ QCOMPARE(item.childCount(), 4);
assertDescription(item.child(0), "The description");
assertCustomSetupCode(item.child(1), "The setup code");
assertCustomTearDownCode(item.child(2), "The tear down code");
+ QCOMPARE(item.child(3)->childCount(), 2);
+ assertStep(item.child(3), 0, "First step");
+ assertStep(item.child(3), 1, "Second step");
+ tutorial.removeStep(&step1);
+
+ QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
+ QCOMPARE(item.childCount(), 4);
+ assertDescription(item.child(0), "The description");
+ assertCustomSetupCode(item.child(1), "The setup code");
+ assertCustomTearDownCode(item.child(2), "The tear down code");
+ QCOMPARE(item.child(3)->childCount(), 1);
+ assertStep(item.child(3), 0, "Second step");
+
tutorial.setCustomTearDownCode("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 2);
+ QCOMPARE(item.childCount(), 3);
assertDescription(item.child(0), "The description");
assertCustomSetupCode(item.child(1), "The setup code");
+ QCOMPARE(item.child(2)->childCount(), 1);
+ assertStep(item.child(2), 0, "Second step");
tutorial.setDescription("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
- QCOMPARE(item.childCount(), 1);
+ QCOMPARE(item.childCount(), 2);
assertCustomSetupCode(item.child(0), "The setup code");
+ QCOMPARE(item.child(1)->childCount(), 1);
+ assertStep(item.child(1), 0, "Second step");
tutorial.setCustomSetupCode("");
QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
+ QCOMPARE(item.childCount(), 1);
+ QCOMPARE(item.child(0)->childCount(), 1);
+ assertStep(item.child(0), 0, "Second step");
+
+ tutorial.removeStep(&step2);
+
+ QCOMPARE(item.text(), i18nc("@item", "Tutorial"));
QCOMPARE(item.childCount(), 0);
}
@@ -448,6 +559,14 @@
QCOMPARE(tearDownItem->child(0)->text(), i18nc("@item", code.toAscii()));
}
+void TutorialTreeItemTest::assertStep(TreeItem* rootStepItem, int index,
+ const QString& stepId) const {
+ QCOMPARE(rootStepItem->text(), i18nc("@item", "Steps:"));
+ QVERIFY(qobject_cast<StepTreeItem*>(rootStepItem->child(index)));
+ QCOMPARE(rootStepItem->child(index)->text(),
+ i18nc("@item", "Step %1", stepId));
+}
+
void TutorialTreeItemTest::assertDataChanged(const QSignalSpy& spy, int index,
TreeItem* item) const {
QCOMPARE(spy.at(index).count(), 1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|