Initial import

This commit is contained in:
mlemanczyk committed 2012-09-24 20:55:07 +02:00
1 parent ea3f8549e4
commit fa6feafba7
133 files changed
+17503 -4

No files matched your search

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DelphiProjectHandler.Model;
using DelphiProjectHandler.Operations;
using System.IO;
namespace DelphiProjectHandler.Tests
{
[TestFixture]
public class BulkOperationLoaderTests
{
protected const string cXml =
@"<?xml version=""1.0"" encoding=""UTF-8""?>" +
@"<projects>" +
@" <project name=""c:\source\fpm\dpr\Murte2mm.dpr"">" +
@" <remove>" +
@" <file>c:\source\fpm\u\Utils\RteSegsUtils.pas</file>" +
@" <file>c:\source\fpm\u\Utils\NextDataRefreshTimeState.pas</file>" +
@" </remove>" +
@" <add>" +
@" <file>c:\source\fpm\u\Utils\AbsoluteIdUtils.pas</file>" +
@" <file>c:\source\fpm\u\Utils\CycleDateState.pas</file>" +
@" </add>" +
@" </project>" +
@" <project name=""c:\source\fpm\dpr\Code.dpr"">" +
@" <remove>" +
@" <file>c:\source\fpm\u\Utils\AbsoluteIdUtils.pas</file>" +
@" </remove>" +
@" <add>" +
@" <file>c:\source\fpm\u\IO\CodeTableInterface.pas</file>" +
@" <file>c:\source\fpm\u\IO\CodeTable.pas</file>" +
@" </add>" +
@" </project>" +
@"</projects>";
[Test]
public void Load()
{
Stream vMemoryStream = new MemoryStream();
TextWriter vWriter = new StreamWriter(vMemoryStream);
vWriter.Write(cXml);
vWriter.Flush();
vMemoryStream.Position = 0;
ProjectBulkOperations vOperations = ProjectBulkOperationLoader.FromStream(vMemoryStream);
Assert.AreEqual(2, vOperations.Count, "Invalid no. of projects read");
Assert.AreEqual(2, vOperations[0].Add.Count, "Invalid no. of files to add - Project 0");
Assert.AreEqual(2, vOperations[1].Add.Count, "Invalid no. of files to add - Project 1");
Assert.AreEqual(2, vOperations[0].Remove.Count, "Invalid no. of files to remove - Project 0");
Assert.AreEqual(1, vOperations[1].Remove.Count, "Invalid no. of files to remove - Project 1");
Assert.AreEqual(@"c:\source\fpm\u\Utils\RteSegsUtils.pas", vOperations[0].Remove[0], "Wrong file to remove. Project 0, Item 0");
Assert.AreEqual(@"c:\source\fpm\u\Utils\NextDataRefreshTimeState.pas", vOperations[0].Remove[1], "Wrong file to remove. Project 0, Item 1");
Assert.AreEqual(@"c:\source\fpm\u\Utils\AbsoluteIdUtils.pas", vOperations[0].Add[0], "Wrong file to add. Project 0, Item 0");
Assert.AreEqual(@"c:\source\fpm\u\Utils\CycleDateState.pas", vOperations[0].Add[1], "Wrong file to add. Project 0, Item 1");
Assert.AreEqual(@"c:\source\fpm\u\Utils\AbsoluteIdUtils.pas", vOperations[1].Remove[0], "Wrong file to remove. Project 1, Item 0");
Assert.AreEqual(@"c:\source\fpm\u\IO\CodeTableInterface.pas", vOperations[1].Add[0], "Wrong file to add. Project 1, Item 0");
Assert.AreEqual(@"c:\source\fpm\u\IO\CodeTable.pas", vOperations[1].Add[1], "Wrong file to add. Project 1, Item 1");
}
}
}
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C5750BD9-B5F5-49D4-BE26-5883BFA2894F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DelphiProjectHandler.Tests</RootNamespace>
<AssemblyName>DelphiProjectHandler.Tests</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<StartupObject>
</StartupObject>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\..\..\Program Files\TestDriven.NET 3\NUnit\2.5\framework\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BulkOperationLoaderTests.cs" />
<Compile Include="DelphiUnitCleanerOperationTests.cs" />
<Compile Include="IcarusAnalyzerTests.cs" />
<Compile Include="LibraryPaths\ClipboardLibraryPathsProviderTests.cs" />
<Compile Include="LibraryPaths\DelphiLibraryPathBuilderTests.cs" />
<Compile Include="LibraryPaths\DelphiLibraryPathProviderTests.cs" />
<Compile Include="LibraryPaths\DelphiRegistryKeysTests.cs" />
<Compile Include="LibraryPaths\LibraryPathProviderFactoryTests.cs" />
<Compile Include="Utils\RelativePathClassTests.cs" />
<Compile Include="SourceControl\SourceOffsiteClassTests.cs" />
<Compile Include="TestsRunner.cs" />
<Compile Include="UnitFormReaderClassTests.cs" />
<Compile Include="UnitItemClassTests.cs" />
<Compile Include="UnitListClassTests.cs" />
<Compile Include="UsesClauseReaderClassTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\MethodRunnerClass.cs" />
<Compile Include="Utilities\MethodRunnerClassTests.cs" />
<Compile Include="Utils\ListUtilsTests.cs" />
<Compile Include="Utils\PathUtilsClassTests.cs" />
<Compile Include="Utils\StringListUtilsTests.cs" />
<Content Include="ProfilingSessions\Session20090809_153225.sdps" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DelphiProjectHandler\DelphiProjectHandler.csproj">
<Project>{5C84FFF1-2B72-440F-A36D-7D411CF7AE61}</Project>
<Name>DelphiProjectHandler</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,360 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/11/2009
* Time: 2:41 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using NUnit.Framework;
using DelphiProjectHandler;
namespace DelphiProjectHandler.Tests
{
[TestFixture]
public class IcarusAnalyzerTests
{
protected void CompareUnitCount(SuggestedUnitStructure iList, int iExpectedInterface, int iExpectedImplementation, int iExpectedMovedCount, int iExpectedDeletedCount, string iErrorMsg)
{
Assert.AreEqual(iExpectedInterface, iList.Uses.Interface.Count, "Invalid no. of returned interface units. " + iErrorMsg);
Assert.AreEqual(iExpectedImplementation, iList.Uses.Implementation.Count, "Invalid no. of returned implementation units. " + iErrorMsg);
Assert.AreEqual(iExpectedMovedCount, iList.MoveToInterface.Count, "Invalid no. of units moved to implementation. " + iErrorMsg);
Assert.AreEqual(iExpectedDeletedCount, iList.ToDelete.Count, "Invalid no. of deleted units. " + iErrorMsg);
}
[Test]
public void Parse()
{
#region (Test value)
const string cReport =
"****************************************************************************\r\n" +
"* Uses Report for *\r\n" +
"* D:\\DM\\SG894652_MAIN_CCRC\\DISPMGR\\DPR\\ACARSAPI.DPR *\r\n" +
"* 8/11/2009 1:21:21 AM *\r\n" +
"****************************************************************************\r\n" +
"\r\n" +
"Usage:\r\n" +
"----------------------------------------------------------------------------\r\n" +
"\r\n" +
"Module AbsoluteIdUtils uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" SysUtils in implementation (has initialization, used by unit with init)\r\n" +
" StrUtils in implementation (used by unit with init)\r\n" +
" gdeclare in implementation (has initialization, used by unit with init)\r\n" +
" DBStatusCodes in implementation (used by unit with init)\r\n" +
" Aptio in implementation (has initialization, used by unit with init)\r\n" +
" Navio in implementation (used by unit with init)\r\n" +
" Wptio in implementation (used by unit with init)\r\n" +
"\r\n" +
"Module AbstractCacheStreamerClass uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" --> SqlCacheUtils in implementation (used by unit with init)\r\n" +
" Logger in interface (has initialization, used by unit with init)\r\n" +
" ==> DBUNIT unnecessary (has initialization, used by unit with init)\r\n" +
" ConnectionInfoClass in interface (used by unit with init)\r\n" +
" --> DatabaseQueryFactoryClass in implementation (used by unit with init)\r\n" +
"\r\n" +
"Module AbstractCacheStreamerClass uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" Windows source not found\r\n" +
" SysUtils in implementation (has initialization, used by unit with init)\r\n" +
" StrUtils in implementation (used by unit with init)\r\n" +
" ==> ActiveX unnecessary (used by unit with init)\r\n" +
" gdeclare in implementation (has initialization, used by unit with init)\r\n" +
" DBStatusCodes in implementation (used by unit with init)\r\n" +
" Aptio in implementation (has initialization, used by unit with init)\r\n" +
" Navio in implementation (used by unit with init)\r\n" +
" Wptio in implementation (used by unit with init)\r\n" +
"Module AbstractTable uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" SysUtils in implementation (has initialization, used by unit with init)\r\n" +
" LoggerCategories in implementation (used by unit with init)\r\n" +
"\r\n" +
"Library ACARSAPI uses:\r\n" +
"\r\n" +
" Used units:\r\n" +
"\r\n" +
" Windows source not found\r\n" +
" ==> Messages unnecessary (used by unit with init)\r\n" +
" SysUtils in implementation (has initialization, used by unit with init)\r\n" +
" Classes in implementation (has initialization, used by unit with init)\r\n" +
" Controls in implementation (has initialization, used by unit with init)\r\n" +
" Dialogs in implementation (has initialization, used by unit with init)\r\n" +
" ==> CommonTypes unnecessary (used by unit with init)\r\n" +
" DateTime in implementation (has initialization, used by unit with init)\r\n" +
" Mystd in implementation (used by unit with init)\r\n" +
" ==> DBUNIT unnecessary (has initialization, used by unit with init)\r\n" +
" CommonConsts in implementation (used by unit with init)\r\n" +
" GDeclare in implementation (has initialization, used by unit with init)\r\n" +
" CODEio in implementation (used by unit with init)\r\n" +
" ACWGTSio in implementation (used by unit with init)\r\n" +
" APTio in implementation (has initialization, used by unit with init)\r\n" +
" FltEdits in implementation (has initialization, used by unit with init)\r\n" +
" FSDLYio in implementation (has initialization, used by unit with init)\r\n" +
" oWait in implementation (used by unit with init)\r\n" +
" WINDEV in implementation (has initialization, used by unit with init)\r\n" +
"\r\n" +
"Note:\r\n" +
"Units that are marked as \"unnecessary\" in the project source\r\n" +
"are not needed in the main code block. However you would\r\n" +
"normally want to keep them listed anyway, because it tells\r\n" +
"the Delphi IDE that the unit belongs to the project.\r\n" +
"\r\n" +
"Module ActiveX uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" Windows source not found\r\n" +
" Messages in interface (used by unit with init)\r\n" +
"\r\n" +
"Module ActnList uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" Messages in interface (used by unit with init)\r\n" +
" Classes in interface (has initialization, used by unit with init)\r\n" +
" ==> Contnrs unnecessary (used by unit with init)\r\n" +
" ImgList in interface (used by unit with init)\r\n" +
"\r\n" +
"Module ActnList uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" Windows source not found\r\n" +
" SysUtils in implementation (has initialization, used by unit with init)\r\n" +
" ==> Graphics unnecessary (has initialization, used by unit with init)\r\n" +
" Consts in implementation (used by unit with init)\r\n" +
" Menus in implementation (has initialization, used by unit with init)\r\n" +
" Controls in implementation (has initialization, used by unit with init)\r\n" +
" Forms in implementation (has initialization, used by unit with init)\r\n" +
"\r\n" +
"Module ACWGTSBroker uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" --> SysUtils in implementation (has initialization, used by unit with init)\r\n" +
" --> Classes in implementation (has initialization, used by unit with init)\r\n" +
" Contnrs in interface (used by unit with init)\r\n" +
" QueryInterface in interface (used by unit with init)\r\n" +
" --> DatabaseQueryFactoryClass in implementation (used by unit with init)\r\n" +
" ==> DatabaseProviderFactoryClass unnecessary (has initialization, used by unit with init)\r\n" +
" AbstractQuery in interface (used by unit with init)\r\n" +
" ==> MetaTableAgentClass unnecessary (has initialization, used by unit with init)\r\n" +
" ACWGTSio in interface (used by unit with init)\r\n" +
" ==> oConsole unnecessary (used by unit with init)\r\n" +
" DMBaseBrokerClass in interface (used by unit with init)\r\n" +
" --> DMBaseSQLBrokerClass in implementation (used by unit with init)\r\n" +
" DMBaseArchSQLBrokerClass in interface (used by unit with init)\r\n" +
"\r\n" +
"Module ACWGTSBroker uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" ==> Datetime unnecessary (has initialization, used by unit with init)\r\n" +
" MyStd in implementation (used by unit with init)\r\n" +
" DBUNIT in implementation (has initialization, used by unit with init)\r\n" +
" CommonConsts in implementation (used by unit with init)\r\n" +
" DMGlobals in implementation (used by unit with init)\r\n" +
" gdeclare in implementation (has initialization, used by unit with init)\r\n" +
" ==> OracleKeywordClass unnecessary (has initialization, used by unit with init)\r\n" +
" ==> DMUtils unnecessary (used by unit with init)\r\n" +
" DMBtrvQueryFactory in implementation (has initialization, used by unit with init)\r\n" +
" DMSQLQueryFactory in implementation (has initialization, used by unit with init)\r\n" +
"\r\n" +
"Module WinSpool uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" Windows source not found\r\n" +
"\r\n" +
"Module WPTIO uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" --> Sysutils in implementation (has initialization, used by unit with init)\r\n" +
" --> MYSTD in implementation (used by unit with init)\r\n" +
" --> DBunit in implementation (has initialization, used by unit with init)\r\n" +
" GDeclare in interface (has initialization, used by unit with init)\r\n" +
" --> GEODESIC in implementation (used by unit with init)\r\n" +
"\r\n" +
"Module WPTIO uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" ==> CommonTypes unnecessary (used by unit with init)\r\n" +
" CommonConsts in implementation (used by unit with init)\r\n" +
" DMGlobals in implementation (used by unit with init)\r\n" +
" DBOperations in implementation (used by unit with init)\r\n" +
" CODEIO in implementation (used by unit with init)\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"\r\n" +
"Modules that are referenced in the Delphi project file, but not used:\r\n" +
"----------------------------------------------------------------------------\r\n" +
"\r\n" +
"CommonTypes (used by unit with init)\r\n" +
"DBUNIT (has initialization, used by unit with init)\r\n" +
"Messages (used by unit with init)\r\n" +
"\r\n" +
"Note:\r\n" +
"Units that are marked as \"unnecessary\" in the project source\r\n" +
"are not needed in the main code block. However you would\r\n" +
"normally want to keep them listed anyway, because it tells\r\n" +
"the Delphi IDE that the unit belongs to the project.\r\n" +
"\r\n" +
"\r\n" +
"Modules that are used but not added to the Delphi project file:\r\n" +
"----------------------------------------------------------------------------\r\n" +
"\r\n" +
" (none)\r\n" +
"\r\n" +
"\r\n" +
"References:\r\n" +
"----------------------------------------------------------------------------\r\n" +
"\r\n" +
"AbsoluteIdUtils references (7):\r\n" +
"\r\n" +
"Aptio, DBStatusCodes, gdeclare, Navio, StrUtils, SysUtils, Wptio\r\n" +
"\r\n" +
"AbsoluteIdUtils is referenced by (1):\r\n" +
"\r\n" +
"PTEdits\r\n" +
"\r\n" +
"Module CommDlg uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" Windows source not found\r\n" +
" Messages in interface (used by unit with init)\r\n" +
" ShlObj in interface (used by unit with init)\r\n" +
"\r\n" +
"Program COMMDRVR uses:\r\n" +
"\r\n" +
" Used units:\r\n" +
"\r\n" +
" ==> ShareMem unnecessary (has initialization)\r\n" +
" Forms in implementation (has initialization, used by unit with init)\r\n" +
" Logger in implementation (has initialization, used by unit with init)\r\n" +
" GDeclare in implementation (has initialization, used by unit with init)\r\n" +
" ==> DBUnit unnecessary (has initialization, used by unit with init)\r\n" +
" ==> oLOGDISP unnecessary\r\n" +
" oLOGCONS in implementation (used by unit with init)\r\n" +
" oCOMMLNK in implementation\r\n" +
" oCOMMCTL in implementation (used by unit with init)\r\n" +
" ==> MessageTypeRecognizer unnecessary (used by unit with init)\r\n" +
" ==> GDCL_ALL unnecessary (has initialization, used by unit with init)\r\n" +
" BasAbout in implementation\r\n" +
" ==> HelpInvoker unnecessary (used by unit with init)\r\n" +
" ==> ComCreator unnecessary\r\n" +
" ==> AppLauncherInterface unnecessary\r\n" +
" ==> AppLauncher unnecessary\r\n" +
" ==> RegSvr32Launcher unnecessary\r\n" +
" ==> ComObjectLibrary unnecessary (has initialization)\r\n" +
" ==> ComCreatorGuiInstallApproval unnecessary\r\n" +
" ==> DefaultWebBrowserLauncher unnecessary\r\n" +
" ==> UIGlobal unnecessary (has initialization)\r\n" +
" oSKEDLST in implementation\r\n" +
" oCDMet in implementation\r\n" +
" ==> oCDStart unnecessary\r\n" +
" ==> SMI unnecessary (has initialization, used by unit with init)\r\n" +
" ==> Notamio unnecessary (used by unit with init)\r\n" +
" ==> NotamBroker unnecessary (has initialization)\r\n" +
" ==> oFWAPSAlert unnecessary (has initialization)\r\n" +
" ==> OPMSGio unnecessary (used by unit with init)\r\n" +
" ==> EramMessageProcessorInterface unnecessary (used by unit with init)\r\n" +
" ==> EramRejectCNLProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramFDRelFinder unnecessary\r\n" +
" ==> EramCNLAckProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramMessageProcessor unnecessary (has initialization)\r\n" +
" ==> EramFPLAckProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramRejectFPLProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramCHGAckProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramDEPAckProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramDLAAckProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramRejectDEPProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramRejectDLAProcessor unnecessary (used by unit with init)\r\n" +
" ==> EramRejectCHGProcessor unnecessary (used by unit with init)\r\n" +
" ==> ERAMConfiguration unnecessary\r\n" +
" ==> FunctionalityProvider unnecessary (has initialization, used by unit with init)\r\n" +
" ==> FlightWxImagesFunctionality unnecessary (has initialization)\r\n" +
" ==> NOTAMContinuityAlerterTypes unnecessary\r\n" +
" ==> NOTAMserialNumberAlerterCSN unnecessary\r\n" +
" ==> NOTAMContinuityCheckRequester unnecessary\r\n" +
" ==> NOTAMContinuityLogger unnecessary\r\n" +
" ==> NOTAMCheckFacility unnecessary\r\n" +
" ==> WsiFileTypes unnecessary (used by unit with init)\r\n" +
" ==> ErrorsysExceptionHandler unnecessary\r\n" +
" ==> Nmsg_zzz unnecessary\r\n" +
" ==> BulletinProcessors unnecessary\r\n" +
" ==> NORviaNOTAMreformatter unnecessary\r\n" +
" ==> AutoCorrectList unnecessary\r\n" +
" ==> AutoCorrect unnecessary\r\n" +
" ==> IncomingOTSrollbackManager unnecessary\r\n" +
" ==> IncomingNATMessageProcessor unnecessary\r\n" +
" ==> IncomingNORMessageProcessor unnecessary\r\n" +
" ==> FLMsgQueue unnecessary\r\n" +
" ==> OMSG_ZZZ unnecessary\r\n" +
" ==> OPMSGBroker unnecessary (has initialization)\r\n" +
" OCOMDRVR in implementation\r\n" +
" ==> MQIN_ZZZ unnecessary\r\n" +
" ==> RECV_ZZZ unnecessary\r\n" +
" ==> FlightPlanReview unnecessary\r\n" +
" ==> FlightPlanReviewHandler unnecessary\r\n" +
" ==> ETAtoRESsender unnecessary\r\n" +
"\r\n" +
"Note:\r\n" +
"Units that are marked as \"unnecessary\" in the project source\r\n" +
"are not needed in the main code block. However you would\r\n" +
"normally want to keep them listed anyway, because it tells\r\n" +
"the Delphi IDE that the unit belongs to the project.\r\n" +
"\r\n" +
"Module COMMGRIB uses:\r\n" +
"\r\n" +
" Units used in interface:\r\n" +
"\r\n" +
" --> SYSUTILS in implementation (has initialization, used by unit with init)\r\n" +
" ==> MYSTD unnecessary (used by unit with init)\r\n" +
" --> GDeclare in implementation (has initialization, used by unit with init)\r\n" +
" ==> DateTime unnecessary (has initialization, used by unit with init)\r\n" +
" ==> dbunit unnecessary (has initialization, used by unit with init)\r\n" +
" --> QMSGDESK in implementation (used by unit with init)\r\n" +
" ==> DYNEXEC unnecessary (used by unit with init)\r\n" +
" --> uGRIBSIT in implementation\r\n" +
"\r\n" +
"Module COMMGRIB uses:\r\n" +
"\r\n" +
" Units used in implementation:\r\n" +
"\r\n" +
" ==> CommonConsts unnecessary (used by unit with init)\r\n" +
" ==> CommonTypes unnecessary (used by unit with init)\r\n";
#endregion
SuggestedUnitStructureList vActual = IcarusAnalyzerReportParser.Parse(cReport);
Assert.AreEqual(10, vActual.Count, "Invalid no. of unit analyzes returned");
CompareUnitCount(vActual["absoluteidutils"], 0, 7, 0, 0, "Test 1");
CompareUnitCount(vActual["abstractcachestreamerclass"], 2, 10, 2, 2, "Test 2");
CompareUnitCount(vActual["abstracttable"], 0, 2, 0, 0, "Test 3");
CompareUnitCount(vActual["activex"], 2, 0, 0, 0, "Test 4");
CompareUnitCount(vActual["actnlist"], 3, 6, 0, 2, "Test 5");
CompareUnitCount(vActual["acwgtsbroker"], 6, 11, 4, 6, "Test 6");
CompareUnitCount(vActual["winspool"], 1, 0, 0, 0, "Test 7");
CompareUnitCount(vActual["wptio"], 1, 8, 4, 1, "Test 8");
CompareUnitCount(vActual["commdlg"], 3, 0, 0, 0, "Test 9");
CompareUnitCount(vActual["commgrib"], 0, 4, 4, 6, "Test 10");
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using NUnit.Framework;
using DelphiProjectHandler.LibraryPaths;
namespace DelphiProjectHandler.Tests.LibraryPaths
{
[TestFixture]
public class ClipboardLibraryPathsProviderTests
{
protected string cPaths = @"$(DELPHI)\Lib;$(DELPHI)\Bin;$(DELPHI)\Imports;$(DELPHI)\Projects\Bpl;$(DM_VIEW)\Lib;$(DM_TP)\abbrevia\source;$(DM_TP)\TGlobe\SOURCE;$(DM_TP)\AsyncPRO\source;$(DM_TP)\RegExpr\Source;$(DM_TP)\BTrieveSDK;$(DM_TP)\PxLib;$(DM_TP)\ExcMagicD6;$(DM_TP)\JWA\Win32Api;$(DM_TP)\XMLParser;$(DM_TP)\XMLPRO\source;$(DM_TP)\CalcExpress;$(DM_TP)\Indy9;$(DM_VIEW)\I;$(DM_VIEW)\Maps;$(DM_VIEW)\Forms;$(DM_VIEW)\U;$(DM_VIEW)\U\Brokers;$(DM_VIEW)\U\Eram;$(DM_VIEW)\U\FPValidators;$(BASA_DM);$(BASA_DM)\UUtils;$(BASA_DM)\UBtrieve;$(BASA_DM)\UBtrieve\UBroker;$(BASA_DM)\UFacilitator;$(BASA_DM)\USQL\UBroker;$(BASA_DM)\USQL\UOperation;$(BASA_DM)\USQL\UQueryBuilder;$(BASA_DM)\USQL\UUtil;$(BASA_DM)\USQL\UUtil\VersionInfo;$(BASA_DM)\USQLCache;$(BASA_DM)\USQLCache\UOperation;$(BASA_DM)\USQLCache\UUtil;$(BASA_DM)\UStream;$(BASA_DM)\UTransfer;$(BASA_DM)\USQL;$(DM_TP)\FCSUtils;$(DM_TP)\FCSUtils\System;$(DM_TP)\FCSUtils\DateUtils;$(DM_TP)\FCSUtils\DbUtils;$(DM_TP)\FCSUtils\Logging;$(DM_TP)\FCSUtils\Security;$(DM_TP)\FCSUtils\XMLRTTI;$(DM_TP)\ZipMaster;$(DM_TP)\KeyHelp;$(DM_TP)\DelphiKit;$(DM_VIEW)\U\EuroATCPlanValidation;$(DM_VIEW)\U\EuroATCPlanValidation\CFMU;$(DM_TP)\Guggenheim\Dcu;$(DM_TP)\JEDI\JCL\lib\d6;$(DM_TP)\JEDI\JCL\source;$(DM_TP)\JEDI\jvcl\lib\D6;$(DM_TP)\JEDI\jvcl\common;$(DM_TP)\JEDI\jvcl\Resources";
[Test]
[STAThread]
public void List()
{
ILibraryPathsProvider vProvider = new ClipboardLibraryPathsProvider();
Clipboard.SetText(cPaths);
IList<string> vPaths = vProvider.List();
Assert.AreEqual(58, vPaths.Count);
Assert.GreaterOrEqual(vPaths.IndexOf(@"$(DELPHI)\Lib"), 0, "Test 1");
Assert.GreaterOrEqual(vPaths.IndexOf(@"$(DM_TP)\JEDI\jvcl\Resources"), 0, "Test 2");
Assert.AreEqual(-1, vPaths.IndexOf(";"), "Test 3");
}
}
}
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using DelphiProjectHandler.LibraryPaths;
namespace DelphiProjectHandler.Tests.LibraryPaths
{
[TestFixture]
public class DelphiLibraryPathBuilderTests
{
[Test]
public void Build()
{
Dictionary<string, string> vEnvironmentStrings = new Dictionary<string, string>();
vEnvironmentStrings.Add("BASA_DM", "$(DM_TP)\\Basa");
vEnvironmentStrings.Add("DM_TP", "$(DM_VIEW)\\THIRDPARTY");
vEnvironmentStrings.Add("DM_VIEW", "d:\\DM\\sg894652_2006.2_ccrc\\dispmgr");
vEnvironmentStrings.Add("FCSUtils", "$(DM_TP)\\FcsUtils");
vEnvironmentStrings.Add("delphi", "c:\\program files\\borland\\delphi5");
List<string> vPaths = new List<string>();
vPaths.Add("$(DM_View)\\DPR");
vPaths.Add("$(DM_TP)\\BASA");
vPaths.Add("$(Delphi)\\Lib");
vPaths.Add("C:\\source\\dm\\latest");
ILibraryPathsBuilder vBuilder = new DelphiLibraryPathsBuilder();
ICollection<string> vActual = vBuilder.Build(vPaths, vEnvironmentStrings);
Assert.AreEqual(4, vActual.Count, "Invalid no. of returned paths");
Assert.IsTrue(vActual.Contains(@"d:\dm\sg894652_2006.2_ccrc\dispmgr\dpr"), "Path 0 wasn't found");
Assert.IsTrue(vActual.Contains(@"d:\dm\sg894652_2006.2_ccrc\dispmgr\thirdparty\basa"), "Path 1 wasn't found");
Assert.IsTrue(vActual.Contains(@"c:\program files\borland\delphi5\lib"), "Path 2 wasn't found");
Assert.IsTrue(vActual.Contains(@"c:\source\dm\latest"), "Path 3 wasn't found");
}
}
}
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using DelphiProjectHandler.LibraryPaths;
namespace DelphiProjectHandler.Tests.LibraryPaths
{
[TestFixture]
class DelphiLibraryPathProviderTests
{
[Test]
public void Delphi5Paths()
{
ILibraryPathsProvider vProvider = new DelphiLibraryPathsProvider(LibraryPathType.Delphi5);
IList<string> vLibraryPaths = vProvider.List();
Assert.GreaterOrEqual(vLibraryPaths.IndexOf("c:\\program files\\borland\\delphi5\\lib"), 0, "Test 1");
Assert.GreaterOrEqual(vLibraryPaths.IndexOf("d:\\dm\\sg894652_5.3_ccrc\\dispmgr\\u"), 0, "Test 2");
}
[Test]
public void Delphi6Paths()
{
ILibraryPathsProvider vProvider = new DelphiLibraryPathsProvider(LibraryPathType.Delphi6);
IList<string> vLibraryPaths = vProvider.List();
Assert.GreaterOrEqual(vLibraryPaths.IndexOf("c:\\program files\\borland\\delphi6\\lib\\"), 0, "Test 1");
// Assert.GreaterOrEqual(vLibraryPaths.IndexOf("d:\\dm\\sg894652_2006.2_ccrc\\dispmgr\\u"), 0, "Test 2");
}
}
}
@@ -0,0 +1,61 @@
/*
* Created by SharpDevelop.
* User: SG0894652
* Date: 8/10/2009
* Time: 11:21 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using NUnit.Framework;
using DelphiProjectHandler.LibraryPaths;
namespace DelphiProjectHandler.Tests.LibraryPaths
{
[TestFixture]
public class DelphiRegistryKeysTests
{
[Test]
public void LibraryKey()
{
Assert.IsNotNull(DelphiRegistryKeys.LibraryKey(LibraryPathType.Delphi5), "Delphi5 should be created");
Assert.IsNotNull(DelphiRegistryKeys.LibraryKey(LibraryPathType.Delphi6), "Delphi5 should be created");
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void LibraryKey_NotSupported()
{
DelphiRegistryKeys.LibraryKey(LibraryPathType.Delphi2009);
}
[Test]
public void RootDirKey()
{
Assert.IsNotNull(DelphiRegistryKeys.RootDirKey(LibraryPathType.Delphi5), "Delphi5 should be created");
Assert.IsNotNull(DelphiRegistryKeys.RootDirKey(LibraryPathType.Delphi6), "Delphi5 should be created");
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void RootDirKey_NotSupported()
{
DelphiRegistryKeys.RootDirKey(LibraryPathType.Delphi2009);
}
[Test]
public void EnvironmentPathsKey()
{
Assert.IsNotNull(DelphiRegistryKeys.EnvironmentPathsKey(LibraryPathType.Delphi6), "Delphi6 should be created");
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void EnvironmentPathsKey_NotSupported()
{
DelphiRegistryKeys.EnvironmentPathsKey(LibraryPathType.Delphi5);
}
}
}
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using DelphiProjectHandler.LibraryPaths;
namespace DelphiProjectHandler.Tests.LibraryPaths
{
[TestFixture]
public class LibraryPathProviderFactoryTests
{
protected void TestCreateProvider(LibraryPathType iLibraryType, Type iExpectedType, string iErrorMsg)
{
ILibraryPathsProvider vProvider = LibraryPathsProviderFactory.CreateProvider(iLibraryType);
Assert.IsNotNull(vProvider, "Provider was not created. " + iErrorMsg);
Assert.IsInstanceOf(iExpectedType, vProvider, "Created provider is of wrong type. " + iErrorMsg);
}
[Test]
public void CreateProvider_Supported()
{
TestCreateProvider(LibraryPathType.Delphi5, typeof(DelphiLibraryPathsProvider), "Test 1");
TestCreateProvider(LibraryPathType.Delphi6, typeof(DelphiLibraryPathsProvider), "Test 2");
TestCreateProvider(LibraryPathType.Clipboard, typeof(ClipboardLibraryPathsProvider), "Test 3");
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void CreateProvider_NotSupported_Delphi2005()
{
LibraryPathsProviderFactory.CreateProvider(LibraryPathType.Delphi2005);
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void CreateProvider_NotSupported_Delphi2007()
{
LibraryPathsProviderFactory.CreateProvider(LibraryPathType.Delphi2007);
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void CreateProvider_NotSupported_Delphi7()
{
LibraryPathsProviderFactory.CreateProvider(LibraryPathType.Delphi7);
}
[Test]
public void ListSupportedProviders()
{
LibraryPathType[] vSupported = LibraryPathsProviderFactory.ListSupportedProviders();
Assert.AreEqual(3, vSupported.Length, "No. of supported providers is wrong");
Assert.AreEqual(LibraryPathType.Delphi5, vSupported[0], "Item 0 is wrong");
Assert.AreEqual(LibraryPathType.Delphi6, vSupported[1], "Item 1 is wrong");
Assert.AreEqual(LibraryPathType.Clipboard, vSupported[2], "Item 2 is wrong");
}
[Test]
public void IsProviderSupported_Supported()
{
Assert.IsTrue(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Delphi5), "Delphi5 should be supported");
Assert.IsTrue(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Delphi6), "Delphi6 should be supported");
Assert.IsTrue(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Clipboard), "Clipboard should be supported");
}
[Test]
public void IsProviderSupported_NotSupported()
{
Assert.IsFalse(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Delphi7), "Delphi7 should not be supported");
Assert.IsFalse(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Delphi2005), "Delphi2005 should not be supported");
Assert.IsFalse(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Delphi2007), "Delphi2007 should not be supported");
Assert.IsFalse(LibraryPathsProviderFactory.IsProviderSupported(LibraryPathType.Delphi2009), "Delphi2009 should not be supported");
}
}
}
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DelphiProjectHandler.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ProfiMile Lemańczyk sp. j.")]
[assembly: AssemblyProduct("DelphiProjectHandler.Tests")]
[assembly: AssemblyCopyright("Copyright © ProfiMile Lemańczyk sp. j. 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("acbed1ed-f36b-449f-a655-f6f40da7d4d4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,198 @@
using System;
using System.IO;
using NUnit.Framework;
using DelphiProjectHandler.SourceControl;
namespace DelphiProjectHandler.Tests.SourceControl
{
[TestFixture]
public class SourceOffsiteClassTests: SourceOffsite
{
#region (Overrides)
public SourceOffsiteClassTests()
:
base("fcsweb4.dev.sabre.com", 8888, "ft-latest", "mpl", "mpl", @"d:\source\ft-latest")
{
}
protected override string RunCommand(string iFileName)
{
if (!MockRunCommand)
return base.RunCommand(iFileName);
else
if (MockSuccess)
return TestValueSuccessful;
else
return TestValueUnsuccessful;
}
protected override string GetApplicationFileName()
{
if (!MockGetApplicationFileName)
return base.GetApplicationFileName();
else
if (MockSuccess)
return @"c:\program files\SourceOffsite\soscmd.exe";
else
return @"c:\program files\SourceOffsite\soscmd_wrong.exe";
}
#endregion
#region (Properties)
protected bool MockRunCommand
{
get { return fMockRunCommand; }
set { fMockRunCommand = value; }
}
private bool fMockRunCommand = false;
protected bool MockGetApplicationFileName
{
get { return fMockGetApplicationFileName; }
set { fMockGetApplicationFileName = value; }
}
private bool fMockGetApplicationFileName;
protected bool MockSuccess
{
get { return fMockSuccess; }
set { fMockSuccess = value; }
}
private bool fMockSuccess;
protected string TestValueSuccessful
{
get { return fTestValueSuccessful; }
set { fTestValueSuccessful = value; }
}
private string fTestValueSuccessful = "";
protected string TestValueUnsuccessful
{
get { return fTestValueUnsuccessful; }
set { fTestValueUnsuccessful = value; }
}
private string fTestValueUnsuccessful = "";
#endregion
#region (Test methods)
protected void TestGetCommandParameters(string iProjectPath, string iFileName)
{
string vExpected = string.Format(
@"-command CheckoutFile -server {0}:{1} " +
@"-alias {2} -name {3} -password {4} " +
@"-project $/{5} -file {6}",
ServerName, ServerPort, Alias, UserName, Password, iProjectPath, Path.GetFileName(iFileName));
string vActual = GetCommandParameters(iFileName);
Assert.AreEqual(vExpected, vActual, "Wrong command line was returned. Project path: {0}, File name: {1}", iProjectPath, iFileName);
}
protected void TestCheckoutFile(string iFileName, bool iExpected)
{
MockRunCommand = true;
try
{
MockSuccess = iExpected;
bool vActual = CheckoutFile(iFileName);
Assert.AreEqual(iExpected, vActual, "Wrong checkout result. FileName: " + iFileName);
}
finally
{
MockRunCommand = false;
}
}
#endregion
#region (Setup/TearDown)
[SetUp]
protected virtual void Setup()
{
TestValueSuccessful = "Checked out file: ftadmin.dpr\r\n";
TestValueUnsuccessful = "Unable to lock file: ftadmin.dpr\r\n";
}
[TearDown]
protected virtual void TearDown()
{
}
#endregion
[Test]
public void CheckoutFile()
{
TestCheckoutFile(@"d:\source\ft-latest\all\dpr\ftadmin.dpr", true);
TestCheckoutFile(@"d:\source\ft-latest\all\dpr\ftadmin.dpr", false);
}
[Test]
public void WasFileCheckedOut()
{
bool vActual = WasFileCheckedOut(TestValueSuccessful);
Assert.IsTrue(vActual, "Successful checkout was not recognized");
vActual = WasFileCheckedOut(TestValueUnsuccessful);
Assert.IsFalse(vActual, "Unsuccessful checkout was not recognized");
}
[Test]
//[Ignore("Not on VPN")]
public void RunCommand()
{
TestRunCommand(false, true, @"d:\source\ft-latest\all\dpr\test_project.dpr", "Error: Server response = 401 NoSuchFileOrProject\r\nError: Server response = 401 NoSuchFileOrProject\r\n");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void RunCommand_EmptyFileName()
{
TestRunCommand(false, true, "", "");
}
[Test]
[ExpectedException(typeof(System.ComponentModel.Win32Exception))]
public void RunCommand_WrongApplicationName()
{
TestRunCommand(true, false, "doesn't have meaning.txt", "");
}
private void TestRunCommand(bool iMockBehavior, bool iSuccessful, string iFileName, string iExpected)
{
MockGetApplicationFileName = iMockBehavior;
try
{
MockSuccess = iSuccessful;
string vActual = RunCommand(iFileName);
Assert.AreEqual(iExpected, vActual, "File Name: " + iFileName);
}
finally
{
MockGetApplicationFileName = false;
}
}
[Test]
public void TestCreate()
{
SourceOffsiteClassTests vControl = new SourceOffsiteClassTests();
Assert.AreEqual("fcsweb4.dev.sabre.com", vControl.ServerName, "ServerName is wrong");
Assert.AreEqual(8888, vControl.ServerPort, "ServerPort is wrong");
Assert.AreEqual("ft-latest", vControl.Alias, "Alias is wrong");
Assert.AreEqual("mpl", vControl.UserName, "UserName is wrong");
Assert.AreEqual("mpl", vControl.Password, "Password is wrong");
Assert.AreEqual(@"d:\source\ft-latest", vControl.BaseFolder, "BaseFolder is wrong");
}
[Test]
public void GetCommandParameters()
{
TestGetCommandParameters(@"all/dpr", @"d:\source\ft-latest\all\dpr\ftadmin.dpr");
TestGetCommandParameters(@"", @"ftadmin.dpr");
}
}
}
+14
View File
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DelphiProjectHandler.Tests
{
class Program
{
static void Main(string[] args)
{
// Runner.Main(args);
}
}
}
@@ -0,0 +1,59 @@
using System;
using NUnit.Framework;
using DelphiProjectHandler;
namespace DelphiProjectHandler.Tests
{
[TestFixture]
public class UnitFormReaderClassTests
{
protected void TestGetBinaryFormName(string iTestValue, string iExpected, string iMessage)
{
string vActual = UnitFormReader.GetBinaryFormName(iTestValue);
Assert.AreEqual(iExpected, vActual, iMessage);
}
[Test]
public void GetBinaryFormName()
{
#region (Test values)
string vTestValue1 = @"ÿ TFRMACFTDISCREPANCIES 0É TPF0ñTfrmAcftDiscrepanciesfrmAcftDiscrepanciesLeftî TopiWidth™Height¸ CaptionAircraft DiscrepanciesVisibleOnClose FormClose OnCloseQueryFormCloseQuery";
string vTestValue2 = @"ÿ TFRMAIRCRAFTINFO 02 TPF0TfrmAircraftInfofrmAircraftInfoLeftÖ Top";
string vTestValue3 = @"ÿ TFRMBASESI 0í TPF0ñTfrmBaseSI frmBaseSILeftUTop° CaptionfrmBa";
#endregion
TestGetBinaryFormName(vTestValue1, "frmAcftDiscrepancies", "1");
TestGetBinaryFormName(vTestValue2, "frmAircraftInfo", "2");
TestGetBinaryFormName(vTestValue3, "frmBaseSI", "3");
}
[Test]
[ExpectedException(typeof(Exception))]
public void GetBinaryFormName_FormNameIsLast()
{
string vTestValue = @"ÿ TFRMBASESI 0í TPF0ñTfrmBase";
TestGetBinaryFormName(vTestValue, "", "");
}
[Test]
[ExpectedException(typeof(Exception))]
public void GetBinaryFromName_WithoutMarker()
{
string vTestValue = @"ÿ TFRMACFTDISCREPANCIES 0É ñTfrmAcftDiscrepanciesfrmAcftDiscrepanciesLeftî TopiWidth™Height¸ CaptionAircraft DiscrepanciesVisibleOnClose FormClose OnCloseQueryFormCloseQuery";
TestGetBinaryFormName(vTestValue, "", "");
}
[Test]
[ExpectedException(typeof(Exception))]
public void GetBinaryFormName_WithoutFormName()
{
string vTestValue = @"ÿ TFRMACFTDISCREPANCIES 0É TPF0ñ";
TestGetBinaryFormName(vTestValue, "", "");
}
}
}
@@ -0,0 +1,308 @@
using System;
using NUnit.Framework;
using DelphiProjectHandler;
namespace DelphiProjectHandler.Tests
{
[TestFixture]
public class UnitItemClassTests
{
protected void DoTestCreate_Name(string iExpectedName)
{
UnitItem vUnit = new UnitItem(iExpectedName);
Assert.AreEqual(iExpectedName, vUnit.Name, "Name wasn't set properly");
Assert.AreEqual("", vUnit.Path, "Path wasn't set to empty string");
}
protected void DoTestNameChange(string iInitialName, string iNewName)
{
UnitItem vUnit = new UnitItem(iInitialName);
DoTestNameChange(vUnit, iInitialName, iNewName);
}
protected void DoTestNameChange(UnitItem iUnitItem, string iInitialName, string iNewName)
{
Assert.AreEqual(iInitialName, iUnitItem.Name, "Name wasn't set properly.");
iUnitItem.Name = iNewName;
Assert.AreEqual(iNewName, iUnitItem.Name, "Name wasn't changed correctly.");
}
protected void DoTestPathChange(UnitItem iUnitItem, string iInitialPath, string iNewPath, string iMessage)
{
Assert.AreEqual(iInitialPath, iUnitItem.Path, "Path wasn't set properly. " + iMessage);
iUnitItem.Path = iNewPath;
Assert.AreEqual(iNewPath, iUnitItem.Path, "Path wasn't changed correctly. " + iMessage);
}
protected void DoTestPathChange(string iInitialPath, string iNewPath)
{
UnitItem vUnit = new UnitItem("unit_name", iInitialPath, true, "");
DoTestPathChange(vUnit, iInitialPath, iNewPath, "");
vUnit = new UnitItem("", iInitialPath, true, "");
DoTestPathChange(vUnit, iInitialPath, iNewPath, "Created with empty name.");
}
protected void DoTestToString_WithConditions(bool iAddConditions, string iSeparator, bool iSeparatorLast, string iExpected)
{
UnitItem vUnit = new UnitItem("unit_name", "unit_path", true, "");
if (iAddConditions)
{
vUnit.StartingConditions = "{$condition1}";
vUnit.EndingConditions = "{$condition2}";
}
string vActual = vUnit.ToString(" ", iSeparator, iSeparatorLast);
Assert.AreEqual(iExpected, vActual);
}
protected void DoTestHasConditions(bool iExpected, bool iActualHasConditions, string iExpectedConditions, string iActualConditions, string iMessage)
{
Assert.AreEqual(iExpected, iActualHasConditions, "HasConditions value is wrong: " + iMessage);
Assert.AreEqual(iExpectedConditions, iActualConditions, "Conditions value is wrong: " + iMessage);
}
protected void DoTestHasStartingConditions(string iConditions, bool iExpected)
{
UnitItem vUnit = new UnitItem("unit_name");
vUnit.StartingConditions = iConditions;
DoTestHasConditions(iExpected, vUnit.HasStartingConditions, iConditions, vUnit.StartingConditions, "Starting");
}
protected void DoTestHasEndingConditions(string iConditions, bool iExpected)
{
UnitItem vUnit = new UnitItem("unit_name");
vUnit.EndingConditions = iConditions;
DoTestHasConditions(iExpected, vUnit.HasEndingConditions, iConditions, vUnit.EndingConditions, "Ending");
}
protected void DoTestHasForm(string iForm, bool iExpected)
{
UnitItem vUnit = new UnitItem("Created with unit name only");
vUnit.Form = iForm;
DoTestHasForm(vUnit, iForm, iExpected);
vUnit = new UnitItem("Created with empty path and form", "", false, iForm);
DoTestHasForm(vUnit, iForm, iExpected);
}
protected void DoTestHasForm(UnitItem iUnitItem, string iExpectedFormName, bool iExpectedHasForm)
{
Assert.AreEqual(iExpectedHasForm, iUnitItem.HasForm, "HasForm value is wrong. " + iUnitItem.Name);
Assert.AreEqual(iExpectedFormName, iUnitItem.Form, "Form value is wrong. " + iUnitItem.Name);
}
[Test]
public void Create_NameAndPath()
{
UnitItem vUnit = new UnitItem("unit_name", "unit_path", true, "");
Assert.AreEqual("unit_name", vUnit.Name, "Name wasn't set properly");
Assert.AreEqual("unit_path", vUnit.Path, "Path wasn't set properly");
}
[Test]
public void Create_Name()
{
DoTestCreate_Name("unit_name");
}
[Test]
public void Create_EmptyName()
{
DoTestCreate_Name("");
}
[Test]
public void NameChange()
{
DoTestNameChange("unit_name", "new_unit_name");
DoTestNameChange("unit_name", "");
DoTestNameChange("", "new_unit_name");
}
[Test]
public void PathChange()
{
DoTestPathChange("unit_path", "new_unit_path");
}
[Test]
public void HasStartingConditions()
{
DoTestHasStartingConditions("", false);
DoTestHasStartingConditions("{$IFDEF test_condition}", true);
}
[Test]
public void HasEndingConditions()
{
DoTestHasEndingConditions("", false);
DoTestHasEndingConditions("{$ENDIF}", true);
}
[Test]
public void HasForm()
{
DoTestHasForm("form1", true);
DoTestHasForm("", false);
}
[Test]
public void PathChange_ToEmpty()
{
DoTestPathChange("unit_path", "");
}
[Test]
public void PathChange_FromEmpty()
{
DoTestPathChange("", "new_unit_path");
}
[Test]
public void PathChange_ToSamePath()
{
DoTestPathChange("same_path", "same_path");
}
[Test]
public void ToString_WithoutPath()
{
UnitItem vUnit = new UnitItem("unit_name");
Assert.AreEqual("unit_name", vUnit.ToString("", "", false));
}
[Test]
public void ToString_WithPath_WithoutBacklash()
{
UnitItem vUnit = new UnitItem("unit_name", @"c:\temp", true, "");
string vExpected = "unit_name in 'c:\\temp\\unit_name.pas'";
string vActual = vUnit.ToString("", "", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_WithPath_WithBackslash()
{
UnitItem vUnit = new UnitItem("unit_name", @"c:\temp\", true, "");
string vExpected = "unit_name in 'c:\\temp\\unit_name.pas'";
string vActual = vUnit.ToString("", "", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_RelativePath_WithBackslash()
{
UnitItem vUnit = new UnitItem("unit_name", @"..\..\", true, "");
string vExpected = "unit_name in '..\\..\\unit_name.pas'";
string vActual = vUnit.ToString("", "", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_RelativePath_WithoutBackslash()
{
UnitItem vUnit = new UnitItem("unit_name", @"..\..", true, "");
string vExpected = "unit_name in '..\\..\\unit_name.pas'";
string vActual = vUnit.ToString("", "", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_RelativePath_BlankPath()
{
UnitItem vUnit = new UnitItem("unit_name", "", true, "");
string vExpected = "unit_name in 'unit_name.pas'";
string vActual = vUnit.ToString("", "", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_WithConditions()
{
string vExpected =
" {$condition1}\n" +
" unit_name in 'unit_path\\unit_name.pas'\n" +
" {$condition2}";
DoTestToString_WithConditions(true, "", false, vExpected);
}
[Test]
public void ToString_WithSeparator_First()
{
string vExpected =
" {$condition1}\n" +
" unit_name in 'unit_path\\unit_name.pas',\n" +
" {$condition2}";
DoTestToString_WithConditions(true, ",", false, vExpected);
}
[Test]
public void ToString_WithSeparator_Last()
{
string vExpected =
" {$condition1}\n" +
" unit_name in 'unit_path\\unit_name.pas'\n" +
" {$condition2};";
DoTestToString_WithConditions(true, ";", true, vExpected);
}
[Test]
public void ToString_WithSeparator_WithoutConditions_First()
{
string vExpected = " unit_name in 'unit_path\\unit_name.pas',";
DoTestToString_WithConditions(false, ",", false, vExpected);
}
[Test]
public void ToString_WithSeparator_WithoutConditions_Last()
{
string vExpected = " unit_name in 'unit_path\\unit_name.pas';";
DoTestToString_WithConditions(false, ";", true, vExpected);
}
[Test]
public void ToString_StartingConditionOnly()
{
string vExpected =
" {$begin}\n" +
" unit_name;";
UnitItem vUnit = new UnitItem("unit_name");
vUnit.StartingConditions = "{$begin}";
string vActual = vUnit.ToString(" ", ";", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_EndingConditionOnly()
{
string vExpected =
" unit_name,\n" +
" {$end}";
UnitItem vUnit = new UnitItem("unit_name");
vUnit.EndingConditions = "{$end}";
string vActual = vUnit.ToString(" ", ",", false);
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_WithForm()
{
string vExpected =
" unit_name {unit_name};";
UnitItem vUnit = new UnitItem("unit_name", "", false, "unit_name");
string vActual = vUnit.ToString(" ", ";", true);
Assert.AreEqual(vExpected, vActual);
}
}
}
@@ -0,0 +1,433 @@
using System;
using NUnit.Framework;
using DelphiProjectHandler;
namespace DelphiProjectHandler.Tests
{
[TestFixture]
public class UnitListClassTests
{
#region (Properties)
protected UnitList TestList
{
get { return fTestList; }
}
private UnitList fTestList;
#endregion
#region (Helper methods)
protected UnitList CreateList()
{
return new UnitList();
}
protected UnitList CreateDefaultList(int iCount, bool iWithPath, bool iWithConditions)
{
UnitList vList = CreateList();
for (int vItemIdx = 0; vItemIdx < iCount; vItemIdx++)
{
UnitItem vUnit = CreateItem("DefaultName" + vItemIdx.ToString(), "DefaultPath" + vItemIdx.ToString(), iWithPath);
if (iWithConditions)
{
vUnit.StartingConditions = "{$starting_condition}";
vUnit.EndingConditions = "{$ending_condition}";
}
vList.Add(vUnit);
}
return vList;
}
protected UnitItem CreateItem(string iName, string iPath, bool iWithPath)
{
return new UnitItem(iName, iPath, iWithPath, "");
}
protected UnitItem CreateItem(string iPrefix, int iIndex, bool iWithPath)
{
return CreateItem(iPrefix + "Name" + iIndex.ToString(), iPrefix + "Path" + iIndex.ToString(), iWithPath);
}
#endregion
#region (Test methods)
protected void DoTestInsert(UnitList iList, UnitItem iUnitItem, int iIndex)
{
int vOldCount = iList.Count;
iList.Insert(iIndex, iUnitItem);
Assert.AreEqual(vOldCount + 1, iList.Count, "Item wasn't inserted properly");
Assert.AreEqual(iUnitItem, iList[iIndex], "Item wasn't assigned correctly");
}
protected void DoTestContains_NotExisting(UnitList iList, string iUnitPrefix, int iUnitIdx)
{
UnitItem vNotExisting = CreateItem(iUnitPrefix, iUnitIdx, true);
Assert.IsFalse(iList.Contains(vNotExisting.Name), "Wrong Contains result. Item shouldn't be on the list: " + vNotExisting.Name);
}
protected void DoTestToString_MultipleUnitsInConditionals(UnitList iList, int iStartingItemIdx, int iEndingItemIdx, string iExpected)
{
iList[iStartingItemIdx].StartingConditions = "{$starting_condition}";
iList[iEndingItemIdx].EndingConditions = "{$ending_condition}";
string vActual = iList.ToString();
Assert.AreEqual(iExpected, vActual);
}
#endregion
#region (Setup)
[SetUp]
protected void SetUp()
{
fTestList = CreateDefaultList(10, true, false);
}
[TearDown]
protected void TearDown()
{
fTestList = null;
}
#endregion
[Test]
public void Create()
{
UnitList vList = CreateList();
Assert.AreEqual(0, vList.Count, "List after creation is not empty");
}
[Test]
public void Add()
{
UnitList vList = CreateList();
for (int vItemIdx = 0; vItemIdx < 10; vItemIdx++)
{
UnitItem vExpected = CreateItem("unit ", vItemIdx, true);
vList.Add(vExpected);
Assert.AreEqual(vItemIdx + 1, vList.Count, "Unit item wasn't added to the list");
Assert.AreEqual(vExpected, vList[vItemIdx], "Unit item wasn't set properly");
}
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Add_Duplicates()
{
UnitList vList = CreateList();
UnitItem vItem = CreateItem("duplicated", 0, true);
vList.Add(vItem);
vList.Add(vItem);
}
[Test]
public void Insert_AtTheBeginning()
{
for (int vItemIdx = 0; vItemIdx < 5; vItemIdx++)
{
UnitItem vExpected = CreateItem("unit ", vItemIdx, true);
DoTestInsert(TestList, vExpected, 0);
}
}
[Test]
public void Insert_AtTheEnd()
{
for (int vItemIdx = 0; vItemIdx < 5; vItemIdx++)
{
UnitItem vExpected = CreateItem("unit ", vItemIdx, true);
DoTestInsert(TestList, vExpected, TestList.Count);
}
}
[Test]
public void Remove_ByItem()
{
while (TestList.Count > 0)
{
UnitItem vToDelete = TestList[0];
int vOldCount = TestList.Count;
TestList.Remove(vToDelete);
Assert.AreEqual(vOldCount - 1, TestList.Count, "Item wasn't deleted from the list");
Assert.IsFalse(TestList.Contains(vToDelete), "Item wasn't deleted. Still exists on the list");
}
}
[Test]
public void Remove_ByName()
{
while (TestList.Count > 0)
{
UnitItem vToDelete = TestList[0];
int vOldCount = TestList.Count;
TestList.Remove(vToDelete.Name);
Assert.AreEqual(vOldCount - 1, TestList.Count, "Item wasn't deleted from the list");
Assert.IsFalse(TestList.Contains(vToDelete), "Item wasn't deleted. Still exists on the list");
}
}
[Test]
public void Set()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NewItem", vUnitIdx, true);
TestList[vUnitIdx] = vExpected;
Assert.AreEqual(vExpected, TestList[vUnitIdx], "Item wasn't set properly");
}
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void Set_Duplicated()
{
UnitList vList = CreateDefaultList(2, true, false);
UnitItem vItem = CreateItem("duplicated", 0, true);
vList[0] = vItem;
vList[1] = vItem;
}
[Test]
public void Contains_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.IsTrue(TestList.Contains(vExpected.Name), "Wrong Contains result. Item should be on the list");
}
}
[Test]
public void Contains_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
DoTestContains_NotExisting(TestList, "DiffDefault", vUnitIdx);
DoTestContains_NotExisting(TestList, "Default", vUnitIdx + TestList.Count + 1);
}
}
[Test]
public void IndexOf_Name_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.AreEqual(vUnitIdx, TestList.IndexOf(vExpected.Name), "Wrong IndexOf by name result. Item should be found");
}
}
[Test]
public void IndexOf_Name_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NotExisting", vUnitIdx, true);
Assert.AreEqual(-1, TestList.IndexOf(vExpected.Name), "Wrong IndexOf by name result. Item shouldn't be on the list");
}
}
[Test]
public void IndexOf_NameStart_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.AreEqual(vUnitIdx, TestList.IndexOf(vExpected.Name, vUnitIdx), "Wrong IndexOf by name result. Item should be found");
Assert.AreEqual(-1, TestList.IndexOf(vExpected.Name, vUnitIdx + 1), "Wrong IndexOf by name result. Item shouldn't be found");
}
}
[Test]
public void IndexOf_NameStart_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NotExisting", vUnitIdx, true);
Assert.AreEqual(-1, TestList.IndexOf(vExpected.Name, vUnitIdx), "Wrong IndexOf by name result. Item shouldn't be on the list");
}
}
[Test]
public void IndexOf_NameStartCount_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.AreEqual(vUnitIdx, TestList.IndexOf(vExpected.Name, vUnitIdx, 1), "Wrong IndexOf by name result");
Assert.AreEqual(-1, TestList.IndexOf(vExpected.Name, vUnitIdx + 1, 1), "Wrong IndexOf by name result. Item shouldn't be found. vUnitIdx + 1");
Assert.AreEqual(-1, TestList.IndexOf(vExpected.Name, vUnitIdx, 0), "Wrong IndexOf by name result. Item shouldn't be found. Count = 0");
}
}
[Test]
public void IndexOf_NameStartCount_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NotExisting", vUnitIdx, true);
Assert.AreEqual(-1, TestList.IndexOf(vExpected.Name, vUnitIdx, 1), "Wrong IndexOf by name result. Item shouldn't be on the list");
}
}
[Test]
public void LastIndexOf_Name_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.AreEqual(vUnitIdx, TestList.LastIndexOf(vExpected.Name), "Wrong IndexOf by name result. Item should be found");
}
}
[Test]
public void LastIndexOf_Name_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NotExisting", vUnitIdx, true);
Assert.AreEqual(-1, TestList.LastIndexOf(vExpected.Name), "Wrong IndexOf by name result. Item shouldn't be on the list");
}
}
[Test]
public void LastIndexOf_NameStart_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.AreEqual(vUnitIdx, TestList.LastIndexOf(vExpected.Name, vUnitIdx), "Wrong IndexOf by name result. Item should be found");
Assert.AreEqual(-1, TestList.LastIndexOf(vExpected.Name, vUnitIdx - 1), "Wrong IndexOf by name result. Item shouldn't be found");
}
}
[Test]
public void LastIndexOf_NameStart_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NotExisting", vUnitIdx, true);
Assert.AreEqual(-1, TestList.LastIndexOf(vExpected.Name, vUnitIdx), "Wrong IndexOf by name result. Item shouldn't be on the list");
}
}
[Test]
public void LastIndexOf_NameStartCount_Existing()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = TestList[vUnitIdx];
Assert.AreEqual(vUnitIdx, TestList.LastIndexOf(vExpected.Name, vUnitIdx, 1), "Wrong IndexOf by name result");
Assert.AreEqual(-1, TestList.LastIndexOf(vExpected.Name, vUnitIdx - 1, 1), "Wrong IndexOf by name result. Item shouldn't be found. vUnitIdx + 1");
Assert.AreEqual(-1, TestList.LastIndexOf(vExpected.Name, vUnitIdx, 0), "Wrong IndexOf by name result. Item shouldn't be found. Count = 0");
}
}
[Test]
public void LastIndexOf_NameStartCount_NonExisting()
{
for (int vUnitIdx = 0; vUnitIdx < TestList.Count; vUnitIdx++)
{
UnitItem vExpected = CreateItem("NotExisting", vUnitIdx, true);
Assert.AreEqual(-1, TestList.LastIndexOf(vExpected.Name, vUnitIdx, 1), "Wrong IndexOf by name result. Item shouldn't be on the list");
}
}
[Test]
public void ToString_WithPaths()
{
string vExpected =
"uses\n" +
" DefaultName0 in 'DefaultPath0\\DefaultName0.pas',\n" +
" DefaultName1 in 'DefaultPath1\\DefaultName1.pas';";
UnitList vList = CreateDefaultList(2, true, false);
string vActual = vList.ToString();
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_WithoutPaths()
{
string vExpected =
"uses\n" +
" DefaultName0,\n" +
" DefaultName1;";
UnitList vList = CreateDefaultList(2, false, false);
string vActual = vList.ToString();
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_WithPaths_WithConditions()
{
string vExpected =
"uses\n" +
" {$starting_condition}\n" +
" DefaultName0 in 'DefaultPath0\\DefaultName0.pas',\n" +
" {$ending_condition}\n" +
" {$starting_condition}\n" +
" DefaultName1 in 'DefaultPath1\\DefaultName1.pas'\n" +
" {$ending_condition};";
UnitList vList = CreateDefaultList(2, true, true);
string vActual = vList.ToString();
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_WithoutPaths_WithConditions()
{
string vExpected =
"uses\n" +
" {$starting_condition}\n" +
" DefaultName0,\n" +
" {$ending_condition}\n" +
" {$starting_condition}\n" +
" DefaultName1\n" +
" {$ending_condition};";
UnitList vList = CreateDefaultList(2, false, true);
string vActual = vList.ToString();
Assert.AreEqual(vExpected, vActual);
}
[Test]
public void ToString_MultipleUnitsInConditionals_AtEnd()
{
string vExpected =
"uses\n" +
" DefaultName0,\n" +
" {$starting_condition}\n" +
" DefaultName1,\n" +
" DefaultName2\n" +
" {$ending_condition};";
UnitList vList = CreateDefaultList(3, false, false);
DoTestToString_MultipleUnitsInConditionals(vList, 1, 2, vExpected);
}
[Test]
public void ToString_MultipleUnitsInConditionals_AtBeginning()
{
string vExpected =
"uses\n" +
" {$starting_condition}\n" +
" DefaultName0,\n" +
" DefaultName1,\n" +
" {$ending_condition}\n" +
" DefaultName2;";
UnitList vList = CreateDefaultList(3, false, false);
DoTestToString_MultipleUnitsInConditionals(vList, 0, 1, vExpected);
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,58 @@
using System;
using System.Reflection;
namespace DelphiProjectHandler.Tests.Utilities
{
/// <summary>
/// Runs static and non-static private methods.
/// </summary>
public class MethodRunner
{
/// <summary>
/// Runs a private method of an object instance.
/// </summary>
/// <param name="iObject">Existing object instance.</param>
/// <param name="iMethodName">Method to run.</param>
/// <param name="iParams">Parameters for the method.</param>
/// <returns>Result of running the method.</returns>
public static object RunInstance(object iObject, string iMethodName, object[] iParams)
{
BindingFlags vFlags = BindingFlags.Instance;
return RunMethod(iObject.GetType(), iObject, vFlags, iMethodName, iParams);
}
/// <summary>
/// Runs a private static method of a class.
/// </summary>
/// <param name="iType">Class type.</param>
/// <param name="iMethodName">Method to run.</param>
/// <param name="iParams">Parameters for the method.</param>
/// <returns>Result of running the method.</returns>
public static object RunStatic(Type iType, string iMethodName, object[] iParams)
{
BindingFlags vFlags = BindingFlags.Static;
return RunMethod(iType, null, vFlags, iMethodName, iParams);
}
/// <summary>
/// Runs a private static or non-static method of a class or existing object instance.
/// </summary>
/// <param name="iType">Class type.</param>
/// <param name="iObject">Existing object instance.</param>
/// <param name="iBindingFlags">Flags used when searching for the method.
/// By default BindingFlags.NonPublic and BindingFlags.Public will be
/// added.</param>
/// <param name="iMethodName">Method to run.</param>
/// <param name="iParams">Parameters for the method.</param>
/// <returns>Result of running the method.</returns>
protected static object RunMethod(Type iType, object iObject, BindingFlags iBindingFlags, string iMethodName, params object[] iParams)
{
iBindingFlags = iBindingFlags | BindingFlags.NonPublic | BindingFlags.Public;
MethodInfo vMethodInfo = iType.GetMethod(iMethodName, iBindingFlags);
if (vMethodInfo == null)
throw new ArgumentException("Private method " + iMethodName + " was not found in type " + iType.ToString());
return vMethodInfo.Invoke(iObject, iParams);
}
}
}
@@ -0,0 +1,93 @@
using System;
using NUnit.Framework;
namespace DelphiProjectHandler.Tests.Utilities
{
[TestFixture]
public class MethodRunnerClassTests
{
protected class MethodRunnerTester
{
protected static int Calculate(int iLeft, int iRight, int iMultiplier)
{
return (iLeft + iRight) * iMultiplier;
}
public MethodRunnerTester(int iOffset)
{
Offset = iOffset;
}
public int Offset;
public void VoidFunction(int iLeft, int iRight, ref int ivTotal)
{
ivTotal = Calculate(iLeft, iRight, 2) + Offset;
}
public int Function(int iLeft, int iRight)
{
return Calculate(iLeft, iRight, 3) + Offset;
}
public static void StaticVoidFunction(int iLeft, int iRight, ref int ivTotal)
{
ivTotal = Calculate(iLeft, iRight, 4);
}
public static int StaticFunction(int iLeft, int iRight)
{
return Calculate(iLeft, iRight, 5);
}
}
[Test]
public void RunInstanceFunction()
{
MethodRunnerTester vTester = new MethodRunnerTester(1);
int vActual = (int)MethodRunner.RunInstance(vTester, "Function", new object[] { 2, 3 });
Assert.AreEqual(16, vActual, "Wrong result for instance function");
}
[Test]
public void RunInstanceVoidFunction()
{
MethodRunnerTester vTester = new MethodRunnerTester(2);
int vActual = 0;
object[] vParams = new object[] { 2, 3, vActual };
MethodRunner.RunInstance(vTester, "VoidFunction", vParams);
Assert.AreEqual(12, vParams[2], "Wrong result for void instance function");
}
[Test]
public void RunStaticFunction()
{
int vActual = (int)MethodRunner.RunStatic(typeof(MethodRunnerTester), "StaticFunction", new object[] { 2, 3 });
Assert.AreEqual(25, vActual, "Wrong result for instance function");
}
[Test]
public void RunStaticVoidFunction()
{
int vActual = 0;
object[] vParams = new object[] { 2, 3, vActual };
MethodRunner.RunStatic(typeof(MethodRunnerTester), "StaticVoidFunction", vParams);
Assert.AreEqual(20, vParams[2], "Wrong result for instance function");
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void RunNonExistingMethod()
{
MethodRunnerTester vTester = new MethodRunnerTester(1);
MethodRunner.RunInstance(vTester, "NonExistingMethod", null);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void RunNonExistingStaticMethod()
{
MethodRunner.RunStatic(typeof(MethodRunnerTester), "NonExistingMethod", null);
}
}
}
@@ -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"
);
}
}
}