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
|
/* This file is part of the KDE project
Copyright 2010 Marijn Kruisselbrink <mkruisselbrink@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; only
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "TestStyleStorage.h"
#include <StyleStorage.h>
#include <Map.h>
#include <qtest_kde.h>
using namespace Calligra::Sheets;
class MyStyleStorage : public StyleStorage
{
public:
MyStyleStorage(Map* map) : StyleStorage(map) {}
using StyleStorage::garbageCollection;
};
void TestStyleStorage::testGarbageCollection()
{
Map map;
MyStyleStorage storage(&map);
QRect rect(5, 5, 1, 1);
QColor c1(Qt::red);
QColor c2(Qt::blue);
SharedSubStyle style1(new SubStyleOne<Style::BackgroundColor, QColor>(c1));
SharedSubStyle style2(new SubStyleOne<Style::BackgroundColor, QColor>(c2));
// we need to do this for multiple cells, so hopefully we'll end up with substyles that are for the same cell but not in the same leafnode in the rtree
for (int i = 0; i < 100; i++)
storage.insert(rect.adjusted(10*i, 0, 10*i, 0), style1);
for (int i = 0; i < 100; i++)
QCOMPARE(storage.contains(rect.adjusted(10*i, 0, 10*i, 0)).backgroundColor(), c1);
for (int i = 0; i < 100; i++)
storage.insert(rect.adjusted(10*i, 0, 10*i, 0), style2);
for (int i = 0; i < 100; i++)
QCOMPARE(storage.contains(rect.adjusted(10*i, 0, 10*i, 0)).backgroundColor(), c2);
for (int i = 0; i < 100; i++)
storage.insert(rect.adjusted(10*i, 0, 10*i, 0), style1);
for (int i = 0; i < 100; i++)
QCOMPARE(storage.contains(rect.adjusted(10*i, 0, 10*i, 0)).backgroundColor(), c1);
for (int j = 0; j < 1000; j++) {
storage.garbageCollection();
for (int i = 0; i < 100; i++)
QCOMPARE(storage.contains(rect.adjusted(10*i, 0, 10*i, 0)).backgroundColor(), c1);
}
}
QTEST_KDEMAIN(TestStyleStorage, GUI)
#include "TestStyleStorage.moc"
|