From a67718cc40bb4bf7df41d611d37030548fe2c1d0 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann <Thomas.Hartmann@nokia.com> Date: Wed, 20 Jan 2010 13:13:31 +0100 Subject: [PATCH] QmlDesigner.tests: Adding test for RewritingException --- .../qml/qmldesigner/coretests/testcore.cpp | 41 +++++++++++++++++++ .../auto/qml/qmldesigner/coretests/testcore.h | 1 + 2 files changed, 42 insertions(+) diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.cpp b/tests/auto/qml/qmldesigner/coretests/testcore.cpp index b031b3f41a3..a99c7b2649c 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/testcore.cpp @@ -39,6 +39,7 @@ #include <qmlanchors.h> #include <invalididexception.h> #include <invalidmodelnodeexception.h> +#include <rewritingexception.h> #include <nodeinstanceview.h> #include <nodeinstance.h> #include <QDebug> @@ -2540,6 +2541,46 @@ void TestCore::testRewriterNodeSliding() QCOMPARE(rootNode.nodeListProperty(QLatin1String("data")).toModelNodeList().at(1).id(), QLatin1String("rectangle2")); } +void TestCore::testRewriterExecptionHandling() +{ + const QLatin1String qmlString("import Qt 4.6\n" + "Text {\n" + "}"); + + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString); + PlainTextEditModifier textModifier(&textEdit); + + QScopedPointer<Model> model(Model::create("Qt/Item", 4, 6)); + QVERIFY(model.data()); + + QScopedPointer<TestView> view(new TestView); + model->attachView(view.data()); + + // read in + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&textModifier); + model->attachView(testRewriterView.data()); + + ModelNode rootNode = view->rootModelNode(); + QVERIFY(rootNode.isValid()); + QCOMPARE(rootNode.type(), QLatin1String("Qt/Text")); + + try + { + RewriterTransaction transaction = view->beginRewriterTransaction(); + rootNode.variantProperty("bla") = QVariant("blah\""); + rootNode.variantProperty("text") = QVariant("text"); + transaction.commit(); + QFAIL("RewritingExecption should be thrown"); + } catch (RewritingException &e) { + QVERIFY(rootNode.isValid()); + QCOMPARE(rootNode.type(), QLatin1String("Qt/Text")); + QVERIFY(!rootNode.hasProperty("bla")); + QVERIFY(!rootNode.hasProperty("text")); + } +} + void TestCore::testRewriterFirstDefinitionInside() { const QString qmlString("import Qt 4.6\n" diff --git a/tests/auto/qml/qmldesigner/coretests/testcore.h b/tests/auto/qml/qmldesigner/coretests/testcore.h index 1e9f09140e1..d02d15d4fd1 100644 --- a/tests/auto/qml/qmldesigner/coretests/testcore.h +++ b/tests/auto/qml/qmldesigner/coretests/testcore.h @@ -117,6 +117,7 @@ private slots: void testRewriterForArrayMagic(); void testRewriterWithSignals(); void testRewriterNodeSliding(); + void testRewriterExecptionHandling(); // // unit tests QmlModelNodeFacade/QmlModelState -- GitLab