Added NightAlert project for travel kit
This commit is contained in:
142
ThirdParty/SocketIoClientDotNet/Src/SocketIoClientDotNet.Tests.net45/ParserTests/ByteArrayTest.cs
vendored
Normal file
142
ThirdParty/SocketIoClientDotNet/Src/SocketIoClientDotNet.Tests.net45/ParserTests/ByteArrayTest.cs
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Quobject.SocketIoClientDotNet.Parser;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace SocketIoClientDotNet.Tests.ParserTests
|
||||
{
|
||||
public class ByteArrayTest
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public void EncodeByteArray()
|
||||
{
|
||||
var packet = new Packet(Parser.BINARY_EVENT)
|
||||
{
|
||||
Id = 23,
|
||||
Nsp = "/woot",
|
||||
Data = System.Text.Encoding.UTF8.GetBytes("abc")
|
||||
};
|
||||
Helpers.TestBin(packet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeByteArray2()
|
||||
{
|
||||
var packet = new Packet(Parser.BINARY_EVENT)
|
||||
{
|
||||
Id = 0,
|
||||
Nsp = "/",
|
||||
Data = new byte[2]
|
||||
};
|
||||
Helpers.TestBin(packet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void EncodeByteArrayInJson()
|
||||
{
|
||||
var exptected = System.Text.Encoding.UTF8.GetBytes("asdfasdf");
|
||||
var _args = new List<object> { "buffa" };
|
||||
_args.Add(exptected);
|
||||
|
||||
var data = Packet.Args2JArray(_args);
|
||||
|
||||
var packet = new Packet()
|
||||
{
|
||||
Type = Parser.BINARY_EVENT,
|
||||
Id = 999,
|
||||
Nsp = "/deep",
|
||||
Data = data
|
||||
};
|
||||
Helpers.TestBin(packet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeByteArrayDeepInJson()
|
||||
{
|
||||
var buf = System.Text.Encoding.UTF8.GetBytes("howdy");
|
||||
var jobj = new JObject();
|
||||
jobj.Add("hello","lol");
|
||||
jobj.Add("message",buf);
|
||||
jobj.Add("goodbye","gotcha");
|
||||
|
||||
var _args = new List<object> { "jsonbuff" };
|
||||
_args.Add(jobj);
|
||||
|
||||
var data = Packet.Args2JArray(_args);
|
||||
|
||||
var packet = new Packet()
|
||||
{
|
||||
Type = Parser.BINARY_EVENT,
|
||||
Id = 999,
|
||||
Nsp = "/deep",
|
||||
Data = data
|
||||
};
|
||||
Helpers.TestBin(packet);
|
||||
}
|
||||
|
||||
|
||||
// Cannot do any of the following in C# ???
|
||||
//[Fact]
|
||||
//public void EncodeDeepBinaryJSONWithNullValue()
|
||||
//{
|
||||
// var data = JObject.Parse("{a: \"b\", c: 4, e: {g: null}, h: null}");
|
||||
// data["h"].Replace(new Byte[9]);
|
||||
|
||||
// var packet = new Packet(Parser.BINARY_EVENT)
|
||||
// {
|
||||
// Id = 600,
|
||||
// Nsp = "/",
|
||||
// Data = data
|
||||
// };
|
||||
// Helpers.TestBin(packet);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void EncodeBinaryAckWithByteArray()
|
||||
//{
|
||||
// var data = JArray.Parse("[a, null, {}]");
|
||||
// data[1] = System.Text.Encoding.UTF8.GetBytes("xxx");
|
||||
|
||||
// var packet = new Packet(Parser.BINARY_ACK)
|
||||
// {
|
||||
// Id = 127,
|
||||
// Nsp = "/back",
|
||||
// Data = data
|
||||
// };
|
||||
// Helpers.TestBin(packet);
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public void CleanItselfUpOnClose()
|
||||
//{
|
||||
|
||||
// var packet = new Packet(Parser.ACK)
|
||||
// {
|
||||
// Id = 0,
|
||||
// Nsp = "/",
|
||||
// Data = System.Text.Encoding.UTF8.GetBytes("abc")
|
||||
// };
|
||||
|
||||
|
||||
// Encoder.Encode(packet, new Parser.Encoder.CallbackImp((encodedPackets) =>
|
||||
// {
|
||||
// var decoder = new Parser.Decoder();
|
||||
// decoder.On(Parser.Decoder.EVENT_DECODED, new ListenerImpl((args) =>
|
||||
// {
|
||||
// throw new Exception("received a packet when not all data was sent.");
|
||||
// }));
|
||||
|
||||
// decoder.Add((string)encodedPackets[0]);
|
||||
// decoder.Add((byte[])encodedPackets[1]);
|
||||
// decoder.Destroy();
|
||||
// Assert.Equal(0, decoder.Reconstructor.Buffers.Count);
|
||||
// }));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
80
ThirdParty/SocketIoClientDotNet/Src/SocketIoClientDotNet.Tests.net45/ParserTests/Helpers.cs
vendored
Normal file
80
ThirdParty/SocketIoClientDotNet/Src/SocketIoClientDotNet.Tests.net45/ParserTests/Helpers.cs
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Quobject.EngineIoClientDotNet.ComponentEmitter;
|
||||
using Quobject.SocketIoClientDotNet.Parser;
|
||||
using System.Text;
|
||||
using Xunit;
|
||||
|
||||
namespace SocketIoClientDotNet.Tests.ParserTests
|
||||
{
|
||||
public class Helpers
|
||||
{
|
||||
private static Parser.Encoder Encoder = new Parser.Encoder();
|
||||
|
||||
public static void Test(Packet obj)
|
||||
{
|
||||
Encoder.Encode(obj, new Parser.Encoder.CallbackImp((encodedPackets) =>
|
||||
{
|
||||
var decoder = new Parser.Decoder();
|
||||
decoder.On(Parser.Decoder.EVENT_DECODED, new ListenerImpl((data1) =>
|
||||
{
|
||||
var packet = (Packet) data1;
|
||||
AssertPacket(obj, packet);
|
||||
}));
|
||||
decoder.Add((string)encodedPackets[0]);
|
||||
}));
|
||||
}
|
||||
|
||||
public static void TestBin(Packet obj)
|
||||
{
|
||||
object originalData = obj.Data;
|
||||
Encoder.Encode(obj, new Parser.Encoder.CallbackImp((encodedPackets) =>
|
||||
{
|
||||
var decoder = new Parser.Decoder();
|
||||
decoder.On(Parser.Decoder.EVENT_DECODED, new ListenerImpl((args) =>
|
||||
{
|
||||
var packet = (Packet) args;
|
||||
obj.Data = originalData;
|
||||
obj.Attachments = -1;
|
||||
AssertPacket(obj, packet);
|
||||
}));
|
||||
|
||||
foreach (var packet in encodedPackets)
|
||||
{
|
||||
if (packet is string)
|
||||
{
|
||||
decoder.Add((string)packet);
|
||||
} else if (packet is byte[])
|
||||
{
|
||||
decoder.Add((byte[])packet);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
public static void AssertPacket(Packet expected, Packet actual)
|
||||
{
|
||||
Assert.Equal(expected.Type, actual.Type);
|
||||
Assert.Equal(expected.Id, actual.Id);
|
||||
Assert.Equal(expected.Nsp, actual.Nsp);
|
||||
Assert.Equal(expected.Attachments, actual.Attachments);
|
||||
|
||||
if (expected.Data is JArray)
|
||||
{
|
||||
var exp = (JArray) expected.Data;
|
||||
var act = (JArray) expected.Data;
|
||||
Assert.Equal(exp.ToString(), act.ToString());
|
||||
}
|
||||
else if (expected.Data is JObject)
|
||||
{
|
||||
var exp = (JObject) expected.Data;
|
||||
var act = (JObject) expected.Data;
|
||||
Assert.Equal(exp.ToString(), act.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(expected.Data.ToString(), actual.Data.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
ThirdParty/SocketIoClientDotNet/Src/SocketIoClientDotNet.Tests.net45/ParserTests/ParserTest.cs
vendored
Normal file
60
ThirdParty/SocketIoClientDotNet/Src/SocketIoClientDotNet.Tests.net45/ParserTests/ParserTest.cs
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Quobject.EngineIoClientDotNet.ComponentEmitter;
|
||||
using Quobject.SocketIoClientDotNet.Parser;
|
||||
using Xunit;
|
||||
|
||||
namespace SocketIoClientDotNet.Tests.ParserTests
|
||||
{
|
||||
public class ParserTest
|
||||
{
|
||||
[Fact]
|
||||
public void Decode()
|
||||
{
|
||||
var decoder = new Parser.Decoder();
|
||||
var called = false;
|
||||
decoder.On(Parser.Decoder.EVENT_DECODED, new ListenerImpl((data1) =>
|
||||
{
|
||||
called = true;
|
||||
|
||||
}));
|
||||
decoder.Add("0/woot");
|
||||
Assert.True(called);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void EncodeConnection()
|
||||
{
|
||||
var packet = new Packet(Parser.CONNECT) {Nsp = "/woot"};
|
||||
Helpers.Test(packet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeDisconnection()
|
||||
{
|
||||
var packet = new Packet(Parser.DISCONNECT) { Nsp = "/woot" };
|
||||
Helpers.Test(packet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeEvent()
|
||||
{
|
||||
|
||||
//var packet = new Packet(Parser.EVENT) { Nsp = "/", Data = JArray.Parse("[\"a\", 1, {}]") };
|
||||
//Helpers.Test(packet);
|
||||
|
||||
//var packet2 = new Packet(Parser.EVENT) { Nsp = "/test", Data = JArray.Parse("[\"a\", 1, {}]") };
|
||||
//Helpers.Test(packet2);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeAck()
|
||||
{
|
||||
//var packet = new Packet(Parser.ACK) {Id = 123 , Nsp = "/", Data = JArray.Parse("[\"a\", 1, {}]") };
|
||||
//Helpers.Test(packet);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user