]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Fixes in tests
authorJamJar00 <jamster.30@btinternet.com>
Tue, 14 Jun 2016 14:14:20 +0000 (15:14 +0100)
committerJamJar00 <jamster.30@btinternet.com>
Tue, 14 Jun 2016 14:14:20 +0000 (15:14 +0100)
Hazel.UnitTests/TestHelper.cs
Hazel.UnitTests/UdpConnectionTests.cs
HazelTest/App.config [new file with mode: 0644]
HazelTest/ClientExample.cs [new file with mode: 0644]
HazelTest/HazelTest.csproj [new file with mode: 0644]
HazelTest/Program.cs [new file with mode: 0644]
HazelTest/Properties/AssemblyInfo.cs [new file with mode: 0644]
HazelTest/ServerExample.cs [new file with mode: 0644]

index 7334be34022465de72892810971bdb7f12b79a69..838a41ae8ca024f36baad949f2ffcc1cefda268c 100644 (file)
@@ -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();
         }
     }
 }
index 363fb4ddb835753788ac0ef468595c716388b71f..3db82c56b367b35f4c86e268e3d3bb678fb7b8ba 100644 (file)
@@ -54,7 +54,7 @@ namespace Hazel.UnitTests
         ///     Tests dual mode connectivity.
         /// </summary>
         [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 (file)
index 0000000..8e15646
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+    </startup>
+</configuration>
\ No newline at end of file
diff --git a/HazelTest/ClientExample.cs b/HazelTest/ClientExample.cs
new file mode 100644 (file)
index 0000000..8d2d875
--- /dev/null
@@ -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<byte>(", ", args.Bytes) + ") from " + connection.EndPoint.ToString());
+
+            args.Recycle();
+        }
+    }
+}
diff --git a/HazelTest/HazelTest.csproj b/HazelTest/HazelTest.csproj
new file mode 100644 (file)
index 0000000..f298322
--- /dev/null
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{F869A12F-7E4A-4DDA-AD96-A226E4923859}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>HazelTest</RootNamespace>
+    <AssemblyName>HazelTest</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <PublishUrl>publish\</PublishUrl>
+    <Install>true</Install>
+    <InstallFrom>Disk</InstallFrom>
+    <UpdateEnabled>false</UpdateEnabled>
+    <UpdateMode>Foreground</UpdateMode>
+    <UpdateInterval>7</UpdateInterval>
+    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
+    <UpdatePeriodically>false</UpdatePeriodically>
+    <UpdateRequired>false</UpdateRequired>
+    <MapFileExtensions>true</MapFileExtensions>
+    <ApplicationRevision>0</ApplicationRevision>
+    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <IsWebBootstrapper>false</IsWebBootstrapper>
+    <UseApplicationTrust>false</UseApplicationTrust>
+    <BootstrapperEnabled>true</BootstrapperEnabled>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="ClientExample.cs" />
+    <Compile Include="ServerExample.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Hazel\Hazel.csproj">
+      <Project>{02cfbd30-d77d-400f-94b2-700f60efdd7f}</Project>
+      <Name>Hazel</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <BootstrapperPackage Include=".NETFramework,Version=v4.5">
+      <Visible>False</Visible>
+      <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
+      <Install>true</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
+      <Visible>False</Visible>
+      <ProductName>.NET Framework 3.5 SP1</ProductName>
+      <Install>false</Install>
+    </BootstrapperPackage>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
diff --git a/HazelTest/Program.cs b/HazelTest/Program.cs
new file mode 100644 (file)
index 0000000..96fa667
--- /dev/null
@@ -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 (file)
index 0000000..7f6f215
--- /dev/null
@@ -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 (file)
index 0000000..0bed680
--- /dev/null
@@ -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<byte>(", ", args.Bytes) + ") from " + connection.EndPoint.ToString());
+
+            connection.SendBytes(args.Bytes, args.SendOption);
+
+            args.Recycle();
+        }
+    }
+}
+*/
\ No newline at end of file