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

Commit

Permalink
-Implemented #311/#354: Add methods File.GetFileId and Directory.GetD…
Browse files Browse the repository at this point in the history
…irectoryId to return a unique file or directory identifier.

-Implemented #357: Added new Windows 10 property: FILE_DAX_VOLUME to VolumeInfo class.
-Added new Windows 10 property: FILE_DAX_VOLUME to VolumeInfo class.
-Renamed some native enums and structs to their (original) WIN32 name.
-Update some unit tests.
  • Loading branch information
Yomodo authored and Yomodo committed Jun 26, 2017
1 parent 47cc905 commit f59b649
Show file tree
Hide file tree
Showing 158 changed files with 2,231 additions and 1,492 deletions.
29 changes: 20 additions & 9 deletions AlphaFS.UnitTest/AlphaFS.UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,19 @@
<Compile Include="..\AlphaFS\AssemblyVersionInfo.cs">
<Link>AssemblyVersionInfo.cs</Link>
</Compile>
<Compile Include="Classes\AlphaFS_FileSystemEntryInfo.cs" />
<Compile Include="Crc\AlphaFS_Class_Crc.cs" />
<Compile Include="Device Class\AlphaFS_DeviceInfo_EnumerateDevices.cs" />
<Compile Include="Classes\AlphaFS_BackupFileStream.cs" />
<Compile Include="Device Class\AlphaFS_DeviceInfo_InitializeInstance.cs" />
<Compile Include="FileIdInfo\AlphaFS_Directory_GetFileId_LocalAndNetwork_Success.cs" />
<Compile Include="FileIdInfo\AlphaFS_File_GetFileId_LocalAndNetwork_Success.cs" />
<Compile Include="ByHandleFileInfo Class\AlphaFS_Directory_GetFileInfo_LocalAndNetwork_Success.cs" />
<Compile Include="CRC Class\AlphaFS_Crc64Iso_StaticDefaultSeedAndPolynomialWithShortAsciiString2.cs" />
<Compile Include="CRC Class\AlphaFS_Crc64Iso_StaticDefaultSeedAndPolynomialWithShortAsciiString.cs" />
<Compile Include="CRC Class\AlphaFS_Crc32_StaticDefaultSeedAndPolynomialWithShortAsciiString2.cs" />
<Compile Include="CRC Class\AlphaFS_Crc32_StaticDefaultSeedAndPolynomialWithShortAsciiString.cs" />
<Compile Include="ByHandleFileInfo Class\AlphaFS_File_GetFileInfoByHandle_LocalAndNetwork_Success.cs" />
<Compile Include="FileSystemEntryInfo Class\AlphaFS_Directory_GetFileSystemEntryInfo_LocalAndNetwork_Success.cs" />
<Compile Include="FileSystemEntryInfo Class\AlphaFS_File_GetFileSystemEntryInfo_LocalAndNetwork_Success.cs" />
<Compile Include="DeviceInfo Class\AlphaFS_Device_EnumerateDevices_Local_Success.cs" />
<Compile Include="BackupFileStream Class\AlphaFS_BackupFileStream_InitializeInstance_LocalAndNetwork_Success.cs" />
<Compile Include="DeviceInfo Class\AlphaFS_DeviceInfo_InitializeInstance_LocalAndNetwork_Success.cs" />
<Compile Include="Directory Class\AlphaFS_Directory_Compress_Decompress.cs" />
<Compile Include="Directory Class\AlphaFS_Directory_Encryption.cs" />
<Compile Include="Directory Class\AlphaFS_Directory_IsEmpty.cs" />
Expand Down Expand Up @@ -175,6 +183,7 @@
<Compile Include="DirectoryInfo Class\DirectoryInfo_MoveTo.cs" />
<Compile Include="DirectoryInfo Class\DirectoryInfo_Attributes.cs" />
<Compile Include="DirectoryInfo Class\DirectoryInfo_Refresh.cs" />
<Compile Include="DriveInfo Class\DriveInfo_InitializeInstance_LocalAndNetwork_Success.cs" />
<Compile Include="File Class\AlphaFS_File_GetHash.cs" />
<Compile Include="File Class\File_CreateText.cs" />
<Compile Include="File Class\File_OpenWrite.cs" />
Expand All @@ -199,9 +208,9 @@
<Compile Include="File Class\File_Exists.cs" />
<Compile Include="File Class\File_SetAccessControl.cs" />
<Compile Include="File Class\File_GetAccessControl.cs" />
<Compile Include="FileInfo Class\FileInfo_Attributes.cs" />
<Compile Include="FileInfo Class\FileInfo_InitializeInstance.cs" />
<Compile Include="FileInfo Class\FileInfo_Refresh.cs" />
<Compile Include="FileInfo Class\FileInfo_Attributes_LocalAndNetwork_Success.cs" />
<Compile Include="FileInfo Class\FileInfo_InitializeInstance_ExistingFile_LocalAndNetwork_Success.cs" />
<Compile Include="FileInfo Class\FileInfo_Refresh_LocalAndNetwork_Success.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDomainDfsRoot.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDfsRoot.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateDfsLinks.cs" />
Expand All @@ -214,9 +223,10 @@
<Compile Include="Host Class\AlphaFS_Host_EnumerateOpenResources.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateOpenConnections.cs" />
<Compile Include="Host Class\AlphaFS_Host_EnumerateShares.cs" />
<Compile Include="Classes\ClassesTest.cs" />
<Compile Include="DFS Class\AlphaFS_Network_DfsXxx.cs" />
<Compile Include="Directory Class\Directory_CreateDirectory_And_Delete.cs" />
<Compile Include="Directory Class\DirectoryTest.cs" />
<Compile Include="OperatingSystem Class\AlphaFS_BackupFileStream_InitializeInstance_LocalAndNetwork_Success.cs" />
<Compile Include="Path Class\Path_GetFullPath.cs" />
<Compile Include="Path Class\Path_IsPathRooted.cs" />
<Compile Include="Path Class\Path_GetExtension.cs" />
Expand Down Expand Up @@ -254,6 +264,7 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Copyright (C) 2008-2017 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;
using System.Reflection;

