From 8ac73be9178ac9b7445534522f5b574df29fa560 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Fri, 8 May 2009 06:11:44 +0000 Subject: * Introduced new HttpServer.Tests project * Split the GetAssetStreamHandler testing into separate tests for BaseRequestHandler * Ignored some gens --- OpenSim/Framework/Servers/GetAssetStreamHandler.cs | 7 ---- .../Servers/HttpServer/BaseRequestHandler.cs | 7 ++++ .../HttpServer/Tests/BaseRequestHandlerTests.cs | 43 +++++++++++++++++++++ .../Servers/Tests/GetAssetStreamHandlerTests.cs | 39 +++++-------------- .../Tests/Common/BaseRequestHandlerTestHelper.cs | 44 ++++++++++++++++++++++ prebuild.xml | 33 +++++++++++++++- 6 files changed, 136 insertions(+), 37 deletions(-) create mode 100644 OpenSim/Framework/Servers/HttpServer/Tests/BaseRequestHandlerTests.cs create mode 100644 OpenSim/Tests/Common/BaseRequestHandlerTestHelper.cs diff --git a/OpenSim/Framework/Servers/GetAssetStreamHandler.cs b/OpenSim/Framework/Servers/GetAssetStreamHandler.cs index 1b87496..ba0355c 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 da4f9a8..c47a44a 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 0000000..14998c5 --- /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 d3a0368..157a883 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 0000000..4052920 --- /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 8e2906a..2e7a59c 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -78,7 +78,9 @@ - + + + @@ -3212,6 +3214,35 @@ + + + + ../../../../../bin/ + + + + + ../../../../../bin/ + + + + ../../../../../bin/ + + + + + + + + + + + + + + + + -- cgit v1.1