Cosmos/Tests/Cosmos.System.Tests/VFSManagerTest.cs
Quajak 0d268eebef Added unittests for the VFSManager
Changed how the cluster is cleared again
Also added method to find unused cluster to use, rather than incorrectly using GetFatEntry to find cluster
2020-11-07 19:58:49 +01:00

85 lines
3.7 KiB
C#

using Cosmos.HAL.BlockDevice;
using Cosmos.System.FileSystem;
using Cosmos.System.FileSystem.FAT;
using Cosmos.System.FileSystem.Listing;
using Cosmos.System.FileSystem.VFS;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
namespace Cosmos.System.Tests
{
class VFSManagerTest
{
[SetUp]
public void Setup()
{
var xDevice = new TestBlockDevice();
var xPartition = new Partition(xDevice, 0, xDevice.BlockCount);
BlockDevice.Devices.Clear();
BlockDevice.Devices.Add(xPartition);
VFSManager.RegisterVFS(new CosmosVFS(), true);
}
[Test]
public void Test_Disk_Manager()
{
const string root = @"0:\";
long initialSize = VFSManager.GetTotalSize(root);
VFSManager.Format(root, "", true);
Assert.AreEqual(initialSize, VFSManager.GetAvailableFreeSpace(root));
Assert.AreEqual(0, VFSManager.GetDirectoryListing(root).Count);
VFSManager.CreateFile(root + "\\test.txt");
Assert.IsNotNull(VFSManager.GetFile(root + "\\test.txt"));
}
[Test]
public void Test_Disk_Manager_Reformating()
{
const string root = @"0:\";
long initialSize = VFSManager.GetTotalSize(root);
VFSManager.Format(root, "", true);
Assert.AreEqual(initialSize, VFSManager.GetAvailableFreeSpace(root));
Assert.AreEqual(0, VFSManager.GetDirectoryListing(root).Count);
VFSManager.CreateFile(root + "\\test.txt");
VFSManager.CreateFile(root + "\\test1.txt");
VFSManager.CreateFile(root + "\\test2.txt");
VFSManager.CreateFile(root + "\\test3.txt");
VFSManager.CreateFile(root + "\\test4.txt");
VFSManager.CreateDirectory(root + "\\SubDir");
VFSManager.CreateFile(root + "\\SubDir\\file.txt");
Assert.IsNotNull(VFSManager.GetFile(root + "\\SubDir\\file.txt"));
List<DirectoryEntry> lists = VFSManager.GetDirectoryListing(root);
Assert.AreEqual(6, lists.Count);
Assert.AreEqual(DirectoryEntryTypeEnum.File, lists[0].mEntryType);
Assert.AreEqual(DirectoryEntryTypeEnum.Directory, lists[5].mEntryType);
VFSManager.Format(root, "", true);
Assert.AreEqual(0, VFSManager.GetDirectoryListing(root).Count);
VFSManager.CreateDirectory(root + "\\dir");
VFSManager.CreateFile(root + "\\newfile.txt");
Assert.IsNotNull(VFSManager.GetFile(root + "\\newfile.txt"));
Assert.AreEqual(2, VFSManager.GetDirectoryListing(root).Count);
}
[Test]
public void Test_Disk_Manager_Reformating_First_Directories()
{
const string root = @"0:\";
long initialSize = VFSManager.GetTotalSize(root);
VFSManager.Format(root, "", true);
Assert.AreEqual(initialSize, VFSManager.GetAvailableFreeSpace(root));
Assert.AreEqual(0, VFSManager.GetDirectoryListing(root).Count);
VFSManager.CreateDirectory(root + "\\SubDir");
VFSManager.CreateFile(root + "\\SubDir\\filet.txt");
Assert.IsNotNull(VFSManager.GetFile(root + "\\SubDir\\filet.txt"));
Assert.AreEqual(1, VFSManager.GetDirectoryListing(root).Count);
VFSManager.Format(root, "", true);
Assert.AreEqual(0, VFSManager.GetDirectoryListing(root).Count);
VFSManager.CreateDirectory(root + "\\dir");
Assert.AreEqual(1, VFSManager.GetDirectoryListing(root).Count);
Assert.AreEqual(0, VFSManager.GetDirectoryListing(root + "\\dir").Count);
}
}
}