Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge branch '#456'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yomodo committed Jun 10, 2018
2 parents 0fa06e6 + 9ea257d commit 3f66909
Show file tree
Hide file tree
Showing 20 changed files with 495 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,23 @@ private void AlphaFS_Volume_GetDriveFormat(bool isNetwork)

var logicalDriveCount = 0;

foreach (var logicalDrive in System.IO.DriveInfo.GetDrives())
foreach (var driveInfo in System.IO.DriveInfo.GetDrives())
{
var driveName = isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(logicalDrive.Name) : logicalDrive.Name;
var driveName = isNetwork ? Alphaleonis.Win32.Filesystem.Path.LocalToUnc(driveInfo.Name) : driveInfo.Name;

Console.Write("#{0:000}\tInput Logical Drive Path: [{1}]", ++logicalDriveCount, driveName);


// Skip mapped drives and CDRom drives.

if (logicalDrive.DriveType == System.IO.DriveType.NoRootDirectory || logicalDrive.DriveType == System.IO.DriveType.CDRom)
{
Console.WriteLine();
continue;
}


var driveFormat = Alphaleonis.Win32.Filesystem.Volume.GetDriveFormat(driveName);

Console.WriteLine("\t\tDrive Format: [{0}]", driveFormat);


if (isNetwork)
{
// Some USB drives do not report drive format.

if (null != driveFormat)
Assert.AreEqual(logicalDrive.DriveFormat, driveFormat);
}
// Some USB drives do not report drive format when path is UNC.

else
Assert.AreEqual(logicalDrive.DriveFormat, driveFormat);
if (!Alphaleonis.Utils.IsNullOrWhiteSpace(driveFormat))

Assert.AreEqual(driveInfo.DriveFormat, driveFormat);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ public void AlphaFS_Volume_GetUniqueVolumeNameForPath_Local_Success()


var logicalDriveCount = 0;
foreach (var drive in System.IO.DriveInfo.GetDrives())

foreach (var driveInfo in System.IO.DriveInfo.GetDrives())
{
// Skip mapped drives and network drives.

if (drive.DriveType == System.IO.DriveType.NoRootDirectory || drive.DriveType == System.IO.DriveType.Network)
if (driveInfo.DriveType == System.IO.DriveType.NoRootDirectory || driveInfo.DriveType == System.IO.DriveType.Network)
continue;


var driveName = drive.Name;
var driveName = driveInfo.Name;

var deviceGuid = Alphaleonis.Win32.Filesystem.Volume.GetVolumeGuid(driveName);

Expand All @@ -65,16 +65,28 @@ public void AlphaFS_Volume_GetUniqueVolumeNameForPath_Local_Success()

var pathNames = Alphaleonis.Win32.Filesystem.Volume.EnumerateVolumePathNames(volumeNameResult).ToArray();

foreach (var displayName in pathNames)
foreach (var uniqueName in pathNames)
{
Console.WriteLine("\n\t(Input Volume GUID Path) EnumerateVolumePathNames: Volume points to logcal drive: [{0}]\n", displayName);
Console.WriteLine("\n\tUnique name: [{0}]", uniqueName);


try
{
var targetInfo = Alphaleonis.Win32.Filesystem.Directory.GetLinkTargetInfo(uniqueName);

// Volumes don't always have drive letters.
UnitTestConstants.Dump(targetInfo);

if (!string.IsNullOrWhiteSpace(displayName))
Assert.AreEqual(driveName, displayName);
Assert.AreEqual(deviceGuid, Alphaleonis.Win32.Filesystem.Path.LongPathPrefix + targetInfo.SubstituteName.Replace(Alphaleonis.Win32.Filesystem.Path.NonInterpretedPathPrefix, string.Empty));
}
catch
{
if (!string.IsNullOrWhiteSpace(uniqueName))
Assert.AreEqual(driveName, uniqueName);
}
}


Console.WriteLine();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,21 @@ public partial class DriveInfoTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void DriveInfo_GetDrives_Local_Success()
{
UnitTestConstants.PrintUnitTestHeader(false);


var drives = Alphaleonis.Win32.Filesystem.DriveInfo.GetDrives().ToList();

foreach (var driveInfo in drives)
{
Console.WriteLine("Logical Drive: [{0}]", driveInfo.Name);

UnitTestConstants.Dump(driveInfo);


if (null != driveInfo.DiskSpaceInfo)
UnitTestConstants.Dump(driveInfo.DiskSpaceInfo, true);

var drivesSystemIO = System.IO.DriveInfo.GetDrives().Select(drive => drive.Name).ToArray();

Console.WriteLine();
}
var drivesAlphaFS = Alphaleonis.Win32.Filesystem.DriveInfo.GetDrives().Select(drive => drive.Name).ToArray();

foreach (var drivePath in drivesAlphaFS)
Console.WriteLine("Logical Drive: [{0}]\n", drivePath);

Assert.IsTrue(drives.Count > 0);

Assert.AreEqual(drives[0].Name[0], UnitTestConstants.SysDrive[0]);
CollectionAssert.AreEqual(drivesSystemIO, drivesAlphaFS);
}
}
}
4 changes: 4 additions & 0 deletions AlphaFS.UnitTest/AlphaFS.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,15 @@
</Compile>
<Compile Include="AlphaFS Device Class\AlphaFS Volume Class\AlphaFS_Volume.DefineDosDevice_RegularDriveMapping.cs" />
<Compile Include="AlphaFS Device Class\AlphaFS_Device.EnumerateDevices.cs" />
<Compile Include="Directory Class\AlphaFS_Directory.Copy\AlphaFS_Directory.Copy_ExistingDirectory_UsingGlobalRootAsSourcePath.cs" />
<Compile Include="Directory Class\Directory.CreateDirectory\Directory.CreateDirectory_EmptyAsPath_ThrowsArgumentException.cs" />
<Compile Include="Directory Class\Directory.CreateDirectory\Directory.CreateDirectory_NullAsPath_ThrowsArgumentNullException.cs" />
<Compile Include="Directory Class\Directory.Delete\Directory.Delete_EmptyAsPath_ThrowsArgumentException.cs" />
<Compile Include="Directory Class\Directory.Delete\Directory.Delete_NullAsPath_ThrowsArgumentNullException.cs" />
<Compile Include="DirectoryInfo Class\DirectoryInfo.InitializeInstance\DirectoryInfo.InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse.cs" />
<Compile Include="File Class\File.Copy\File.Copy_EmptySourceFileNameAsPath_ThrowsArgumentException.cs" />
<Compile Include="File Class\File.Copy\File.Copy_EmptyDestFileNameAsPath_ThrowsArgumentException.cs" />
<Compile Include="File Class\File.Copy\AlphaFS_File.Copy_ExistingFile_UsingGlobalRootAsSourcePath.cs" />
<Compile Include="File Class\File.Copy\File.Copy_NullDestFileNameAsPath_ThrowsArgumentNullException.cs" />
<Compile Include="File Class\File.Copy\File.Copy_NullSourceFileNameAsPath_ThrowsArgumentNullException.cs" />
<Compile Include="File Class\File.Delete\File.Delete_EmptyAsPath_ThrowsArgumentException.cs" />
Expand All @@ -161,6 +164,7 @@
<Compile Include="File Class\File.Move\File.Move_NullDestFileNameAsPath_ThrowsArgumentNullException.cs" />
<Compile Include="File Class\File.Move\File.Move_NullSourceFileNameAsPath_ThrowsArgumentNullException.cs" />
<Compile Include="File Class\FileTest.cs" />
<Compile Include="FileInfo Class\FileInfo.InitializeInstance\FileInfo.InitializeInstance_ExistingDirectoryAsFileName_PropertyExistsShouldbeFalse.cs" />
<Compile Include="Path Class\PathTest.cs" />
<Compile Include="UnitTest Utility\DirectoryAssert.cs" />
<Compile Include="UnitTest Utility\Dump.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AlphaFS.UnitTest
{
public partial class CopyTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath_LocalAndNetwork_Success()
{
AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath(false);
AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath(true);
}


private void AlphaFS_Directory_Copy_ExistingDirectory_UsingGlobalRootAsSourcePath(bool isNetwork)
{
var testOk = false;

using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var folder = tempRoot.CreateDirectoryRandomizedAttributes();

var dosDevices = Alphaleonis.Win32.Filesystem.Volume.QueryAllDosDevices().Where(device => device.StartsWith("HarddiskVolumeShadowCopy", StringComparison.OrdinalIgnoreCase)).ToArray();

foreach (var dosDevice in dosDevices)
{
if (testOk)
break;

var shadowSource = Alphaleonis.Win32.Filesystem.Path.GlobalRootDevicePrefix + dosDevice;

var sourceFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

var drive = System.IO.Directory.GetDirectoryRoot(sourceFolder).TrimEnd('\\');

var globalRoot = sourceFolder.Replace(drive, shadowSource);


var dirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(globalRoot);

Console.WriteLine("Input GlobalRoot Path: [{0}]\n", dirInfo.FullName);

if (!dirInfo.Exists)
UnitTestAssert.InconclusiveBecauseFileNotFound("No volume shadow copy found.");


var enumOptions = Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.Recursive | Alphaleonis.Win32.Filesystem.DirectoryEnumerationOptions.SkipReparsePoints;
var copyOptions = Alphaleonis.Win32.Filesystem.CopyOptions.None;

var copyCount = 0;

foreach (var fsi in dirInfo.EnumerateDirectories(enumOptions))
{
if (copyCount == 3)
break;


// Copy all folders from "\Program Files".

var folderCopy = System.IO.Path.Combine(folder.FullName, System.IO.Path.GetFileName(fsi.FullName));

Console.WriteLine("Copy directory #{0}.", copyCount + 1);


var cmr = Alphaleonis.Win32.Filesystem.Directory.Copy(fsi.FullName, folderCopy, copyOptions);


UnitTestConstants.Dump(cmr);
Console.WriteLine();


Assert.AreEqual(0, cmr.ErrorCode);


testOk = true;

copyCount++;
}
}
}

Console.WriteLine();

Assert.IsTrue(testOk);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void DirectoryInfo_FolderName255Characters(bool isNetwork)
{
var folder = tempRoot.Directory.FullName;

Console.WriteLine("Input Directory Path: [{0}]", folder);
Console.WriteLine("Input Directory Path: [{0}]\n", folder);


// System.IO: 244, anything higher throws System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright (C) 2008-2018 Peter Palotas, Jeffrey Jangli, Alexandr Normuradov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace AlphaFS.UnitTest
{
public partial class DirectoryInfoTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse_LocalAndNetwork_Success()
{
DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse(false);
DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse(true);
}


private void DirectoryInfo_InitializeInstance_ExistingFileAsDirectoryeName_PropertyExistsShouldbeFalse(bool isNetwork)
{
using (var tempRoot = new TemporaryDirectory(isNetwork))
{
var file = tempRoot.CreateFileRandomizedAttributes();

Console.WriteLine("Input File Path: [{0}]", file.FullName);

var systemIODirInfo = new System.IO.DirectoryInfo(file.FullName);

var alphaFSDirInfo = new Alphaleonis.Win32.Filesystem.DirectoryInfo(file.FullName);

UnitTestConstants.Dump(alphaFSDirInfo);


Assert.AreEqual(systemIODirInfo.Exists, alphaFSDirInfo.Exists);

Assert.IsFalse(alphaFSDirInfo.EntryInfo.IsDirectory);
}

Console.WriteLine();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void DirectoryInfo_InitializeInstance_FolderNameGreaterThan255Characters
{
var folder = tempRoot.Directory.FullName;

Console.WriteLine("Input Directory Path: [{0}]", folder);
Console.WriteLine("Input Directory Path: [{0}]\n", folder);


// System.IO: 244, anything higher throws System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
Expand Down
Loading

0 comments on commit 3f66909

Please sign in to comment.