[Ktutorial-commits] SF.net SVN: ktutorial:[118] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-07 07:39:04
|
Revision: 118 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=118&view=rev Author: danxuliu Date: 2010-03-07 07:38:57 +0000 (Sun, 07 Mar 2010) Log Message: ----------- Add basic version of Step class to store the data of a step. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/Step.cpp trunk/ktutorial/ktutorial-editor/src/Step.h trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-07 07:21:18 UTC (rev 117) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-07 07:38:57 UTC (rev 118) @@ -8,6 +8,7 @@ set(ktutorial_editor_SRCS KTutorialEditor.cpp + Step.cpp Tutorial.cpp ) Added: trunk/ktutorial/ktutorial-editor/src/Step.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Step.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/Step.cpp 2010-03-07 07:38:57 UTC (rev 118) @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "Step.h" + +//public: + +Step::Step(QObject* parent) { +} + +QString Step::id() const { + return mId; +} + +void Step::setId(const QString& id) { + mId = id; + + emit dataChanged(this); +} + +QString Step::text() const { + return mText; +} + +void Step::setText(const QString& text) { + mText = text; + + emit dataChanged(this); +} + +QString Step::customSetupCode() const { + return mCustomSetupCode; +} + +void Step::setCustomSetupCode(const QString& code) { + mCustomSetupCode = code; + + emit dataChanged(this); +} + +QString Step::customTearDownCode() const { + return mCustomTearDownCode; +} + +void Step::setCustomTearDownCode(const QString& code) { + mCustomTearDownCode = code; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/Step.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/Step.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/Step.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/Step.h 2010-03-07 07:38:57 UTC (rev 118) @@ -0,0 +1,68 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef STEP_H +#define STEP_H + +#include <QObject> + +/** + * Container for step data. + * It stores the data used in KTutorial steps, but it has nothing to do with + * them (they don't even know each other). Its purpose is store the data needed to + * generate the code to create a true KTutorial::Step. + * + * When any attribute is modified, dataChanged(Step*) signal is emitted. + */ +class Step: public QObject { +Q_OBJECT +public: + + Step(QObject* parent = 0); + + QString id() const; + void setId(const QString& id); + + QString text() const; + void setText(const QString& text); + + QString customSetupCode() const; + void setCustomSetupCode(const QString& code); + + QString customTearDownCode() const; + void setCustomTearDownCode(const QString& code); + +Q_SIGNALS: + + /** + * Emitted when any data in the step changed. + * + * @param step This step. + */ + void dataChanged(Step* step); + +private: + + QString mId; + QString mText; + QString mCustomSetupCode; + QString mCustomTearDownCode; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/Step.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-07 07:21:18 UTC (rev 117) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-07 07:38:57 UTC (rev 118) @@ -14,7 +14,7 @@ ENDFOREACH(_className) ENDMACRO(UNIT_TESTS) -unit_tests(Tutorial) +unit_tests(Step Tutorial) MACRO(MEM_TESTS) FOREACH(_testname ${ARGN}) @@ -22,4 +22,4 @@ ENDFOREACH(_testname) ENDMACRO(MEM_TESTS) -mem_tests(Tutorial) +mem_tests(Step Tutorial) Added: trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp 2010-03-07 07:38:57 UTC (rev 118) @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include "Step.h" + +class StepTest: public QObject { +Q_OBJECT + +private slots: + + void testSetId(); + + void testSetText(); + + void testSetCustomSetupCode(); + + void testSetCustomTearDownCode(); + +}; + +//Step* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(Step*); + +void StepTest::testSetId() { + Step step; + + //Step* must be registered in order to be used with QSignalSpy + int stepStarType = qRegisterMetaType<Step*>("Step*"); + QSignalSpy dataChangedSpy(&step, SIGNAL(dataChanged(Step*))); + + step.setId("The id"); + + QCOMPARE(step.id(), QString("The id")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), stepStarType); + QCOMPARE(qvariant_cast<Step*>(argument), &step); +} + +void StepTest::testSetText() { + Step step; + + //Step* must be registered in order to be used with QSignalSpy + int stepStarType = qRegisterMetaType<Step*>("Step*"); + QSignalSpy dataChangedSpy(&step, SIGNAL(dataChanged(Step*))); + + step.setText("The text"); + + QCOMPARE(step.text(), QString("The text")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), stepStarType); + QCOMPARE(qvariant_cast<Step*>(argument), &step); +} + +void StepTest::testSetCustomSetupCode() { + Step step; + + //Step* must be registered in order to be used with QSignalSpy + int stepStarType = qRegisterMetaType<Step*>("Step*"); + QSignalSpy dataChangedSpy(&step, SIGNAL(dataChanged(Step*))); + + step.setCustomSetupCode("The setup code"); + + QCOMPARE(step.customSetupCode(), QString("The setup code")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), stepStarType); + QCOMPARE(qvariant_cast<Step*>(argument), &step); +} + +void StepTest::testSetCustomTearDownCode() { + Step step; + + //Step* must be registered in order to be used with QSignalSpy + int stepStarType = qRegisterMetaType<Step*>("Step*"); + QSignalSpy dataChangedSpy(&step, SIGNAL(dataChanged(Step*))); + + step.setCustomTearDownCode("The tear down code"); + + QCOMPARE(step.customTearDownCode(), QString("The tear down code")); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), stepStarType); + QCOMPARE(qvariant_cast<Step*>(argument), &step); +} + +QTEST_MAIN(StepTest) + +#include "StepTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/StepTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |