예제 #1
0
        public void d_CreateContainFileRecursive()
        {
            Dir422 TestDir = root.GetDir("TestDir");
            Dir422 BlahDir = TestDir.CreateDir("BlahDir");

            BlahDir.CreateFile("blahFile");
            Assert.AreEqual(true, root.ContainsFile("blahFile", true));
        }
예제 #2
0
        [SetUp]            //like @Before
        public void Init() //create memory file system
        {
            memFS = new MemoryFileSystem();
            root  = memFS.GetRoot();

            //do different subdirectory routes
            Dir422 one = root.CreateDir("one");
            Dir422 two = root.CreateDir("two");

            Dir422 curr1 = one;
            Dir422 curr2 = two;

            // /one/a/b/c and /two/a/b/c
            for (int i = 0; i < 3; i++)
            {
                curr1 = curr1.CreateDir(((char)('a' + i)).ToString());
                curr2 = curr2.CreateDir(((char)('a' + i)).ToString());
            }
        }
예제 #3
0
        public void c_CreateContainsDirectoryRecursive()
        {
            //Dir422 dir = new StdFSDir(rootDir + "/FooDir");
            //dir.CreateDir("BarDir");
            //Dir422 dirParent = dir.Parent;
            Dir422 FooDir = root.GetDir("FooDir");

            FooDir.CreateDir("BarDir");
            Assert.AreEqual(true, root.ContainsDir("BarDir", true));
        }
예제 #4
0
        [SetUp]                                        //like @Before
        public void Init()                             //create standard file system
        {
            Assert.True(Directory.Exists(rootString)); //make sure this directory exists.

            stdFS = StandardFileSystem.Create(rootString);
            root  = stdFS.GetRoot();

            Dir422 one = root.CreateDir("one");
            Dir422 two = root.CreateDir("two");

            Dir422 curr1 = one;
            Dir422 curr2 = two;

            // /one/a/b/c and /two/a/b/c
            for (int i = 0; i < 3; i++)
            {
                curr1 = curr1.CreateDir(((char)('a' + i)).ToString());
                curr2 = curr2.CreateDir(((char)('a' + i)).ToString());
            }
        }
예제 #5
0
파일: tests.cs 프로젝트: Drew-Miller/CS422
        public void MCreateDir()
        {
            MemoryFileSystem mfs  = new MemoryFileSystem();
            Dir422           dir1 = mfs.GetRoot().CreateDir("Dir1");
            Dir422           dir2 = dir1.CreateDir("Dir2");

            Assert.NotNull(dir1);
            Assert.NotNull(mfs.Contains(dir1));

            Assert.False(mfs.GetRoot().ContainsDir("Dir2", false));
            Assert.True(mfs.GetRoot().ContainsDir("Dir2", true));
        }
예제 #6
0
        public void StdFSDirCreateDirTest()
        {
            Dir422 three = root.CreateDir("three");

            Assert.AreEqual("three", three.Name);
        }
예제 #7
0
        public void RunTest(FileSys422 mySys)
        {
            Dir422 root = mySys.GetRoot();

            //We should not be able to go above our root.
            Assert.IsNull(root.Parent);

            // Checking that we do not have a file
            Assert.IsFalse(root.ContainsFile("NewFile.txt", false));
            //create the file
            root.CreateFile("NewFile.txt");
            // Check that we can find it.
            Assert.IsTrue(root.ContainsFile("NewFile.txt", false));

            // Same with directory
            Assert.IsFalse(root.ContainsDir("SubDir", false));
            Dir422 subDir = root.CreateDir("SubDir");

            Assert.IsTrue(root.ContainsDir("SubDir", false));

            //Creating a file in a sub dir
            subDir.CreateFile("subText.txt");

            // Testing the recursive methods on files
            Assert.IsFalse(root.ContainsFile("subText.txt", false));
            Assert.IsTrue(root.ContainsFile("subText.txt", true));

            //Testing recurcive method on dirs
            subDir.CreateDir("newSubDir");

            Assert.IsFalse(root.ContainsDir("newSubDir", false));
            Assert.IsTrue(root.ContainsDir("newSubDir", true));

            //Checking getDir
            Dir422 recivedDir = root.GetDir("InvalidDir");

            Assert.IsNull(recivedDir);
            recivedDir = root.GetDir("SubDir");
            Assert.AreEqual("SubDir", recivedDir.Name);

            // Checking that if a file does not exist we return null,
            // otherwise we recived the file we wanted.
            File422 recidedFile = root.GetFile("InvalidFile");

            Assert.IsNull(recidedFile);
            recidedFile = root.GetFile("NewFile.txt");
            Assert.AreEqual("NewFile.txt", recidedFile.Name);

            //Checking the name validation function.
            // All of these methods use the same Validate Name method.
            Assert.IsNull(subDir.CreateFile("file/New.txt"));
            Assert.IsNull(subDir.CreateDir("file/New"));

            string bufString = "hello world";

            byte[] buff        = ASCIIEncoding.ASCII.GetBytes(bufString);
            var    writeStream = recidedFile.OpenReadWrite();

            writeStream.Write(buff, 0, 11);

            var readStream = recidedFile.OpenReadOnly();

            Assert.IsNull(readStream);

            writeStream.Dispose();

            readStream = recidedFile.OpenReadOnly();
            Assert.IsNotNull(readStream);

            //First read 'hello ' from each stream
            byte[] readBuf = new byte[6];
            readStream.Read(readBuf, 0, 6);
            Assert.AreEqual("hello ", ASCIIEncoding.ASCII.GetString(readBuf));

            //Having two streams open for read
            var readStream2 = recidedFile.OpenReadOnly();

            Assert.IsNotNull(readStream2);

            byte[] readBuf2 = new byte[6];
            readStream2.Read(readBuf2, 0, 6);
            Assert.AreEqual("hello ", ASCIIEncoding.ASCII.GetString(readBuf2));

            //Next read 'world' from each stream
            readBuf = new byte[5];
            readStream.Read(readBuf, 0, 5);
            Assert.AreEqual("world", ASCIIEncoding.ASCII.GetString(readBuf));

            readBuf2 = new byte[5];
            readStream2.Read(readBuf2, 0, 5);
            Assert.AreEqual("world", ASCIIEncoding.ASCII.GetString(readBuf2));

            //try to open a stream to write while there are streams open for read
            writeStream = recidedFile.OpenReadWrite();
            Assert.IsNull(writeStream);

            //Close streams and try again
            readStream.Close();
            readStream2.Close();

            writeStream = recidedFile.OpenReadWrite();
            Assert.IsNotNull(writeStream);
        }
예제 #8
0
 public void b_CreateContainDir()
 {
     root.CreateDir("TestDir");
     Assert.AreEqual(true, root.ContainsDir("TestDir", false));
 }
예제 #9
0
 public void b_CreateContainsDirectory()
 {
     root.CreateDir("FooDir");
     Assert.AreEqual(true, root.ContainsDir("FooDir", false));
 }