Initial import
This commit is contained in:
1 parent
ea3f8549e4
commit
fa6feafba7
133 files changed
+17503
-4
No files matched your search
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Created by SharpDevelop.
|
||||
* User: SG0894652
|
||||
* Date: 8/10/2009
|
||||
* Time: 9:01 PM
|
||||
*
|
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using DelphiProjectHandler.Dialogs;
|
||||
|
||||
namespace DelphiProjectHandler.Tests.Utils
|
||||
{
|
||||
[TestFixture]
|
||||
public class ListUtilsTests
|
||||
{
|
||||
#region (Test methods)
|
||||
|
||||
protected void CompareLists<T>(IList<T> iActual, IList<T> iExpected, string iErrorMsg)
|
||||
{
|
||||
Assert.AreEqual(iExpected.Count, iActual.Count, "Different no. of items returned.");
|
||||
for (int vItemIdx = 0; vItemIdx < iActual.Count; vItemIdx++)
|
||||
Assert.AreEqual(iExpected[vItemIdx], iActual[vItemIdx], "Different items found. Item: " + vItemIdx.ToString() + ". " + iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestRemoveDuplicates<T>(T[] iValues, T[] iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<T> vActual = ListUtils.RemoveDuplicates<T>(iValues);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestNormalize<T>(T[] iValues, T[] iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<T> vActual = ListUtils.Normalize<T>(iValues);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void RemoveDuplicates()
|
||||
{
|
||||
TestRemoveDuplicates<int>(
|
||||
new int[] {123, 234, 345, 456, 123, 123, 234, 234, 345, 345, 456, 456},
|
||||
new int[] {123, 234, 345, 456}, "Test 1"
|
||||
);
|
||||
TestRemoveDuplicates<string>(
|
||||
new string[] {"123", "234", "345", "abc", "def", "ghi", "123", "234", "345", "abc", "def", "ghi", "123", "234", "345", "abc", "def", "ghi", null, null},
|
||||
new string[] {"123", "234", "345", "abc", "def", "ghi", null}, "Test 2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Normalize()
|
||||
{
|
||||
TestNormalize<int>(
|
||||
new int[] {123, 234, 345, 456, 123, 123, 234, 234, 345, 345, 456, 456},
|
||||
new int[] {123, 234, 345, 456}, "Test 1"
|
||||
);
|
||||
TestNormalize<string>(
|
||||
new string[] {"123", "234", "345", "abc", "def", "ghi", "123", "234", "345", "abc", "def", "ghi", "123", "234", "345", "abc", "def", "ghi", null, null},
|
||||
new string[] {"123", "234", "345", "abc", "def", "ghi", null}, "Test 2");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
|
||||
using DelphiProjectHandler.Dialogs;
|
||||
|
||||
namespace DelphiProjectHandler.Tests.Utils
|
||||
{
|
||||
[TestFixture]
|
||||
public class PathUtilsClassTests
|
||||
{
|
||||
#region (Helper methods)
|
||||
|
||||
protected void CompareLists(IList<string> iActual, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
Assert.AreEqual(iExpected.Count, iActual.Count, "Different no. of items returned.");
|
||||
for (int vItemIdx = 0; vItemIdx < iActual.Count; vItemIdx++)
|
||||
Assert.AreEqual(iExpected[vItemIdx], iActual[vItemIdx], "Different items found. Item: " + vItemIdx.ToString() + ". " + iErrorMsg);
|
||||
}
|
||||
|
||||
protected void DoFail(string iMessage, string iCorrectPath, string iPathToFix)
|
||||
{
|
||||
Assert.Fail(iMessage + "; " + GetPathsMessage(iCorrectPath, iPathToFix));
|
||||
}
|
||||
|
||||
protected string GetPathsMessage(string iBasePath, string iPath)
|
||||
{
|
||||
return string.Format("Base path: {0}; Path: {1}", iBasePath, iPath);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region (Test methods)
|
||||
|
||||
protected void TestConcatFolders(int iStartIndex, string[] iFolders, string iExpected)
|
||||
{
|
||||
string vActual = PathUtils.ConcatFolders(iStartIndex, iFolders);
|
||||
Assert.AreEqual(iExpected, vActual);
|
||||
}
|
||||
|
||||
protected void TestBuildGoUpPath(int iCount, string iExpected)
|
||||
{
|
||||
string vActual = PathUtils.BuildGoUpPath(iCount);
|
||||
Assert.AreEqual(iExpected, vActual, "Number of levels: " + iCount.ToString());
|
||||
}
|
||||
|
||||
protected void TestSplitPaths(string iPath, string[] iExpected)
|
||||
{
|
||||
string[] vActual = PathUtils.SplitPath(iPath);
|
||||
Assert.AreEqual(iExpected.Length, vActual.Length, "Different number of folders returned. Path: " + iPath);
|
||||
for (int vFolderIdx = 0; vFolderIdx < vActual.Length; vFolderIdx++)
|
||||
Assert.AreEqual(iExpected[vFolderIdx], vActual[vFolderIdx], string.Format("Wrong folder. Path: {0}, Index: {1}", iPath, vFolderIdx.ToString()));
|
||||
}
|
||||
|
||||
protected void TestFixRootPath(string iCorrectPath, string iPathToFix, string iExpected)
|
||||
{
|
||||
try
|
||||
{
|
||||
string vActual = PathUtils.FixRootPath(iCorrectPath, iPathToFix);
|
||||
Assert.AreEqual(iExpected, vActual, GetPathsMessage(iCorrectPath, iPathToFix));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DoFail(e.Message, iCorrectPath, iPathToFix);
|
||||
}
|
||||
}
|
||||
|
||||
protected void TestFixRootPath(string iBasePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
string vRootPath = "";
|
||||
if (iBasePath != "")
|
||||
vRootPath = Path.GetPathRoot(iBasePath).TrimEnd(Path.DirectorySeparatorChar);
|
||||
TestFixRootPath(iBasePath, @"\temp2", vRootPath + @"\temp2");
|
||||
TestFixRootPath(iBasePath, @"d:\temp2", @"d:\temp2");
|
||||
TestFixRootPath(iBasePath, @"temp2", @"temp2");
|
||||
TestFixRootPath(iBasePath, @"", @"");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DoFail(e.Message, iBasePath, "<unknown>");
|
||||
}
|
||||
}
|
||||
|
||||
protected void TestCombine(string iBasePath, string iAddedPath, string iExpected, bool iShouldFail)
|
||||
{
|
||||
string vActual = "";
|
||||
try
|
||||
{
|
||||
vActual = PathUtils.Combine(iBasePath, iAddedPath);
|
||||
if (iShouldFail)
|
||||
DoFail("Exception should be raised, while it wasn't", iBasePath, iAddedPath);
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
if (!iShouldFail)
|
||||
DoFail("Exception was raised while it shouldn't. " + e.Message, iBasePath, iAddedPath);
|
||||
else
|
||||
return;
|
||||
}
|
||||
Assert.AreEqual(iExpected, vActual, GetPathsMessage(iBasePath, iAddedPath));
|
||||
}
|
||||
|
||||
protected void TestCombine(string iBasePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
string vBasePath = PathUtils.AddEndingDirectorySeparator(iBasePath);
|
||||
TestCombine(iBasePath, @"c:\", @"c:\", iBasePath != "");
|
||||
TestCombine(iBasePath, @"c:\temp", @"c:\temp", iBasePath != "");
|
||||
TestCombine(iBasePath, @"c:", @"c:", iBasePath != "");
|
||||
TestCombine(iBasePath, @"\temp", vBasePath + @"temp", false);
|
||||
TestCombine(iBasePath, @"temp", vBasePath + @"temp", false);
|
||||
TestCombine(iBasePath, @"\", vBasePath, false);
|
||||
TestCombine(iBasePath, @"", vBasePath, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DoFail(e.Message, iBasePath, "");
|
||||
}
|
||||
}
|
||||
|
||||
protected void TestRemoveEndingDirectorySeparator(string iPath, string iExpected)
|
||||
{
|
||||
string vActual = PathUtils.RemoveEndingDirectorySeparator(iPath);
|
||||
Assert.AreEqual(iExpected, vActual, "Test value: " + iPath);
|
||||
}
|
||||
|
||||
protected void TestAddEndingDirectorySeparator(string iPath, string iExpected)
|
||||
{
|
||||
string vActual = PathUtils.AddEndingDirectorySeparator(iPath);
|
||||
Assert.AreEqual(iExpected, vActual, "Test value: " + iPath);
|
||||
}
|
||||
|
||||
protected void TestAddEndingDirectorySeparator_List(IList<string> iPaths, IList<string> iExpected)
|
||||
{
|
||||
IList<string> vActual = PathUtils.AddEndingDirectorySeparator(iPaths);
|
||||
CompareLists(vActual, iExpected, "");
|
||||
}
|
||||
|
||||
protected void TestHaveSameRoots(string iLeftPath, string iRightPath, bool iExpected)
|
||||
{
|
||||
bool vActual = PathUtils.HaveSameRoots(iLeftPath, iRightPath);
|
||||
Assert.AreEqual(iExpected, vActual, "Left path: " + iLeftPath + "; Right path: " + iRightPath);
|
||||
}
|
||||
|
||||
protected void TestGetFirstDifferentFolderIdx(string[] iLeftFolders, string[] iRightFolders, int iExpected)
|
||||
{
|
||||
int vActual = PathUtils.GetFirstDifferentFolderIdx(iLeftFolders, iRightFolders);
|
||||
Assert.AreEqual(iExpected, vActual);
|
||||
}
|
||||
|
||||
protected void TestIsValidPath(string iPath, bool iExpected, string iErrorMsg)
|
||||
{
|
||||
bool vActual = PathUtils.IsValidPath(iPath);
|
||||
Assert.AreEqual(iExpected, vActual, "Path was recognized incorrectly. " + iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestRemoveInvalidPaths(IList<string> iPaths, IList<string> iExpected)
|
||||
{
|
||||
IList<string> vActual = PathUtils.RemoveInvalidPaths(iPaths);
|
||||
Assert.AreEqual(iExpected.Count, vActual.Count, "Wrong no. of items was returned");
|
||||
for (int vItemIdx = 0; vItemIdx < vActual.Count; vItemIdx++)
|
||||
Assert.AreEqual(iExpected[vItemIdx], vActual[vItemIdx], "Paths are different. Index: " + vItemIdx.ToString());
|
||||
}
|
||||
|
||||
protected void TestNormalize(IList<string> iPaths, IList<string> iExpected)
|
||||
{
|
||||
IList<string> vActual = PathUtils.Normalize(iPaths);
|
||||
CompareLists(vActual, iExpected, "");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void ConcatFolders_StartOn1st()
|
||||
{
|
||||
TestConcatFolders(0, new string[] { "folder1" }, @"folder1\");
|
||||
TestConcatFolders(0, new string[] { "folder1", "folder2" }, @"folder1\folder2\");
|
||||
TestConcatFolders(0, new string[] { "folder1", "folder2", @"folder3\" }, @"folder1\folder2\folder3\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConcatFolders_StartOn2nd()
|
||||
{
|
||||
TestConcatFolders(1, new string[] { "folder1" }, @"");
|
||||
TestConcatFolders(1, new string[] { "folder1", "folder2" }, @"folder2\");
|
||||
TestConcatFolders(1, new string[] { "folder1", "folder2", @"folder3\" }, @"folder2\folder3\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConcatFolders_StartOn3rd()
|
||||
{
|
||||
TestConcatFolders(2, new string[] { "folder1" }, @"");
|
||||
TestConcatFolders(2, new string[] { "folder1", "folder2" }, @"");
|
||||
TestConcatFolders(2, new string[] { "folder1", "folder2", @"folder3\" }, @"folder3\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConcatFolders_InvalidIndex()
|
||||
{
|
||||
TestConcatFolders(-1, new string[] { "folder1", "folder2" }, @"");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuildGoUpPath()
|
||||
{
|
||||
TestBuildGoUpPath(-1, @"");
|
||||
TestBuildGoUpPath(0, @"");
|
||||
TestBuildGoUpPath(1, @"..\");
|
||||
TestBuildGoUpPath(2, @"..\..\");
|
||||
TestBuildGoUpPath(3, @"..\..\..\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SplitPaths()
|
||||
{
|
||||
TestSplitPaths(@"temp1", new string[] { "temp1" });
|
||||
TestSplitPaths(@"temp1\temp2", new string[] { "temp1", "temp2" });
|
||||
TestSplitPaths(@"c:\temp1\temp2", new string[] { "c:", "temp1", "temp2" });
|
||||
TestSplitPaths(@"c:\temp1\temp2\", new string[] { "c:", "temp1", "temp2", "" });
|
||||
TestSplitPaths(@"\temp1\temp2\", new string[] { "", "temp1", "temp2", "" });
|
||||
TestSplitPaths(@"\temp1\temp2", new string[] { "", "temp1", "temp2" });
|
||||
TestSplitPaths(@"", new string[] { });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FixRootPath()
|
||||
{
|
||||
TestFixRootPath(@"c:\");
|
||||
TestFixRootPath(@"temp1");
|
||||
TestFixRootPath(@"\temp1");
|
||||
TestFixRootPath(@"");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Combine()
|
||||
{
|
||||
TestCombine(@"c:\");
|
||||
TestCombine(@"c:\temp1");
|
||||
TestCombine(@"c:");
|
||||
TestCombine(@"\temp1");
|
||||
TestCombine(@"temp1");
|
||||
TestCombine(@"\");
|
||||
TestCombine(@"");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveEndingDirectorySeparator()
|
||||
{
|
||||
TestRemoveEndingDirectorySeparator(@"c:\", @"c:\");
|
||||
TestRemoveEndingDirectorySeparator(@"c:\temp", @"c:\temp");
|
||||
TestRemoveEndingDirectorySeparator(@"c:\temp\", @"c:\temp");
|
||||
TestRemoveEndingDirectorySeparator(@"\", @"\");
|
||||
TestRemoveEndingDirectorySeparator(@"", @"");
|
||||
TestRemoveEndingDirectorySeparator(@"\temp\", @"\temp");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddEndingDirectorySeparator()
|
||||
{
|
||||
TestAddEndingDirectorySeparator(@"c:\temp", @"c:\temp\");
|
||||
TestAddEndingDirectorySeparator(@"c:\", @"c:\");
|
||||
TestAddEndingDirectorySeparator(@"c:\temp\", @"c:\temp\");
|
||||
TestAddEndingDirectorySeparator(@"\", @"\");
|
||||
TestAddEndingDirectorySeparator(@"", @"");
|
||||
TestAddEndingDirectorySeparator(@"c:", @"c:\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddEndingDirectorySeparator_List()
|
||||
{
|
||||
TestAddEndingDirectorySeparator_List(
|
||||
new string[] {@"c:\temp", @"c:\", @"c:\temp\", @"\", "", "c:"},
|
||||
new string[] {@"c:\temp\", @"c:\", @"c:\temp\", @"\", "", @"c:\"});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HaveSameRoots()
|
||||
{
|
||||
TestHaveSameRoots(@"c:\", @"c:\temp", true);
|
||||
TestHaveSameRoots(@"c:\", @"c:\", true);
|
||||
TestHaveSameRoots(@"c:\Temp\", @"c:\temp", true);
|
||||
TestHaveSameRoots(@"\temp", @"\temp2", true);
|
||||
TestHaveSameRoots(@"\", @"\", true);
|
||||
TestHaveSameRoots(@"c:\", @"d:\", false);
|
||||
TestHaveSameRoots(@"c:\temp", @"d:\temp", false);
|
||||
TestHaveSameRoots(@"\temp", @"c:\temp", false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFirstDifferentFolderIdx()
|
||||
{
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] {"folder1", "folder2", "folder3"},
|
||||
new string[] {"folder1", "folder2", "folder5"},
|
||||
2);
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] { "folder1" },
|
||||
new string[] { "folder2" },
|
||||
0);
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] { "folder1", "folder2" },
|
||||
new string[] { "folder1", "folder2", "folder3", "folder4" },
|
||||
2);
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] { "folder1", "folder2", "folder3", "folder4" },
|
||||
new string[] { "folder1", "folder2" },
|
||||
2);
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] { "folder1", "folder2" },
|
||||
new string[] { "folder1", "folder2" },
|
||||
2);
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] { "folder1" },
|
||||
new string[] { "folder1" },
|
||||
1);
|
||||
TestGetFirstDifferentFolderIdx(
|
||||
new string[] { },
|
||||
new string[] { },
|
||||
0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsValidPath()
|
||||
{
|
||||
TestIsValidPath(@"C:\", true, "Test 1");
|
||||
TestIsValidPath(@"C:\Windows", true, "Test 2");
|
||||
TestIsValidPath(@"C:\Windows\", true, "Test 3");
|
||||
TestIsValidPath(@"C:\1234", false, "Test 4");
|
||||
TestIsValidPath(@"C:\Windows\abc123", false, "Test 5");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveInvalidPaths()
|
||||
{
|
||||
TestRemoveInvalidPaths(
|
||||
new string[] {@"C:\", @"c:\12345", @"C:\windows", @"c:\windows\abc123", @"C:\windows\", @"c:\1234\abc"},
|
||||
new string[] {@"C:\", @"C:\windows", @"C:\windows\"});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Normalize()
|
||||
{
|
||||
TestNormalize(
|
||||
new string[] {@"C:\WINDOWS", null, @"C:\", @"", @"C:\123abc", @"C:\windows", @"c:\windows\", @"", @"c:\windows\123abc\", null},
|
||||
new string[] {@"c:\", @"c:\windows\"}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
|
||||
using DelphiProjectHandler.Dialogs;
|
||||
|
||||
namespace DelphiProjectHandler.Tests.Utils
|
||||
{
|
||||
[TestFixture]
|
||||
public class RelativePathClassTests
|
||||
{
|
||||
#region (Test methods)
|
||||
|
||||
protected string GetTestFailMessage(string iBasePath, string iPath)
|
||||
{
|
||||
return string.Format("Base path: {0}, Destination path: {1}", iBasePath, iPath);
|
||||
}
|
||||
|
||||
protected void DoGetRelativePath(string iBasePath, string iPath, string iExpected)
|
||||
{
|
||||
try
|
||||
{
|
||||
string vActual = RelativePath.GetRelativePath(iBasePath, iPath);
|
||||
Assert.AreEqual(iExpected, vActual, GetTestFailMessage(iBasePath, iPath));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.Fail(e.Message + "; " + GetTestFailMessage(iBasePath, iPath));
|
||||
}
|
||||
}
|
||||
|
||||
protected void DoGetRelativePath(string iBasePath, string iPath)
|
||||
{
|
||||
DoGetRelativePath(iBasePath, iPath, iPath);
|
||||
}
|
||||
|
||||
protected void DoGetRelativeFileName(bool iRelativeToPath, string iBaseFileName, string iFileName, string iExpected)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (iRelativeToPath)
|
||||
iBaseFileName = PathUtils.AddEndingDirectorySeparator(Path.GetDirectoryName(iBaseFileName));
|
||||
|
||||
string vActual = RelativePath.GetRelativeFileName(iBaseFileName, iFileName);
|
||||
Assert.AreEqual(iExpected, vActual, GetTestFailMessage(iBaseFileName, iFileName));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Assert.Fail(e.Message + "; " + GetTestFailMessage(iBaseFileName, iFileName));
|
||||
}
|
||||
}
|
||||
|
||||
protected void DoGetRelativeFileName(bool iToBasePath, string iBaseFileName, string iFileName)
|
||||
{
|
||||
DoGetRelativeFileName(iToBasePath, iBaseFileName, iFileName, iFileName);
|
||||
}
|
||||
|
||||
protected void DoGetRelativeFileNameByFolder(string iBaseFolder, string iFileName, string iExpected)
|
||||
{
|
||||
string vActual = RelativePath.GetRelativeFilenameByFolder(iBaseFolder, iFileName);
|
||||
Assert.AreEqual(iExpected, vActual, GetTestFailMessage(iBaseFolder, iFileName));
|
||||
}
|
||||
|
||||
protected void DoGetRelativeFileNameByFolder(string iBaseFolder, string iFileName)
|
||||
{
|
||||
DoGetRelativeFileNameByFolder(iBaseFolder, iFileName, iFileName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void GetRelativePath_DifferentRoots()
|
||||
{
|
||||
DoGetRelativePath(@"c:\windows\temp", @"d:\windows\temp\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativePath_Rooted_NotRooted()
|
||||
{
|
||||
DoGetRelativePath(@"c:\windows\temp", @"windows\temp\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativePath_Rooted()
|
||||
{
|
||||
DoGetRelativePath(@"c:\Windows\temp", @"c:\windows\temp\folder1\folder2", @"folder1\folder2\");
|
||||
DoGetRelativePath(@"c:\windows\temp\folder1\folder2", @"c:\windows\temp\", @"..\..\");
|
||||
DoGetRelativePath(@"c:\windows\temp\folder1\folder2", @"c:\windows\temp\folder3\folder4", @"..\..\folder3\folder4\");
|
||||
DoGetRelativePath(@"c:\windows\temp\", "", @"c:\windows\temp\");
|
||||
DoGetRelativePath(@"c:\windows\temp", @"c:\windows\temp", "");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativePath_Rooted_RootFolder()
|
||||
{
|
||||
DoGetRelativePath(@"c:\windows\temp", @"\windows\temp\folder1\folder2", @"folder1\folder2\");
|
||||
DoGetRelativePath(@"c:\windows\temp\folder1\folder2", @"\windows\temp\", @"..\..\");
|
||||
DoGetRelativePath(@"c:\windows\temp\folder1\folder2", @"\windows\temp\folder3\folder4", @"..\..\folder3\folder4\");
|
||||
DoGetRelativePath(@"c:\windows\temp\", @"\", @"..\..\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativePath_NotRooted()
|
||||
{
|
||||
DoGetRelativePath(@"Windows\temp", @"windows\temp\folder1\folder2", @"folder1\folder2\");
|
||||
DoGetRelativePath(@"windows\temp\folder1\folder2", @"windows\temp\", @"..\..\");
|
||||
DoGetRelativePath(@"windows\temp\folder1\folder2", @"windows\temp\folder3\folder4", @"..\..\folder3\folder4\");
|
||||
DoGetRelativePath(@"windows\temp\", "", @"windows\temp\");
|
||||
DoGetRelativePath(@"windows\temp", @"windows\temp", "");
|
||||
|
||||
DoGetRelativePath(@"\windows\temp", @"c:\windows\temp\folder1\folder2", @"folder1\folder2\");
|
||||
DoGetRelativePath(@"\windows\temp\folder1\folder2", @"c:\windows\temp\", @"..\..\");
|
||||
DoGetRelativePath(@"\windows\temp\folder1\folder2", @"c:\windows\temp\folder3\folder4", @"..\..\folder3\folder4\");
|
||||
DoGetRelativePath(@"\windows\temp\", "", @"\windows\temp\");
|
||||
DoGetRelativePath(@"\windows\temp", @"c:\windows\temp", "");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativePath_NotRooted_Rooted()
|
||||
{
|
||||
DoGetRelativePath(@"windows\temp", @"c:\windows\temp\folder1\folder2\");
|
||||
DoGetRelativePath(@"windows\temp\folder1\folder2", @"c:\windows\temp\");
|
||||
DoGetRelativePath(@"windows\temp\folder1\folder2", @"c:\windows\temp\folder3\folder4\");
|
||||
DoGetRelativePath(@"windows\temp\", "", @"windows\temp\");
|
||||
DoGetRelativePath(@"windows\temp", @"c:\windows\temp\");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativeFileName_DifferentRoots()
|
||||
{
|
||||
for (int vIdx = 0; vIdx <= 1; vIdx++)
|
||||
{
|
||||
bool vToBasePath = Convert.ToBoolean(vIdx);
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", @"d:\windows\temp\file2.txt");
|
||||
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", @"windows\temp\file2.txt");
|
||||
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", @"c:\windows\temp\folder1\folder2\file2.txt", @"folder1\folder2\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\folder1\folder2\file1.txt", @"c:\windows\temp\file2.txt", @"..\..\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\folder1\folder2\file1.txt", @"c:\windows\temp\folder3\folder4\file2.txt", @"..\..\folder3\folder4\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", "file2.txt", @"c:\windows\temp\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", @"c:\windows\temp\file2.txt", "file2.txt");
|
||||
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", @"\windows\temp\folder1\folder2\file2.txt", @"folder1\folder2\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\folder1\folder2\file1.txt", @"\windows\temp\file2.txt", @"..\..\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\folder1\folder2\file1.txt", @"\windows\temp\folder3\folder4\file2.txt", @"..\..\folder3\folder4\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"c:\windows\temp\file1.txt", @"\file2.txt", @"..\..\file2.txt");
|
||||
|
||||
DoGetRelativeFileName(vToBasePath, @"\windows\temp\file1.txt", @"c:\windows\temp\folder1\folder2\file2.txt", @"folder1\folder2\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"\windows\temp\folder1\folder2\file1.txt", @"c:\windows\temp\file2.txt", @"..\..\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"\windows\temp\folder1\folder2\file1.txt", @"c:\windows\temp\folder3\folder4\file2.txt", @"..\..\folder3\folder4\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"\windows\temp\file1.txt", @"c:\windows\temp\file2.txt", "file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"\windows\temp\file1.txt", "file2.txt", @"\windows\temp\file2.txt");
|
||||
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\file1.txt", @"windows\temp\folder1\folder2\file2.txt", @"folder1\folder2\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\folder1\folder2\file1.txt", @"windows\temp\file2.txt", @"..\..\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\folder1\folder2\file1.txt", @"windows\temp\folder3\folder4\file2.txt", @"..\..\folder3\folder4\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\file1.txt", "file2.txt", @"windows\temp\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\file1.txt", @"windows\temp\file2.txt", "file2.txt");
|
||||
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\file1.txt", @"c:\windows\temp\folder1\folder2\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\folder1\folder2\file1.txt", @"c:\windows\temp\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\folder1\folder2\file1.txt", @"c:\windows\temp\folder3\folder4\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\file1.txt", "file2.txt", @"windows\temp\file2.txt");
|
||||
DoGetRelativeFileName(vToBasePath, @"windows\temp\file1.txt", @"c:\windows\temp\file2.txt");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsPathRooted()
|
||||
{
|
||||
Assert.IsTrue(Path.IsPathRooted(@"c:\temp"), @"c:\temp");
|
||||
Assert.IsTrue(Path.IsPathRooted(@"c:\"), @"c:\");
|
||||
Assert.IsTrue(Path.IsPathRooted(@"c:"), @"c:");
|
||||
Assert.IsTrue(Path.IsPathRooted(@"\temp"), @"\temp");
|
||||
Assert.IsFalse(Path.IsPathRooted(@"temp"), @"temp");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativeFileName()
|
||||
{
|
||||
DoGetRelativeFileName(false, @"c:\Temp\folder1\folder2\filename1.txt", @"c:\temp\folder1\filename2.txt", @"..\filename2.txt");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetRelativeFileNameByFolder()
|
||||
{
|
||||
DoGetRelativeFileNameByFolder(@"c:\Temp\folder1\folder2", @"c:\temp\filename1.txt", @"..\..\filename1.txt");
|
||||
DoGetRelativeFileNameByFolder(@"", @"c:\temp\filename1.txt");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Created by SharpDevelop.
|
||||
* User: SG0894652
|
||||
* Date: 8/10/2009
|
||||
* Time: 9:20 PM
|
||||
*
|
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
|
||||
using DelphiProjectHandler.Dialogs;
|
||||
|
||||
namespace DelphiProjectHandler.Tests.Utils
|
||||
{
|
||||
[TestFixture]
|
||||
public class StringListUtilsTests
|
||||
{
|
||||
#region (Test methods)
|
||||
|
||||
protected void CompareLists(IList<string> iActual, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
Assert.AreEqual(iExpected.Count, iActual.Count, "Different no. of items returned.");
|
||||
for (int vItemIdx = 0; vItemIdx < iActual.Count; vItemIdx++)
|
||||
Assert.AreEqual(iExpected[vItemIdx], iActual[vItemIdx], "Different items found. Item: " + vItemIdx.ToString() + ". " + iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestRemoveEmpty(IList<string> iStrings, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<string> vActual = StringListUtils.RemoveEmpty(iStrings);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestToLower(IList<string> iStrings, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<string> vActual = StringListUtils.ToLower(iStrings);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestToUpper(IList<string> iStrings, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<string> vActual = StringListUtils.ToUpper(iStrings);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestRemoveDuplicates(IList<string> iStrings, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<string> vActual = StringListUtils.RemoveDuplicates(iStrings);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestNormalize(IList<string> iStrings, IList<string> iExpected, string iErrorMsg)
|
||||
{
|
||||
IList<string> vActual = StringListUtils.Normalize(iStrings);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
protected void TestSort(IList<string> iStrings, IList<string> iExpected, bool iAscending, bool iIgnoreCase, string iErrorMsg)
|
||||
{
|
||||
IList<string> vActual = StringListUtils.Sort(iStrings, iAscending, iIgnoreCase);
|
||||
CompareLists(vActual, iExpected, iErrorMsg);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Test]
|
||||
public void RemoveEmpty()
|
||||
{
|
||||
TestRemoveEmpty(
|
||||
new string[] {"", "1", " ", "2", " ", "3 ", null, "4", null, "5"},
|
||||
new string[] {"1", "2", "3 ", "4", "5"}, "Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToLower()
|
||||
{
|
||||
TestToLower(
|
||||
new string[] {"ABC", null, "DeF", "", "ghi"},
|
||||
new string[] {"abc", null, "def", "", "ghi"}, "Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToUpper()
|
||||
{
|
||||
TestToUpper(
|
||||
new string[] {"ABC", null, "DeF", "", "ghi"},
|
||||
new string[] {"ABC", null, "DEF", "", "GHI"}, "Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Normalize()
|
||||
{
|
||||
TestNormalize(
|
||||
new string[] {"ABC", null, "DeF", "", "ghi", "abc", "def", "", "ghi", null},
|
||||
new string[] {"abc", "def", "ghi"}, "Test 1"
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveDuplicates()
|
||||
{
|
||||
TestRemoveDuplicates(
|
||||
new string[] {"123", "234", "345", "abc", "def", "ghi", "123", "234", "345", "abc", "def", "ghi", "123", "234", "345", "abc", "def", "ghi", null, null},
|
||||
new string[] {"123", "234", "345", "abc", "def", "ghi", null}, "Test 2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Sort()
|
||||
{
|
||||
TestSort(
|
||||
new string[] {"g", "f", "e", "d", "c", "b", "a", "G", "F", "E", "D", "C", "B", "A"},
|
||||
new string[] {"A", "a", "b", "B", "C", "c", "D", "d", "E", "e", "f", "F", "g", "G"},
|
||||
true, true, "Test 1"
|
||||
);
|
||||
|
||||
TestSort(
|
||||
new string[] {"A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g"},
|
||||
new string[] {"G", "g", "F", "f", "E", "e", "d", "D", "C", "c", "B", "b", "A", "a"},
|
||||
false, true, "Test 2"
|
||||
);
|
||||
|
||||
TestSort(
|
||||
new string[] {"g", "f", "e", "d", "c", "b", "a", "G", "F", "E", "D", "C", "B", "A"},
|
||||
new string[] {"a", "A", "b", "B", "c", "C", "d", "D", "e", "E", "f", "F", "g", "G"},
|
||||
true, false, "Test 3"
|
||||
);
|
||||
|
||||
TestSort(
|
||||
new string[] {"A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g"},
|
||||
new string[] {"G", "g", "F", "f", "E", "e", "D", "d", "C", "c", "B", "b", "A", "a"},
|
||||
false, false, "Test 4"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user