[Ktutorial-commits] SF.net SVN: ktutorial:[305] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
|
From: <dan...@us...> - 2011-05-16 16:39:34
|
Revision: 305
http://ktutorial.svn.sourceforge.net/ktutorial/?rev=305&view=rev
Author: danxuliu
Date: 2011-05-16 16:39:27 +0000 (Mon, 16 May 2011)
Log Message:
-----------
Add WaitForProperty class to wait for a property to change its value to the expected one.
Modified Paths:
--------------
trunk/ktutorial/ktutorial-library/src/CMakeLists.txt
trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp
trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt
trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingModuleTest.cpp
trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingTest.cpp
Added Paths:
-----------
trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp
trunk/ktutorial/ktutorial-library/src/WaitForProperty.h
trunk/ktutorial/ktutorial-library/tests/WaitForPropertyTest.cpp
Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2011-05-08 15:16:11 UTC (rev 304)
+++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2011-05-16 16:39:27 UTC (rev 305)
@@ -28,6 +28,7 @@
WaitForEvent.cpp
WaitForNot.cpp
WaitForOr.cpp
+ WaitForProperty.cpp
WaitForSignal.cpp
WaitForWindow.cpp
)
@@ -58,6 +59,7 @@
WaitForEvent.h
WaitForNot.h
WaitForOr.h
+ WaitForProperty.h
WaitForSignal.h
WaitForWindow.h
)
Added: trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp 2011-05-16 16:39:27 UTC (rev 305)
@@ -0,0 +1,94 @@
+/***************************************************************************
+ * Copyright (C) 2011 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 "WaitForProperty.h"
+
+#include <QMetaProperty>
+
+#include <KDebug>
+
+//public:
+
+WaitForProperty::WaitForProperty(): WaitFor() {
+}
+
+WaitForProperty::WaitForProperty(QObject* object, const QString& propertyName,
+ const QVariant& value): WaitFor() {
+ setProperty(object, propertyName, value);
+}
+
+void WaitForProperty::setProperty(QObject* object, const QString& propertyName,
+ const QVariant& value) {
+ mObject = object;
+ mPropertyName = propertyName;
+ mValue = value;
+
+ if (!mObject) {
+ kWarning() << "The object that contains the property" << mPropertyName
+ << "to wait for is null!";
+ return;
+ }
+
+ const QMetaObject* metaObject = mObject->metaObject();
+ int propertyIndex = metaObject->indexOfProperty(mPropertyName.toUtf8());
+
+ if (propertyIndex == -1) {
+ kWarning() << "The class" << metaObject->className() << "does not"
+ << "contain a property named" << mPropertyName << "!";
+ return;
+ }
+
+ QMetaProperty metaProperty = metaObject->property(propertyIndex);
+
+ if (!metaProperty.hasNotifySignal()) {
+ kWarning() << "The property" << mPropertyName << "in the class"
+ << metaObject->className() << "does not have a notification"
+ << "signal!";
+ return;
+ }
+
+ const char* notifySignalSignature = metaProperty.notifySignal().signature();
+ QString notifySignal = QString("2%1").arg(notifySignalSignature);
+
+ connect(object, notifySignal.toUtf8(),
+ this, SLOT(checkPropertyValueToEndTheWait()));
+}
+
+bool WaitForProperty::conditionMet() const {
+ if (!mObject) {
+ return false;
+ }
+
+ if (mObject->property(mPropertyName.toUtf8()) != mValue) {
+ return false;
+ }
+
+ return true;
+}
+
+//private slots:
+
+void WaitForProperty::checkPropertyValueToEndTheWait() {
+ if (!isActive()) {
+ return;
+ }
+
+ if (conditionMet()) {
+ emit waitEnded(this);
+ }
+}
Property changes on: trunk/ktutorial/ktutorial-library/src/WaitForProperty.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/ktutorial/ktutorial-library/src/WaitForProperty.h
===================================================================
--- trunk/ktutorial/ktutorial-library/src/WaitForProperty.h (rev 0)
+++ trunk/ktutorial/ktutorial-library/src/WaitForProperty.h 2011-05-16 16:39:27 UTC (rev 305)
@@ -0,0 +1,145 @@
+/***************************************************************************
+ * Copyright (C) 2011 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 WAITFORPROPERTY_H
+#define WAITFORPROPERTY_H
+
+#include <QVariant>
+
+#include "ktutorial_export.h"
+
+#include "WaitFor.h"
+
+/**
+ * Waits for a property to have a specific value.
+ * When the property changes its value to the specified one and the
+ * WaitForProperty is active, the wait ends.
+ *
+ * Note that the condition can be met even if the wait did not end. The
+ * condition is met if the property has the expected value. However, the wait
+ * ends only when the property changes to the expected value while the WaitFor
+ * is active. That is, in an active WaitFor, the condition would be met even if
+ * the expected value was set in the property when the WaitFor was inactive, but
+ * the wait would not end until the expected value was set again in the property
+ * after the WaitFor was activated.
+ *
+ * Not every property can be used to wait for its value to change. Only
+ * properties that have a notify signal can be used with that purpose.
+ *
+ * WaitForProperty with properties that do not have a notify signal can still be
+ * used to enrich other WaitFors (for example, a WaitForAnd containing a
+ * WaitForSignal and a WaitForProperty: waiting for a signal to be emitted but
+ * only changing to the next step if, in addition, some property has some
+ * value), but they can not be used alone as single WaitFors (for example,
+ * waiting just for the property "visible" of some widget to have some value
+ * would never end).
+ *
+ * Using a WaitForProperty just to perform further checks when other WaitFor
+ * ends its waiting should be done only with properties that do not have a
+ * notify signal. For example, if a WaitForAnd contains a WaitForSignal and a
+ * WaitForProperty, and the WaitForProperty uses a property with a notify
+ * signal, it may happen that the property changes to the expected value after
+ * the signal was emitted. If that happens, the WaitForProperty would end its
+ * waiting, and so the WaitForAnd as the WaitForSignal had already ended its
+ * waiting too. It may not be the desired behavior if the WaitForProperty was
+ * there to be checked only when the WaitForSignal ended. In that case, instead
+ * of using a WaitForProperty, the proper way to do it is executing a custom
+ * slot when the WaitForSignal ends its waiting, and checking the value of the
+ * property in a "if" construction in that slot.
+ */
+class KTUTORIAL_EXPORT WaitForProperty: public WaitFor {
+Q_OBJECT
+public:
+
+ /**
+ * Creates a new WaitForProperty.
+ * This constructor is needed to dynamically create WaitForProperty objects
+ * in scripts using ScriptingModule::newWaitFor(const QString&). Method
+ * setProperty(QObject*, const QString&, const QVariant&) must be called to
+ * finish setting up the object. For C++ tutorials, use
+ * WaitForProperty(QObject*, const QString&, const QVariant&) constructor
+ * instead of this one.
+ */
+ Q_INVOKABLE WaitForProperty();
+
+ /**
+ * Creates a new WaitForProperty.
+ *
+ * @param object The object that contains the property.
+ * @param propertyName The name of the property.
+ * @param value The value of the property to wait for.
+ */
+ WaitForProperty(QObject* object, const QString& propertyName,
+ const QVariant& value);
+
+ /**
+ * Sets the property to wait for.
+ * This method can be invoked from a script.
+ *
+ * In fact, you should only invoke this method from a script, and only once,
+ * to set up the object. For C++ tutorials, use
+ * WaitForProperty(QObject*, const QString&, const QVariant&) constructor
+ * when creating this WaitForProperty.
+ *
+ * @param object The object that contains the property.
+ * @param propertyName The name of the property.
+ * @param value The value of the property to wait for.
+ */
+ Q_INVOKABLE void setProperty(QObject* sender, const QString& propertyName,
+ const QVariant& value);
+
+ /**
+ * Returns true if the property has the expected value, false otherwise.
+ * Note that it will return true even if the property got the expected value
+ * when this WaitForProperty was inactive. That is, as long as the property
+ * has the expected value, it will return true, no matter when that value
+ * was set.
+ *
+ * @return True if the property has the expected value, false otherwise.
+ */
+ virtual bool conditionMet() const;
+
+private:
+
+ /**
+ * The object that contains the property.
+ */
+ QObject* mObject;
+
+ /**
+ * The name of the property.
+ */
+ QString mPropertyName;
+
+ /**
+ * The value of the property to wait for.
+ */
+ QVariant mValue;
+
+private slots:
+
+ /**
+ * When the property value changes to the expected one, this method notifies
+ * that the wait for the property ended.
+ * The wait is only ended if this WaitForProperty is active.
+ */
+ void checkPropertyValueToEndTheWait();
+
+};
+
+#endif
Property changes on: trunk/ktutorial/ktutorial-library/src/WaitForProperty.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp 2011-05-08 15:16:11 UTC (rev 304)
+++ trunk/ktutorial/ktutorial-library/src/scripting/ScriptingModule.cpp 2011-05-16 16:39:27 UTC (rev 305)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2009-2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2009-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -27,6 +27,7 @@
#include "../WaitForEvent.h"
#include "../WaitForNot.h"
#include "../WaitForOr.h"
+#include "../WaitForProperty.h"
#include "../WaitForSignal.h"
#include "../WaitForWindow.h"
@@ -39,6 +40,7 @@
sSelf->registerWaitForMetaObject(WaitForEvent::staticMetaObject);
sSelf->registerWaitForMetaObject(WaitForNot::staticMetaObject);
sSelf->registerWaitForMetaObject(WaitForOr::staticMetaObject);
+ sSelf->registerWaitForMetaObject(WaitForProperty::staticMetaObject);
sSelf->registerWaitForMetaObject(WaitForSignal::staticMetaObject);
sSelf->registerWaitForMetaObject(WaitForWindow::staticMetaObject);
}
Modified: trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt 2011-05-08 15:16:11 UTC (rev 304)
+++ trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt 2011-05-16 16:39:27 UTC (rev 305)
@@ -38,6 +38,7 @@
WaitForEvent
WaitForNot
WaitForOr
+ WaitForProperty
WaitForSignal
WaitForWindow
)
@@ -61,6 +62,7 @@
WaitForEvent
WaitForNot
WaitForOr
+ WaitForProperty
WaitForSignal
WaitForWindow
)
Added: trunk/ktutorial/ktutorial-library/tests/WaitForPropertyTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/WaitForPropertyTest.cpp (rev 0)
+++ trunk/ktutorial/ktutorial-library/tests/WaitForPropertyTest.cpp 2011-05-16 16:39:27 UTC (rev 305)
@@ -0,0 +1,273 @@
+/***************************************************************************
+ * Copyright (C) 2011 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>
+
+#define protected public
+#define private public
+#include "WaitForProperty.h"
+#undef private
+#undef protected
+
+class WaitForPropertyTest: public QObject {
+Q_OBJECT
+Q_PROPERTY(QString stringProperty READ stringProperty
+ NOTIFY stringPropertyChanged)
+Q_PROPERTY(int intProperty READ intProperty)
+
+public:
+
+ QString stringProperty() const {
+ return mStringProperty;
+ }
+
+ int intProperty() const {
+ return mIntProperty;
+ }
+
+signals:
+
+ void stringPropertyChanged();
+
+protected:
+
+ void connectNotify(const char* signal) {
+ if (QLatin1String(signal) == SIGNAL(stringPropertyChanged())) {
+ mStringPropertyChangedConnectionCount++;
+ }
+ }
+
+private:
+
+ QString mStringProperty;
+ int mStringPropertyChangedConnectionCount;
+
+ int mIntProperty;
+
+private slots:
+
+ void init() {
+ mStringProperty = "";
+ mStringPropertyChangedConnectionCount = 0;
+
+ mIntProperty = 0;
+ }
+
+ void testConstructor();
+ void testConstructorWithPropertyWithoutNotifySignal();
+ void testConstructorWithNullObject();
+ void testConstructorWithUnknownPropertyName();
+ void testConstructorDefault();
+ void testConstructorDefaultWithPropertyWithoutNotifySignal();
+ void testConstructorDefaultWithNullObject();
+ void testConstructorDefaultWithUnknownPropertyName();
+
+ void testConditionMet();
+ void testConditionMetWhenStepWasNotActive();
+ void testConditionMetWithPropertyWithoutNotifySignal();
+ void testConditionMetWithValueTypeDifferentFromPropertyType();
+
+ void testPropertyChangeToExpectedValue();
+ void testPropertyChangeToExpectedValueWhenNotActive();
+
+};
+
+void WaitForPropertyTest::testConstructor() {
+ WaitForProperty waitForProperty(this, "stringProperty", "Expected value");
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+ QCOMPARE(mStringPropertyChangedConnectionCount, 1);
+}
+
+void WaitForPropertyTest::testConstructorWithPropertyWithoutNotifySignal() {
+ WaitForProperty waitForProperty(this, "intProperty", 42);
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConstructorWithNullObject() {
+ WaitForProperty waitForProperty(0, "stringProperty", "Expected value");
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConstructorWithUnknownPropertyName() {
+ WaitForProperty waitForProperty(this, "unknownProperty", "Expected value");
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConstructorDefault() {
+ WaitForProperty waitForProperty;
+ waitForProperty.setProperty(this, "stringProperty", "Expected value");
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+ QCOMPARE(mStringPropertyChangedConnectionCount, 1);
+}
+
+void WaitForPropertyTest::
+ testConstructorDefaultWithPropertyWithoutNotifySignal() {
+ WaitForProperty waitForProperty;
+ waitForProperty.setProperty(this, "intProperty", 42);
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConstructorDefaultWithNullObject() {
+ WaitForProperty waitForProperty;
+ waitForProperty.setProperty(0, "stringProperty", "Expected value");
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConstructorDefaultWithUnknownPropertyName() {
+ WaitForProperty waitForProperty;
+ waitForProperty.setProperty(this, "unknownProperty", "Expected value");
+
+ QVERIFY(!waitForProperty.isActive());
+ QVERIFY(!waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConditionMet() {
+ WaitForProperty waitForProperty(this, "stringProperty", "Expected value");
+
+ waitForProperty.setActive(true);
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ mStringProperty = "Another value";
+ emit stringPropertyChanged();
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ mStringProperty = "Expected value";
+ emit stringPropertyChanged();
+
+ QVERIFY(waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConditionMetWhenStepWasNotActive() {
+ WaitForProperty waitForProperty(this, "stringProperty", "Expected value");
+
+ mStringProperty = "Another value";
+ emit stringPropertyChanged();
+
+ waitForProperty.setActive(true);
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ waitForProperty.setActive(false);
+
+ mStringProperty = "Expected value";
+ emit stringPropertyChanged();
+
+ waitForProperty.setActive(true);
+
+ QVERIFY(waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::testConditionMetWithPropertyWithoutNotifySignal() {
+ WaitForProperty waitForProperty(this, "intProperty", 42);
+
+ waitForProperty.setActive(true);
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ mIntProperty = 4;
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ mIntProperty = 42;
+
+ QVERIFY(waitForProperty.conditionMet());
+}
+
+void WaitForPropertyTest::
+ testConditionMetWithValueTypeDifferentFromPropertyType() {
+ WaitForProperty waitForProperty(this, "intProperty", "42");
+
+ waitForProperty.setActive(true);
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ mIntProperty = 4;
+
+ QVERIFY(!waitForProperty.conditionMet());
+
+ mIntProperty = 42;
+
+ QVERIFY(waitForProperty.conditionMet());
+}
+
+//WaitFor* must be declared as a metatype to be used in qvariant_cast
+Q_DECLARE_METATYPE(WaitFor*);
+
+void WaitForPropertyTest::testPropertyChangeToExpectedValue() {
+ WaitForProperty waitForProperty(this, "stringProperty", "Expected value");
+ waitForProperty.setActive(true);
+
+ //WaitFor* must be registered in order to be used with QSignalSpy
+ int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*");
+ QSignalSpy waitEndedSpy(&waitForProperty, SIGNAL(waitEnded(WaitFor*)));
+
+ mStringProperty = "Another value";
+ emit stringPropertyChanged();
+
+ QVERIFY(!waitForProperty.conditionMet());
+ QCOMPARE(waitEndedSpy.count(), 0);
+
+ mStringProperty = "Expected value";
+ emit stringPropertyChanged();
+
+ QVERIFY(waitForProperty.conditionMet());
+ QCOMPARE(waitEndedSpy.count(), 1);
+ QVariant argument = waitEndedSpy.at(0).at(0);
+ QCOMPARE(argument.userType(), waitForStarType);
+ QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForProperty);
+}
+
+void WaitForPropertyTest::testPropertyChangeToExpectedValueWhenNotActive() {
+ WaitForProperty waitForProperty(this, "stringProperty", "Expected value");
+ waitForProperty.setActive(false);
+
+ qRegisterMetaType<WaitFor*>("WaitFor*");
+ QSignalSpy waitEndedSpy(&waitForProperty, SIGNAL(waitEnded(WaitFor*)));
+
+ mStringProperty = "Another value";
+ emit stringPropertyChanged();
+
+ QVERIFY(!waitForProperty.conditionMet());
+ QCOMPARE(waitEndedSpy.count(), 0);
+
+ mStringProperty = "Expected value";
+ emit stringPropertyChanged();
+
+ QVERIFY(waitForProperty.conditionMet());
+ QCOMPARE(waitEndedSpy.count(), 0);
+}
+
+QTEST_MAIN(WaitForPropertyTest)
+
+#include "WaitForPropertyTest.moc"
Property changes on: trunk/ktutorial/ktutorial-library/tests/WaitForPropertyTest.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingModuleTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingModuleTest.cpp 2011-05-08 15:16:11 UTC (rev 304)
+++ trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingModuleTest.cpp 2011-05-16 16:39:27 UTC (rev 305)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2009-2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2009-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -33,6 +33,7 @@
#include "../WaitForEvent.h"
#include "../WaitForNot.h"
#include "../WaitForOr.h"
+#include "../WaitForProperty.h"
#include "../WaitForSignal.h"
#include "../WaitForWindow.h"
@@ -169,6 +170,10 @@
type = metaObject(scriptingModule, "WaitForOr");
QCOMPARE(type.className(), WaitForOr::staticMetaObject.className());
+ QVERIFY(containsMetaObject(scriptingModule, "WaitForProperty"));
+ type = metaObject(scriptingModule, "WaitForProperty");
+ QCOMPARE(type.className(), WaitForProperty::staticMetaObject.className());
+
QVERIFY(containsMetaObject(scriptingModule, "WaitForSignal"));
type = metaObject(scriptingModule, "WaitForSignal");
QCOMPARE(type.className(), WaitForSignal::staticMetaObject.className());
Modified: trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingTest.cpp
===================================================================
--- trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingTest.cpp 2011-05-08 15:16:11 UTC (rev 304)
+++ trunk/ktutorial/ktutorial-library/tests/scripting/ScriptingTest.cpp 2011-05-16 16:39:27 UTC (rev 305)
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2009-2010 by Daniel Calviño Sánchez *
+ * Copyright (C) 2009-2011 by Daniel Calviño Sánchez *
* dan...@gm... *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -42,6 +42,13 @@
//tutorials work as expected
class ScriptingTest: public QObject {
Q_OBJECT
+Q_PROPERTY(int intProperty READ intProperty NOTIFY intPropertyChanged)
+public:
+
+ int intProperty() const {
+ return mIntProperty;
+ }
+
public slots:
bool booleanValue() {
@@ -62,6 +69,8 @@
void otherDummySignal();
void anotherDummySignal();
+ void intPropertyChanged();
+
private slots:
void initTestCase();
@@ -83,6 +92,8 @@
bool mBooleanValue;
+ int mIntProperty;
+
int mDummySlotCallCount;
KTemporaryFile* mTemporaryFile;
@@ -98,6 +109,7 @@
void ScriptingTest::init() {
mBooleanValue = false;
+ mIntProperty = 0;
mDummySlotCallCount = 0;
mTemporaryFile = new KTemporaryFile();
@@ -314,6 +326,8 @@
out << "tutorial.addStep(secondStep);\n";
out << "thirdStep = ktutorial.newStep(\"third\");\n";
out << "tutorial.addStep(thirdStep);\n";
+ out << "fourthStep = ktutorial.newStep(\"fourth\");\n";
+ out << "tutorial.addStep(fourthStep);\n";
out << "endStep = ktutorial.newStep(\"end\");\n";
out << "endStep.setText(\"The tutorial has ended.\");\n";
out << "tutorial.addStep(endStep);\n";
@@ -351,8 +365,14 @@
out << "waitForChildAddedEvent = ktutorial.newWaitFor(\"WaitForEvent\");\n";
out << "waitForChildAddedEvent.setEvent(testObject, \"ChildAdded\");\n";
- out << "thirdStep.addWaitFor(waitForChildAddedEvent, \"end\");\n";
+ out << "thirdStep.addWaitFor(waitForChildAddedEvent, \"fourth\");\n";
+ out << "waitForIntProperty = ktutorial.newWaitFor(\"WaitForProperty\");\n";
+ out << "waitForIntProperty.setProperty(testObject, \"intProperty\", \
+\"42\");\n";
+
+ out << "fourthStep.addWaitFor(waitForIntProperty, \"end\");\n";
+
out.flush();
ScriptedTutorial scriptedTutorial(mTemporaryFile->fileName());
@@ -397,6 +417,11 @@
QObject* childObject = new QObject();
childObject->setParent(this);
+ QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("fourth"));
+
+ mIntProperty = 42;
+ emit intPropertyChanged();
+
QCOMPARE(scriptedTutorial.mCurrentStep->id(), QString("end"));
QCOMPARE(scriptedTutorial.mCurrentStep->text(),
QString("The tutorial has ended."));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|