From 2962830c5b38a0ed8bb3992f9b8b935043cc6442 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 6 Dec 2010 14:58:01 +1000 Subject: Port some QtDeclarative test cases as examples --- tests/README | 2 + tests/qdeclarativebinding/data/tst_binding.qml | 75 ++++++++++ tests/qdeclarativebinding/data/tst_binding2.qml | 70 +++++++++ tests/qdeclarativebinding/qdeclarativebinding.pro | 6 + tests/qdeclarativebinding/qdeclarativebinding.qrc | 6 + .../tst_qdeclarativebinding.cpp | 44 ++++++ .../data/InvalidSciFile.qml | 48 ++++++ .../qdeclarativeborderimage/data/colors-round.sci | 7 + tests/qdeclarativeborderimage/data/colors.png | Bin 0 -> 1655 bytes tests/qdeclarativeborderimage/data/invalid.sci | 7 + .../data/tst_borderimage.qml | 162 +++++++++++++++++++++ .../qdeclarativeborderimage.pro | 6 + .../qdeclarativeborderimage.qrc | 9 ++ .../tst_qdeclarativeborderimage.cpp | 44 ++++++ tests/tests.pro | 7 +- 15 files changed, 492 insertions(+), 1 deletion(-) create mode 100644 tests/README create mode 100644 tests/qdeclarativebinding/data/tst_binding.qml create mode 100644 tests/qdeclarativebinding/data/tst_binding2.qml create mode 100644 tests/qdeclarativebinding/qdeclarativebinding.pro create mode 100644 tests/qdeclarativebinding/qdeclarativebinding.qrc create mode 100644 tests/qdeclarativebinding/tst_qdeclarativebinding.cpp create mode 100644 tests/qdeclarativeborderimage/data/InvalidSciFile.qml create mode 100644 tests/qdeclarativeborderimage/data/colors-round.sci create mode 100644 tests/qdeclarativeborderimage/data/colors.png create mode 100644 tests/qdeclarativeborderimage/data/invalid.sci create mode 100644 tests/qdeclarativeborderimage/data/tst_borderimage.qml create mode 100644 tests/qdeclarativeborderimage/qdeclarativeborderimage.pro create mode 100644 tests/qdeclarativeborderimage/qdeclarativeborderimage.qrc create mode 100644 tests/qdeclarativeborderimage/tst_qdeclarativeborderimage.cpp (limited to 'tests') diff --git a/tests/README b/tests/README new file mode 100644 index 0000000..4f56a04 --- /dev/null +++ b/tests/README @@ -0,0 +1,2 @@ +This directory contains some QtDeclarative tests that have been ported +from the "tested with C++" style in Qt 4.7 to the qtest-qml style. diff --git a/tests/qdeclarativebinding/data/tst_binding.qml b/tests/qdeclarativebinding/data/tst_binding.qml new file mode 100644 index 0000000..3b1cf8a --- /dev/null +++ b/tests/qdeclarativebinding/data/tst_binding.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtTest 1.0 + +Rectangle { + id: screen + width: 320; height: 240 + property string text + property bool changeColor: false + + Text { id: s1; text: "Hello" } + Rectangle { id: r1; width: 1; height: 1; color: "yellow" } + Rectangle { id: r2; width: 1; height: 1; color: "red" } + + Binding { target: screen; property: "text"; value: s1.text; id: binding1 } + Binding { target: screen; property: "color"; value: r1.color } + Binding { target: screen; property: "color"; when: screen.changeColor == true; value: r2.color; id: binding3 } + + TestCase { + name: "Binding" + + function test_binding() { + compare(screen.color, "#ffff00") // Yellow + compare(screen.text, "Hello") + verify(!binding3.when) + + screen.changeColor = true + compare(screen.color, "#ff0000") // Red + + verify(binding1.target == screen) + compare(binding1.property, "text") + compare(binding1.value, "Hello") + } + } +} diff --git a/tests/qdeclarativebinding/data/tst_binding2.qml b/tests/qdeclarativebinding/data/tst_binding2.qml new file mode 100644 index 0000000..414800f --- /dev/null +++ b/tests/qdeclarativebinding/data/tst_binding2.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtTest 1.0 + +Rectangle { + id: screen + width: 320; height: 240 + property string text + property bool changeColor: false + + Text { id: s1; text: "Hello" } + Rectangle { id: r1; width: 1; height: 1; color: "yellow" } + Rectangle { id: r2; width: 1; height: 1; color: "red" } + + Binding { target: screen; property: "text"; value: s1.text } + Binding { target: screen; property: "color"; value: r1.color } + Binding { target: screen; property: "color"; value: r2.color; when: screen.changeColor == true } + + TestCase { + name: "Binding2" + + function test_binding2() { + compare(screen.color, "#ffff00") // Yellow + compare(screen.text, "Hello") + + screen.changeColor = true + compare(screen.color, "#ff0000") // Red + } + } +} diff --git a/tests/qdeclarativebinding/qdeclarativebinding.pro b/tests/qdeclarativebinding/qdeclarativebinding.pro new file mode 100644 index 0000000..708794c --- /dev/null +++ b/tests/qdeclarativebinding/qdeclarativebinding.pro @@ -0,0 +1,6 @@ +TEMPLATE=app +TARGET=tst_qdeclarativebinding +CONFIG += warn_on testcase +SOURCES += tst_qdeclarativebinding.cpp +RESOURCES += qdeclarativebinding.qrc +include(../../src/quicktestlib/quicktestlib_dep.pri) diff --git a/tests/qdeclarativebinding/qdeclarativebinding.qrc b/tests/qdeclarativebinding/qdeclarativebinding.qrc new file mode 100644 index 0000000..dfda961 --- /dev/null +++ b/tests/qdeclarativebinding/qdeclarativebinding.qrc @@ -0,0 +1,6 @@ + + + data/tst_binding.qml + data/tst_binding2.qml + + diff --git a/tests/qdeclarativebinding/tst_qdeclarativebinding.cpp b/tests/qdeclarativebinding/tst_qdeclarativebinding.cpp new file mode 100644 index 0000000..adab1f4 --- /dev/null +++ b/tests/qdeclarativebinding/tst_qdeclarativebinding.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativetest.h" + +QTEST_QUICK_MAIN(qdeclarativebinding) diff --git a/tests/qdeclarativeborderimage/data/InvalidSciFile.qml b/tests/qdeclarativeborderimage/data/InvalidSciFile.qml new file mode 100644 index 0000000..8a56582 --- /dev/null +++ b/tests/qdeclarativeborderimage/data/InvalidSciFile.qml @@ -0,0 +1,48 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 + +BorderImage { + source: "invalid.sci" + width: 300 + height: 300 +} diff --git a/tests/qdeclarativeborderimage/data/colors-round.sci b/tests/qdeclarativeborderimage/data/colors-round.sci new file mode 100644 index 0000000..5d2f49f --- /dev/null +++ b/tests/qdeclarativeborderimage/data/colors-round.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.right:30 +border.bottom:40 +horizontalTileRule:Round +verticalTileRule:Repeat +source:colors.png diff --git a/tests/qdeclarativeborderimage/data/colors.png b/tests/qdeclarativeborderimage/data/colors.png new file mode 100644 index 0000000..dfb62f3 Binary files /dev/null and b/tests/qdeclarativeborderimage/data/colors.png differ diff --git a/tests/qdeclarativeborderimage/data/invalid.sci b/tests/qdeclarativeborderimage/data/invalid.sci new file mode 100644 index 0000000..98c72c9 --- /dev/null +++ b/tests/qdeclarativeborderimage/data/invalid.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.down:30 +border.up:40 +horizontalTileRule:Roun +verticalTileRule:Repea +source:colors.png diff --git a/tests/qdeclarativeborderimage/data/tst_borderimage.qml b/tests/qdeclarativeborderimage/data/tst_borderimage.qml new file mode 100644 index 0000000..5a803e8 --- /dev/null +++ b/tests/qdeclarativeborderimage/data/tst_borderimage.qml @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import QtTest 1.0 + +Item { + id: top + + BorderImage { + id: noSource + source: "" + } + + property string srcImage: "colors.png" + + BorderImage { + id: clearSource + source: srcImage + } + + BorderImage { + id: resized + source: "colors.png" + width: 300 + height: 300 + } + + BorderImage { + id: smooth + source: "colors.png" + smooth: true + width: 300 + height: 300 + } + + BorderImage { + id: tileModes1 + source: "colors.png" + width: 100 + height: 300 + horizontalTileMode: BorderImage.Repeat + verticalTileMode: BorderImage.Repeat + } + + BorderImage { + id: tileModes2 + source: "colors.png" + width: 300 + height: 150 + horizontalTileMode: BorderImage.Round + verticalTileMode: BorderImage.Round + } + + TestCase { + name: "BorderImage" + + function test_noSource() { + compare(noSource.source, "") + compare(noSource.width, 0) + compare(noSource.height, 0) + compare(noSource.horizontalTileMode, BorderImage.Stretch) + compare(noSource.verticalTileMode, BorderImage.Stretch) + } + + // TODO: imageSource() + + function test_clearSource() { + compare(clearSource.source, "qrc:data/colors.png") + compare(clearSource.width, 120) + compare(clearSource.height, 120) + + srcImage = "" + compare(clearSource.source, "") + compare(clearSource.width, 0) + compare(clearSource.height, 0) + } + + function test_resized() { + compare(resized.width, 300) + compare(resized.height, 300) + compare(resized.horizontalTileMode, BorderImage.Stretch) + compare(resized.verticalTileMode, BorderImage.Stretch) + } + + function test_smooth() { + compare(smooth.smooth, true) + compare(smooth.width, 300) + compare(smooth.height, 300) + compare(smooth.horizontalTileMode, BorderImage.Stretch) + compare(smooth.verticalTileMode, BorderImage.Stretch) + } + + function test_tileModes() { + compare(tileModes1.width, 100) + compare(tileModes1.height, 300) + compare(tileModes1.horizontalTileMode, BorderImage.Repeat) + compare(tileModes1.verticalTileMode, BorderImage.Repeat) + + compare(tileModes2.width, 300) + compare(tileModes2.height, 150) + compare(tileModes2.horizontalTileMode, BorderImage.Round) + compare(tileModes2.verticalTileMode, BorderImage.Round) + } + + // TODO: sciSource() + + function test_invalidSciFile() { + ignoreWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch.") // for "Roun" + ignoreWarning("QDeclarativeGridScaledImage: Invalid tile rule specified. Using Stretch.") // for "Repea" + + var component = Qt.createComponent("InvalidSciFile.qml") + var invalidSciFile = component.createObject(top) + + compare(invalidSciFile.status, Image.Error) + compare(invalidSciFile.width, 300) + compare(invalidSciFile.height, 300) + compare(invalidSciFile.horizontalTileMode, BorderImage.Stretch) + compare(invalidSciFile.verticalTileMode, BorderImage.Stretch) + } + + // TODO: pendingRemoteRequest() + } +} diff --git a/tests/qdeclarativeborderimage/qdeclarativeborderimage.pro b/tests/qdeclarativeborderimage/qdeclarativeborderimage.pro new file mode 100644 index 0000000..503e565 --- /dev/null +++ b/tests/qdeclarativeborderimage/qdeclarativeborderimage.pro @@ -0,0 +1,6 @@ +TEMPLATE=app +TARGET=tst_qdeclarativeborderimage +CONFIG += warn_on testcase +SOURCES += tst_qdeclarativeborderimage.cpp +RESOURCES += qdeclarativeborderimage.qrc +include(../../src/quicktestlib/quicktestlib_dep.pri) diff --git a/tests/qdeclarativeborderimage/qdeclarativeborderimage.qrc b/tests/qdeclarativeborderimage/qdeclarativeborderimage.qrc new file mode 100644 index 0000000..d3c103d --- /dev/null +++ b/tests/qdeclarativeborderimage/qdeclarativeborderimage.qrc @@ -0,0 +1,9 @@ + + + data/tst_borderimage.qml + data/InvalidSciFile.qml + data/colors.png + data/colors-round.sci + data/invalid.sci + + diff --git a/tests/qdeclarativeborderimage/tst_qdeclarativeborderimage.cpp b/tests/qdeclarativeborderimage/tst_qdeclarativeborderimage.cpp new file mode 100644 index 0000000..70f4663 --- /dev/null +++ b/tests/qdeclarativeborderimage/tst_qdeclarativeborderimage.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativetest.h" + +QTEST_QUICK_MAIN(qdeclarativeborderimage) diff --git a/tests/tests.pro b/tests/tests.pro index 032ca80..5e7b986 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -1,2 +1,7 @@ TEMPLATE = subdirs -SUBDIRS = qmlexample +SUBDIRS += \ + qdeclarativebinding \ + qdeclarativeborderimage + +# This test fails, so don't run it by default +#SUBDIRS += qmlexample -- cgit v1.2.3