forked from quickfix/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageTest.cs
More file actions
284 lines (238 loc) · 7.47 KB
/
Copy pathMessageTest.cs
File metadata and controls
284 lines (238 loc) · 7.47 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
using NUnit.Framework;
using System;
using System.Collections;
using QuickFix;
[TestFixture]
public class MessageTestCase
{
[Test]
public void testIdentifyType()
{
try
{
Assert.AreEqual( "A", Message.identifyType( "8=FIX.4.219=1235=A108=3010=031" ).getValue() );
}
catch( MessageParseError ) { Assert.IsTrue(false, "Message could not be parsed"); }
try
{
Assert.AreEqual( "AB", Message.identifyType("8=FIX.4.29=1235=AB108=3010=031").getValue() );
} catch( MessageParseError ) { Assert.IsTrue(false, "Message could not be parsed"); }
try
{
Message.identifyType("8=FIX.4.29=12108=3010=031");
Assert.IsTrue(false, "Message should not have a type");
} catch( MessageParseError ) {}
try
{
Message.identifyType(null);
Assert.Fail("exception should be thrown");
}
catch( MessageParseError ) {}
}
[Test]
public void testMessageFromString()
{
Message message = null;
try
{
message = new Message("8=FIX.4.29=1235=A108=3010=036");
} catch(InvalidMessage) { }
Assert.IsTrue(true, "Message should be invalid");
try
{
message = new Message("8=FIX.4.29=1235=A108=3010=026");
} catch(InvalidMessage) { Assert.IsTrue(false, "Message should be valid"); }
Assert.AreEqual("8=FIX.4.29=1235=A108=3010=026", message.ToString());
}
[Test]
public void testMessageGroups()
{
Message message = new Message();
QuickFix42.NewOrderSingle.NoAllocs numAllocs = new QuickFix42.NewOrderSingle.NoAllocs();
numAllocs.set( new AllocAccount("AllocACC1") );
numAllocs.set( new AllocShares(1010.10) );
message.addGroup(numAllocs);
numAllocs.set( new AllocAccount("AllocACC2") );
numAllocs.set( new AllocShares(2020.20) );
message.addGroup(numAllocs);
StringField field = null;
IEnumerator i = numAllocs.GetEnumerator();
Assert.IsTrue( i.MoveNext() );
field = (StringField)i.Current;
Assert.AreEqual( "AllocACC2", field.getValue() );
Assert.IsTrue( i.MoveNext() );
field = (StringField)i.Current;
Assert.AreEqual( "2020.2", field.getValue() );
Assert.IsTrue( !i.MoveNext() );
try
{
message.getGroup( 1, numAllocs );
Assert.AreEqual( "AllocACC1",
numAllocs.getField( new AllocAccount() ).getValue() );
Assert.IsTrue( 1010.10 ==
numAllocs.getField( new AllocShares() ).getValue() );
message.getGroup( 2, numAllocs );
Assert.AreEqual( "AllocACC2",
numAllocs.getField( new AllocAccount() ).getValue() );
Assert.IsTrue( 2020.20 ==
numAllocs.getField( new AllocShares() ).getValue() );
}
catch( FieldNotFound )
{
Assert.Fail( "no exception should be thrown" );
}
try
{
message.getGroup( 3, numAllocs );
Assert.Fail( "exception should be thrown" );
}
catch( FieldNotFound ) {}
}
[Test]
public void testMessageSetGetString()
{
Message message = new Message();
try
{
message.getString(5);
Assert.IsTrue(false, "exception not thrown");
} catch(FieldNotFound ) {}
message.setString(5, "string5");
try
{
Assert.AreEqual("string5", message.getString(5));
} catch(FieldNotFound ) { Assert.IsTrue(false, "exception thrown"); }
try
{
message.setString(100, null);
Assert.IsTrue(false, "exception not thrown");
} catch(NullReferenceException) {}
}
[Test]
public void testMessagesetGetBoolean()
{
Message message = new Message();
try
{
message.getBoolean(7);
Assert.IsTrue(false, "exception not thrown");
} catch(FieldNotFound ) {}
message.setBoolean(7, true);
try
{
Assert.AreEqual(true, message.getBoolean(7));
} catch(FieldNotFound ) { Assert.IsTrue(false, "exception thrown"); }
}
[Test]
public void testMessageSetGetChar()
{
Message message = new Message();
try
{
message.getChar(12);
Assert.IsTrue(false, "exception not thrown");
} catch(FieldNotFound) {}
message.setChar(12, 'a');
try
{
Assert.AreEqual('a', message.getChar(12));
} catch(FieldNotFound) { Assert.IsTrue(false, "exception thrown"); }
}
[Test]
public void testMessageSetGetInt()
{
Message message = new Message();
try
{
message.getInt(56);
Assert.IsTrue(false, "exception not thrown");
} catch(FieldNotFound) {}
message.setInt(56, 23);
try
{
Assert.AreEqual(23, message.getInt(56));
} catch(FieldNotFound) { Assert.IsTrue(false, "exception thrown"); }
}
[Test]
public void testMessageSetGetDouble()
{
Message message = new Message();
try
{
message.getDouble(9812);
Assert.IsTrue(false, "exception not thrown");
} catch(FieldNotFound) {}
message.setDouble(9812, 12.3443);
try
{
Assert.AreEqual(12.3443, message.getDouble(9812));
} catch(FieldNotFound) { Assert.IsTrue(false, "exception thrown"); }
message.setDouble(9813, 5.0, 3);
message.setDouble(9814, -2.1004, 3);
try
{
Assert.AreEqual("5.000", message.getString(9813));
Assert.AreEqual("-2.1004", message.getString(9814));
} catch(FieldNotFound) { Assert.IsTrue(false, "exception thrown"); }
}
[Test]
public void testMessageSetGetUtcTimeStamp()
{
Message message = new Message();
try
{
message.getUtcTimeStamp(8);
Assert.IsTrue(false, "exception not thrown");
} catch(FieldNotFound) {}
DateTime time = new DateTime(2002, 8, 6, 12, 34, 56, 0);
message.setUtcTimeStamp(8, time);
try
{
Assert.AreEqual(message.getUtcTimeStamp(8).Ticks, time.Ticks);
} catch(FieldNotFound) { Assert.IsTrue(false, "exception thrown"); }
}
[Test]
public void testRemoveField()
{
Message message = new Message();
message.setField( new StringField(12, "value") );
Assert.IsTrue( message.isSetField(12) );
message.removeField( 12 );
Assert.IsTrue( !message.isSetField(12) );
}
[Test]
public void testMessageIterator()
{
Message message = new Message();
IEnumerator i = message.GetEnumerator();
Assert.IsFalse(i.MoveNext());
try
{
message = new Message("8=FIX.4.29=1235=A108=3010=026");
i = message.GetEnumerator();
Assert.IsTrue(i.MoveNext());
StringField field = (StringField)i.Current;
Assert.AreEqual(108, field.getField());
Assert.AreEqual("30", field.getValue());
Assert.IsFalse(i.MoveNext());
IEnumerator j = message.getHeader().GetEnumerator();
Assert.IsTrue(j.MoveNext());
field = (StringField)j.Current;
Assert.AreEqual(8, field.getField());
Assert.AreEqual("FIX.4.2", field.getValue());
Assert.IsTrue(j.MoveNext());
field = (StringField)j.Current;
Assert.AreEqual(9, field.getField());
Assert.AreEqual("12", field.getValue());
Assert.IsTrue(j.MoveNext());
field = (StringField)j.Current;
Assert.AreEqual(35, field.getField());
Assert.AreEqual("A", field.getValue());
Assert.IsFalse(j.MoveNext());
}
catch( InvalidMessage)
{
Assert.Fail("exception thrown");
}
}
}