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
This commit is contained in:
parent
64a1dbb629
commit
b1e97f48bf
|
@ -191,6 +191,11 @@
|
||||||
<XNAUseContentPipeline>false</XNAUseContentPipeline>
|
<XNAUseContentPipeline>false</XNAUseContentPipeline>
|
||||||
<Name>PathHelper</Name>
|
<Name>PathHelper</Name>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Source\PathHelper.Test.cs">
|
||||||
|
<XNAUseContentPipeline>false</XNAUseContentPipeline>
|
||||||
|
<Name>PathHelper.Test</Name>
|
||||||
|
<DependentUpon>PathHelper.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Source\Scheduling\AbortedException.cs">
|
<Compile Include="Source\Scheduling\AbortedException.cs">
|
||||||
<XNAUseContentPipeline>false</XNAUseContentPipeline>
|
<XNAUseContentPipeline>false</XNAUseContentPipeline>
|
||||||
<Name>AbortedException</Name>
|
<Name>AbortedException</Name>
|
||||||
|
|
|
@ -81,14 +81,14 @@ namespace Nuclex.Support.Collections {
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// This method is intended to support collections that need to dispose their
|
/// 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.
|
/// on any item that implements IDisposable.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// Do not call this method during a GC run (eg. from your destructor) as it
|
/// Do not call this method from your destructor as it will access the
|
||||||
/// will access the contained items in order to unparent and to Dispose() them,
|
/// contained items in order to unparent and to Dispose() them, which leads
|
||||||
/// which leads to undefined behavior since the object might have already been
|
/// to undefined behavior since the object might have already been collected
|
||||||
/// collected by the GC.
|
/// by the GC. Call it only if your object is being manually disposed.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected void DisposeItems() {
|
protected void DisposeItems() {
|
||||||
|
|
137
Source/PathHelper.Test.cs
Normal file
137
Source/PathHelper.Test.cs
Normal file
|
@ -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 {
|
||||||
|
|
||||||
|
/// <summary>Unit Test for the path helper class</summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class PathHelperTest {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests whether the relative path creator keeps the absolute path if
|
||||||
|
/// the location being passed is not relative to the base path.
|
||||||
|
/// </summary>
|
||||||
|
[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/"))
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests whether the relative path creator correctly builds the relative
|
||||||
|
/// path to the parent folder of the base path.
|
||||||
|
/// </summary>
|
||||||
|
[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("../"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests whether the relative path creator correctly builds the relative
|
||||||
|
/// path to a nested folder in the base path.
|
||||||
|
/// </summary>
|
||||||
|
[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/"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests whether the relative path creator correctly builds the relative
|
||||||
|
/// path to another folder on the same level as base path.
|
||||||
|
/// </summary>
|
||||||
|
[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"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts unix-style directory separators into the format used by the current platform
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">Path to converts into the platform-dependent format</param>
|
||||||
|
/// <returns>Platform-specific version of the provided unix-style path</returns>
|
||||||
|
private string platformify(string path) {
|
||||||
|
return path.Replace('/', Path.DirectorySeparatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Nuclex.Support
|
||||||
|
|
||||||
|
#endif // UNITTEST
|
|
@ -37,7 +37,7 @@ namespace Nuclex.Support {
|
||||||
return absolutePath;
|
return absolutePath;
|
||||||
|
|
||||||
// Calculate the required length for the StrinBuilder to be slightly more
|
// 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;
|
int requiredLength = (baseDirectories.Length - (lastCommonRoot + 1)) * 3;
|
||||||
for(int index = lastCommonRoot + 1; index < absoluteDirectories.Length; index++)
|
for(int index = lastCommonRoot + 1; index < absoluteDirectories.Length; index++)
|
||||||
requiredLength += absoluteDirectories[index].Length + 1;
|
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
|
// Go to the common path by adding .. until we're where we want to be
|
||||||
for(int index = lastCommonRoot + 1; index < baseDirectories.Length; index++) {
|
for(int index = lastCommonRoot + 1; index < baseDirectories.Length; index++) {
|
||||||
if(baseDirectories[index].Length > 0) {
|
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(Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
relativePath.Append("..");
|
relativePath.Append("..");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user