File indexing completed on 2024-05-19 16:37:09

0001 /*
0002     SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "framesvgtest.h"
0008 #include <QStandardPaths>
0009 
0010 void FrameSvgTest::initTestCase()
0011 {
0012     QStandardPaths::setTestModeEnabled(true);
0013     m_cacheDir = QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
0014     m_cacheDir.removeRecursively();
0015 
0016     m_frameSvg = new Plasma::FrameSvg;
0017     m_frameSvg->setImagePath(QFINDTESTDATA("data/background.svgz"));
0018     QVERIFY(m_frameSvg->isValid());
0019 }
0020 
0021 void FrameSvgTest::cleanupTestCase()
0022 {
0023     delete m_frameSvg;
0024 
0025     m_cacheDir.removeRecursively();
0026 }
0027 
0028 void FrameSvgTest::margins()
0029 {
0030     QCOMPARE(m_frameSvg->marginSize(Plasma::Types::LeftMargin), (qreal)26);
0031     QCOMPARE(m_frameSvg->marginSize(Plasma::Types::TopMargin), (qreal)26);
0032     QCOMPARE(m_frameSvg->marginSize(Plasma::Types::RightMargin), (qreal)26);
0033     QCOMPARE(m_frameSvg->marginSize(Plasma::Types::BottomMargin), (qreal)26);
0034 }
0035 
0036 void FrameSvgTest::contentsRect()
0037 {
0038     m_frameSvg->resizeFrame(QSize(100, 100));
0039     QCOMPARE(m_frameSvg->contentsRect(), QRectF(26, 26, 48, 48));
0040 }
0041 
0042 void FrameSvgTest::repaintBlocked()
0043 {
0044     // check the properties to be correct even if set during a repaint blocked transaction
0045     m_frameSvg->setRepaintBlocked(true);
0046     QVERIFY(m_frameSvg->isRepaintBlocked());
0047 
0048     m_frameSvg->setElementPrefix("prefix");
0049     m_frameSvg->setEnabledBorders(Plasma::FrameSvg::TopBorder | Plasma::FrameSvg::LeftBorder);
0050     m_frameSvg->resizeFrame(QSizeF(100, 100));
0051 
0052     m_frameSvg->setRepaintBlocked(false);
0053 
0054     QCOMPARE(m_frameSvg->prefix(), QString("prefix"));
0055     QCOMPARE(m_frameSvg->enabledBorders(), Plasma::FrameSvg::TopBorder | Plasma::FrameSvg::LeftBorder);
0056     QCOMPARE(m_frameSvg->frameSize(), QSizeF(100, 100));
0057 }
0058 
0059 void FrameSvgTest::setTheme()
0060 {
0061     // Should not crash
0062 
0063     Plasma::FrameSvg *frameSvg = new Plasma::FrameSvg;
0064     frameSvg->setImagePath("widgets/background");
0065     frameSvg->setTheme(new Plasma::Theme("breeze-light", this));
0066     frameSvg->framePixmap();
0067     frameSvg->setTheme(new Plasma::Theme("breeze-dark", this));
0068     frameSvg->framePixmap();
0069     delete frameSvg;
0070 
0071     frameSvg = new Plasma::FrameSvg;
0072     frameSvg->setImagePath("widgets/background");
0073     frameSvg->setTheme(new Plasma::Theme("breeze-light", this));
0074     frameSvg->framePixmap();
0075     frameSvg->setTheme(new Plasma::Theme("breeze-dark", this));
0076     frameSvg->framePixmap();
0077     delete frameSvg;
0078 }
0079 
0080 QTEST_MAIN(FrameSvgTest)
0081 
0082 #include "moc_framesvgtest.cpp"