File: test_controller.cpp

package info (click to toggle)
kdevelop 4%3A24.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 71,888 kB
  • sloc: cpp: 290,869; python: 3,626; javascript: 3,518; sh: 1,316; ansic: 703; xml: 401; php: 95; lisp: 66; makefile: 31; sed: 12
file content (83 lines) | stat: -rw-r--r-- 2,525 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
    SPDX-FileCopyrightText: 2007 Alexander Dymo <adymo@kdevelop.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include "test_controller.h"

#include <QTextEdit>
#include <QTest>
#include <QDebug>
#include <QStandardPaths>

#include <sublime/controller.h>
#include <sublime/tooldocument.h>
#include <sublime/view.h>
#include <sublime/area.h>

using namespace Sublime;

void TestController::initTestCase()
{
    QStandardPaths::setTestModeEnabled(true);
}

void TestController::documentDeletion()
{
    Controller controller;
    Document *doc = new ToolDocument(QStringLiteral("tool"), &controller, new SimpleToolWidgetFactory<QTextEdit>(QStringLiteral("tool")));
    QCOMPARE(controller.documents().count(), 1);
    delete doc;
    QCOMPARE(controller.documents().count(), 0);
}

void TestController::areaDeletion()
{
    Controller controller;
    Document *doc = new ToolDocument(QStringLiteral("tool"), &controller, new SimpleToolWidgetFactory<QTextEdit>(QStringLiteral("tool")));
    //create a view which does not belong to an area
    View* view1 = doc->createView();
    Q_UNUSED(view1);
    //create an area and two views in it
    Area *area = new Area(&controller, QStringLiteral("MyArea"));
    controller.addDefaultArea(area);
    QCOMPARE(controller.defaultAreas().count(), 1);
    View* view2 = doc->createView();
    view2->setObjectName(QStringLiteral("VIEW2"));
    area->addView(view2);
    View* view3 = doc->createView();
    view3->setObjectName(QStringLiteral("VIEW3"));
    area->addView(view3);
    QCOMPARE(doc->views().count(), 3);
    QCOMPARE(area->views().count(), 2);

    delete area;
    view2 = nullptr; view3= nullptr;

    QEXPECT_FAIL("", "Fails because of delayed view deletion", Continue);
    QCOMPARE(doc->views().count(), 1);
    QCOMPARE(controller.defaultAreas().count(), 0);

    QTest::qWait(100); // wait for deleteLaters
    qDebug() << "Deleting doc";
    delete doc;
    QTest::qWait(100); // wait for deleteLaters
    qDebug() << "View2 & view3 are destructored at this point (but no earlier).";
}

void TestController::namedAreas()
{
    Controller controller;
    Area *area1 = new Area(&controller, QStringLiteral("1"));
    controller.addDefaultArea(area1);
    Area *area2 = new Area(&controller, QStringLiteral("2"));
    controller.addDefaultArea(area2);

    QCOMPARE(controller.defaultArea(QStringLiteral("1")), area1);
    QCOMPARE(controller.defaultArea(QStringLiteral("2")), area2);
}

QTEST_MAIN(TestController)

#include "moc_test_controller.cpp"