summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-03-11 07:53:42 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-03-11 07:54:35 (GMT)
commit303730a3fdd399a3e0a65b08338b4db75aa2acee (patch)
tree4d265dfdf43a214a44f2f1e0408f6e873a1c671e /tests/auto
parent79dc9daa146410c7da8d4691e9a4489251980ab3 (diff)
downloadQt-303730a3fdd399a3e0a65b08338b4db75aa2acee.zip
Qt-303730a3fdd399a3e0a65b08338b4db75aa2acee.tar.gz
Qt-303730a3fdd399a3e0a65b08338b4db75aa2acee.tar.bz2
Replace QDeclarativeContext::addDefaultObject() -> setContextObject()
It is faster and easier to use to just support a single context object.
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp32
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/testtypes.h10
-rw-r--r--tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp12
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp2
4 files changed, 12 insertions, 44 deletions
diff --git a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp
index f0117f5..b212820 100644
--- a/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp
+++ b/tests/auto/declarative/qdeclarativecontext/tst_qdeclarativecontext.cpp
@@ -58,7 +58,7 @@ private slots:
void engineMethod();
void parentContext();
void setContextProperty();
- void addDefaultObject();
+ void setContextObject();
void destruction();
void idAsContextProperty();
@@ -224,24 +224,6 @@ private:
int _c;
};
-class TestObject2 : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int b READ b NOTIFY bChanged)
-
-public:
- TestObject2() : _b(10) {}
-
- int b() const { return _b; }
- void setB(int b) { _b = b; emit bChanged(); }
-
-signals:
- void bChanged();
-
-private:
- int _b;
-};
-
#define TEST_CONTEXT_PROPERTY(ctxt, name, value) \
{ \
QDeclarativeComponent component(&engine); \
@@ -367,35 +349,31 @@ void tst_qdeclarativecontext::setContextProperty()
}
}
-void tst_qdeclarativecontext::addDefaultObject()
+void tst_qdeclarativecontext::setContextObject()
{
QDeclarativeContext ctxt(&engine);
TestObject to;
- TestObject2 to2;
to.setA(2);
to.setB(192);
to.setC(18);
- to2.setB(111999);
- ctxt.addDefaultObject(&to2);
- ctxt.addDefaultObject(&to);
+ ctxt.setContextObject(&to);
ctxt.setContextProperty("c", QVariant(9));
// Static context properties
TEST_CONTEXT_PROPERTY(&ctxt, a, QVariant(2));
- TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(111999));
+ TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(192));
TEST_CONTEXT_PROPERTY(&ctxt, c, QVariant(9));
to.setA(12);
to.setB(100);
to.setC(7);
- to2.setB(1612);
ctxt.setContextProperty("c", QVariant(3));
TEST_CONTEXT_PROPERTY(&ctxt, a, QVariant(12));
- TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(1612));
+ TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(100));
TEST_CONTEXT_PROPERTY(&ctxt, c, QVariant(3));
// Changes in context properties
diff --git a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
index a283e3f..78a5e0f 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
+++ b/tests/auto/declarative/qdeclarativeecmascript/testtypes.h
@@ -207,18 +207,10 @@ class MyDefaultObject1 : public QObject
Q_OBJECT
Q_PROPERTY(int horseLegs READ horseLegs CONSTANT);
Q_PROPERTY(int antLegs READ antLegs CONSTANT);
+ Q_PROPERTY(int emuLegs READ emuLegs CONSTANT);
public:
int horseLegs() const { return 4; }
int antLegs() const { return 6; }
-};
-
-class MyDefaultObject2 : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(int antLegs READ antLegs CONSTANT);
- Q_PROPERTY(int emuLegs READ emuLegs CONSTANT);
-public:
- int antLegs() const { return 5; } // Had an accident
int emuLegs() const { return 2; }
};
diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
index bdd2c93..caefdbf 100644
--- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
+++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp
@@ -350,7 +350,6 @@ void tst_qdeclarativeecmascript::basicExpressions()
MyQmlObject object2;
MyQmlObject object3;
MyDefaultObject1 default1;
- MyDefaultObject2 default2;
MyDefaultObject3 default3;
object1.setStringProperty("Object1");
object2.setStringProperty("Object2");
@@ -359,13 +358,12 @@ void tst_qdeclarativeecmascript::basicExpressions()
QDeclarativeContext context(engine.rootContext());
QDeclarativeContext nestedContext(&context);
- context.addDefaultObject(&default1);
- context.addDefaultObject(&default2);
+ context.setContextObject(&default1);
context.setContextProperty("a", QVariant(1944));
context.setContextProperty("b", QVariant("Milk"));
context.setContextProperty("object", &object1);
context.setContextProperty("objectOverride", &object2);
- nestedContext.addDefaultObject(&default3);
+ nestedContext.setContextObject(&default3);
nestedContext.setContextProperty("b", QVariant("Cow"));
nestedContext.setContextProperty("objectOverride", &object3);
nestedContext.setContextProperty("millipedeLegs", QVariant(100));
@@ -1639,7 +1637,7 @@ void tst_qdeclarativeecmascript::listToVariant()
MyQmlContainer container;
QDeclarativeContext context(engine.rootContext());
- context.addDefaultObject(&container);
+ context.setContextObject(&container);
QObject *object = component.create(&context);
QVERIFY(object != 0);
@@ -1911,7 +1909,7 @@ void tst_qdeclarativeecmascript::ownership()
{
OwnershipObject own;
QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
- context->addDefaultObject(&own);
+ context->setContextObject(&own);
{
QDeclarativeComponent component(&engine, TEST_FILE("ownership.qml"));
@@ -1971,7 +1969,7 @@ void tst_qdeclarativeecmascript::qlistqobjectMethods()
{
QListQObjectMethodsObject obj;
QDeclarativeContext *context = new QDeclarativeContext(engine.rootContext());
- context->addDefaultObject(&obj);
+ context->setContextObject(&obj);
QDeclarativeComponent component(&engine, TEST_FILE("qlistqobjectMethods.qml"));
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index a1e6d6b..1b59608 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -214,7 +214,7 @@ void tst_QDeclarativeListModel::dynamic()
QDeclarativeEngine engine;
QDeclarativeListModel model;
QDeclarativeEngine::setContextForObject(&model,engine.rootContext());
- engine.rootContext()->addDefaultObject(&model);
+ engine.rootContext()->setContextObject(&model);
QDeclarativeExpression e(engine.rootContext(), script, &model);
if (!warning.isEmpty())
QTest::ignoreMessage(QtWarningMsg, warning.toLatin1());