diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs index 1b874967bd..ba0355cff0 100644 --- a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs +++ b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs @@ -126,13 +126,6 @@ namespace OpenSim.Framework.Servers return result; } - public string[] SplitParams(string path) - { - string param = GetParam(path); - - return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); - } - // private byte[] ProcessOutgoingAssetData(byte[] assetData) // { // string data = Encoding.ASCII.GetString(assetData); diff --git a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs index da4f9a859d..c47a44aa88 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseRequestHandler.cs @@ -75,5 +75,12 @@ namespace OpenSim.Framework.Servers.HttpServer return path.StartsWith(Path); } + + public string[] SplitParams(string path) + { + string param = GetParam(path); + + return param.Split(new char[] { '/', '?', '&' }, StringSplitOptions.RemoveEmptyEntries); + } } } diff --git a/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs b/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs new file mode 100644 index 0000000000..14998c55c2 --- /dev/null +++ b/OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs @@ -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); + } + } +} diff --git a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs index d3a03688b7..157a8838d0 100644 --- a/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs +++ b/OpenSim/Framework/Servers/Tests/GetAssetStreamHandlerTests.cs @@ -3,13 +3,17 @@ using System.Collections.Generic; using System.Text; using NUnit.Framework; using OpenSim.Data; +using OpenSim.Framework.Servers.HttpServer; using OpenSim.Tests.Common; namespace OpenSim.Framework.Servers.Tests { [TestFixture] public class GetAssetStreamHandlerTests - { + { + private static byte[] EmptyByteArray = new byte[] {}; + private const string ASSETS_PATH = "/assets"; + [Test] public void TestConstructor() { @@ -24,18 +28,7 @@ namespace OpenSim.Framework.Servers.Tests TestHelper.InMethod(); GetAssetStreamHandler handler = new GetAssetStreamHandler(null); - - 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/")); + BaseRequestHandlerTestHelper.BaseTestGetParams(handler, ASSETS_PATH); } [Test] @@ -44,17 +37,7 @@ namespace OpenSim.Framework.Servers.Tests TestHelper.InMethod(); GetAssetStreamHandler handler = new GetAssetStreamHandler(null); - - 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."); + BaseRequestHandlerTestHelper.BaseTestSplitParams(handler, ASSETS_PATH); } [Test] @@ -62,11 +45,10 @@ namespace OpenSim.Framework.Servers.Tests { TestHelper.InMethod(); - byte[] emptyResult = new byte[] {}; GetAssetStreamHandler handler = new GetAssetStreamHandler(null); - Assert.AreEqual(new string[] { }, handler.Handle("/assets", 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 empty params."); + Assert.AreEqual(EmptyByteArray, handler.Handle(ASSETS_PATH + "/", null, null, null), "Failed on single slash."); } [Test] @@ -74,10 +56,9 @@ namespace OpenSim.Framework.Servers.Tests { TestHelper.InMethod(); - byte[] emptyResult = new byte[] {}; 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] diff --git a/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs b/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs new file mode 100644 index 0000000000..4052920d84 --- /dev/null +++ b/OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs @@ -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."); + } + } +} diff --git a/prebuild.xml b/prebuild.xml index 8e2906a4d5..2e7a59c185 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -78,7 +78,9 @@ - + + + @@ -3212,6 +3214,35 @@ + + + + ../../../../../bin/ + + + + + ../../../../../bin/ + + + + ../../../../../bin/ + + + + + + + + + + + + + + + +