~unity-team/unity8/ota9.5

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
/*
 * Copyright (C) 2012, 2013 Canonical, Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


import QtQuick 2.0
import QtTest 1.0
import Unity.Test 0.1

TestCase {
    Rectangle {
        id: rect
    }

    MockObjectForInstanceOfTestChild {
        id: testObject
    }

    // Singletons need to be bound to a property and not-named-imported
    // for them to be able to be properly passed back to C++.
    // See https://bugreports.qt-project.org/browse/QTBUG-30730
    property var util: Util

    function test_direct() {
        compare(Util.isInstanceOf(rect, "QQuickRectangle"), true, "rect should be an instance of QQuickRectangle");
        compare(Util.isInstanceOf(util, "TestUtil"), true, "Util should be an instance of TestUtil");
        compare(Util.isInstanceOf(testObject, "MockObjectForInstanceOfTestChild"), true, "testObject should be an instance of MockObjectForInstanceOfTestChild");
    }

    function test_inherited() {
        compare(Util.isInstanceOf(rect, "QQuickItem"), true, "rect should be an instance of QQuickItem");
        compare(Util.isInstanceOf(rect, "QObject"), true, "rect should be an instance of QObject");
        compare(Util.isInstanceOf(util, "QObject"), true, "Util should be an instance of QObject");
        compare(Util.isInstanceOf(testObject, "MockObjectForInstanceOfTest"), true, "testObject should be an instance of MockObjectForInstanceOfTest");
        compare(Util.isInstanceOf(testObject, "QQuickRectangle"), true, "testObject should be an instance of QQuickRectangle");
    }

    function test_negative() {
        compare(Util.isInstanceOf(rect, "QQuickMouseArea"), false, "rect should not be an instance of MouseArea");
        compare(Util.isInstanceOf(util, "QQuickItem"), false, "Util should not be an instance of QQuickItem");
    }

    function test_undefined() {
        compare(Util.isInstanceOf(undefined, "QObject"), false, "passing undefined should fail");
    }
}