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
|
import QtQuick 2.0
import QtTest 1.0
import QuickFlux 1.0
TestCase {
id: testCase
name : "AppListenerGroup"
property var seq : new Array;
Component {
id: creator
AppListenerGroup {
id: group
property string prefix;
property int count: 0
property alias listener1: listener1
property alias listener2: listener2
property alias listener3: listener3
AppListener {
id: listener1;
onDispatched: {
count++;
seq.push(prefix + "Listener1");
}
}
AppListener {
id: listener2;
onDispatched: {
count++;
seq.push(prefix + "Listener2");
}
}
AppListener {
id: listener3;
onDispatched: {
count++;
seq.push(prefix + "Listener3");
}
}
}
}
function test_grouping() {
var group = creator.createObject(testCase);
compare(group.listenerIds.length,3);
compare(group.listener1.waitFor.length,1);
compare(group.listener2.waitFor.length,1);
compare(group.listener3.waitFor.length,1);
compare(group.listener1.waitFor[0],group.listener2.waitFor[0]);
compare(group.listener3.waitFor[0],group.listener2.waitFor[0]);
group.destroy();
}
function test_waitFor() {
seq = new Array;
var group1 = creator.createObject(testCase);
group1.prefix = "group1";
var group2 = creator.createObject(testCase);
group2.prefix = "group2";
// group1 should receive message first, but now it depend on group2
group1.waitFor = group2.listenerIds;
AppDispatcher.dispatch("example message");
compare(seq,["group2Listener1",
"group2Listener2",
"group2Listener3",
"group1Listener3",
"group1Listener2",
"group1Listener1"]);
}
}
|