forked from RevenantX/LiteNetLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReaderWriterSimpleDataTest.cs
More file actions
300 lines (230 loc) · 8.41 KB
/
ReaderWriterSimpleDataTest.cs
File metadata and controls
300 lines (230 loc) · 8.41 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
using LiteNetLib.Utils;
using NUnit.Framework;
namespace LiteNetLib.Tests
{
[TestFixture]
[Category("DataReaderWriter")]
public class ReaderWriterSimpleDataTest
{
[Test]
public void WriteReadBool()
{
var ndw = new NetDataWriter();
ndw.Put(true);
var ndr = new NetDataReader(ndw.Data);
var readBool = ndr.GetBool();
Assert.AreEqual(readBool, true);
}
[Test]
public void WriteReadBoolArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {true, false, true, false, false});
var ndr = new NetDataReader(ndw.Data);
var readBoolArray = ndr.GetBoolArray();
Assert.That(new[] {true, false, true, false, false}, Is.EqualTo(readBoolArray).AsCollection);
}
[Test]
public void WriteReadByte()
{
var ndw = new NetDataWriter();
ndw.Put((byte) 8);
var ndr = new NetDataReader(ndw.Data);
var readByte = ndr.GetByte();
Assert.AreEqual(readByte, (byte) 8);
}
[Test]
public void WriteReadByteArray()
{
var ndw = new NetDataWriter();
ndw.Put(new byte[] {1, 2, 4, 8, 16, byte.MaxValue, byte.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readByteArray = new byte[7];
ndr.GetBytes(readByteArray, 7);
Assert.That(
new byte[] {1, 2, 4, 8, 16, byte.MaxValue, byte.MinValue},
Is.EqualTo(readByteArray).AsCollection);
}
[Test]
public void WriteReadDouble()
{
var ndw = new NetDataWriter();
ndw.Put(3.1415);
var ndr = new NetDataReader(ndw.Data);
var readDouble = ndr.GetDouble();
Assert.AreEqual(readDouble, 3.1415);
}
[Test]
public void WriteReadDoubleArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {1.1, 2.2, 3.3, 4.4, double.MaxValue, double.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readDoubleArray = ndr.GetDoubleArray();
Assert.That(
new[] {1.1, 2.2, 3.3, 4.4, double.MaxValue, double.MinValue},
Is.EqualTo(readDoubleArray).AsCollection);
}
[Test]
public void WriteReadFloat()
{
var ndw = new NetDataWriter();
ndw.Put(3.1415f);
var ndr = new NetDataReader(ndw.Data);
var readFloat = ndr.GetFloat();
Assert.AreEqual(readFloat, 3.1415f);
}
[Test]
public void WriteReadFloatArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {1.1f, 2.2f, 3.3f, 4.4f, float.MaxValue, float.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readFloatArray = ndr.GetFloatArray();
Assert.That(
new[] {1.1f, 2.2f, 3.3f, 4.4f, float.MaxValue, float.MinValue},
Is.EqualTo(readFloatArray).AsCollection);
}
[Test]
public void WriteReadInt()
{
var ndw = new NetDataWriter();
ndw.Put(32);
var ndr = new NetDataReader(ndw.Data);
var readInt = ndr.GetInt();
Assert.AreEqual(readInt, 32);
}
[Test]
public void WriteReadIntArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {1, 2, 3, 4, 5, 6, 7, int.MaxValue, int.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readIntArray = ndr.GetIntArray();
Assert.That(new[] {1, 2, 3, 4, 5, 6, 7, int.MaxValue, int.MinValue}, Is.EqualTo(readIntArray).AsCollection);
}
[Test]
public void WriteReadLong()
{
var ndw = new NetDataWriter();
ndw.Put(64L);
var ndr = new NetDataReader(ndw.Data);
var readLong = ndr.GetLong();
Assert.AreEqual(readLong, 64L);
}
[Test]
public void WriteReadLongArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {1L, 2L, 3L, 4L, long.MaxValue, long.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readLongArray = ndr.GetLongArray();
Assert.That(new[] {1L, 2L, 3L, 4L, long.MaxValue, long.MinValue}, Is.EqualTo(readLongArray).AsCollection);
}
[Test]
public void WriteReadNetEndPoint()
{
var ndw = new NetDataWriter();
ndw.Put(NetUtils.MakeEndPoint("127.0.0.1", 7777));
var ndr = new NetDataReader(ndw.Data);
var readNetEndPoint = ndr.GetNetEndPoint();
Assert.AreEqual(readNetEndPoint, NetUtils.MakeEndPoint("127.0.0.1", 7777));
}
[Test]
public void WriteReadSByte()
{
var ndw = new NetDataWriter();
ndw.Put((sbyte) 8);
var ndr = new NetDataReader(ndw.Data);
var readSByte = ndr.GetSByte();
Assert.AreEqual(readSByte, (sbyte) 8);
}
[Test]
public void WriteReadShort()
{
var ndw = new NetDataWriter();
ndw.Put((short) 16);
var ndr = new NetDataReader(ndw.Data);
var readShort = ndr.GetShort();
Assert.AreEqual(readShort, (short) 16);
}
[Test]
public void WriteReadShortArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new short[] {1, 2, 3, 4, 5, 6, short.MaxValue, short.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readShortArray = ndr.GetShortArray();
Assert.That(
new short[] {1, 2, 3, 4, 5, 6, short.MaxValue, short.MinValue},
Is.EqualTo(readShortArray).AsCollection);
}
[Test]
public void WriteReadString()
{
var ndw = new NetDataWriter();
ndw.Put("String", 10);
var ndr = new NetDataReader(ndw.Data);
var readString = ndr.GetString(10);
Assert.AreEqual(readString, "String");
}
[Test]
public void WriteReadStringArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {"First", "Second", "Third", "Fourth"});
var ndr = new NetDataReader(ndw.Data);
var readStringArray = ndr.GetStringArray(10);
Assert.That(new[] {"First", "Second", "Third", "Fourth"}, Is.EqualTo(readStringArray).AsCollection);
}
[Test]
public void WriteReadUInt()
{
var ndw = new NetDataWriter();
ndw.Put(34U);
var ndr = new NetDataReader(ndw.Data);
var readUInt = ndr.GetUInt();
Assert.AreEqual(readUInt, 34U);
}
[Test]
public void WriteReadUIntArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {1U, 2U, 3U, 4U, 5U, 6U, uint.MaxValue, uint.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readUIntArray = ndr.GetUIntArray();
Assert.That(
new[] {1U, 2U, 3U, 4U, 5U, 6U, uint.MaxValue, uint.MinValue},
Is.EqualTo(readUIntArray).AsCollection);
}
[Test]
public void WriteReadULong()
{
var ndw = new NetDataWriter();
ndw.Put(64UL);
var ndr = new NetDataReader(ndw.Data);
var readULong = ndr.GetULong();
Assert.AreEqual(readULong, 64UL);
}
[Test]
public void WriteReadULongArray()
{
var ndw = new NetDataWriter();
ndw.PutArray(new[] {1UL, 2UL, 3UL, 4UL, 5UL, ulong.MaxValue, ulong.MinValue});
var ndr = new NetDataReader(ndw.Data);
var readULongArray = ndr.GetULongArray();
Assert.That(
new[] {1UL, 2UL, 3UL, 4UL, 5UL, ulong.MaxValue, ulong.MinValue},
Is.EqualTo(readULongArray).AsCollection);
}
[Test]
public void WriteReadUShort()
{
var ndw = new NetDataWriter();
ndw.Put((ushort) 16);
var ndr = new NetDataReader(ndw.Data);
var readUShort = ndr.GetUShort();
Assert.AreEqual(readUShort, (ushort) 16);
}
}
}