forked from supercollider-quarks/UnitTesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MixedBundleTester.sc
125 lines (115 loc) · 2.73 KB
/
MixedBundleTester.sc
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
saves all sent messages so that UnitTests can query it later
but its not a Mock object : it still sends to the server
could be implemented as one though
*/
MixedBundleTester : MixedBundle {
classvar <bundlesSent;
// private //
prSend { arg server, latency;
latency = latency ?? { server.latency };
super.prSend(server,latency);
SystemClock.sched(latency,{
bundlesSent = bundlesSent.add( this );
})
}
clumpedSendNow { arg server;
if(messages.notNil,{
messages.clump(10).do({ arg bundle,i;
server.listSendBundle(i * 0.001,bundle);
});
SystemClock.sched(messages.size * 0.001,{
this.doFunctions;
bundlesSent = bundlesSent.add(this);
nil
});
^messages.size
},{
this.doFunctions;
bundlesSent = bundlesSent.add(this);
^0
})
}
*reset {
bundlesSent = [];
}
// matches message :
// [9,"defName"] matches any [9,"defName" (, 1001,0,1)]
*findMessage { arg message;
if(bundlesSent.isNil,{ ^false });
^bundlesSent.any({ |b|
if(b.messages.isNil,{
false
},{
b.messages.any({ |m|
if(m.size < message.size,{
false
},{
m.copyRange(0,message.size - 1) == message
})
})
})
})
}
// matches message :
// ["/d_recv"] matches any [/d_recv, (data )]
*findPreparationMessage { arg message;
if(bundlesSent.isNil,{ ^false });
^bundlesSent.any({ |b|
if(b.preparationMessages.isNil,{
false
},{
b.preparationMessages.any({ |pm|
if(pm.size < message.size,{
false
},{
pm.copyRange(0,message.size - 1) == message
})
})
})
})
}
*report {
bundlesSent.do({ |bnd,i|
Post << "######## Bundle " << i << " ###########################" << Char.nl;
"preparationMessages:".postln;
bnd.preparationMessages.do({ |pm|
Post << Char.tab << pm << Char.nl;
});
"messages:".postln;
bnd.messages.do({ |msg|
Post << Char.tab << msg << Char.nl;
});
"sendFunctions:".postln;
bnd.sendFunctions.do({ |sf|
Post << Char.tab << sf << Char.nl;
});
"functions:".postln;
bnd.functions.do({ |sf|
Post << Char.tab;
if(sf.isKindOf(Function),{
sf.instVarAt('context').postln;
},{
if(sf.isKindOf(Message),{
"Message %:%(%)".format(sf.receiver,sf.selector, sf.args).postln;
},{
sf.postln;
});
});
});
"".postln;
})
}
// parse preparation messages for the def names of d_recv
defNames {
var names;
if(preparationMessages.isNil,{ ^[] });
names = preparationMessages.select({ |msg| msg[0] == "/d_recv" })
.collect({ |msg| SynthDesc.defNameFromBytes(msg[1]) });
^names
}
includesDefName { arg defName;
if(defName.isNil,{ Error("MixedBundleTester-includesDefName : defName was nil").throw });
^this.defNames.indexOfEqual(defName).notNil
}
}