diff --git a/tests/auto/qmltest/animatedimage/stickman.gif b/tests/auto/qmltest/animatedimage/stickman.gif new file mode 100644 index 0000000000..7c4cd18687 Binary files /dev/null and b/tests/auto/qmltest/animatedimage/stickman.gif differ diff --git a/tests/auto/qmltest/animatedimage/tst_animatedimage.qml b/tests/auto/qmltest/animatedimage/tst_animatedimage.qml new file mode 100644 index 0000000000..bc2bbea1cb --- /dev/null +++ b/tests/auto/qmltest/animatedimage/tst_animatedimage.qml @@ -0,0 +1,220 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + property string srcImage: "stickman.gif" + property bool canconnect + property bool checkfinished: false + + Component.onCompleted: { + var check = new XMLHttpRequest; + check.open("GET", "http://127.0.0.1:14445/stickman.gif"); + check.onreadystatechange = function() { + + console.log("Status: ", check.status) + console.log("Readystate", check.readyState) + if (check.readyState == XMLHttpRequest.DONE) { + if (check.status == 404) { + top.canconnect = false; + }else{ + top.canconnect = true; + } + top.checkfinished = true; + } + } + check.send(); + } + + AnimatedImage { + id: noSource + source: "" + } + + AnimatedImage { + id: clearSource + source: srcImage + } + + AnimatedImage { + id: resized + source: srcImage + width: 300 + height: 300 + } + + AnimatedImage { + id: smooth + source: srcImage + smooth: true + width: 300 + height: 300 + } + + AnimatedImage { + id: tileModes1 + source: srcImage + width: 100 + height: 300 + fillMode: AnimatedImage.Tile + } + + AnimatedImage { + id: tileModes2 + source: srcImage + width: 300 + height: 150 + fillMode: AnimatedImage.TileVertically + } + AnimatedImage { + id: tileModes3 + source: srcImage + width: 300 + height: 150 + fillMode: AnimatedImage.TileHorizontally + } + + TestCase { + name: "AnimatedImage" + + function test_noSource() { + compare(noSource.source, "") + compare(noSource.width, 0) + compare(noSource.height, 0) + compare(noSource.fillMode, AnimatedImage.Stretch) + } + + function test_imageSource_data() { + return [ + { + tag: "local", + source: "stickman.gif", + remote: false, + error: "" + }, + { + tag: "local not found", + source: "no-such-file.png", + remote: false, + error: "SUBinline:1:21: QML AnimatedImage: Error Reading Animated Image File SUBno-such-file.png" + }, + { + tag: "remote", + source: "http://127.0.0.1:14445/stickman.gif", + remote: true, + error: "" + } + ] + } + + function test_imageSource(row) { + var expectError = (row.error.length != 0) + var canconnect = false; + + if (expectError) { + var parentUrl = Qt.resolvedUrl(".") + ignoreWarning(row.error.replace(/SUB/g, parentUrl)) + } + + var img = Qt.createQmlObject('import QtQuick 2.0; AnimatedImage { source: "'+row.source+'" }', top) + + if (row.remote) { + skip("Remote solution not yet complete") + tryCompare(img, "status", AnimatedImage.Loading) + tryCompare(top, "checkfinished", true, 10000) + if (top.canconnect == false) + skip("Cannot access remote") + } + + if (!expectError) { + tryCompare(img, "status", AnimatedImage.Ready, 10000) + compare(img.width, 160) + compare(img.height, 120) + compare(img.fillMode, AnimatedImage.Stretch) + } else { + tryCompare(img, "status", AnimatedImage.Error) + } + + img.destroy() + } + + function test_clearSource() { + compare(clearSource.source, Qt.resolvedUrl(srcImage)) + compare(clearSource.width, 160) + 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.fillMode, AnimatedImage.Stretch) + } + + function test_smooth() { + compare(smooth.smooth, true) + compare(smooth.width, 300) + compare(smooth.height, 300) + compare(smooth.fillMode, AnimatedImage.Stretch) + } + + function test_tileModes() { + compare(tileModes1.width, 100) + compare(tileModes1.height, 300) + compare(tileModes1.fillMode, AnimatedImage.Tile) + + compare(tileModes2.width, 300) + compare(tileModes2.height, 150) + compare(tileModes2.fillMode, AnimatedImage.TileVertically) + + compare(tileModes3.width, 300) + compare(tileModes3.height, 150) + compare(tileModes3.fillMode, AnimatedImage.TileHorizontally) + } + + } +} diff --git a/tests/auto/qmltest/borderimage/remote.sci b/tests/auto/qmltest/borderimage/remote.sci new file mode 100644 index 0000000000..70d5213453 --- /dev/null +++ b/tests/auto/qmltest/borderimage/remote.sci @@ -0,0 +1,7 @@ +border.left:10 +border.top:20 +border.right:30 +border.bottom:40 +horizontalTileRule:Round +verticalTileRule:Repeat +source:http://127.0.0.1:14445/colors.png diff --git a/tests/auto/qmltest/borderimage/tst_borderimage.qml b/tests/auto/qmltest/borderimage/tst_borderimage.qml index 98a71711ed..113c0de77d 100644 --- a/tests/auto/qmltest/borderimage/tst_borderimage.qml +++ b/tests/auto/qmltest/borderimage/tst_borderimage.qml @@ -44,6 +44,24 @@ import QtTest 1.0 Item { id: top + property bool canconnect + property bool checkfinished: false + + Component.onCompleted: { + var check = new XMLHttpRequest; + check.open("GET", "http://127.0.0.1:14445/colors.png"); + check.onreadystatechange = function() { + if (check.readyState == XMLHttpRequest.DONE) { + if (check.status == 404) { + top.canconnect = false; + }else{ + top.canconnect = true; + } + top.checkfinished = true; + } + } + check.send(); + } BorderImage { id: noSource @@ -59,14 +77,14 @@ Item { BorderImage { id: resized - source: "colors.png" + source: srcImage width: 300 height: 300 } BorderImage { id: smooth - source: "colors.png" + source: srcImage smooth: true width: 300 height: 300 @@ -74,7 +92,7 @@ Item { BorderImage { id: tileModes1 - source: "colors.png" + source: srcImage width: 100 height: 300 horizontalTileMode: BorderImage.Repeat @@ -83,7 +101,7 @@ Item { BorderImage { id: tileModes2 - source: "colors.png" + source: srcImage width: 300 height: 150 horizontalTileMode: BorderImage.Round @@ -114,8 +132,13 @@ Item { source: "no-such-file.png", remote: false, error: "SUBinline:1:21: QML BorderImage: Cannot open: SUBno-such-file.png" + }, + { + tag: "remote", + source: "http://127.0.0.1:14445/colors.png", + remote: true, + error: "" } - // TODO: remote tests that need to use http ] } @@ -130,11 +153,16 @@ Item { ('import QtQuick 2.0; BorderImage { source: "' + row.source + '" }', top) - if (row.remote) + if (row.remote) { + skip("Remote solution not yet complete") tryCompare(img, "status", BorderImage.Loading) + tryCompare(top, "checkfinished", true, 10000) + if (top.canconnect == false) + skip("Cannot access remote") + } if (!expectError) { - tryCompare(img, "status", BorderImage.Ready) + tryCompare(img, "status", BorderImage.Ready, 10000) compare(img.width, 120) compare(img.height, 120) compare(img.horizontalTileMode, BorderImage.Stretch) @@ -197,25 +225,35 @@ Item { source: "no-such-file.sci", remote: false, valid: false + }, + { + tag: "remote", + source: "remote.sci", + remote: true, + valid: true } - // TODO: remote tests that need to use http ] } function test_sciSource(row) { - var img = Qt.createQmlObject - ('import QtQuick 2.0; BorderImage { source: "' + - row.source + '"; width: 300; height: 300 }', top) - - if (row.remote) - tryCompare(img, "status", BorderImage.Loading) + var img = Qt.createQmlObject('import QtQuick 2.0; BorderImage { height: 300; width: 300 }', top) + + if (row.remote) { + skip("Remote solution not yet complete") + img.source = row.source; + tryCompare(top, "checkfinished", true, 10000) + if (top.canconnect == false) + skip("Cannot access remote") + }else{ + img.source = row.source; + } compare(img.source, Qt.resolvedUrl(row.source)) compare(img.width, 300) compare(img.height, 300) if (row.valid) { - tryCompare(img, "status", BorderImage.Ready) + tryCompare(img, "status", BorderImage.Ready, 10000) compare(img.border.left, 10) compare(img.border.top, 20) compare(img.border.right, 30) diff --git a/tests/auto/qmltest/fontloader/dummy.ttf b/tests/auto/qmltest/fontloader/dummy.ttf new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/qmltest/fontloader/tarzeau_ocr_a.ttf b/tests/auto/qmltest/fontloader/tarzeau_ocr_a.ttf new file mode 100644 index 0000000000..cf93f9651f Binary files /dev/null and b/tests/auto/qmltest/fontloader/tarzeau_ocr_a.ttf differ diff --git a/tests/auto/qmltest/fontloader/tst_fontloader.qml b/tests/auto/qmltest/fontloader/tst_fontloader.qml new file mode 100644 index 0000000000..d389283e49 --- /dev/null +++ b/tests/auto/qmltest/fontloader/tst_fontloader.qml @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + FontLoader { + id: fontloader + } + + FontLoader { + id: fontswitch + } + + TextInput { + id: testinput + font.family: fontloader.name + } + + + + TestCase { + name: "FontLoader" + + function test_fontloading() { + compare(fontloader.status, FontLoader.Null) + compare(testinput.font.family, "") + fontloader.source = "tarzeau_ocr_a.ttf"; + tryCompare(fontloader.status, FontLoader.Loading) + tryCompare(fontloader.status, FontLoader.Ready) + compare(testinput.font.family, "OCRA") + fontloader.source = "dummy.ttf"; + tryCompare(fontloader.status, FontLoader.Error) + compare(testinput.font.family, "") + fontloader.source = ""; + fontloader.name = "Courier"; + tryCompare(fontloader.status, FontLoader.Ready) + compare(testinput.font.family, "Courier") + } + + function test_fontswitching() { + compare(fontswitch.status, FontLoader.Null) + fontswitch.source = "tarzeau_ocr_a.ttf"; + tryCompare(fontswitch.status, FontLoader.Loading) + tryCompare(fontswitch.status, FontLoader.Ready) + tryCompare(fontswitch.name, "OCRA") + fontswitch.source = ""; + fontswitch.name = "Courier"; + tryCompare(fontswitch.status, FontLoader.Ready) + tryCompare(fontswitch.name, "Courier") + fontswitch.source = "tarzeau_ocr_a.ttf"; + tryCompare(fontswitch.status, FontLoader.Loading) + tryCompare(fontswitch.status, FontLoader.Ready) + compare(fontswitch.name, "OCRA") + } + } +} diff --git a/tests/auto/qmltest/gradient/tst_gradient.qml b/tests/auto/qmltest/gradient/tst_gradient.qml new file mode 100644 index 0000000000..ed587502b6 --- /dev/null +++ b/tests/auto/qmltest/gradient/tst_gradient.qml @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + Gradient { + id: emptygradient + } + + Gradient { + id: twogradients + GradientStop { position: 0.0; color: "red" } + GradientStop { position: 1.0; color: "green" } + } + + Gradient { + id: elevengradients + GradientStop { position: 0.0; color: "red" } + GradientStop { position: 0.1; color: "orange" } + GradientStop { position: 0.2; color: "yellow" } + GradientStop { position: 0.3; color: "green" } + GradientStop { position: 0.4; color: "blue" } + GradientStop { position: 0.5; color: "violet" } + GradientStop { position: 0.6; color: "indigo" } + GradientStop { position: 0.7; color: "brown" } + GradientStop { position: 0.8; color: "lightgray" } + GradientStop { position: 0.9; color: "gray" } + GradientStop { position: 1.0; color: "black" } + } + + Gradient { + id: movedgradients + property real stopposition: 0.5 + GradientStop { position: 0.0; color: "red" } + GradientStop { position: movedgradients.stopposition; color: "blue" } + GradientStop { position: 1.0; color: "green" } + } + + Gradient { + id: defaultgradient + GradientStop { } + GradientStop { position: 1.0; color: "red" } + } + + TestCase { + name: "Gradient" + + function test_empty() { + compare(emptygradient.stops.length, 0) + } + + function test_lengthtwo() { + compare(twogradients.stops.length, 2) + compare(twogradients.stops[0].color.toString(), "#ff0000") + compare(twogradients.stops[1].color.toString(), "#008000") + } + + function test_multiplestops() { + compare(elevengradients.stops.length, 11) + compare(elevengradients.stops[0].color.toString(), "#ff0000") + compare(elevengradients.stops[4].color.toString(), "#0000ff") + compare(elevengradients.stops[4].position, 0.4) + compare(elevengradients.stops[9].position, 0.9) + } + + function test_moved() { + compare(movedgradients.stops.length, 3) + compare(movedgradients.stops[1].position, 0.5) + movedgradients.stopposition = 0.3; + compare(movedgradients.stops[1].position, 0.3) + } + + function test_default() { + compare(defaultgradient.stops.length, 2) + compare(defaultgradient.stops[0].color.toString(), "#000000") + } + } +} diff --git a/tests/auto/qmltest/image/logo.png b/tests/auto/qmltest/image/logo.png new file mode 100644 index 0000000000..d75936b007 Binary files /dev/null and b/tests/auto/qmltest/image/logo.png differ diff --git a/tests/auto/qmltest/image/tst_image.qml b/tests/auto/qmltest/image/tst_image.qml new file mode 100644 index 0000000000..f6ad01014a --- /dev/null +++ b/tests/auto/qmltest/image/tst_image.qml @@ -0,0 +1,216 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + property string srcImage: "logo.png" + property bool canconnect + property bool checkfinished: false + + Component.onCompleted: { + var check = new XMLHttpRequest; + check.open("GET", "http://127.0.0.1:14445/logo.png"); + check.onreadystatechange = function() { + if (check.readyState == XMLHttpRequest.DONE) { + if (check.status == 404) { + top.canconnect = false; + } else { + top.canconnect = true; + } + top.checkfinished = true; + } + } + check.send(); + } + + Image { + id: noSource + source: "" + } + + Image { + id: clearSource + source: srcImage + } + + Image { + id: resized + source: srcImage + width: 300 + height: 300 + } + + Image { + id: smooth + source: srcImage + smooth: true + width: 300 + height: 300 + } + + Image { + id: tileModes1 + source: srcImage + width: 100 + height: 300 + fillMode: Image.Tile + } + + Image { + id: tileModes2 + source: srcImage + width: 300 + height: 150 + fillMode: Image.TileVertically + } + Image { + id: tileModes3 + source: srcImage + width: 300 + height: 150 + fillMode: Image.TileHorizontally + } + + TestCase { + name: "Image" + + function test_noSource() { + compare(noSource.source, "") + compare(noSource.width, 0) + compare(noSource.height, 0) + compare(noSource.fillMode, Image.Stretch) + } + + function test_imageSource_data() { + return [ + { + tag: "local", + source: "logo.png", + remote: false, + error: "" + }, + { + tag: "local not found", + source: "no-such-file.png", + remote: false, + error: "SUBinline:1:21: QML Image: Cannot open: SUBno-such-file.png" + }, + { + tag: "remote", + source: "http://127.0.0.1:14445/logo.png", + remote: true, + error: "" + } + ] + } + + function test_imageSource(row) { + var expectError = (row.error.length != 0) + if (expectError) { + var parentUrl = Qt.resolvedUrl(".") + ignoreWarning(row.error.replace(/SUB/g, parentUrl)) + } + + var img = Qt.createQmlObject('import QtQuick 2.0; Image { source: "'+row.source+'" }', top) + + if (row.remote) { + skip("Remote solution not yet complete") + tryCompare(img, "status", Image.Loading) + tryCompare(top, "checkfinished", true, 10000) + if (top.canconnect == false) + skip("Cannot access remote") + } + + if (!expectError) { + tryCompare(img, "status", Image.Ready, 10000) + compare(img.width, 59) + compare(img.height, 71) + compare(img.fillMode, Image.Stretch) + } else { + tryCompare(img, "status", Image.Error) + } + + img.destroy() + } + + function test_clearSource() { + compare(clearSource.source, Qt.resolvedUrl(srcImage)) + compare(clearSource.width, 59) + compare(clearSource.height, 71) + + 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.fillMode, Image.Stretch) + } + + function test_smooth() { + compare(smooth.smooth, true) + compare(smooth.width, 300) + compare(smooth.height, 300) + compare(smooth.fillMode, Image.Stretch) + } + + function test_tileModes() { + compare(tileModes1.width, 100) + compare(tileModes1.height, 300) + compare(tileModes1.fillMode, Image.Tile) + + compare(tileModes2.width, 300) + compare(tileModes2.height, 150) + compare(tileModes2.fillMode, Image.TileVertically) + + compare(tileModes3.width, 300) + compare(tileModes3.height, 150) + compare(tileModes3.fillMode, Image.TileHorizontally) + } + + } +} diff --git a/tests/auto/qmltest/listmodel/tst_listmodel.qml b/tests/auto/qmltest/listmodel/tst_listmodel.qml new file mode 100644 index 0000000000..7c393a1899 --- /dev/null +++ b/tests/auto/qmltest/listmodel/tst_listmodel.qml @@ -0,0 +1,132 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + ListModel { id: emptymodel } + ListModel { id: manyitems } + ListModel { id: insertmodel } + ListModel { id: move; ListElement { name: "Element0" } ListElement { name: "Element1" } } + ListModel { id: firstmodel; ListElement { name: "FirstModelElement0" } } + ListModel { id: secondmodel; ListElement { name: "SecondModelElement0" } ListElement { name: "SecondModelElement1" } } + ListModel { id: altermodel; ListElement { name: "AlterModelElement0" } ListElement { name: "AlterModelElement1" } } + + TestCase { + name: "ListModel" + + function test_empty() { + compare(emptymodel.count, 0) + emptymodel.clear(); + compare(emptymodel.count, 0) + } + + function test_multipleitems_data() { + return [ + { + tag: "10items", + numitems: 10 + }, + { + tag: "100items", + numitems: 100 + }, + { + tag: "10000items", + numitems: 10000 + } + ] + } + + function test_multipleitems(row) { + var i; + manyitems.clear(); + compare(manyitems.count, 0) + for (i = 0; i < row.numitems; ++i) { + manyitems.append({"name":"Item"+i}) + } + compare(manyitems.count, row.numitems) + } + + function test_insert() { + insertmodel.insert(0, {"name": "Element0"}) + compare(insertmodel.get(0).name, "Element0") + insertmodel.insert(1, {"name": "Element1"}) + compare(insertmodel.get(1).name, "Element1") + } + + function test_altermodeled() { + tryCompare(altermodel.count, 2) + compare(altermodel.get(0).name, "AlterModelElement0") + compare(altermodel.get(1).name, "AlterModelElement1") + altermodel.append({"name":"AlterModelElement2"}) + tryCompare(altermodel.count, 3) + compare(altermodel.get(0).name, "AlterModelElement0") + compare(altermodel.get(1).name, "AlterModelElement1") + compare(altermodel.get(2).name, "AlterModelElement2") + altermodel.insert(2,{"name":"AlterModelElement1.5"}) + tryCompare(altermodel.count, 4) + compare(altermodel.get(0).name, "AlterModelElement0") + compare(altermodel.get(1).name, "AlterModelElement1") + compare(altermodel.get(2).name, "AlterModelElement1.5") + compare(altermodel.get(3).name, "AlterModelElement2") + tryCompare(altermodel.count, 4) + altermodel.move(2,1,1); + compare(altermodel.get(0).name, "AlterModelElement0") + compare(altermodel.get(1).name, "AlterModelElement1.5") + compare(altermodel.get(2).name, "AlterModelElement1") + compare(altermodel.get(3).name, "AlterModelElement2") + altermodel.remove(1,2) + tryCompare(altermodel.count, 2) + compare(altermodel.get(0).name, "AlterModelElement0") + compare(altermodel.get(1).name, "AlterModelElement2") + altermodel.set(1,{"name":"AlterModelElement1"}) + compare(altermodel.get(0).name, "AlterModelElement0") + compare(altermodel.get(1).name, "AlterModelElement1") + altermodel.setProperty(0, "name", "AlteredProperty") + compare(altermodel.get(0).name, "AlteredProperty") + altermodel.clear() + tryCompare(altermodel.count, 0) + compare(altermodel.get(0), undefined) + } + } +} diff --git a/tests/auto/qmltest/listview/tst_listview.qml b/tests/auto/qmltest/listview/tst_listview.qml new file mode 100644 index 0000000000..535c551ede --- /dev/null +++ b/tests/auto/qmltest/listview/tst_listview.qml @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + ListView { + id: emptylist + height: 20 + width: 50 + } + + ListView { + id: viewmanyitems + model: manyitems + } + + ListView { + id: modelchange + model: firstmodel + delegate: Text { text: model.name } + } + + ListView { + id: modelalter + model: altermodel + delegate: Text { text: model.name } + } + + ListModel { id: emptymodel } + ListModel { id: manyitems } + ListModel { id: firstmodel; ListElement { name: "FirstModelElement0" } } + ListModel { id: secondmodel; ListElement { name: "SecondModelElement0" } ListElement { name: "SecondModelElement1" } } + ListModel { id: altermodel; ListElement { name: "AlterModelElement0" } ListElement { name: "AlterModelElement1" } } + + TestCase { + name: "ListView" + + function test_empty() { + compare(emptylist.count, 0) + emptylist.model = emptymodel; + compare(emptylist.count, 0) + } + + function test_multipleitems_data() { + return [ + { + tag: "10items", + numitems: 10 + }, + { + tag: "100items", + numitems: 100 + }, + { + tag: "10000items", + numitems: 10000 + } + ] + } + + function test_multipleitems(row) { + var i; + manyitems.clear(); + compare(manyitems.count, 0) + for (i = 0; i < row.numitems; ++i) { + manyitems.append({"name":"Item"+i}) + } + compare(manyitems.count, row.numitems) + tryCompare(viewmanyitems.count, row.numitems) + } + + function test_modelchange() { + tryCompare(modelchange.count, 1) + modelchange.currentIndex = 0; + compare(modelchange.currentItem.text, "FirstModelElement0") + modelchange.model = secondmodel; + tryCompare(modelchange.count, 2) + modelchange.currentIndex = 0; + compare(modelchange.currentItem.text, "SecondModelElement0") + modelchange.currentIndex = 1; + compare(modelchange.currentItem.text, "SecondModelElement1") + } + + function test_modelaltered() { + tryCompare(modelalter.count, 2) + modelalter.currentIndex = 0; + compare(modelalter.currentItem.text, "AlterModelElement0") + modelalter.currentIndex = 1; + compare(modelalter.currentItem.text, "AlterModelElement1") + altermodel.append({"name":"AlterModelElement2"}) + tryCompare(modelalter.count, 3) + modelalter.currentIndex = 0; + compare(modelalter.currentItem.text, "AlterModelElement0") + modelalter.currentIndex = 1; + compare(modelalter.currentItem.text, "AlterModelElement1") + modelalter.currentIndex = 2; + compare(modelalter.currentItem.text, "AlterModelElement2") + altermodel.insert(2,{"name":"AlterModelElement1.5"}) + tryCompare(modelalter.count, 4) + modelalter.currentIndex = 0; + compare(modelalter.currentItem.text, "AlterModelElement0") + modelalter.currentIndex = 1; + compare(modelalter.currentItem.text, "AlterModelElement1") + modelalter.currentIndex = 2; + compare(modelalter.currentItem.text, "AlterModelElement1.5") + modelalter.currentIndex = 3; + compare(modelalter.currentItem.text, "AlterModelElement2") + altermodel.move(2,1,1); + tryCompare(modelalter.count, 4) + modelalter.currentIndex = 0; + compare(modelalter.currentItem.text, "AlterModelElement0") + modelalter.currentIndex = 1; + compare(modelalter.currentItem.text, "AlterModelElement1.5") + modelalter.currentIndex = 2; + compare(modelalter.currentItem.text, "AlterModelElement1") + modelalter.currentIndex = 3; + compare(modelalter.currentItem.text, "AlterModelElement2") + altermodel.remove(1,2) + tryCompare(modelalter.count, 2) + modelalter.currentIndex = 0; + compare(modelalter.currentItem.text, "AlterModelElement0") + modelalter.currentIndex = 1; + compare(modelalter.currentItem.text, "AlterModelElement2") + altermodel.set(1,{"name":"AlterModelElement1"}) + modelalter.currentIndex = 0; + compare(modelalter.currentItem.text, "AlterModelElement0") + modelalter.currentIndex = 1; + compare(modelalter.currentItem.text, "AlterModelElement1") + altermodel.clear() + tryCompare(modelalter.count, 0) + compare(modelalter.currentItem, null) + } + } +} diff --git a/tests/auto/qmltest/rectangle/tst_rectangle.qml b/tests/auto/qmltest/rectangle/tst_rectangle.qml new file mode 100644 index 0000000000..038bb96c0f --- /dev/null +++ b/tests/auto/qmltest/rectangle/tst_rectangle.qml @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + Rectangle { id: empty } + + Rectangle { id: radius } + + Rectangle { + id: resized + width: 300 + height: 300 + } + + Rectangle { + id: smooth + smooth: true + width: 300 + height: 300 + } + + Rectangle { + id: gradient + width: 100 + height: 300 + gradient: Gradient { + GradientStop { position: 0.0; color: "red" } + GradientStop { position: 0.5; color: "yellow" } + GradientStop { position: 1.0; color: "green" } + } + } + + Rectangle { + id: rectangleborder + width: 300 + height: 150 + border.width: 1 + border.color: "gray" + } + + TestCase { + name: "Rectangle" + + function test_empty() { + compare(empty.width, 0) + compare(empty.height, 0) + } + + function test_radius() { + compare(radius.width, 0) + compare(radius.height, 0) + compare(radius.radius, 0) + radius.height = 100; + radius.width = 100; + radius.radius = 10; + compare(radius.width, 100) + compare(radius.height, 100) + compare(radius.radius, 10) + } + + function test_resized() { + compare(resized.width, 300) + compare(resized.height, 300) + resized.height = 500; + resized.width = 500; + compare(resized.width, 500) + compare(resized.height, 500) + } + + function test_smooth() { + compare(smooth.smooth, true) + compare(smooth.width, 300) + compare(smooth.height, 300) + + } + + function test_gradient() { + var grad = gradient.gradient; + var gstops = grad.stops; + compare(gstops[0].color.toString(), "#ff0000") + compare(gstops[1].color.toString(), "#ffff00") + compare(gstops[2].color.toString(), "#008000") + } + + function test_borders() { + compare(rectangleborder.border.width, 1) + compare(rectangleborder.border.color.toString(), "#808080") + rectangleborder.border.width = 10; + rectangleborder.border.color = "brown"; + compare(rectangleborder.border.width, 10) + compare(rectangleborder.border.color.toString(), "#a52a2a") + } + + } +} diff --git a/tests/auto/qmltest/text/tst_text.qml b/tests/auto/qmltest/text/tst_text.qml new file mode 100644 index 0000000000..599fabcc8b --- /dev/null +++ b/tests/auto/qmltest/text/tst_text.qml @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + Text { + id: emptyText + } + + Text { + id: txtfamily + text: "Hello world!" + font.family: "Courier" + } + + Text { + id: txtcolor + text: "Hello world!" + color: "red" + } + + Text { + id: txtelide + text: "Hello world!" + elide: Text.ElideRight + } + + Text { + property string first: "Hello world!" + property string second: "Hello\nworld!" + property string third: "Hello\nworld\n!" + + id: txtlinecount + text: first + width: 100 + wrapMode: Text.WrapAnywhere + } + + TestCase { + name: "Text" + + function test_empty() { + compare(emptyText.text, "") + } + + function test_family() { + compare(txtfamily.font.family, "Courier") + txtfamily.font.family = "Helvetica"; + compare(txtfamily.font.family, "Helvetica") + } + + function test_color() { + compare(txtcolor.color, "#ff0000") + txtcolor.color = "blue"; + compare(txtcolor.color, "#0000ff") + } + + function test_elide() { + compare(txtelide.elide, Text.ElideRight) + txtelide.elide = Text.ElideLeft; + compare(txtelide.elide, Text.ElideLeft) + txtelide.elide = Text.ElideMiddle; + compare(txtelide.elide, Text.ElideMiddle) + } + + function test_linecount() { + compare(txtlinecount.lineCount, 1) + txtlinecount.text = txtlinecount.second; + compare(txtlinecount.lineCount, 2) + txtlinecount.text = txtlinecount.third; + compare(txtlinecount.lineCount, 3) + txtlinecount.text = txtlinecount.first; + compare(txtlinecount.lineCount, 1) + txtlinecount.width = 50; + compare(txtlinecount.lineCount, 3) + } + + } +} diff --git a/tests/auto/qmltest/textedit/tst_textedit.qml b/tests/auto/qmltest/textedit/tst_textedit.qml new file mode 100644 index 0000000000..a0f0a8c8d7 --- /dev/null +++ b/tests/auto/qmltest/textedit/tst_textedit.qml @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + TextEdit { + id: emptyText + height: 20 + width: 50 + } + + TextEdit { + id: txtfamily + text: "Hello world!" + font.family: "Courier" + height: 20 + width: 50 + } + + TextEdit { + id: txtcolor + text: "Hello world!" + color: "red" + height: 20 + width: 50 + } + + TextEdit { + id: txtentry + text: "" + height: 20 + width: 50 + } + + TextEdit { + id: txtfunctions + text: "The quick brown fox jumped over the lazy dog" + height: 20 + width: 50 + } + + TextEdit { + id: txtlines + property string styledtextvalue: "Line 1
Line 2
Line 3" + text: "Line 1\nLine 2\nLine 3" + textFormat: Text.PlainText + } + + TestCase { + name: "TextEdit" + when: windowShown + + function test_empty() { + compare(emptyText.text, "") + } + + function test_family() { + compare(txtfamily.font.family, "Courier") + txtfamily.font.family = "Helvetica"; + compare(txtfamily.font.family, "Helvetica") + } + + function test_color() { + compare(txtcolor.color, "#ff0000") + txtcolor.color = "blue"; + compare(txtcolor.color, "#0000ff") + } + + function test_textentry() { + txtentry.focus = true; + compare(txtentry.text, "") + keyClick(Qt.Key_H) + keyClick(Qt.Key_E) + keyClick(Qt.Key_L) + keyClick(Qt.Key_L) + keyClick(Qt.Key_O) + keyClick(Qt.Key_Space) + keyClick(Qt.Key_W) + keyClick(Qt.Key_O) + keyClick(Qt.Key_R) + keyClick(Qt.Key_L) + keyClick(Qt.Key_D) + compare(txtentry.text, "hello world") + } + + function test_functions() { + compare(txtfunctions.getText(4,9), "quick") + txtfunctions.select(4,9); + compare(txtfunctions.selectedText, "quick") + txtfunctions.deselect(); + compare(txtfunctions.selectedText, "") + txtfunctions.select(4,9); + txtfunctions.cut(); + compare(txtfunctions.text, "The brown fox jumped over the lazy dog") + txtfunctions.text = "Qt"; + txtfunctions.insert(txtfunctions.text.length, " ") + compare(txtfunctions.text, "Qt "); + txtfunctions.cursorPosition = txtfunctions.text.length; + txtfunctions.paste(); + compare(txtfunctions.text, "Qt quick"); + txtfunctions.cursorPosition = txtfunctions.text.length; + txtfunctions.selectWord(); + compare(txtfunctions.selectedText, "quick") + txtfunctions.copy(); + txtfunctions.selectAll(); + compare(txtfunctions.selectedText, "Qt quick") + txtfunctions.deselect(); + compare(txtfunctions.selectedText, "") + txtfunctions.paste(); + compare(txtfunctions.text, "Qt quickquick"); + } + + function test_linecounts() { + compare(txtlines.lineCount, 3) + txtlines.text = txtlines.styledtextvalue; + compare(txtlines.text, "Line 1
Line 2
Line 3") + tryCompare(txtlines.lineCount, 1) + txtlines.textFormat = Text.StyledText; + tryCompare(txtlines.lineCount, 3) + txtlines.textFormat = Text.RichText; + tryCompare(txtlines.lineCount, 3) + } + } +} diff --git a/tests/auto/qmltest/textinput/tst_textinput.qml b/tests/auto/qmltest/textinput/tst_textinput.qml new file mode 100644 index 0000000000..2399456730 --- /dev/null +++ b/tests/auto/qmltest/textinput/tst_textinput.qml @@ -0,0 +1,286 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.0 + +Item { + id: top + + TextInput { + id: emptyText + height: 20 + width: 50 + } + + TextInput { + id: txtfamily + text: "Hello world!" + font.family: "Courier" + height: 20 + width: 50 + } + + TextInput { + id: txtcolor + text: "Hello world!" + color: "red" + height: 20 + width: 50 + } + + TextInput { + id: txtentry + text: "" + height: 20 + width: 50 + } + + TextInput { + id: txtfunctions + text: "The quick brown fox jumped over the lazy dog" + height: 20 + width: 50 + } + + TextInput { + id: txtintvalidator + text: "" + height: 20 + width: 50 + validator: IntValidator { id: iv; top: 20; bottom: 10; } + } + + TextInput { + id: txtdoublevalidator + text: "" + height: 20 + width: 50 + validator: DoubleValidator { id: dv; top: 2.0; bottom: 1.0; } + } + + TextInput { + id: txtregexpvalidator + text: "" + height: 20 + width: 50 + validator: RegExpValidator { id: rv; regExp: /[a-z]{3}/ } + } + + + + TestCase { + name: "TextInput" + when: windowShown + + function test_empty() { + compare(emptyText.text, "") + } + + function test_family() { + compare(txtfamily.font.family, "Courier") + txtfamily.font.family = "Helvetica"; + compare(txtfamily.font.family, "Helvetica") + } + + function test_color() { + compare(txtcolor.color, "#ff0000") + txtcolor.color = "blue"; + compare(txtcolor.color, "#0000ff") + } + + function test_textentry() { + txtentry.focus = true; + compare(txtentry.text, "") + keyClick(Qt.Key_H) + keyClick(Qt.Key_E) + keyClick(Qt.Key_L) + keyClick(Qt.Key_L) + keyClick(Qt.Key_O) + keyClick(Qt.Key_Space) + keyClick(Qt.Key_W) + keyClick(Qt.Key_O) + keyClick(Qt.Key_R) + keyClick(Qt.Key_L) + keyClick(Qt.Key_D) + compare(txtentry.text, "hello world") + } + + function test_functions() { + compare(txtfunctions.getText(4,9), "quick") + txtfunctions.select(4,9); + compare(txtfunctions.selectedText, "quick") + txtfunctions.deselect(); + compare(txtfunctions.selectedText, "") + txtfunctions.select(4,9); + txtfunctions.cut(); + compare(txtfunctions.text, "The brown fox jumped over the lazy dog") + txtfunctions.text = "Qt"; + txtfunctions.insert(txtfunctions.text.length, " ") + compare(txtfunctions.text, "Qt "); + txtfunctions.cursorPosition = txtfunctions.text.length; + txtfunctions.paste(); + compare(txtfunctions.text, "Qt quick"); + txtfunctions.cursorPosition = txtfunctions.text.length; + txtfunctions.selectWord(); + compare(txtfunctions.selectedText, "quick") + txtfunctions.copy(); + txtfunctions.selectAll(); + compare(txtfunctions.selectedText, "Qt quick") + txtfunctions.deselect(); + compare(txtfunctions.selectedText, "") + txtfunctions.paste(); + compare(txtfunctions.text, "Qt quickquick"); + } + + function test_intvalidators_data() { + return [ + { + tag: "toolow", + testnumber: "5", + acceptable: false + }, + { + tag: "toohigh", + testnumber: "50", + acceptable: false + }, + { + tag: "onlowerbounds", + testnumber: "10", + acceptable: true + }, + { + tag: "onupperbounds", + testnumber: "20", + acceptable: true + }, + { + tag: "middle", + testnumber: "15", + acceptable: true + }, + { + tag: "negativemiddle", + testnumber: "-15", + acceptable: false + } + ] + + } + + function test_intvalidators(row) { + compare(txtintvalidator.validator.top, 20) + compare(txtintvalidator.validator.bottom, 10) + txtintvalidator.text = row.testnumber; + compare(txtintvalidator.acceptableInput, row.acceptable) + } + + function test_doublevalidators_data() { + return [ + { + tag: "toolow", + testnumber: "0.5", + acceptable: false + }, + { + tag: "toohigh", + testnumber: "2.5", + acceptable: false + }, + { + tag: "onlowerbounds", + testnumber: "1.0", + acceptable: true + }, + { + tag: "onupperbounds", + testnumber: "2.0", + acceptable: true + }, + { + tag: "middle", + testnumber: "1.5", + acceptable: true + }, + { + tag: "negativemiddle", + testnumber: "-1.5", + acceptable: false + } + ] + + } + + function test_doublevalidators(row) { + compare(txtdoublevalidator.validator.top, 2.0) + compare(txtdoublevalidator.validator.bottom, 1.0) + txtdoublevalidator.text = row.testnumber; + compare(txtdoublevalidator.acceptableInput, row.acceptable) + } + + function test_regexpvalidators_data() { + return [ + { + tag: "toolow", + testtext: "ab", + acceptable: false + }, + { + tag: "toohigh", + testtext: "abcd", + acceptable: false + }, + { + tag: "acceptable", + testtext: "abc", + acceptable: true + } + ] + + } + + function test_regexpvalidators(row) { + compare(txtregexpvalidator.validator.regExp, /[a-z]{3}/) + txtregexpvalidator.text = row.testtext; + compare(txtregexpvalidator.acceptableInput, row.acceptable) + } + } +}