~saviq/ubuntu/saucy/qtdeclarative-opensource-src/add-qtquick-delegate-range

« back to all changes in this revision

Viewing changes to tests/auto/qmltest/textedit/tst_textedit.qml

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
import QtQuick 2.0
 
42
import QtTest 1.0
 
43
 
 
44
Item {
 
45
    id: top
 
46
 
 
47
    TextEdit {
 
48
        id: emptyText
 
49
        height: 20
 
50
        width: 50
 
51
    }
 
52
 
 
53
    TextEdit {
 
54
        id: txtfamily
 
55
        text: "Hello world!"
 
56
        font.family: "Courier"
 
57
        height: 20
 
58
        width: 50
 
59
    }
 
60
 
 
61
    TextEdit {
 
62
        id: txtcolor
 
63
        text: "Hello world!"
 
64
        color: "red"
 
65
        height: 20
 
66
        width: 50
 
67
    }
 
68
 
 
69
    TextEdit {
 
70
        id: txtentry
 
71
        text: ""
 
72
        height: 20
 
73
        width: 50
 
74
    }
 
75
 
 
76
    TextEdit {
 
77
        id: txtfunctions
 
78
        text: "The quick brown fox jumped over the lazy dog"
 
79
        height: 20
 
80
        width: 50
 
81
    }
 
82
 
 
83
    TextEdit {
 
84
        id: txtlines
 
85
        property string styledtextvalue: "Line 1<br>Line 2<br>Line 3"
 
86
        text: "Line 1\nLine 2\nLine 3"
 
87
        textFormat: Text.PlainText
 
88
    }
 
89
 
 
90
    TestCase {
 
91
        name: "TextEdit"
 
92
        when: windowShown
 
93
 
 
94
        function test_empty() {
 
95
            compare(emptyText.text, "")
 
96
        }
 
97
 
 
98
        function test_family() {
 
99
            compare(txtfamily.font.family, "Courier")
 
100
            txtfamily.font.family = "Helvetica";
 
101
            compare(txtfamily.font.family, "Helvetica")
 
102
        }
 
103
 
 
104
        function test_color() {
 
105
            compare(txtcolor.color, "#ff0000")
 
106
            txtcolor.color = "blue";
 
107
            compare(txtcolor.color, "#0000ff")
 
108
        }
 
109
 
 
110
        function test_textentry() {
 
111
            txtentry.focus = true;
 
112
            compare(txtentry.text, "")
 
113
            keyClick(Qt.Key_H)
 
114
            keyClick(Qt.Key_E)
 
115
            keyClick(Qt.Key_L)
 
116
            keyClick(Qt.Key_L)
 
117
            keyClick(Qt.Key_O)
 
118
            keyClick(Qt.Key_Space)
 
119
            keyClick(Qt.Key_W)
 
120
            keyClick(Qt.Key_O)
 
121
            keyClick(Qt.Key_R)
 
122
            keyClick(Qt.Key_L)
 
123
            keyClick(Qt.Key_D)
 
124
            compare(txtentry.text, "hello world")
 
125
        }
 
126
 
 
127
        function test_functions() {
 
128
            compare(txtfunctions.getText(4,9), "quick")
 
129
            txtfunctions.select(4,9);
 
130
            compare(txtfunctions.selectedText, "quick")
 
131
            txtfunctions.deselect();
 
132
            compare(txtfunctions.selectedText, "")
 
133
            txtfunctions.select(4,9);
 
134
            txtfunctions.cut();
 
135
            compare(txtfunctions.text, "The  brown fox jumped over the lazy dog")
 
136
            txtfunctions.text = "Qt";
 
137
            txtfunctions.insert(txtfunctions.text.length, " ")
 
138
            compare(txtfunctions.text, "Qt ");
 
139
            txtfunctions.cursorPosition = txtfunctions.text.length;
 
140
            txtfunctions.paste();
 
141
            compare(txtfunctions.text, "Qt quick");
 
142
            txtfunctions.cursorPosition = txtfunctions.text.length;
 
143
            txtfunctions.selectWord();
 
144
            compare(txtfunctions.selectedText, "quick")
 
145
            txtfunctions.copy();
 
146
            txtfunctions.selectAll();
 
147
            compare(txtfunctions.selectedText, "Qt quick")
 
148
            txtfunctions.deselect();
 
149
            compare(txtfunctions.selectedText, "")
 
150
            txtfunctions.paste();
 
151
            compare(txtfunctions.text, "Qt quickquick");
 
152
        }
 
153
 
 
154
        function test_linecounts() {
 
155
            compare(txtlines.lineCount, 3)
 
156
            txtlines.text = txtlines.styledtextvalue;
 
157
            compare(txtlines.text, "Line 1<br>Line 2<br>Line 3")
 
158
            tryCompare(txtlines.lineCount, 1)
 
159
            txtlines.textFormat = Text.StyledText;
 
160
            tryCompare(txtlines.lineCount, 3)
 
161
            txtlines.textFormat = Text.RichText;
 
162
            tryCompare(txtlines.lineCount, 3)
 
163
        }
 
164
    }
 
165
}