Warning, /plasma/plasma-workspace/wallpapers/image/plugin/autotests/tst_imagebackend.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.5 0008 import QtQuick.Window 2.15 0009 import QtTest 1.0 0010 0011 import org.kde.plasma.wallpapers.image 2.0 as Wallpaper 0012 0013 TestCase { 0014 id: root 0015 0016 width: 320 0017 height: 240 0018 0019 when: windowShown 0020 name: "ImageBackendTest" 0021 0022 Wallpaper.ImageBackend { 0023 id: imageWallpaper 0024 usedInConfig: false 0025 //the oneliner of difference between image and slideshow wallpapers 0026 renderingMode: Wallpaper.ImageBackend.SingleImage 0027 targetSize: Qt.size(root.width, root.height) 0028 } 0029 0030 Wallpaper.MediaProxy { 0031 id: mediaProxy 0032 source: imageWallpaper.image 0033 targetSize: imageWallpaper.targetSize 0034 } 0035 0036 SignalSpy { 0037 id: modelImageChangedSignalSpy 0038 target: mediaProxy 0039 signalName: "modelImageChanged" 0040 } 0041 0042 Component { 0043 id: mainImage 0044 0045 Image { 0046 anchors.fill: parent 0047 asynchronous: false 0048 fillMode: Image.Stretch 0049 sourceSize: imageWallpaper.targetSize 0050 0051 function wait() { 0052 while (status === Image.Loading) { 0053 statusSpy.wait(5000); 0054 } 0055 } 0056 0057 SignalSpy { 0058 id: statusSpy 0059 target: parent 0060 signalName: "statusChanged" 0061 } 0062 } 0063 } 0064 0065 Window { 0066 id: window 0067 width: root.width 0068 height: root.height 0069 visible: true 0070 title: mediaProxy.modelImage.toString() 0071 } 0072 0073 function test_setSingleImage() { 0074 imageWallpaper.renderingMode = Wallpaper.ImageBackend.SingleImage 0075 0076 verify(testImage.toString().length > 0); 0077 imageWallpaper.image = testImage; 0078 compare(mediaProxy.modelImage, testImage); 0079 0080 const image = createTemporaryObject(mainImage, window, {source: mediaProxy.modelImage}); 0081 compare(image.status, Image.Ready); 0082 const grabbed = grabImage(image); 0083 compare(grabbed.pixel(0, 0), Qt.rgba(0, 0, 0, 255)); 0084 } 0085 0086 function test_setPackageImage() { 0087 imageWallpaper.renderingMode = Wallpaper.ImageBackend.SingleImage 0088 0089 verify(testPackage.toString().length > 0); 0090 imageWallpaper.image = testPackage; 0091 compare(mediaProxy.modelImage.toString().indexOf("image://package/get?dir="), 0); 0092 0093 const image = createTemporaryObject(mainImage, window, {source: mediaProxy.modelImage}); 0094 compare(image.status, Image.Loading); 0095 image.wait(); 0096 compare(image.status, Image.Ready); 0097 const grabbed1 = grabImage(image); 0098 compare(grabbed1.pixel(0, 0), Qt.rgba(255, 255, 255, 255)); 0099 0100 // Change target size 0101 image.sourceSize = Qt.size(1920, 1080); 0102 compare(image.status, Image.Loading); 0103 image.wait(); 0104 compare(image.status, Image.Ready); 0105 0106 const grabbed2 = grabImage(image); 0107 compare(grabbed2.pixel(0, 0), Qt.rgba(0, 0, 0, 255)); 0108 0109 // Change backend's target size 0110 modelImageChangedSignalSpy.clear(); 0111 imageWallpaper.targetSize = Qt.size(root.width + 1, root.height + 1); 0112 compare(modelImageChangedSignalSpy.count, 1); 0113 } 0114 0115 function test_setBizzareFileName() { 0116 imageWallpaper.renderingMode = Wallpaper.ImageBackend.SingleImage; 0117 0118 verify(testBizzareFileName.length > 0); 0119 modelImageChangedSignalSpy.clear(); 0120 mediaProxy.source = testBizzareFileName; 0121 compare(modelImageChangedSignalSpy.count, 1); 0122 compare(mediaProxy.providerType, Wallpaper.Provider.Image); 0123 compare(mediaProxy.modelImage, testBizzareFileName_modelImage); 0124 console.debug(mediaProxy.modelImage); 0125 0126 mediaProxy.source = Qt.binding(() => imageWallpaper.image); 0127 } 0128 0129 function test_startSlideShow() { 0130 verify(testDirs[0].length > 0); 0131 0132 imageWallpaper.slidePaths = testDirs; 0133 imageWallpaper.slideTimer = 1000; // use nextSlide 0134 imageWallpaper.slideshowMode = Wallpaper.SortingMode.Alphabetical; 0135 imageWallpaper.slideshowFoldersFirst = false; 0136 0137 imageWallpaper.renderingMode = Wallpaper.ImageBackend.SlideShow; 0138 wait(1000); // &SlideModel::done 0139 0140 let image = mediaProxy.modelImage; 0141 0142 imageWallpaper.nextSlide(); 0143 verify(image != mediaProxy.modelImage); 0144 0145 image = mediaProxy.modelImage; 0146 imageWallpaper.nextSlide(); 0147 verify(image != mediaProxy.modelImage); 0148 } 0149 }