1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, 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 The Qt Company Ltd 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.12
import QtTest 1.0
import QtQuick.Controls 2.12
import QtQuick.Window 2.12
TestCase {
id: testCase
width: 400
height: 400
visible: true
when: windowShown
name: "SpinBox"
Component {
id: signalSpy
SignalSpy { }
}
Component {
id: spinBox
SpinBox { }
}
Component {
id: mouseArea
MouseArea { }
}
function test_defaults() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
compare(control.from, 0)
compare(control.to, 99)
compare(control.value, 0)
compare(control.stepSize, 1)
compare(control.editable, false)
compare(control.up.pressed, false)
compare(control.up.indicator.enabled, true)
compare(control.down.pressed, false)
compare(control.down.indicator.enabled, false)
}
function test_value() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
compare(control.value, 0)
control.value = 50
compare(control.value, 50)
control.value = 99
compare(control.value, 99)
control.value = -99
compare(control.value, 0)
control.value = 100
compare(control.value, 99)
}
function test_range() {
var control = createTemporaryObject(spinBox, testCase, {from: 0, to: 100, value: 50})
verify(control)
compare(control.from, 0)
compare(control.to, 100)
compare(control.value, 50)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.value = 1000
compare(control.value, 100)
compare(control.up.indicator.enabled, false)
compare(control.down.indicator.enabled, true)
control.wrap = true
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.value = -1
compare(control.value, 0)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.from = 25
compare(control.from, 25)
compare(control.value, 25)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.wrap = false
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, false)
control.value = 30
compare(control.from, 25)
compare(control.value, 30)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.from = 30
compare(control.from, 30)
compare(control.value, 30)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, false)
control.to = 75
compare(control.to, 75)
compare(control.value, 30)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, false)
control.value = 50
compare(control.value, 50)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.to = 50
compare(control.to, 50)
compare(control.value, 50)
compare(control.up.indicator.enabled, false)
compare(control.down.indicator.enabled, true)
control.to = 40
compare(control.to, 40)
compare(control.value, 40)
compare(control.up.indicator.enabled, false)
compare(control.down.indicator.enabled, true)
}
function test_inverted() {
var control = createTemporaryObject(spinBox, testCase, {from: 100, to: -100})
verify(control)
compare(control.from, 100)
compare(control.to, -100)
compare(control.value, 0)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
control.value = 200
compare(control.value, 100)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, false)
control.value = -200
compare(control.value, -100)
compare(control.up.indicator.enabled, false)
compare(control.down.indicator.enabled, true)
control.value = 0
compare(control.value, 0)
compare(control.up.indicator.enabled, true)
compare(control.down.indicator.enabled, true)
}
function test_mouse_data() {
return [
{ tag: "up", button: "up", value: 50, enabled: true, hold: false, modified: 1, expected: 51 },
{ tag: "down", button: "down", value: 50, enabled: true, hold: false, modified: 1, expected: 49 },
{ tag: "up:disabled", button: "up", value: 99, enabled: false, hold: false, modified: 0, expected: 99 },
{ tag: "down:disabled", button: "down", value: 0, enabled: false, hold: false, modified: 0, expected: 0 },
{ tag: "up:hold", button: "up", value: 95, enabled: true, hold: true, modified: 4, expected: 99 },
{ tag: "down:hold", button: "down", value: 5, enabled: true, hold: true, modified: 5, expected: 0 }
]
}
function test_mouse(data) {
var control = createTemporaryObject(spinBox, testCase, {value: data.value})
verify(control)
var button = control[data.button]
verify(button)
var pressedSpy = signalSpy.createObject(control, {target: button, signalName: "pressedChanged"})
verify(pressedSpy.valid)
var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"})
verify(valueModifiedSpy.valid)
mousePress(button.indicator)
compare(pressedSpy.count, data.enabled ? 1 : 0)
compare(button.pressed, data.enabled)
compare(control.value, data.value)
compare(valueModifiedSpy.count, 0)
if (data.hold)
tryCompare(control, "value", data.expected)
mouseRelease(button.indicator)
compare(pressedSpy.count, data.enabled ? 2 : 0)
compare(button.pressed, false)
compare(control.value, data.expected)
compare(valueModifiedSpy.count, data.modified)
}
function test_keys_data() {
return [
{ tag: "1", properties: { from: 1, to: 10, value: 1, stepSize: 1 }, upSteps: [2,3,4], downSteps: [3,2,1,1] },
{ tag: "2", properties: { from: 1, to: 10, value: 10, stepSize: 2 }, upSteps: [10,10], downSteps: [8,6,4] },
{ tag: "25", properties: { from: 0, to: 100, value: 50, stepSize: 25 }, upSteps: [75,100,100], downSteps: [75,50,25,0,0] },
{ tag: "wrap1", properties: { wrap: true, from: 1, to: 10, value: 1, stepSize: 1 }, upSteps: [2,3], downSteps: [2,1,10,9] },
{ tag: "wrap2", properties: { wrap: true, from: 1, to: 10, value: 10, stepSize: 2 }, upSteps: [1,3,5], downSteps: [3,1,10,8,6] },
{ tag: "wrap25", properties: { wrap: true, from: 0, to: 100, value: 50, stepSize: 25 }, upSteps: [75,100,0,25], downSteps: [0,100,75] }
]
}
function test_keys(data) {
var control = createTemporaryObject(spinBox, testCase, data.properties)
verify(control)
var upPressedCount = 0
var downPressedCount = 0
var valueModifiedCount = 0
var upPressedSpy = signalSpy.createObject(control, {target: control.up, signalName: "pressedChanged"})
verify(upPressedSpy.valid)
var downPressedSpy = signalSpy.createObject(control, {target: control.down, signalName: "pressedChanged"})
verify(downPressedSpy.valid)
var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"})
verify(valueModifiedSpy.valid)
control.forceActiveFocus()
verify(control.activeFocus)
for (var u = 0; u < data.upSteps.length; ++u) {
var wasUpEnabled = control.wrap || control.value < control.to
keyPress(Qt.Key_Up)
compare(control.up.pressed, wasUpEnabled)
compare(control.down.pressed, false)
if (wasUpEnabled) {
++upPressedCount
++valueModifiedCount
}
compare(upPressedSpy.count, upPressedCount)
compare(valueModifiedSpy.count, valueModifiedCount)
compare(control.value, data.upSteps[u])
keyRelease(Qt.Key_Up)
compare(control.down.pressed, false)
compare(control.up.pressed, false)
if (wasUpEnabled)
++upPressedCount
compare(upPressedSpy.count, upPressedCount)
compare(valueModifiedSpy.count, valueModifiedCount)
}
for (var d = 0; d < data.downSteps.length; ++d) {
var wasDownEnabled = control.wrap || control.value > control.from
keyPress(Qt.Key_Down)
compare(control.down.pressed, wasDownEnabled)
compare(control.up.pressed, false)
if (wasDownEnabled) {
++downPressedCount
++valueModifiedCount
}
compare(downPressedSpy.count, downPressedCount)
compare(valueModifiedSpy.count, valueModifiedCount)
compare(control.value, data.downSteps[d])
keyRelease(Qt.Key_Down)
compare(control.down.pressed, false)
compare(control.up.pressed, false)
if (wasDownEnabled)
++downPressedCount
compare(downPressedSpy.count, downPressedCount)
compare(valueModifiedSpy.count, valueModifiedCount)
}
}
function test_locale() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
control.locale = Qt.locale("ar_EG") // Arabic, Egypt
var numbers = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
for (var i = 0; i < 10; ++i) {
control.value = i
compare(control.contentItem.text, numbers[i])
}
}
function test_baseline() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset)
}
function test_focus() {
var control = createTemporaryObject(spinBox, testCase, {from: 10, to: 1000, value: 100, focus: true})
verify(control)
control.forceActiveFocus()
compare(control.activeFocus, true)
compare(control.from, 10)
compare(control.to, 1000)
compare(control.value, 100)
control.focus = false
compare(control.activeFocus, false)
compare(control.from, 10)
compare(control.to, 1000)
compare(control.value, 100)
}
function test_initialFocus() {
var window = testCase.Window.window
verify(window)
compare(window.activeFocusItem, window.contentItem)
var control = createTemporaryObject(spinBox, testCase, { editable: true, focus: true })
verify(control)
tryCompare(control.contentItem, "activeFocus", true)
}
function test_editable() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"})
verify(valueModifiedSpy.valid)
control.contentItem.forceActiveFocus()
compare(control.contentItem.activeFocus, true)
compare(control.editable, false)
control.contentItem.selectAll()
keyClick(Qt.Key_5)
keyClick(Qt.Key_Return)
compare(control.value, 0)
compare(valueModifiedSpy.count, 0)
control.editable = true
compare(control.editable, true)
control.contentItem.selectAll()
keyClick(Qt.Key_5)
keyClick(Qt.Key_Return)
compare(control.value, 5)
compare(valueModifiedSpy.count, 1)
}
function test_wheel_data() {
return [
{ tag: "1", properties: { from: 1, to: 10, value: 1, stepSize: 1 }, upSteps: [2,3,4], downSteps: [3,2,1,1] },
{ tag: "2", properties: { from: 1, to: 10, value: 10, stepSize: 2 }, upSteps: [10,10], downSteps: [8,6,4] },
{ tag: "25", properties: { from: 0, to: 100, value: 50, stepSize: 25 }, upSteps: [75,100,100], downSteps: [75,50,25,0,0] },
{ tag: "wrap1", properties: { wrap: true, from: 1, to: 10, value: 1, stepSize: 1 }, upSteps: [2,3], downSteps: [2,1,10,9] },
{ tag: "wrap2", properties: { wrap: true, from: 1, to: 10, value: 10, stepSize: 2 }, upSteps: [1,3,5], downSteps: [3,1,10,8,6] },
{ tag: "wrap25", properties: { wrap: true, from: 0, to: 100, value: 50, stepSize: 25 }, upSteps: [75,100,0,25], downSteps: [0,100,75] }
]
}
function test_wheel(data) {
var ma = createTemporaryObject(mouseArea, testCase, {width: 100, height: 100})
verify(ma)
data.properties.wheelEnabled = true
var control = spinBox.createObject(ma, data.properties)
verify(control)
var valueModifiedCount = 0
var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"})
verify(valueModifiedSpy.valid)
var delta = 120
var spy = signalSpy.createObject(ma, {target: ma, signalName: "wheel"})
verify(spy.valid)
for (var u = 0; u < data.upSteps.length; ++u) {
var wasUpEnabled = control.wrap || control.value < control.to
mouseWheel(control, control.width / 2, control.height / 2, delta, delta)
if (wasUpEnabled)
++valueModifiedCount
compare(valueModifiedSpy.count, valueModifiedCount)
compare(spy.count, 0) // no propagation
compare(control.value, data.upSteps[u])
}
for (var d = 0; d < data.downSteps.length; ++d) {
var wasDownEnabled = control.wrap || control.value > control.from
mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta)
if (wasDownEnabled)
++valueModifiedCount
compare(valueModifiedSpy.count, valueModifiedCount)
compare(spy.count, 0) // no propagation
compare(control.value, data.downSteps[d])
}
}
function test_initiallyDisabledIndicators_data() {
return [
{ tag: "down disabled", from: 0, value: 0, to: 99, upEnabled: true, downEnabled: false },
{ tag: "up disabled", from: 0, value: 99, to: 99, upEnabled: false, downEnabled: true },
{ tag: "inverted, down disabled", from: 99, value: 99, to: 0, upEnabled: true, downEnabled: false },
{ tag: "inverted, up disabled", from: 99, value: 0, to: 0, upEnabled: false, downEnabled: true }
]
}
function test_initiallyDisabledIndicators(data) {
var control = createTemporaryObject(spinBox, testCase, { from: data.from, value: data.value, to: data.to })
verify(control)
compare(control.up.indicator.enabled, data.upEnabled)
compare(control.down.indicator.enabled, data.downEnabled)
}
function test_hover_data() {
return [
{ tag: "up:true", button: "up", hoverEnabled: true, value: 50 },
{ tag: "up:false", button: "up", hoverEnabled: false, value: 50 },
{ tag: "up:max", button: "up", hoverEnabled: true, value: 99 },
{ tag: "down:true", button: "down", hoverEnabled: true, value: 50 },
{ tag: "down:false", button: "down", hoverEnabled: false, value: 50 },
{ tag: "down:min", button: "down", hoverEnabled: true, value: 0 }
]
}
function test_hover(data) {
var control = createTemporaryObject(spinBox, testCase, {hoverEnabled: data.hoverEnabled, value: data.value})
verify(control)
var button = control[data.button]
compare(control.hovered, false)
compare(button.hovered, false)
mouseMove(control, button.indicator.x + button.indicator.width / 2, button.indicator.y + button.indicator.height / 2)
compare(control.hovered, data.hoverEnabled)
compare(button.hovered, data.hoverEnabled && button.indicator.enabled)
mouseMove(control, button.indicator.x - 1, button.indicator.y - 1)
compare(button.hovered, false)
}
function test_hoverWhilePressed_data() {
return [
{ tag: "up" },
{ tag: "down" },
]
}
// QTBUG-74688
function test_hoverWhilePressed(data) {
var control = createTemporaryObject(spinBox, testCase, { hoverEnabled: true, value: 50 })
verify(control)
var button = control[data.tag]
compare(control.hovered, false)
compare(button.hovered, false)
// Hover over the indicator. It should be hovered.
var buttonXCenter = button.indicator.x + button.indicator.width / 2
var buttonYCenter = button.indicator.y + button.indicator.height / 2
mouseMove(control, buttonXCenter, buttonYCenter)
compare(button.hovered, true)
// Press on the indicator and then move the mouse outside of it.
mousePress(control, buttonXCenter, buttonYCenter)
compare(button.hovered, true)
mouseMove(control, buttonXCenter - button.indicator.width, buttonYCenter - button.indicator.height)
// It should not be pressed or hovered.
compare(button.pressed, false)
compare(button.hovered, false)
mouseRelease(control)
}
function test_valueFromText_data() {
return [
{ tag: "editable", editable: true },
{ tag: "non-editable", editable: false }
]
}
function test_valueFromText(data) {
var control = createTemporaryObject(spinBox, testCase, {editable: data.editable})
verify(control)
control.forceActiveFocus()
verify(control.activeFocus)
var valueFromTextCalls = 0
control.valueFromText = function(text, locale) {
++valueFromTextCalls
return Number.fromLocaleString(locale, text);
}
keyClick(Qt.Key_Enter)
compare(valueFromTextCalls, data.editable ? 1 : 0)
keyClick(Qt.Key_Return)
compare(valueFromTextCalls, data.editable ? 2 : 0)
control.focus = false
compare(valueFromTextCalls, data.editable ? 3 : 0)
}
function test_callDefaultValueFromText() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
compare(control.valueFromText("123", control.locale), 123)
}
function test_autoRepeat() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
compare(control.value, 0)
var valueSpy = signalSpy.createObject(control, {target: control, signalName: "valueChanged"})
verify(valueSpy.valid)
var countBefore = 0
// repeat up
mousePress(control.up.indicator)
verify(control.up.pressed)
compare(valueSpy.count, 0)
valueSpy.wait()
valueSpy.wait()
countBefore = valueSpy.count
mouseRelease(control.up.indicator)
verify(!control.up.pressed)
compare(valueSpy.count, countBefore)
valueSpy.clear()
// repeat down
mousePress(control.down.indicator)
verify(control.down.pressed)
compare(valueSpy.count, 0)
valueSpy.wait()
valueSpy.wait()
countBefore = valueSpy.count
mouseRelease(control.down.indicator)
verify(!control.down.pressed)
compare(valueSpy.count, countBefore)
mousePress(control.up.indicator)
verify(control.up.pressed)
valueSpy.wait()
// move inside during repeat -> continue repeat (QTBUG-57085)
mouseMove(control.up.indicator, control.up.indicator.width / 4, control.up.indicator.height / 4)
verify(control.up.pressed)
valueSpy.wait()
valueSpy.clear()
// move outside during repeat -> stop repeat
mouseMove(control.up.indicator, -1, -1)
verify(!control.up.pressed)
// NOTE: The following wait() is NOT a reliable way to test that the
// auto-repeat timer is not running, but there's no way dig into the
// private APIs from QML. If this test ever fails in the future, it
// indicates that the auto-repeat timer logic is broken.
wait(125)
compare(valueSpy.count, 0)
mouseRelease(control.up.indicator, -1, -1)
verify(!control.up.pressed)
}
function test_initialValue() {
var control = createTemporaryObject(spinBox, testCase, {from: 1000, to: 10000})
verify(control)
compare(control.value, 1000)
}
Component {
id: sizeBox
SpinBox {
from: 0
to: items.length - 1
property var items: ["Small", "Medium", "Large"]
validator: RegExpValidator {
regExp: new RegExp("(Small|Medium|Large)", "i")
}
textFromValue: function(value) {
return items[value];
}
valueFromText: function(text) {
for (var i = 0; i < items.length; ++i) {
if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0)
return i
}
return sb.value
}
}
}
function test_textFromValue_data() {
return [
{ tag: "default", component: spinBox, values: [0, 10, 99], displayTexts: ["0", "10", "99"] },
{ tag: "custom", component: sizeBox, values: [0, 1, 2], displayTexts: ["Small", "Medium", "Large"] }
]
}
function test_textFromValue(data) {
var control = createTemporaryObject(data.component, testCase)
verify(control)
for (var i = 0; i < data.values.length; ++i) {
control.value = data.values[i]
compare(control.value, data.values[i])
compare(control.displayText, data.displayTexts[i])
}
}
function test_callDefaultTextFromValue() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
compare(control.textFromValue(123, control.locale), "123")
}
Component {
id: overriddenSpinBox
SpinBox {
value: 50
up.indicator: Rectangle {
property string s: "this is the one"
}
}
}
function test_indicatorOverridden() {
var control = createTemporaryObject(overriddenSpinBox, testCase)
verify(control)
compare(control.up.indicator.s, "this is the one");
}
function test_valueEnterFromOutsideRange() {
// Check that changing from 2 to 99 goes to 98 then changing to 99 puts it back to 98
var control = createTemporaryObject(spinBox, testCase, {from: 2, to: 98, value: 2, editable: true})
verify(control)
control.forceActiveFocus()
verify(control.activeFocus)
keyClick(Qt.Key_Backspace)
keyClick(Qt.Key_Backspace)
keyClick(Qt.Key_9)
keyClick(Qt.Key_9)
keyClick(Qt.Key_Return)
compare(control.value, 98)
compare(control.displayText, "98")
compare(control.contentItem.text, "98")
keyClick(Qt.Key_Backspace)
keyClick(Qt.Key_9)
keyClick(Qt.Key_Return)
compare(control.value, 98)
compare(control.displayText, "98")
compare(control.contentItem.text, "98")
}
}
|