* Introduced new HttpServer.Tests project
* Split the GetAssetStreamHandler testing into separate tests for BaseRequestHandler * Ignored some gens0.6.5-rc1
parent
bf5fda8908
commit
8ac73be917
|
@ -126,13 +126,6 @@ namespace OpenSim.Framework.Servers
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string[] SplitParams(string path)
|
|
||||||
{
|
|
||||||
string param = GetParam(path);
|
|
||||||
|
|
||||||
return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
}
|
|
||||||
|
|
||||||
// private byte[] ProcessOutgoingAssetData(byte[] assetData)
|
// private byte[] ProcessOutgoingAssetData(byte[] assetData)
|
||||||
// {
|
// {
|
||||||
// string data = Encoding.ASCII.GetString(assetData);
|
// string data = Encoding.ASCII.GetString(assetData);
|
||||||
|
|
|
@ -75,5 +75,12 @@ namespace OpenSim.Framework.Servers.HttpServer
|
||||||
|
|
||||||
return path.StartsWith(Path);
|
return path.StartsWith(Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string[] SplitParams(string path)
|
||||||
|
{
|
||||||
|
string param = GetParam(path);
|
||||||
|
|
||||||
|
return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using OpenSim.Tests.Common;
|
||||||
|
|
||||||
|
namespace OpenSim.Framework.Servers.HttpServer.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class BaseRequestHandlerTests
|
||||||
|
{
|
||||||
|
private const string BASE_PATH = "/testpath";
|
||||||
|
|
||||||
|
private class BaseRequestHandlerImpl : BaseRequestHandler
|
||||||
|
{
|
||||||
|
public BaseRequestHandlerImpl(string httpMethod, string path) : base(httpMethod, path)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestConstructor()
|
||||||
|
{
|
||||||
|
BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl( null, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestGetParams()
|
||||||
|
{
|
||||||
|
BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl(null, BASE_PATH);
|
||||||
|
|
||||||
|
BaseRequestHandlerTestHelper.BaseTestGetParams(handler, BASE_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSplitParams()
|
||||||
|
{
|
||||||
|
BaseRequestHandlerImpl handler = new BaseRequestHandlerImpl(null, BASE_PATH);
|
||||||
|
|
||||||
|
BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, BASE_PATH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using OpenSim.Data;
|
using OpenSim.Data;
|
||||||
|
using OpenSim.Framework.Servers.HttpServer;
|
||||||
using OpenSim.Tests.Common;
|
using OpenSim.Tests.Common;
|
||||||
|
|
||||||
namespace OpenSim.Framework.Servers.Tests
|
namespace OpenSim.Framework.Servers.Tests
|
||||||
|
@ -10,6 +11,9 @@ namespace OpenSim.Framework.Servers.Tests
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class GetAssetStreamHandlerTests
|
public class GetAssetStreamHandlerTests
|
||||||
{
|
{
|
||||||
|
private static byte[] EmptyByteArray = new byte[] {};
|
||||||
|
private const string ASSETS_PATH = "/assets";
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestConstructor()
|
public void TestConstructor()
|
||||||
{
|
{
|
||||||
|
@ -24,18 +28,7 @@ namespace OpenSim.Framework.Servers.Tests
|
||||||
TestHelper.InMethod();
|
TestHelper.InMethod();
|
||||||
|
|
||||||
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
||||||
|
BaseRequestHandlerTestHelper.BaseTestGetParams(handler, ASSETS_PATH);
|
||||||
Assert.AreEqual("", handler.GetParam(null), "Failed on null path.");
|
|
||||||
Assert.AreEqual("", handler.GetParam(""), "Failed on empty path.");
|
|
||||||
Assert.AreEqual("", handler.GetParam("s"), "Failed on short url.");
|
|
||||||
Assert.AreEqual("", handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
|
|
||||||
|
|
||||||
Assert.AreEqual("", handler.GetParam("/assets"));
|
|
||||||
Assert.AreEqual("/", handler.GetParam("/assets/"));
|
|
||||||
Assert.AreEqual("/a", handler.GetParam("/assets/a"));
|
|
||||||
Assert.AreEqual("/b/", handler.GetParam("/assets/b/"));
|
|
||||||
Assert.AreEqual("/c/d", handler.GetParam("/assets/c/d"));
|
|
||||||
Assert.AreEqual("/e/f/", handler.GetParam("/assets/e/f/"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -44,17 +37,7 @@ namespace OpenSim.Framework.Servers.Tests
|
||||||
TestHelper.InMethod();
|
TestHelper.InMethod();
|
||||||
|
|
||||||
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
||||||
|
BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, ASSETS_PATH);
|
||||||
Assert.AreEqual(new string[] { }, handler.SplitParams(null), "Failed on null.");
|
|
||||||
Assert.AreEqual(new string[] { }, handler.SplitParams(""), "Failed on empty path.");
|
|
||||||
Assert.AreEqual(new string[] { }, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
|
|
||||||
|
|
||||||
Assert.AreEqual(new string[] { }, handler.SplitParams("/assets"), "Failed on empty params.");
|
|
||||||
Assert.AreEqual(new string[] { }, handler.SplitParams("/assets/"), "Failed on single slash.");
|
|
||||||
Assert.AreEqual(new string[] { "a" }, handler.SplitParams("/assets/a"), "Failed on first segment.");
|
|
||||||
Assert.AreEqual(new string[] { "b" }, handler.SplitParams("/assets/b/"), "Failed on second slash.");
|
|
||||||
Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams("/assets/c/d"), "Failed on second segment.");
|
|
||||||
Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams("/assets/e/f/"), "Failed on trailing slash.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -62,11 +45,10 @@ namespace OpenSim.Framework.Servers.Tests
|
||||||
{
|
{
|
||||||
TestHelper.InMethod();
|
TestHelper.InMethod();
|
||||||
|
|
||||||
byte[] emptyResult = new byte[] {};
|
|
||||||
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
||||||
|
|
||||||
Assert.AreEqual(new string[] { }, handler.Handle("/assets", null, null, null), "Failed on empty params.");
|
Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH, null, null, null), "Failed on empty params.");
|
||||||
Assert.AreEqual(new string[] { }, handler.Handle("/assets/", null, null, null ), "Failed on single slash.");
|
Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH + "/", null, null, null), "Failed on single slash.");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -74,10 +56,9 @@ namespace OpenSim.Framework.Servers.Tests
|
||||||
{
|
{
|
||||||
TestHelper.InMethod();
|
TestHelper.InMethod();
|
||||||
|
|
||||||
byte[] emptyResult = new byte[] {};
|
|
||||||
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
GetAssetStreamHandler handler = new GetAssetStreamHandler(null);
|
||||||
|
|
||||||
Assert.AreEqual(new string[] {}, handler.Handle("/assets/badGuid", null, null, null), "Failed on bad guid.");
|
Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH + "/badGuid", null, null, null), "Failed on bad guid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Test]
|
//[Test]
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using OpenSim.Framework.Servers;
|
||||||
|
using OpenSim.Framework.Servers.HttpServer;
|
||||||
|
|
||||||
|
namespace OpenSim.Tests.Common
|
||||||
|
{
|
||||||
|
public class BaseRequestHandlerTestHelper
|
||||||
|
{
|
||||||
|
private static string[] m_emptyStringArray = new string[] { };
|
||||||
|
|
||||||
|
public static void BaseTestGetParams(BaseRequestHandler handler, string assetsPath)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(String.Empty, handler.GetParam(null), "Failed on null path.");
|
||||||
|
Assert.AreEqual(String.Empty, handler.GetParam(""), "Failed on empty path.");
|
||||||
|
Assert.AreEqual(String.Empty, handler.GetParam("s"), "Failed on short url.");
|
||||||
|
Assert.AreEqual(String.Empty, handler.GetParam("corruptUrl"), "Failed on corruptUrl.");
|
||||||
|
|
||||||
|
Assert.AreEqual(String.Empty, handler.GetParam(assetsPath));
|
||||||
|
Assert.AreEqual("/", handler.GetParam(assetsPath + "/"));
|
||||||
|
Assert.AreEqual("/a", handler.GetParam(assetsPath + "/a"));
|
||||||
|
Assert.AreEqual("/b/", handler.GetParam(assetsPath + "/b/"));
|
||||||
|
Assert.AreEqual("/c/d", handler.GetParam(assetsPath + "/c/d"));
|
||||||
|
Assert.AreEqual("/e/f/", handler.GetParam(assetsPath + "/e/f/"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void BaseTestSplitParams(BaseRequestHandler handler, string assetsPath)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(m_emptyStringArray, handler.SplitParams(null), "Failed on null.");
|
||||||
|
Assert.AreEqual(m_emptyStringArray, handler.SplitParams(""), "Failed on empty path.");
|
||||||
|
Assert.AreEqual(m_emptyStringArray, handler.SplitParams("corruptUrl"), "Failed on corrupt url.");
|
||||||
|
|
||||||
|
Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath), "Failed on empty params.");
|
||||||
|
Assert.AreEqual(m_emptyStringArray, handler.SplitParams(assetsPath + "/"), "Failed on single slash.");
|
||||||
|
|
||||||
|
Assert.AreEqual(new string[] { "a" }, handler.SplitParams(assetsPath + "/a"), "Failed on first segment.");
|
||||||
|
Assert.AreEqual(new string[] { "b" }, handler.SplitParams(assetsPath + "/b/"), "Failed on second slash.");
|
||||||
|
Assert.AreEqual(new string[] { "c", "d" }, handler.SplitParams(assetsPath + "/c/d"), "Failed on second segment.");
|
||||||
|
Assert.AreEqual(new string[] { "e", "f" }, handler.SplitParams(assetsPath + "/e/f/"), "Failed on trailing slash.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
prebuild.xml
33
prebuild.xml
|
@ -78,7 +78,9 @@
|
||||||
|
|
||||||
<Files>
|
<Files>
|
||||||
<Match pattern="*.cs" recurse="true">
|
<Match pattern="*.cs" recurse="true">
|
||||||
<!-- on temporary suspension -->
|
<Exclude pattern="Tests" />
|
||||||
|
|
||||||
|
<!-- on temporary suspension -->
|
||||||
<Exclude pattern="OSHttpHandler\.cs" />
|
<Exclude pattern="OSHttpHandler\.cs" />
|
||||||
<Exclude pattern="OSHttpHttpHandler\.cs" />
|
<Exclude pattern="OSHttpHttpHandler\.cs" />
|
||||||
<Exclude pattern="OSHttpRequestPump\.cs" />
|
<Exclude pattern="OSHttpRequestPump\.cs" />
|
||||||
|
@ -3212,6 +3214,35 @@
|
||||||
</Files>
|
</Files>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
||||||
|
<Project name="OpenSim.Framework.Servers.HttpServer.Tests" path="OpenSim/Framework/Servers/HttpServer/Tests" type="Library">
|
||||||
|
<Configuration name="Debug">
|
||||||
|
<Options>
|
||||||
|
<OutputPath>../../../../../bin/</OutputPath>
|
||||||
|
</Options>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration name="Release">
|
||||||
|
<Options>
|
||||||
|
<OutputPath>../../../../../bin/</OutputPath>
|
||||||
|
</Options>
|
||||||
|
</Configuration>
|
||||||
|
|
||||||
|
<ReferencePath>../../../../../bin/</ReferencePath>
|
||||||
|
<Reference name="System"/>
|
||||||
|
<Reference name="OpenSim.Data"/>
|
||||||
|
<Reference name="OpenSim.Tests.Common"/>
|
||||||
|
<Reference name="OpenSim.Framework"/>
|
||||||
|
<Reference name="OpenSim.Framework.Servers"/>
|
||||||
|
<Reference name="OpenSim.Framework.Servers.HttpServer"/>
|
||||||
|
<Reference name="log4net.dll"/>
|
||||||
|
<Reference name="HttpServer_OpenSim.dll"/>
|
||||||
|
<Reference name="nunit.framework.dll" />
|
||||||
|
|
||||||
|
<Files>
|
||||||
|
<Match pattern="*.cs" recurse="true">
|
||||||
|
</Match>
|
||||||
|
</Files>
|
||||||
|
</Project>
|
||||||
|
|
||||||
<Project name="OpenSim.Framework.Communications.Tests" path="OpenSim/Framework/Communications/Tests" type="Library">
|
<Project name="OpenSim.Framework.Communications.Tests" path="OpenSim/Framework/Communications/Tests" type="Library">
|
||||||
<Configuration name="Debug">
|
<Configuration name="Debug">
|
||||||
<Options>
|
<Options>
|
||||||
|
|
Loading…
Reference in New Issue