File: sharedqmlenginetest.cpp

package info (click to toggle)
libplasma 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,796 kB
  • sloc: cpp: 17,769; sh: 286; xml: 95; python: 57; javascript: 29; makefile: 7
file content (59 lines) | stat: -rw-r--r-- 1,755 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
// SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de>
// SPDX-License-Identifier: LGPL-2.0-or-later

#include <QTest>
#include <plasmaquick/sharedqmlengine.h>

using namespace PlasmaQuick;

class SharedQmlEngineTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void testSettingTranslationDomain()
    {
        std::unique_ptr<SharedQmlEngine> obj(new SharedQmlEngine());

        const QString testDomain = QStringLiteral("testme");
        QVERIFY(obj->translationDomain().isEmpty());
        obj->setTranslationDomain(testDomain);
        QCOMPARE(obj->translationDomain(), testDomain);
        obj.reset(new SharedQmlEngine());
        QVERIFY(obj->translationDomain().isEmpty());
    }

    void testUsingSameEngine()
    {
        std::unique_ptr<SharedQmlEngine> obj1(new SharedQmlEngine());
        std::unique_ptr<SharedQmlEngine> obj2(new SharedQmlEngine());

        QVERIFY(obj1->engine() == obj2->engine());
        QVERIFY(obj1->rootContext() != obj2->rootContext());
    }

    void testDeletingEngine()
    {
        std::unique_ptr<SharedQmlEngine> obj1(new SharedQmlEngine());
        std::weak_ptr<QQmlEngine> weakPtr(obj1->engine());
        QVERIFY(weakPtr.lock());

        // The one in obj1
        QCOMPARE(weakPtr.use_count(), 1);

        {
            std::unique_ptr<SharedQmlEngine> obj2(new SharedQmlEngine());
            // The one in obj1 and in obj2
            QCOMPARE(weakPtr.use_count(), 2);
        }

        obj1.reset(nullptr);
        // Our object is deleted and as the last strong ref it should ensure everything is deleted.
        QVERIFY(!weakPtr.lock());
        QCOMPARE(weakPtr.use_count(), 0);
    }
};

QTEST_MAIN(SharedQmlEngineTest)

#include "sharedqmlenginetest.moc"