File: TestStyleStorage.cpp

package info (click to toggle)
calligra 1%3A2.4.4-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 290,028 kB
  • sloc: cpp: 1,105,019; xml: 24,940; ansic: 11,807; python: 8,457; perl: 2,792; sh: 1,507; yacc: 1,307; ruby: 1,248; sql: 903; lex: 455; makefile: 89
file content (68 lines) | stat: -rw-r--r-- 2,570 bytes parent folder | download | duplicates (3)
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"