Warning, /frameworks/kirigami/autotests/tst_colorutils.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtTest 0009 import org.kde.kirigami as Kirigami 0010 0011 TestCase { 0012 id: testCase 0013 name: "ColorUtilsTest" 0014 0015 function test_linear_interpolation_data() { 0016 return [ 0017 {tag: "black to white", from: Qt.rgba(0.0, 0.0, 0.0), to: Qt.rgba(1.0, 1.0, 1.0), amount: 0.5, expected: Qt.rgba(0.5, 0.5, 0.5)}, 0018 {tag: "white to black", from: Qt.rgba(1.0, 1.0, 1.0), to: Qt.rgba(0.0, 0.0, 0.0), amount: 0.5, expected: Qt.rgba(0.5, 0.5, 0.5)}, 0019 {tag: "red to white", from: Qt.rgba(1.0, 0.0, 0.0), to: Qt.rgba(1.0, 1.0, 1.0), amount: 0.5, expected: Qt.rgba(1.0, 0.5, 0.5)}, 0020 {tag: "green to white", from: Qt.rgba(0.0, 0.0, 1.0), to: Qt.rgba(1.0, 1.0, 1.0), amount: 0.5, expected: Qt.rgba(0.5, 0.5, 1.0)}, 0021 {tag: "transparent to black", from: Qt.rgba(0.0, 0.0, 0.0, 0.0), to: Qt.rgba(0.0, 0.0, 0.0), amount: 0.5, expected: Qt.rgba(0.0, 0.0, 0.0, 0.5)}, 0022 {tag: "transparent to white", from: Qt.rgba(0.0, 0.0, 0.0, 0.0), to: Qt.rgba(1.0, 1.0, 1.0), amount: 0.5, expected: Qt.rgba(0.5, 0.5, 0.5, 0.5)}, 0023 // This would produce a pink color when not accounting for undefined hue when using white. 0024 {tag: "broken separator", from: Qt.color("#af384c"), to: Qt.color("white"), amount: 0.15, expected: Qt.color("#bb4f61")} 0025 ] 0026 } 0027 0028 function test_linear_interpolation(data) { 0029 let result = Kirigami.ColorUtils.linearInterpolation(data.from, data.to, data.amount) 0030 let expected = data.expected 0031 0032 // According to the documentation, fuzzyCompare() should be able to handle 0033 // color values but it seems to just do string comparison. So do a manual 0034 // component-wise comparison instead. 0035 fuzzyCompare(result.r, expected.r, 0.001, "Colors are not the same, Actual: " + result + " Expected: " + expected + ", component is red") 0036 fuzzyCompare(result.g, expected.g, 0.001, "Colors are not the same, Actual: " + result + " Expected: " + expected + ", component is green") 0037 fuzzyCompare(result.b, expected.b, 0.001, "Colors are not the same, Actual: " + result + " Expected: " + expected + ", component is blue") 0038 fuzzyCompare(result.a, expected.a, 0.001, "Colors are not the same, Actual: " + result + " Expected: " + expected + ", component is alpha") 0039 } 0040 } 0041