You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-15 22:56:30 +09:00
transferred from trunk/Generation3 of lidgren-network
This commit is contained in:
35
UnitTests/BitVectorTests.cs
Normal file
35
UnitTests/BitVectorTests.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
public static class BitVectorTests
|
||||
{
|
||||
public static void Run()
|
||||
{
|
||||
NetBitVector v = new NetBitVector(256);
|
||||
for (int i = 0; i < 256; i++)
|
||||
{
|
||||
v.Clear();
|
||||
|
||||
if (!v.IsEmpty())
|
||||
throw new NetException("bit vector fail 1");
|
||||
|
||||
v.Set(i, true);
|
||||
|
||||
if (v.Get(i) == false)
|
||||
throw new NetException("bit vector fail 2");
|
||||
|
||||
if (v.IsEmpty())
|
||||
throw new NetException("bit vector fail 3");
|
||||
|
||||
int f = v.GetFirstSetIndex();
|
||||
|
||||
if (f != i)
|
||||
throw new NetException("bit vector fail 4");
|
||||
}
|
||||
|
||||
Console.WriteLine("NetBitVector tests OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
19
UnitTests/EncryptionTests.cs
Normal file
19
UnitTests/EncryptionTests.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
public static class EncryptionTests
|
||||
{
|
||||
public static void Run()
|
||||
{
|
||||
byte[] salt = NetUtility.ToByteArray("59d7304da9b97e2a9d38");
|
||||
byte[] verifier = NetSRP.ComputePasswordVerifier("user", "password", salt);
|
||||
|
||||
Console.WriteLine("Result: " + NetUtility.ToHexString(verifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
24
UnitTests/MiscTests.cs
Normal file
24
UnitTests/MiscTests.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
public static class MiscTests
|
||||
{
|
||||
public static void Run(NetPeer peer)
|
||||
{
|
||||
NetPeerConfiguration config = new NetPeerConfiguration("Test");
|
||||
|
||||
config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
|
||||
if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false)
|
||||
throw new NetException("setting enabled message types failed");
|
||||
|
||||
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
|
||||
if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true)
|
||||
throw new NetException("setting enabled message types failed");
|
||||
|
||||
Console.WriteLine("Misc tests OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
53
UnitTests/NetQueueTests.cs
Normal file
53
UnitTests/NetQueueTests.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
public static class NetQueueTests
|
||||
{
|
||||
public static void Run()
|
||||
{
|
||||
NetQueue<int> queue = new NetQueue<int>(8);
|
||||
|
||||
queue.Enqueue(1);
|
||||
queue.Enqueue(2);
|
||||
queue.Enqueue(3);
|
||||
|
||||
if (queue.Count != 3)
|
||||
throw new Exception("NetQueue failed");
|
||||
if (queue.TryDequeue() != 1)
|
||||
throw new Exception("NetQueue failure");
|
||||
if (queue.Count != 2)
|
||||
throw new Exception("NetQueue failed");
|
||||
|
||||
queue.EnqueueFirst(42);
|
||||
if (queue.Count != 3)
|
||||
throw new Exception("NetQueue failed");
|
||||
|
||||
if (queue.TryDequeue() != 42)
|
||||
throw new Exception("NetQueue failed");
|
||||
if (queue.TryDequeue() != 2)
|
||||
throw new Exception("NetQueue failed");
|
||||
if (queue.TryDequeue() != 3)
|
||||
throw new Exception("NetQueue failed");
|
||||
if (queue.TryDequeue() != 0)
|
||||
throw new Exception("NetQueue failed");
|
||||
if (queue.TryDequeue() != 0)
|
||||
throw new Exception("NetQueue failed");
|
||||
|
||||
queue.Enqueue(78);
|
||||
if (queue.Count != 1)
|
||||
throw new Exception("NetQueue failed");
|
||||
|
||||
if (queue.TryDequeue() != 78)
|
||||
throw new Exception("NetQueue failed");
|
||||
|
||||
queue.Clear();
|
||||
if (queue.Count != 0)
|
||||
throw new Exception("NetQueue.Clear failed");
|
||||
|
||||
Console.WriteLine("NetQueue tests OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
36
UnitTests/Program.cs
Normal file
36
UnitTests/Program.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Lidgren.Network;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
NetPeerConfiguration config = new NetPeerConfiguration("unittests");
|
||||
NetPeer peer = new NetPeer(config);
|
||||
peer.Start(); // needed for initialization
|
||||
|
||||
System.Threading.Thread.Sleep(50);
|
||||
|
||||
Console.WriteLine("Unique identifier is " + NetUtility.ToHexString(peer.UniqueIdentifier));
|
||||
|
||||
ReadWriteTests.Run(peer);
|
||||
|
||||
NetQueueTests.Run();
|
||||
|
||||
MiscTests.Run(peer);
|
||||
|
||||
BitVectorTests.Run();
|
||||
|
||||
EncryptionTests.Run();
|
||||
|
||||
peer.Shutdown("bye");
|
||||
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
36
UnitTests/Properties/AssemblyInfo.cs
Normal file
36
UnitTests/Properties/AssemblyInfo.cs
Normal file
@@ -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("UnitTests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("UnitTests")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
|
||||
[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("ea1608b3-3a09-4c31-8ee3-04d8b5943ce2")]
|
||||
|
||||
// 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")]
|
||||
75
UnitTests/ReadWriteTests.cs
Normal file
75
UnitTests/ReadWriteTests.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Lidgren.Network;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
public static class ReadWriteTests
|
||||
{
|
||||
public static void Run(NetPeer peer)
|
||||
{
|
||||
NetOutgoingMessage msg = peer.CreateMessage();
|
||||
|
||||
msg.Write(false);
|
||||
msg.Write(-3, 6);
|
||||
msg.Write(42);
|
||||
msg.Write("duke of earl");
|
||||
msg.Write((byte)43);
|
||||
msg.Write((ushort)44);
|
||||
msg.Write(true);
|
||||
|
||||
msg.WritePadBits();
|
||||
|
||||
msg.Write(45.0f);
|
||||
msg.Write(46.0);
|
||||
msg.WriteVariableInt32(-47);
|
||||
msg.WriteVariableUInt32(48);
|
||||
|
||||
byte[] data = msg.PeekDataBuffer();
|
||||
|
||||
NetIncomingMessage inc = (NetIncomingMessage)Activator.CreateInstance(typeof(NetIncomingMessage), true);
|
||||
typeof(NetIncomingMessage).GetField("m_data", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(inc, data);
|
||||
typeof(NetIncomingMessage).GetField("m_bitLength", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(inc, msg.LengthBits);
|
||||
|
||||
StringBuilder bdr = new StringBuilder();
|
||||
|
||||
bdr.Append(inc.ReadBoolean());
|
||||
bdr.Append(inc.ReadInt32(6));
|
||||
bdr.Append(inc.ReadInt32());
|
||||
bdr.Append(inc.ReadString());
|
||||
bdr.Append(inc.ReadByte());
|
||||
|
||||
if (inc.PeekUInt16() != (ushort)44)
|
||||
throw new NetException("Read/write failure");
|
||||
|
||||
bdr.Append(inc.ReadUInt16());
|
||||
bdr.Append(inc.ReadBoolean());
|
||||
|
||||
inc.SkipPadBits();
|
||||
|
||||
bdr.Append(inc.ReadSingle());
|
||||
bdr.Append(inc.ReadDouble());
|
||||
bdr.Append(inc.ReadVariableInt32());
|
||||
bdr.Append(inc.ReadVariableUInt32());
|
||||
|
||||
if (bdr.ToString().Equals("False-342duke of earl4344True4546-4748"))
|
||||
Console.WriteLine("Read/write tests OK");
|
||||
else
|
||||
throw new NetException("Read/write tests FAILED!");
|
||||
|
||||
msg = peer.CreateMessage();
|
||||
|
||||
NetOutgoingMessage tmp = peer.CreateMessage();
|
||||
tmp.Write((int)42, 14);
|
||||
|
||||
msg.Write(tmp);
|
||||
msg.Write(tmp);
|
||||
|
||||
if (msg.LengthBits != tmp.LengthBits * 2)
|
||||
throw new NetException("NetOutgoingMessage.Write(NetOutgoingMessage) failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
64
UnitTests/UnitTests.csproj
Normal file
64
UnitTests/UnitTests.csproj
Normal file
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9D7AC4F7-39CD-4BC8-8F45-00B67C196340}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>UnitTests</RootNamespace>
|
||||
<AssemblyName>UnitTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<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' ">
|
||||
<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">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BitVectorTests.cs" />
|
||||
<Compile Include="MiscTests.cs" />
|
||||
<Compile Include="NetQueueTests.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ReadWriteTests.cs" />
|
||||
<Compile Include="EncryptionTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lidgren.Network\Lidgren.Network.csproj">
|
||||
<Project>{FA245447-5F23-4AA1-BD5F-8D2DDF33CFBD}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
</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>
|
||||
Reference in New Issue
Block a user