From b1e97f48bf02186f046e310e2177cbd47c935764 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Fri, 2 Nov 2007 21:36:15 +0000 Subject: [PATCH] Improved documentation in various places; added UML design concepts for UserInterface library; created unit tests for the PathHelper class; Gui now has width and height to allow usage of unified coordinates; renamed InputProcessor to InputReceiver git-svn-id: file:///srv/devel/repo-conversion/nusu@55 d2e56fa2-650e-0410-a79f-9358c0239efd --- Nuclex.Support (PC).csproj | 5 + Source/Collections/ParentingCollection.cs | 10 +- Source/PathHelper.Test.cs | 137 ++++++++++++++++++++++ Source/PathHelper.cs | 4 +- 4 files changed, 149 insertions(+), 7 deletions(-) create mode 100644 Source/PathHelper.Test.cs diff --git a/Nuclex.Support (PC).csproj b/Nuclex.Support (PC).csproj index cf5ffe8..af6d34b 100644 --- a/Nuclex.Support (PC).csproj +++ b/Nuclex.Support (PC).csproj @@ -191,6 +191,11 @@ false PathHelper + + false + PathHelper.Test + PathHelper.cs + false AbortedException diff --git a/Source/Collections/ParentingCollection.cs b/Source/Collections/ParentingCollection.cs index 150a17f..b1afad6 100644 --- a/Source/Collections/ParentingCollection.cs +++ b/Source/Collections/ParentingCollection.cs @@ -81,14 +81,14 @@ namespace Nuclex.Support.Collections { /// /// /// This method is intended to support collections that need to dispose their - /// items. It will unparent all of the collections items and call Dispose() + /// items. It will unparent all of the collection's items and call Dispose() /// on any item that implements IDisposable. /// /// - /// Do not call this method during a GC run (eg. from your destructor) as it - /// will access the contained items in order to unparent and to Dispose() them, - /// which leads to undefined behavior since the object might have already been - /// collected by the GC. + /// Do not call this method from your destructor as it will access the + /// contained items in order to unparent and to Dispose() them, which leads + /// to undefined behavior since the object might have already been collected + /// by the GC. Call it only if your object is being manually disposed. /// /// protected void DisposeItems() { diff --git a/Source/PathHelper.Test.cs b/Source/PathHelper.Test.cs new file mode 100644 index 0000000..55fc69b --- /dev/null +++ b/Source/PathHelper.Test.cs @@ -0,0 +1,137 @@ +#region CPL License +/* +Nuclex Framework +Copyright (C) 2002-2007 Nuclex Development Labs + +This library is free software; you can redistribute it and/or +modify it under the terms of the IBM Common Public License as +published by the IBM Corporation; either version 1.0 of the +License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +IBM Common Public License for more details. + +You should have received a copy of the IBM Common Public +License along with this library +*/ +#endregion + +using System; +using System.IO; + +#if UNITTEST + +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; + +namespace Nuclex.Support { + + /// Unit Test for the path helper class + [TestFixture] + public class PathHelperTest { + + /// + /// Tests whether the relative path creator keeps the absolute path if + /// the location being passed is not relative to the base path. + /// + [Test] + public void TestRelativePathOfNonRelativePath() { + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/Folder2"), + platformify("D:/Folder1/Folder2") + ), + Is.EqualTo(platformify("D:/Folder1/Folder2")) + ); + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/Folder2/"), + platformify("D:/Folder1/Folder2/") + ), + Is.EqualTo(platformify("D:/Folder1/Folder2/")) + ); + + } + + /// + /// Tests whether the relative path creator correctly builds the relative + /// path to the parent folder of the base path. + /// + [Test] + public void TestRelativePathToParentFolder() { + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/Folder2"), + platformify("C:/Folder1") + ), + Is.EqualTo(platformify("..")) + ); + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/Folder2/"), + platformify("C:/Folder1/") + ), + Is.EqualTo(platformify("../")) + ); + } + + /// + /// Tests whether the relative path creator correctly builds the relative + /// path to a nested folder in the base path. + /// + [Test] + public void TestRelativePathToNestedFolder() { + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1"), + platformify("C:/Folder1/Folder2") + ), + Is.EqualTo(platformify("Folder2")) + ); + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/"), + platformify("C:/Folder1/Folder2/") + ), + Is.EqualTo(platformify("Folder2/")) + ); + } + + /// + /// Tests whether the relative path creator correctly builds the relative + /// path to another folder on the same level as base path. + /// + [Test] + public void TestRelativePathToSiblingFolder() { + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/Folder2/"), + platformify("C:/Folder1/Folder2345") + ), + Is.EqualTo(platformify("../Folder2345")) + ); + Assert.That( + PathHelper.MakeRelative( + platformify("C:/Folder1/Folder2345/"), + platformify("C:/Folder1/Folder2") + ), + Is.EqualTo(platformify("../Folder2")) + ); + } + + /// + /// Converts unix-style directory separators into the format used by the current platform + /// + /// Path to converts into the platform-dependent format + /// Platform-specific version of the provided unix-style path + private string platformify(string path) { + return path.Replace('/', Path.DirectorySeparatorChar); + } + + } + +} // namespace Nuclex.Support + +#endif // UNITTEST diff --git a/Source/PathHelper.cs b/Source/PathHelper.cs index 9c291e3..5b38e13 100644 --- a/Source/PathHelper.cs +++ b/Source/PathHelper.cs @@ -37,7 +37,7 @@ namespace Nuclex.Support { return absolutePath; // Calculate the required length for the StrinBuilder to be slightly more - // friendly in terms of memory usage + // friendly in terms of memory usage. int requiredLength = (baseDirectories.Length - (lastCommonRoot + 1)) * 3; for(int index = lastCommonRoot + 1; index < absoluteDirectories.Length; index++) requiredLength += absoluteDirectories[index].Length + 1; @@ -47,7 +47,7 @@ namespace Nuclex.Support { // Go to the common path by adding .. until we're where we want to be for(int index = lastCommonRoot + 1; index < baseDirectories.Length; index++) { if(baseDirectories[index].Length > 0) { - if(relativePath.Length > 0) // // We don't want the path to start with a slash + if(relativePath.Length > 0) // We don't want the path to start with a slash relativePath.Append(Path.DirectorySeparatorChar); relativePath.Append("..");