File: tst_filter.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 (109 lines) | stat: -rw-r--r-- 2,606 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
// To prove that it could pass QImage via AppDispatcher
import QtQuick 2.0
import QtTest 1.0
import QuickFlux 1.0

TestCase {
    name : "FilterTests"

    AppListener {
        id: listener1
        property int count : 0
        property var lastMessage : null;

        Filter {
            type: "testFilter"
            onDispatched: {
                listener1.count++;
                listener1.lastMessage = message;
            }
        }
    }

    function test_filter() {
        compare(listener1.count, 0);
        compare(listener1.lastMessage, null);
        AppDispatcher.dispatch("non-related-action");
        compare(listener1.count, 0);
        compare(listener1.lastMessage, null);

        var obj = {}
        AppDispatcher.dispatch("testFilter", obj);
        compare(listener1.count, 1);
        compare(listener1.lastMessage, obj);

        AppDispatcher.dispatch("testFilter", obj);
        compare(listener1.count, 2);
        compare(listener1.lastMessage, obj);
    }

    Item {
        id: listener2

        signal dispatched(string type, var message);

        property int count : 0
        property string lastType: ""
        property var lastMessage : null;

        Filter {
            type: "testFilterWithItem"
            onDispatched: {
                listener2.count++;
                listener2.lastType = type;
                listener2.lastMessage = message;
            }
        }
    }

    function test_filter_with_item() {
        listener2.dispatched("testFilterWithItem", { a:1, b:"2"});
        compare(listener2.count, 1);
        compare(listener2.lastType,"testFilterWithItem");
        compare(listener2.lastMessage, {a:1, b:"2"});

    }

    AppListener {

        id: listener3
        property int count: 0

        property var messages: ([]);

        Filter {
            id: filter3
            types: ["action1" , "action2"]
            onDispatched: {
                listener3.count++;
                listener3.messages.push(type);
            }
        }
    }

    function test_types() {
        listener3.count = 0;
        AppDispatcher.dispatch("action1");
        compare(listener3.count, 1);
        AppDispatcher.dispatch("action2");
        compare(listener3.count, 2);
        AppDispatcher.dispatch("action3");
        compare(listener3.count, 2);
        compare(listener3.messages, ["action1", "action2"]);
    }

    AppListener {
        id: listener4

        Filter {
            id: filter4

            Connections {
                // Test can a filter object hold children
            }
        }
    }


}