From: JamJar00 Date: Tue, 14 Jun 2016 14:14:20 +0000 (+0100) Subject: Fixes in tests X-Git-Tag: 1.0.0~146 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=ce2300567e0612051fb3a81e7d8b96006d135283;p=rhonda%2Fimpostor.hazel.git Fixes in tests --- diff --git a/Hazel.UnitTests/TestHelper.cs b/Hazel.UnitTests/TestHelper.cs index 7334be3..838a41a 100644 --- a/Hazel.UnitTests/TestHelper.cs +++ b/Hazel.UnitTests/TestHelper.cs @@ -47,7 +47,7 @@ namespace Hazel.UnitTests } Assert.AreEqual(sendOption, args.SendOption); - + mutex.Set(); }; @@ -72,6 +72,7 @@ namespace Hazel.UnitTests //Setup meta stuff byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; ManualResetEvent mutex = new ManualResetEvent(false); + ManualResetEvent mutex2 = new ManualResetEvent(false); //Setup listener listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) @@ -92,18 +93,23 @@ namespace Hazel.UnitTests Assert.AreEqual(0, args.Connection.Statistics.TotalBytesSent); Assert.AreEqual(data.Length + headerSize, args.Connection.Statistics.TotalBytesReceived); - mutex.Set(); + mutex2.Set(); }; + + mutex.Set(); }; listener.Start(); //Connect connection.Connect(); + + mutex.WaitOne(); + connection.SendBytes(data, sendOption); //Wait until data is received - mutex.WaitOne(); + mutex2.WaitOne(); Assert.AreEqual(data.Length, connection.Statistics.DataBytesSent); Assert.AreEqual(0, connection.Statistics.DataBytesReceived); @@ -145,22 +151,27 @@ namespace Hazel.UnitTests internal static void RunClientDisconnectTest(ConnectionListener listener, Connection connection) { ManualResetEvent mutex = new ManualResetEvent(false); + ManualResetEvent mutex2 = new ManualResetEvent(false); listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2) { - mutex.Set(); + mutex2.Set(); }; + + mutex.Set(); }; listener.Start(); connection.Connect(); + mutex.WaitOne(); + connection.Close(); - mutex.WaitOne(); + mutex2.WaitOne(); } } } diff --git a/Hazel.UnitTests/UdpConnectionTests.cs b/Hazel.UnitTests/UdpConnectionTests.cs index 363fb4d..3db82c5 100644 --- a/Hazel.UnitTests/UdpConnectionTests.cs +++ b/Hazel.UnitTests/UdpConnectionTests.cs @@ -54,7 +54,7 @@ namespace Hazel.UnitTests /// Tests dual mode connectivity. /// [TestMethod] - public void TcpDualModeConnectionTest() + public void UdpDualModeConnectionTest() { using (UdpConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4AndIPv6)) { @@ -141,9 +141,9 @@ namespace Hazel.UnitTests System.Threading.Thread.Sleep(1100); //Enough time for ~10 keep alive packets Assert.IsTrue( - connection.Statistics.TotalBytesSent >= 27 - && connection.Statistics.TotalBytesSent <= 33, - "Received: " + connection.Statistics.TotalBytesSent + connection.Statistics.TotalBytesSent >= 27 && + connection.Statistics.TotalBytesSent <= 33, + "Sent: " + connection.Statistics.TotalBytesSent ); } } @@ -166,9 +166,9 @@ namespace Hazel.UnitTests Thread.Sleep(1100); //Enough time for ~10 keep alive packets Assert.IsTrue( - args.Connection.Statistics.TotalBytesSent >= 27 - && args.Connection.Statistics.TotalBytesSent <= 33, - "Received: " + args.Connection.Statistics.TotalBytesSent + args.Connection.Statistics.TotalBytesSent >= 27 && + args.Connection.Statistics.TotalBytesSent <= 33, + "Sent: " + connection.Statistics.TotalBytesSent ); mutex.Set(); diff --git a/HazelTest/App.config b/HazelTest/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/HazelTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HazelTest/ClientExample.cs b/HazelTest/ClientExample.cs new file mode 100644 index 0000000..8d2d875 --- /dev/null +++ b/HazelTest/ClientExample.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Hazel; +using Hazel.Udp; + +namespace HazelExample +{ + class ClientExample + { + static Connection connection; + + public static void Main(string[] args) + { + NetworkEndPoint endPoint = new NetworkEndPoint("13.74.185.0", 4296); + + connection = new UdpClientConnection(endPoint); + + connection.DataReceived += DataReceived; + + Console.WriteLine("Connecting!"); + + connection.Connect(); + + connection.SendBytes(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + + Console.WriteLine("Press any key to continue..."); + + Console.ReadKey(); + + connection.Close(); + } + + private static void DataReceived(object sender, DataReceivedEventArgs args) + { + Console.WriteLine("Received (" + string.Join(", ", args.Bytes) + ") from " + connection.EndPoint.ToString()); + + args.Recycle(); + } + } +} diff --git a/HazelTest/HazelTest.csproj b/HazelTest/HazelTest.csproj new file mode 100644 index 0000000..f298322 --- /dev/null +++ b/HazelTest/HazelTest.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {F869A12F-7E4A-4DDA-AD96-A226E4923859} + Exe + Properties + HazelTest + HazelTest + v4.5 + 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + {02cfbd30-d77d-400f-94b2-700f60efdd7f} + Hazel + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + \ No newline at end of file diff --git a/HazelTest/Program.cs b/HazelTest/Program.cs new file mode 100644 index 0000000..96fa667 --- /dev/null +++ b/HazelTest/Program.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +using Hazel.Udp; + +namespace Hazel +{ + class Program + { + static void Main2(string[] args) + { + /*using (Connection connection = new UdpClientConnection(new NetworkEndPoint(IPAddress.Loopback, 4296))) + { + connection.Connect(); + connection.DataReceived += connection_DataReceived; + connection.Disconnected += connection_Disconnected; + + while (Console.ReadLine() != "Quit") + connection.SendBytes(new byte[] { 0, 1, 2, 3, 4 }, SendOption.Reliable); + }*/ + + /*using (ConnectionListener listener = new UdpConnectionListener(IPAddress.Any, 4296, IPMode.IPv4)) + { + listener.NewConnection += delegate(object sender, NewConnectionEventArgs a) + { + Console.WriteLine("Hi! " + a.Connection.EndPoint.ToString()); + + a.Connection.DataReceived += delegate(object sender2, DataEventArgs a2) + { + Console.WriteLine("Received " + a2.Bytes.Length + " of data!"); + a.Connection.SendBytes(a2.Bytes, a2.SendOption); + }; + + a.Connection.Disconnected += connection_Disconnected; + }; + + listener.Start(); + + Console.ReadKey(); + }*/ + } + + static void connection_DataReceived(object sender, DataReceivedEventArgs e) + { + Console.WriteLine(e.Bytes.Length); + } + + static void connection_Disconnected(object sender, DisconnectedEventArgs e) + { + Console.WriteLine("Bye Bye!"); + } + } +} diff --git a/HazelTest/Properties/AssemblyInfo.cs b/HazelTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7f6f215 --- /dev/null +++ b/HazelTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("HazelTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("HazelTest")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("403a5501-7047-43f5-84df-822ac7dcf00d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/HazelTest/ServerExample.cs b/HazelTest/ServerExample.cs new file mode 100644 index 0000000..0bed680 --- /dev/null +++ b/HazelTest/ServerExample.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Net; + +using Hazel; +using Hazel.Tcp; +/* +namespace HazelExample +{ + class ServerExample + { + static ConnectionListener listener; + + public static void Main(string[] args) + { + listener = new TcpConnectionListener(IPAddress.Any, 4296); + + listener.NewConnection += NewConnectionHandler; + + Console.WriteLine("Starting server!"); + + listener.Start(); + + Console.WriteLine("Press any key to continue..."); + + Console.ReadKey(); + + listener.Close(); + } + + static void NewConnectionHandler(object sender, NewConnectionEventArgs args) + { + Console.WriteLine("New connection from " + args.Connection.EndPoint.ToString()); + + args.Connection.DataReceived += DataReceivedHandler; + + args.Recycle(); + } + + private static void DataReceivedHandler(object sender, DataEventArgs args) + { + Connection connection = (Connection)sender; + + Console.WriteLine("Received (" + string.Join(", ", args.Bytes) + ") from " + connection.EndPoint.ToString()); + + connection.SendBytes(args.Bytes, args.SendOption); + + args.Recycle(); + } + } +} +*/ \ No newline at end of file