File: tst_applistener.qml

package info (click to toggle)
quickflux 1.1.3%2Bgit20201110.2a37acf-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,036 kB
  • sloc: cpp: 2,874; makefile: 26
file content (110 lines) | stat: -rw-r--r-- 2,584 bytes parent folder | download
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import QtQuick 2.0
import QtTest 1.0
import QuickFlux 1.0

TestCase {

    name : "AppListener"

    Item {
        id: container

        AppListener {
            id: listener
            onDispatched: {
            }
        }
    }


    function test_on() {
        var test1, test2;
        compare(listener.listenerId > 0,true);
        listener.on("test_on_Test1",function(value) {
            test1 = value;
        }).on("test_on_Test2",function(value) {
            test2 = value;
        });

        AppDispatcher.dispatch("test_on_Test1","x");
        compare(test1,"x");
        compare(test2,undefined);

        AppDispatcher.dispatch("test_on_Test2",5676);
        compare(test1,"x");
        compare(test2,5676);
    }

    function test_enabled() {
        var count = 0;
        listener.on("test_enabled",function() {
            count++;
        });

        compare(count,0);
        AppDispatcher.dispatch("test_enabled",null);
        compare(count,1);

        container.enabled = false;
        AppDispatcher.dispatch("test_enabled",null);
        compare(count,1);

        container.enabled = true;
        AppDispatcher.dispatch("test_enabled",null);
        compare(count,2);
    }

    function test_removeListener() {
        var count1 = 0,count2=0;

        var func1 = function() {
            count1++;
        }

        var func2 = function() {
            count2++;
        }

        listener.on("test_removeListener1",func1).on("test_removeListener2",func2);

        AppDispatcher.dispatch("test_removeListener1",null);
        AppDispatcher.dispatch("test_removeListener2",null);
        compare(count1,1);
        compare(count2,1);

        listener.removeListener("test_removeListener1",func1);
        AppDispatcher.dispatch("test_removeListener1",null);
        AppDispatcher.dispatch("test_removeListener2",null);

        compare(count1,1);
        compare(count2,2);

    }

    function test_removeAllListener() {
        var count1 = 0,count2=0;

        var func1 = function() {
            count1++;
        }

        var func2 = function() {
            count2++;
        }

        listener.on("test_removeAllListener",func1).on("test_removeAllListener",func2);

        AppDispatcher.dispatch("test_removeAllListener");
        AppDispatcher.dispatch("test_removeAllListener");
        compare(count1,2);
        compare(count2,2);

        listener.removeAllListener("test_removeAllListener");
        AppDispatcher.dispatch("test_removeAllListener",null);

        compare(count1,2);
        compare(count2,2);
    }

}