forked from shanetrotter/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReflectorTestCase.rb
208 lines (170 loc) · 6.75 KB
/
ReflectorTestCase.rb
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
require 'Reflector'
class MockReflector < Reflector
def getTime
t = Time.gm(2000, "jan", 1, 20, 15, 1)
return t
end
end
require 'runit/testcase'
class ReflectorTestCase < RUNIT::TestCase
def test_identifyMessage
reflector = Reflector.new
message = "I8=FIX42"
assert(reflector.identifyMessage(message) == ?I)
message = "E8=FIX42"
assert(reflector.identifyMessage(message) == ?E)
message = "R8=FIX42"
assert(reflector.identifyMessage(message) == ?R)
message = "8=FIX42"
assert(reflector.identifyMessage(message) == ?X)
message = "iACTION"
assert(reflector.identifyMessage(message) == ?i)
message = "eACTION"
assert(reflector.identifyMessage(message) == ?e)
end
def test_timify_and_fixify
reflector = MockReflector.new
str = reflector.fixify!(reflector.timify!("8=FIX.4.235=D34=249=PATS52=<TIME>56=RCG1=acct111=121=138=240=154=155=ESU260=<TIME>167=FUT204=1207=CME9701=omni19702=19706=E9707=1239708=G"))
assert_equals("8=FIX.4.29=17135=D34=249=PATS52=20000101-20:15:0156=RCG1=acct111=121=138=240=154=155=ESU260=20000101-20:15:01167=FUT204=1207=CME9701=omni19702=19706=E9707=1239708=G10=121", str)
str = reflector.fixify!(reflector.timify!("8=FIX.4.235=D34=249=PATS52=<TIME>56=RCG1=acct111=121=138=240=154=155=ESU260=<TIME>167=FUT204=1207=CME9701=omni19702=19706=E9707=1239708=G9709=PEA"))
assert_equals("8=FIX.4.29=18035=D34=249=PATS52=20000101-20:15:0156=RCG1=acct111=121=138=240=154=155=ESU260=20000101-20:15:01167=FUT204=1207=CME9701=omni19702=19706=E9707=1239708=G9709=PEA10=102", str)
end
def test_fixify_bang
reflector = Reflector.new
str = "8=FIX.4.235=A34=149=TW52=20000426-12:05:06" +
"56=ISLD98=0108=30"
reflector.fixify!(str)
assert_equals("8=FIX.4.29=5735=A34=149=TW52=20000426-12:05:0656=ISLD98=0108=3010=005", str)
str = "8=FIX.4.29=5735=A34=149=TW52=20000426-12:05:06" +
"56=ISLD98=0108=3010=005"
reflector.fixify!(str)
assert_equals("8=FIX.4.29=5735=A34=149=TW52=20000426-12:05:0656=ISLD98=0108=3010=005", str)
end
def test_timify_bang
reflector = Reflector.new
str = "8=FIX.4.29=5735=A34=149=TW52=20011010-10:10:1056=ISLD98=0108=3010=005"
reflector.timify!(str)
assert_equals("8=FIX.4.29=5735=A34=149=TW52=20011010-10:10:1056=ISLD98=0108=3010=005", str)
str = "8=FIX.4.29=5735=A34=149=TW52=<TIME>56=ISLD98=0" +
"108=3010=005"
reflector.timify!(str)
match = (/8=FIX.4.29=5735=A34=149=TW52=\d{8}-\d{2}:\d{2}:\d{2}56=ISLD98=0108=3010=005/ === str)
assert(match != nil)
str = "8=FIX.4.29=5735=A34=149=TW52=<TIME>56=ISLD" +
"122=<TIME>98=0108=3010=005"
reflector.timify!(str)
match = (/8=FIX.4.29=5735=A34=149=TW52=\d{8}-\d{2}:\d{2}:\d{2}56=ISLD122=\d{8}-\d{2}:\d{2}:\d{2}98=0108=3010=005/ === str)
assert(match != nil)
str = "8=FIX.4.29=5735=A34=149=TW52=<TIME+9>56=ISLD98=0" +
"108=3010=005"
reflector.timify!(str)
match = (/8=FIX.4.29=5735=A34=149=TW52=\d{8}-\d{2}:\d{2}:\d{2}56=ISLD98=0108=3010=005/ === str)
assert(match != nil)
str = "8=FIX.4.29=5735=A34=149=TW52=<TIME>56=ISLD98=0" +
"108=3060=<TIME>10=005"
reflector.timify!(str)
match = (/8=FIX.4.29=5735=A34=149=TW52=\d{8}-\d{2}:\d{2}:\d{2}56=ISLD98=0108=3060=\d{8}-\d{2}:\d{2}:\d{2}10=005/ === str)
assert(match != nil)
str = "8=FIX.4.235=D34=249=PATS52=<TIME>56=RCG1=acct111=121=138=240=154=155=ESU2" +
"60=<TIME>167=FUT204=1207=CME9701=omni19702=19706=E9707=1239708=G9710=PEA"
reflector.timify!(str)
match = (/8=FIX.4.235=D34=249=PATS52=\d{8}-\d{2}:\d{2}:\d{2}56=RCG1=acct111=121=138=240=154=155=ESU260=\d{8}-\d{2}:\d{2}:\d{2}167=FUT204=1207=CME9701=omni19702=19706=E9707=1239708=G9710=PEA/ === str)
assert(match != nil)
end
def test_identifyFile
reflector = Reflector.new
messages = "E8=1\nI8=2\n\nI8=3\nE8=4\n#foo\nE8=5\nE8=6\nI8=7\niCONNECT\neDISCONNECT\neCONNECT\niDISCONNECT\nE2,8=8\n"
cum = ""
def reflector.ini=(i)
@ini = i
end
def reflector.ini
return @ini
end
def reflector.cum=(c)
@cum = c
end
def reflector.cum
return @cum
end
def reflector.exp=(e)
@exp = e
end
def reflector.exp
return @exp
end
def reflector.icon=(i)
@icon = i
end
def reflector.icon
return @icon
end
def reflector.idis=(i)
@idis = i
end
def reflector.idis
return @idis
end
def reflector.econ=(e)
@econ = e
end
def reflector.econ
return @econ
end
def reflector.edis=(e)
@edis = e
end
def reflector.edis
return @edis
end
def reflector.err=(e)
@err = e
end
def reflector.err
return @err
end
reflector.ini = ""; reflector.cum = "";
reflector.exp = ""; reflector.icon = "";
reflector.idis = ""; reflector.econ = "";
reflector.edis = ""; reflector.err = "";
def reflector.initiateAction(msg, cid)
@cum += cid.to_s + "," + msg + "|"
@ini += cid.to_s + "," + msg + "|"
end
def reflector.expectedAction(msg, cid)
@cum += cid.to_s + "," + msg + "|"
@exp += cid.to_s + "," + msg + "|"
end
def reflector.connectAction(cid)
@cum += cid.to_s + "," + "iCONNECT" + "|"
@icon += cid.to_s + "," + "iCONNECT" + "|"
end
def reflector.disconnectAction(cid)
@cum += cid.to_s + "," + "iDISCONNECT" + "|"
@idis += cid.to_s + "," + "iDISCONNECT" + "|"
end
def reflector.waitConnectAction(cid)
@cum += cid.to_s + "," + "eCONNECT" + "|"
@econ += cid.to_s + "," + "eCONNECT" + "|"
end
def reflector.waitDisconnectAction(cid)
@cum += cid.to_s + "," + "eDISCONNECT" + "|"
@edis += cid.to_s + "," + "eDISCONNECT" + "|"
end
def reflector.errorAction(lineNum, msg)
@cum += msg + "|"
@err += msg + "|"
end
reflector.processFile(messages)
#messages = "E8=1\nI8=2\n\nI8=3\nE8=4\n#foo\nE8=5\nE8=6\nI8=7\niCONNECT\neDISCONNECT\neCONNECT\niDISCONNECT\nE2,8=8\n"
assert_equals("1,8=1|1,8=2|1,8=3|1,8=4|1,8=5|1,8=6|1,8=7|" +
"1,iCONNECT|1,eDISCONNECT|1,eCONNECT|1,iDISCONNECT|2,8=8|",
reflector.cum)
assert_equals("1,8=2|1,8=3|1,8=7|", reflector.ini)
assert_equals("1,8=1|1,8=4|1,8=5|1,8=6|2,8=8|", reflector.exp)
assert_equals("1,iCONNECT|", reflector.icon)
assert_equals("1,iDISCONNECT|", reflector.idis)
assert_equals("1,eCONNECT|", reflector.econ)
assert_equals("1,eDISCONNECT|", reflector.edis)
end
end