namespace AlphaFS.UnitTest
{
[TestClass]
public partial class ByHandleFileInfoTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void AlphaFS_Directory_GetFileInfoByHandle_LocalAndNetwork_Success()
{
Directory_GetFileInfoByHandle(false);
Directory_GetFileInfoByHandle(true);
}




private void Directory_GetFileInfoByHandle(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = System.IO.Path.GetTempPath();
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);


using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
{
var folder = rootDir.RandomDirectoryFullPath;
Console.WriteLine("\nInput Directory Path: [{0}]]", folder);


var dirInfo = new System.IO.DirectoryInfo(folder);
dirInfo.Create();


var bhfi = Alphaleonis.Win32.Filesystem.Directory.GetFileInfoByHandle(dirInfo.FullName);
Assert.IsTrue(UnitTestConstants.Dump(bhfi, -18));


Assert.AreEqual(dirInfo.CreationTimeUtc, bhfi.CreationTimeUtc);
Assert.AreEqual(dirInfo.LastAccessTimeUtc, bhfi.LastAccessTimeUtc);
Assert.AreEqual(dirInfo.LastWriteTimeUtc, bhfi.LastWriteTimeUtc);

}

Console.WriteLine();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* Copyright (C) 2008-2017 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;
using System.Reflection;

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


[TestMethod]
public void AlphaFS_File_GetFileInfoByHandle_LocalAndNetwork_Success()
{
File_GetFileInfoByHandle(false);
File_GetFileInfoByHandle(true);
}




private void File_GetFileInfoByHandle(bool isNetwork)
{
UnitTestConstants.PrintUnitTestHeader(isNetwork);

var tempPath = System.IO.Path.GetTempPath();
if (isNetwork)
tempPath = Alphaleonis.Win32.Filesystem.Path.LocalToUnc(tempPath);


using (var rootDir = new TemporaryDirectory(tempPath, MethodBase.GetCurrentMethod().Name))
{
var file = rootDir.RandomFileFullPath;
Console.WriteLine("\nInput File Path: [{0}]]", file);


var fileInfo = new System.IO.FileInfo(file);

using (var stream = fileInfo.OpenWrite())
{
var size = new Random().Next(1000, 10000);
stream.Write(new byte[size], 0, size);

var bhfi = Alphaleonis.Win32.Filesystem.File.GetFileInfoByHandle(stream.SafeFileHandle);
Assert.IsTrue(UnitTestConstants.Dump(bhfi, -18));


Assert.AreEqual(fileInfo.CreationTimeUtc, bhfi.CreationTimeUtc);
Assert.AreEqual(fileInfo.LastAccessTimeUtc, bhfi.LastAccessTimeUtc);
Assert.AreEqual(fileInfo.LastWriteTimeUtc, bhfi.LastWriteTimeUtc);

Assert.AreEqual(fileInfo.Length, bhfi.FileSize);
}
}

Console.WriteLine();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
namespace AlphaFS.UnitTest
{
[TestClass]
public class CrcTest
public partial class CRCTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void AlphaFS_Crc32_StaticDefaultSeedAndPolynomialWithShortAsciiString()
{
Expand All @@ -44,53 +45,5 @@ public void AlphaFS_Crc32_StaticDefaultSeedAndPolynomialWithShortAsciiString()
Assert.AreEqual("7a18a923", hash);
}
}


[TestMethod]
public void AlphaFS_Crc32_StaticDefaultSeedAndPolynomialWithShortAsciiString2()
{
using (var crc32 = new Alphaleonis.Win32.Security.Crc32())
{
var text = UnitTestConstants.StreamArrayContent[1];
var hash = crc32.ComputeHash(System.Text.Encoding.ASCII.GetBytes(text)).Aggregate(string.Empty, (current, b) => current + b.ToString("x2").ToLower());

Console.WriteLine("Input text: {0}", text);
Console.WriteLine("\n\tCRC32: {0}", hash);

Assert.AreEqual("85cd3815", hash);
}
}


[TestMethod]
public void AlphaFS_Crc64Iso_StaticDefaultSeedAndPolynomialWithShortAsciiString()
{
using (var crc64 = new Alphaleonis.Win32.Security.Crc64())
{
var text = UnitTestConstants.StreamArrayContent[0];
var hash = crc64.ComputeHash(System.Text.Encoding.ASCII.GetBytes(text)).Aggregate(string.Empty, (current, b) => current + b.ToString("x2").ToLower());

Console.WriteLine("Input text: {0}", text);
Console.WriteLine("\n\tCRC64: {0}", hash);

Assert.AreEqual("724293319a37353f", hash);
}
}


[TestMethod]
public void AlphaFS_Crc64Iso_StaticDefaultSeedAndPolynomialWithShortAsciiString2()
{
using (var crc64 = new Alphaleonis.Win32.Security.Crc64())
{
var text = UnitTestConstants.StreamArrayContent[1];
var hash = crc64.ComputeHash(System.Text.Encoding.ASCII.GetBytes(text)).Aggregate(string.Empty, (current, b) => current + b.ToString("x2").ToLower());

Console.WriteLine("Input text: {0}", text);
Console.WriteLine("\n\tCRC64: {0}", hash);

Assert.AreEqual("4553d9246a204d67", hash);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright (C) 2008-2017 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 CRCTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void AlphaFS_Crc32_StaticDefaultSeedAndPolynomialWithShortAsciiString2()
{
using (var crc32 = new Alphaleonis.Win32.Security.Crc32())
{
var text = UnitTestConstants.StreamArrayContent[1];
var hash = crc32.ComputeHash(System.Text.Encoding.ASCII.GetBytes(text)).Aggregate(string.Empty, (current, b) => current + b.ToString("x2").ToLower());

Console.WriteLine("Input text: {0}", text);
Console.WriteLine("\n\tCRC32: {0}", hash);

Assert.AreEqual("85cd3815", hash);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright (C) 2008-2017 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 CRCTest
{
// Pattern: <class>_<function>_<scenario>_<expected result>


[TestMethod]
public void AlphaFS_Crc64Iso_StaticDefaultSeedAndPolynomialWithShortAsciiString()
{
using (var crc64 = new Alphaleonis.Win32.Security.Crc64())
{
var text = UnitTestConstants.StreamArrayContent[0];
var hash = crc64.ComputeHash(System.Text.Encoding.ASCII.GetBytes(text)).Aggregate(string.Empty, (current, b) => current + b.ToString("x2").ToLower());

Console.WriteLine("Input text: {0}", text);
Console.WriteLine("\n\tCRC64: {0}", hash);

Assert.AreEqual("724293319a37353f", hash);
}
}
}
}
Loading

0 comments on commit f59b649

Please sign in to comment.