File indexing completed on 2024-05-12 04:19:58
0001 // vim: set tabstop=4 shiftwidth=4 expandtab: 0002 /* 0003 Gwenview: an image viewer 0004 Copyright 2011 Aurélien Gâteau <agateau@kde.org> 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License 0008 as published by the Free Software Foundation; either version 2 0009 of the License, or (at your option) any later version. 0010 0011 This program is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 GNU General Public License for more details. 0015 0016 You should have received a copy of the GNU General Public License 0017 along with this program; if not, write to the Free Software 0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA. 0019 0020 */ 0021 // Self 0022 #include "slidecontainerautotest.h" 0023 0024 // Local 0025 #include <lib/slidecontainer.h> 0026 0027 // KF 0028 0029 // Qt 0030 #include <QSignalSpy> 0031 #include <QTest> 0032 #include <QTextEdit> 0033 #include <QVBoxLayout> 0034 0035 QTEST_MAIN(SlideContainerAutoTest) 0036 0037 using namespace Gwenview; 0038 0039 struct TestWindow : public QWidget { 0040 explicit TestWindow(QWidget *parent = nullptr) 0041 : QWidget(parent) 0042 , mContainer(new SlideContainer) 0043 , mContent(nullptr) 0044 { 0045 createContent(); 0046 0047 mMainWidget = new QTextEdit(); 0048 auto layout = new QVBoxLayout(this); 0049 layout->setSpacing(0); 0050 layout->setContentsMargins(0, 0, 0, 0); 0051 layout->addWidget(mMainWidget); 0052 layout->addWidget(mContainer); 0053 } 0054 0055 void createContent() 0056 { 0057 mContent = new QTextEdit; 0058 mContent->setFixedSize(100, 40); 0059 mContainer->setContent(mContent); 0060 } 0061 0062 SlideContainer *mContainer; 0063 QWidget *mMainWidget; 0064 QWidget *mContent; 0065 }; 0066 0067 void SlideContainerAutoTest::testInit() 0068 { 0069 // Even with content, a SlideContainer should be invisible until slideIn() 0070 // is called 0071 TestWindow window; 0072 window.show(); 0073 0074 QTest::qWait(500); 0075 QCOMPARE(window.mMainWidget->height(), window.height()); 0076 } 0077 0078 void SlideContainerAutoTest::testSlideIn() 0079 { 0080 TestWindow window; 0081 QSignalSpy inSpy(window.mContainer, SIGNAL(slidedIn())); 0082 QSignalSpy outSpy(window.mContainer, SIGNAL(slidedOut())); 0083 window.show(); 0084 0085 window.mContainer->slideIn(); 0086 while (window.mContainer->slideHeight() != window.mContent->height()) { 0087 QTest::qWait(100); 0088 } 0089 QCOMPARE(window.mContainer->height(), window.mContent->height()); 0090 QCOMPARE(inSpy.count(), 1); 0091 QCOMPARE(outSpy.count(), 0); 0092 } 0093 0094 void SlideContainerAutoTest::testSlideOut() 0095 { 0096 TestWindow window; 0097 window.show(); 0098 0099 window.mContainer->slideIn(); 0100 while (window.mContainer->slideHeight() != window.mContent->height()) { 0101 QTest::qWait(100); 0102 } 0103 0104 QSignalSpy inSpy(window.mContainer, SIGNAL(slidedIn())); 0105 QSignalSpy outSpy(window.mContainer, SIGNAL(slidedOut())); 0106 window.mContainer->slideOut(); 0107 while (window.mContainer->slideHeight() != 0) { 0108 QTest::qWait(100); 0109 } 0110 QCOMPARE(window.mContainer->height(), 0); 0111 QCOMPARE(inSpy.count(), 0); 0112 QCOMPARE(outSpy.count(), 1); 0113 } 0114 0115 void SlideContainerAutoTest::testSlideInDeleteSlideOut() 0116 { 0117 // If content is deleted while visible, slideOut() should still produce an 0118 // animation 0119 TestWindow window; 0120 window.show(); 0121 0122 window.mContainer->slideIn(); 0123 while (window.mContainer->slideHeight() != window.mContent->height()) { 0124 QTest::qWait(100); 0125 } 0126 window.mContent->deleteLater(); 0127 window.mContainer->slideOut(); 0128 while (window.mContainer->slideHeight() != 0) { 0129 QTest::qWait(100); 0130 } 0131 QCOMPARE(window.mContainer->height(), 0); 0132 } 0133 0134 void SlideContainerAutoTest::testHiddenContentResize() 0135 { 0136 // Resizing content should not trigger a slide if it is not visible. 0137 TestWindow window; 0138 window.show(); 0139 QVERIFY(QTest::qWaitForWindowExposed(&window)); 0140 0141 window.mContent->show(); 0142 window.mContent->setFixedSize(150, 80); 0143 QTest::qWait(500); 0144 QCOMPARE(window.mContainer->height(), 0); 0145 } 0146 0147 #include "moc_slidecontainerautotest.cpp"