[Ktutorial-commits] SF.net SVN: ktutorial:[147] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-03-12 00:08:31
|
Revision: 147 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=147&view=rev Author: danxuliu Date: 2010-03-12 00:08:24 +0000 (Fri, 12 Mar 2010) Log Message: ----------- Add WaitFor and subclasses to store the data of conditions to wait for to be met. Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp trunk/ktutorial/ktutorial-editor/src/WaitFor.h trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp trunk/ktutorial/ktutorial-editor/src/WaitForNot.h trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-11 19:36:17 UTC (rev 146) +++ trunk/ktutorial/ktutorial-editor/src/CMakeLists.txt 2010-03-12 00:08:24 UTC (rev 147) @@ -10,6 +10,10 @@ KTutorialEditor.cpp Step.cpp Tutorial.cpp + WaitFor.cpp + WaitForComposed.cpp + WaitForNot.cpp + WaitForSignal.cpp ) # Instead of compiling the executable directly from the sources, the sources are Added: trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,24 @@ +/*************************************************************************** + * 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 "WaitFor.h" + +//public: + +WaitFor::WaitFor(QObject* parent): QObject(parent) { +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitFor.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitFor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitFor.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitFor.h 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,57 @@ +/*************************************************************************** + * 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 WAITFOR_H +#define WAITFOR_H + +#include <QObject> + +/** + * Base class for conditions to wait for to be met. + * Its subclasses store the data used in KTutorial wait for subclasses, but they + * have nothing to do with them (they don't even know each others). Its purpose + * is store the data needed to generate the code to initialize a true + * KTutorial::WaitFor subclass object. + * + * Subclasses must emit dataChanged(Step*) signal when their data is modified + * (including the data of child conditions). + */ +class WaitFor: public QObject { +Q_OBJECT +public: + + /** + * Creates a new WaitFor. + * + * @param parent The parent QObject. + */ + WaitFor(QObject* parent = 0); + +Q_SIGNALS: + + /** + * Emitted when any data in the WaitFor changed. + * Subclasses must emit this signal when needed. + * + * @param waitFor This WaitFor. + */ + void dataChanged(WaitFor* waitFor); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitFor.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,60 @@ +/*************************************************************************** + * 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 "WaitForComposed.h" + +//public: + +WaitForComposed::WaitForComposed(QObject* parent): + WaitFor(parent), + mCompositionType(And) { +} + +WaitForComposed::~WaitForComposed() { + qDeleteAll(mWaitFors); +} + +WaitForComposed::CompositionType WaitForComposed::compositionType() const { + return mCompositionType; +} + +void WaitForComposed::setCompositionType(CompositionType compositionType) { + mCompositionType = compositionType; + + emit dataChanged(this); +} + +void WaitForComposed::addWaitFor(WaitFor* waitFor) { + Q_ASSERT(!mWaitFors.contains(waitFor)); + + mWaitFors.append(waitFor); + + emit waitForAdded(waitFor); +} + +QList<WaitFor*> WaitForComposed::waitFors() const { + return mWaitFors; +} + +void WaitForComposed::removeWaitFor(WaitFor* waitFor) { + Q_ASSERT(mWaitFors.contains(waitFor)); + + mWaitFors.removeOne(waitFor); + + emit waitForRemoved(waitFor); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,96 @@ +/*************************************************************************** + * 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 WAITFORCOMPOSED_H +#define WAITFORCOMPOSED_H + +#include "WaitFor.h" + +/** + * Container for composed conditions to wait for data. + * It stores the data used in KTutorial WaitForAnd and WaitForOr, 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 initialize a true + * KTutorial::WaitForComposed subclass object. + * + * When the composition type is modified, dataChanged(WaitFor*) signal is + * emitted. When WaitFors are added or removed, waitForAdded(WaitFor*) and + * waitForRemoved(WaitFor*) are emitted. + */ +class WaitForComposed: public WaitFor { +Q_OBJECT +public: + + enum CompositionType { + And, + Or + }; + + /** + * Creates a new WaitForComposed. + * + * @param parent The parent QObject. + */ + WaitForComposed(QObject* parent = 0); + virtual ~WaitForComposed(); + + CompositionType compositionType() const; + void setCompositionType(CompositionType compositionType); + + /** + * Adds a new WaitFor to this WaitForComposed. + * This WaitForComposed gets ownership of the added WaitFor, so it is + * deleted when this WaitForComposed is deleted. + * + * @param waitFor The WaitFor to add. + */ + void addWaitFor(WaitFor* waitFor); + QList<WaitFor*> waitFors() const; + + /** + * Removes a WaitFor from this WaitForComposed. + * The WaitFor must be deleted explicitly. + * + * @param waitFor The WaitFor to remove. + */ + void removeWaitFor(WaitFor* waitFor); + +Q_SIGNALS: + + /** + * Emitted when the WaitFor is added to this WaitForComposed. + * + * @param waitFor The WaitFor added. + */ + void waitForAdded(WaitFor* waitFor); + + /** + * Emitted when the WaitFor is removed from this WaitForComposed. + * + * @param waitFor The WaitFor removed. + */ + void waitForRemoved(WaitFor* waitFor); + +private: + + CompositionType mCompositionType; + QList<WaitFor*> mWaitFors; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForComposed.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,40 @@ +/*************************************************************************** + * 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 "WaitForNot.h" + +//public: + +WaitForNot::WaitForNot(QObject* parent): + WaitFor(parent), + mNegatedWaitFor(0) { +} + +WaitForNot::~WaitForNot() { + delete mNegatedWaitFor; +} + +WaitFor* WaitForNot::negatedWaitFor() const { + return mNegatedWaitFor; +} + +void WaitForNot::setNegatedWaitFor(WaitFor* waitFor) { + mNegatedWaitFor = waitFor; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForNot.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForNot.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForNot.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForNot.h 2010-03-12 00:08:24 UTC (rev 147) @@ -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/>. * + ***************************************************************************/ + +#ifndef WAITFORNOT_H +#define WAITFORNOT_H + +#include "WaitFor.h" + +/** + * Container for negated wait for data. + * It stores the data used in KTutorial WaitForNot, but it has nothing to do + * with it (they don't even know each other). Its purpose is store the data + * needed to generate the code to initialize a true KTutorial::WaitForNot + * object. + * + * When the negated wait for is modified, dataChanged(WaitFor*) signal is + * emitted. + */ +class WaitForNot: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForNot. + * + * @param parent The parent QObject. + */ + WaitForNot(QObject* parent = 0); + virtual ~WaitForNot(); + + WaitFor* negatedWaitFor() const; + + /** + * Sets the negated WaitFor. + * The WaitFor will be destroyed when this WaitForNot is destroyed. However, + * if a WaitFor is set over a previous one, the previous one must be deleted + * explicitly. + * + * @param waitFor The WaitFor to set. + */ + void setNegatedWaitFor(WaitFor* waitFor); + +private: + + WaitFor* mNegatedWaitFor; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForNot.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,44 @@ +/*************************************************************************** + * 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 "WaitForSignal.h" + +//public: + +WaitForSignal::WaitForSignal(QObject* parent): WaitFor(parent) { +} + +QString WaitForSignal::objectName() const { + return mObjectName; +} + +void WaitForSignal::setObjectName(const QString& objectName) { + mObjectName = objectName; + + emit dataChanged(this); +} + +QString WaitForSignal::signalName() const { + return mSignalName; +} + +void WaitForSignal::setSignalName(const QString& signalName) { + mSignalName = signalName; + + emit dataChanged(this); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/WaitForSignal.h 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,57 @@ +/*************************************************************************** + * 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 WAITFORSIGNAL_H +#define WAITFORSIGNAL_H + +#include "WaitFor.h" + +/** + * Container for conditions that wait for a signal to be emitted data. + * It stores the data used in KTutorial WaitForSignal, but it has nothing to do + * with it (they don't even know each other). Its purpose is store the data + * needed to generate the code to initialize a true KTutorial::WaitForSignal + * object. + * + * When any attribute is modified, dataChanged(WaitFor*) signal is emitted. + */ +class WaitForSignal: public WaitFor { +Q_OBJECT +public: + + /** + * Creates a new WaitForSignal. + * + * @param parent The parent QObject. + */ + WaitForSignal(QObject* parent = 0); + + QString objectName() const; + void setObjectName(const QString& objectName); + + QString signalName() const; + void setSignalName(const QString& signalName); + +private: + + QString mObjectName; + QString mSignalName; + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/WaitForSignal.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-11 19:36:17 UTC (rev 146) +++ trunk/ktutorial/ktutorial-editor/tests/unit/CMakeLists.txt 2010-03-12 00:08:24 UTC (rev 147) @@ -17,6 +17,9 @@ unit_tests( Step Tutorial + WaitForComposed + WaitForNot + WaitForSignal ) MACRO(MEM_TESTS) @@ -28,4 +31,7 @@ mem_tests( Step Tutorial + WaitForComposed + WaitForNot + WaitForSignal ) Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,143 @@ +/*************************************************************************** + * 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 "WaitForComposed.h" + +class WaitForComposedTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testSetCompositionType(); + + void testAddWaitFor(); + void testRemoveWaitFor(); + +private: + + int mWaitForStarType; + + void assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor); + +}; + +void WaitForComposedTest::initTestCase() { + //WaitFor* must be registered in order to be used with QSignalSpy + mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); +} + +void WaitForComposedTest::testConstructor() { + QObject parent; + WaitForComposed* waitForComposed = new WaitForComposed(&parent); + + QCOMPARE(waitForComposed->parent(), &parent); + QCOMPARE(waitForComposed->compositionType(), WaitForComposed::And); +} + +void WaitForComposedTest::testSetCompositionType() { + WaitForComposed waitForComposed; + + QSignalSpy dataChangedSpy(&waitForComposed, SIGNAL(dataChanged(WaitFor*))); + + waitForComposed.setCompositionType(WaitForComposed::Or); + + QCOMPARE(waitForComposed.compositionType(), WaitForComposed::Or); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForSignal(dataChangedSpy, 0, &waitForComposed); +} + +void WaitForComposedTest::testAddWaitFor() { + WaitForComposed waitForComposed; + WaitFor* waitFor1 = new WaitFor(); + WaitFor* waitFor2 = new WaitFor(); + WaitFor* waitFor3 = new WaitFor(); + + QSignalSpy waitForAddedSpy(&waitForComposed, + SIGNAL(waitForAdded(WaitFor*))); + + waitForComposed.addWaitFor(waitFor1); + waitForComposed.addWaitFor(waitFor2); + waitForComposed.addWaitFor(waitFor3); + + QCOMPARE(waitForComposed.waitFors().count(), 3); + QCOMPARE(waitForComposed.waitFors()[0], waitFor1); + QCOMPARE(waitForComposed.waitFors()[1], waitFor2); + QCOMPARE(waitForComposed.waitFors()[2], waitFor3); + QCOMPARE(waitForAddedSpy.count(), 3); + assertWaitForSignal(waitForAddedSpy, 0, waitFor1); + assertWaitForSignal(waitForAddedSpy, 1, waitFor2); + assertWaitForSignal(waitForAddedSpy, 2, waitFor3); +} + +void WaitForComposedTest::testRemoveWaitFor() { + WaitForComposed waitForComposed; + + //They will be removed and not deleted by the WaitForComposed, so they are + //created in stack + WaitFor waitFor1; + WaitFor waitFor2; + WaitFor waitFor3; + + waitForComposed.addWaitFor(&waitFor1); + waitForComposed.addWaitFor(&waitFor2); + waitForComposed.addWaitFor(&waitFor3); + + QSignalSpy waitForRemovedSpy(&waitForComposed, + SIGNAL(waitForRemoved(WaitFor*))); + + waitForComposed.removeWaitFor(&waitFor2); + + QCOMPARE(waitForComposed.waitFors().count(), 2); + QCOMPARE(waitForComposed.waitFors()[0], &waitFor1); + QCOMPARE(waitForComposed.waitFors()[1], &waitFor3); + QCOMPARE(waitForRemovedSpy.count(), 1); + assertWaitForSignal(waitForRemovedSpy, 0, &waitFor2); + + waitForComposed.removeWaitFor(&waitFor1); + waitForComposed.removeWaitFor(&waitFor3); + + QCOMPARE(waitForComposed.waitFors().count(), 0); + QCOMPARE(waitForRemovedSpy.count(), 3); + assertWaitForSignal(waitForRemovedSpy, 1, &waitFor1); + assertWaitForSignal(waitForRemovedSpy, 2, &waitFor3); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForComposedTest::assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor) { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mWaitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), waitFor); +} + +QTEST_MAIN(WaitForComposedTest) + +#include "WaitForComposedTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForComposedTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -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 <QtTest> + +#include "WaitForNot.h" + +class WaitForNotTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testSetNegatedWaitFor(); + +}; + +void WaitForNotTest::testConstructor() { + QObject parent; + WaitForNot* waitForNot = new WaitForNot(&parent); + + QCOMPARE(waitForNot->parent(), &parent); + QCOMPARE(waitForNot->negatedWaitFor(), (WaitFor*)0); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +void WaitForNotTest::testSetNegatedWaitFor() { + WaitForNot waitForNot; + WaitFor* negatedWaitFor = new WaitFor(); + + //WaitFor* must be registered in order to be used with QSignalSpy + int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); + QSignalSpy dataChangedSpy(&waitForNot, SIGNAL(dataChanged(WaitFor*))); + + waitForNot.setNegatedWaitFor(negatedWaitFor); + + QCOMPARE(waitForNot.negatedWaitFor(), negatedWaitFor); + QCOMPARE(dataChangedSpy.count(), 1); + QVariant argument = dataChangedSpy.at(0).at(0); + QCOMPARE(argument.userType(), waitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForNot); +} + +QTEST_MAIN(WaitForNotTest) + +#include "WaitForNotTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForNotTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp 2010-03-12 00:08:24 UTC (rev 147) @@ -0,0 +1,97 @@ +/*************************************************************************** + * 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 "WaitForSignal.h" + +class WaitForSignalTest: public QObject { +Q_OBJECT + +private slots: + + void initTestCase(); + + void testConstructor(); + + void testSetObjectName(); + + void testSetSignalName(); + +private: + + int mWaitForStarType; + + void assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor); + +}; + +void WaitForSignalTest::initTestCase() { + //WaitFor* must be registered in order to be used with QSignalSpy + mWaitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*"); +} + +void WaitForSignalTest::testConstructor() { + QObject parent; + WaitForSignal* waitForSignal = new WaitForSignal(&parent); + + QCOMPARE(waitForSignal->parent(), &parent); +} + +void WaitForSignalTest::testSetObjectName() { + WaitForSignal waitForSignal; + + QSignalSpy dataChangedSpy(&waitForSignal, SIGNAL(dataChanged(WaitFor*))); + + waitForSignal.setObjectName("The object name"); + + QCOMPARE(waitForSignal.objectName(), QString("The object name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForSignal(dataChangedSpy, 0, &waitForSignal); +} + +void WaitForSignalTest::testSetSignalName() { + WaitForSignal waitForSignal; + + QSignalSpy dataChangedSpy(&waitForSignal, SIGNAL(dataChanged(WaitFor*))); + + waitForSignal.setSignalName("The signal name"); + + QCOMPARE(waitForSignal.signalName(), QString("The signal name")); + QCOMPARE(dataChangedSpy.count(), 1); + assertWaitForSignal(dataChangedSpy, 0, &waitForSignal); +} + +//WaitFor* must be declared as a metatype to be used in qvariant_cast +Q_DECLARE_METATYPE(WaitFor*); + +/////////////////////////////////// Helpers //////////////////////////////////// + +void WaitForSignalTest::assertWaitForSignal(const QSignalSpy& spy, int index, + WaitFor* waitFor) { + QCOMPARE(spy.at(index).count(), 1); + + QVariant argument = spy.at(index).at(0); + QCOMPARE(argument.userType(), mWaitForStarType); + QCOMPARE(qvariant_cast<WaitFor*>(argument), waitFor); +} + +QTEST_MAIN(WaitForSignalTest) + +#include "WaitForSignalTest.moc" Property changes on: trunk/ktutorial/ktutorial-editor/tests/unit/WaitForSignalTest.cpp ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |