public void DeleteTestDirs()
        {
            bool deleted           = false;
            int  attemptsRemaining = 5;

            while (!deleted && attemptsRemaining > 0)
            {
                try
                {
                    if (Directory.Exists(testDir))
                    {
                        FailSafeDirectoryOperations.DeleteDirectory(testDir, true);
                    }
                    deleted = true;
                    break;
                }
                catch (IOException)
                {
                    if (-attemptsRemaining == 0)
                    {
                        throw;
                    }
                    else
                    {
                        Task.Delay(200).Wait();
                    }
                }
            }
        }
Beispiel #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // free other state (managed objects)
         // set interesting (large) fields to null
     }
     // free your own state (unmanaged objects)
     FailSafeDirectoryOperations.DeleteDirectory(_startDir, true);
 }
        public void GetEntriesThenDelete()
        {
            string        testDirPath = GetTestFilePath();
            DirectoryInfo testDirInfo = new DirectoryInfo(testDirPath);

            testDirInfo.Create();
            string testDir1  = GetTestFileName();
            string testDir2  = GetTestFileName();
            string testFile1 = GetTestFileName();
            string testFile2 = GetTestFileName();
            string testFile3 = GetTestFileName();
            string testFile4 = GetTestFileName();
            string testFile5 = GetTestFileName();

            testDirInfo.CreateSubdirectory(testDir1);
            testDirInfo.CreateSubdirectory(testDir2);
            using (File.Create(Path.Combine(testDirPath, testFile1)))
                using (File.Create(Path.Combine(testDirPath, testFile2)))
                    using (File.Create(Path.Combine(testDirPath, testFile3)))
                    {
                        string[] results;
                        using (File.Create(Path.Combine(testDirPath, testFile4)))
                            using (File.Create(Path.Combine(testDirPath, testFile5)))
                            {
                                results = GetEntries(testDirPath);
                                Assert.NotNull(results);
                                Assert.NotEmpty(results);
                                if (TestFiles)
                                {
                                    Assert.Contains(Path.Combine(testDirPath, testFile1), results);
                                    Assert.Contains(Path.Combine(testDirPath, testFile2), results);
                                    Assert.Contains(Path.Combine(testDirPath, testFile3), results);
                                    Assert.Contains(Path.Combine(testDirPath, testFile4), results);
                                    Assert.Contains(Path.Combine(testDirPath, testFile5), results);
                                }
                                if (TestDirectories)
                                {
                                    Assert.Contains(Path.Combine(testDirPath, testDir1), results);
                                    Assert.Contains(Path.Combine(testDirPath, testDir2), results);
                                }
                            }

                        File.Delete(Path.Combine(testDirPath, testFile4));
                        File.Delete(Path.Combine(testDirPath, testFile5));
                        FailSafeDirectoryOperations.DeleteDirectory(testDir1, true);

                        results = GetEntries(testDirPath);
                        Assert.NotNull(results);
                        Assert.NotEmpty(results);
                        if (TestFiles)
                        {
                            Assert.Contains(Path.Combine(testDirPath, testFile1), results);
                            Assert.Contains(Path.Combine(testDirPath, testFile2), results);
                            Assert.Contains(Path.Combine(testDirPath, testFile3), results);
                        }
                        if (TestDirectories)
                        {
                            Assert.Contains(Path.Combine(testDirPath, testDir2), results);
                        }
                    }
        }
    public static void runTest()
    {
        int    iCountErrors    = 0;
        int    iCountTestcases = 0;
        String strLoc          = "Loc_000oo";
        String strValue        = String.Empty;

        try
        {
            DirectoryInfo dir2;
            String        dirName = "GetFileSystemEntries_str_str_TestDir";
            String[]      strArr;

            FailSafeDirectoryOperations.DeleteDirectory(dirName, true);

            strLoc = "Loc_4y982";

            // [] With null file name
            iCountTestcases++;
            try
            {
                Directory.GetFileSystemEntries(null, "*");
                iCountErrors++;
                printerr("Error_0002! Expected exception not thrown");
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_0003! Unexpected exceptiont thrown: " + exc.ToString());
            }

            // [] With empty file name
            iCountTestcases++;
            try
            {
                Directory.GetFileSystemEntries("", "*");
                iCountErrors++;
                printerr("Error_0004! Expected exception not thrown");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_0005! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //Directory that doesn't exist
            iCountTestcases++;
            try
            {
                Directory.GetFileSystemEntries(dirName, "*");
                iCountErrors++;
                printerr("Error_1001! Expected exception not thrown");
            }
            catch (DirectoryNotFoundException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_1002! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //With wild character's as file name
            iCountTestcases++;
            try
            {
                String strTempDir = Path.Combine("dls;d", "442349-0", "v443094(*)(+*$#$*") + new string(Path.DirectorySeparatorChar, 3);
                Directory.GetFileSystemEntries(strTempDir, "*");
                iCountErrors++;
                printerr("Error_1003! Expected exception not thrown");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_1004! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //With spaces as file name
            iCountTestcases++;
            try
            {
                String strTempDir = "             ";
                Directory.GetFileSystemEntries(strTempDir, "*");
                iCountErrors++;
                printerr("Error_1044! Expected exception not thrown");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_1023! Unexpected exceptiont thrown: " + exc.ToString());
            }

            dir2 = new DirectoryInfo(dirName);
            dir2.Create();

            // [] With null search pattern
            iCountTestcases++;
            try
            {
                Directory.GetFileSystemEntries(dirName, null);
                iCountErrors++;
                printerr("Error_02002! Expected exception not thrown");
            }
            catch (ArgumentNullException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_00023! Unexpected exceptiont thrown: " + exc.ToString());
            }

            // [] With empty search pattern
            iCountTestcases++;
            try
            {
                String[] strInfos = Directory.GetFileSystemEntries(dirName, "");
                // To avoid OS differences we have decided not to throw an argument exception when empty
                // string passed. But we should return 0 items.
                if (strInfos.Length != 0)
                {
                    iCountErrors++;
                    printerr("Error_9004! Invalid number of directories returned");
                }
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_9005! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //With wild character's as search pattern
            iCountTestcases++;
            try
            {
                String strTempDir = Path.Combine("dls;d", "442349-0", "v443094(*)(+*$#$*") + new string(Path.DirectorySeparatorChar, 3);
                Directory.GetFileSystemEntries(dirName, strTempDir);
                iCountErrors++;
                printerr("Error_3003! Expected exception not thrown");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_3004! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //Valid characters for search pattern
            iCountTestcases++;
            try
            {
                String strTempDir = "a..b abc..d";
                Directory.GetFileSystemEntries(dirName, strTempDir);
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_4004! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //Invalid characters for search pattern
            iCountTestcases++;
            try
            {
                String strTempDir = Path.Combine("..ab ab.. .. abc..d", "abc..");
                Directory.GetFileSystemEntries(dirName, strTempDir);
                iCountErrors++;
                printerr("Error_144003! Expected exception not thrown");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_10404! Unexpected exceptiont thrown: " + exc.ToString());
            }

            strLoc = "Loc_0001";
            //Path that doesn't exist
            iCountTestcases++;
            try
            {
                strArr = Directory.GetFileSystemEntries("ThisDirectoryShouldNotExist", "*");
                iCountErrors++;
                printerr("Error_14443! Expected exception not thrown");
            }
            catch (IOException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_10433! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //With lot's of \'s at the end of file name
            iCountTestcases++;
            try
            {
                String strTempDir = Directory.GetCurrentDirectory() + new string(Path.DirectorySeparatorChar, 5);
                strArr = Directory.GetFileSystemEntries(strTempDir, "*");
                if (strArr == null || strArr.Length == 0)
                {
                    printerr("Error_1234!!! INvalid number of file system entries count :: " + strArr.Length);
                    iCountErrors++;
                }
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_10406! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //With the current directory
            iCountTestcases++;
            try
            {
                strArr = Directory.GetFileSystemEntries(s_strTFPath, "*");
                if (strArr == null || strArr.Length == 0)
                {
                    printerr("Error_2434!!! INvalid number of file system entries count :: " + strArr.Length);
                    iCountErrors++;
                }
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_12321!!! Unexpected exceptiont thrown: " + exc.ToString());
            }

            //With valid directory

            strArr = Directory.GetFileSystemEntries(dirName, "*");
            iCountTestcases++;
            if (strArr.Length != 0)
            {
                iCountErrors++;
                printerr("Error_207v7! Incorrect number of directories returned");
            }
            //-----------------------------------------------------------------


            // [] Create a directorystructure get all the filesystementries
            //-----------------------------------------------------------------
            strLoc = "Loc_2398c";

            dir2.CreateSubdirectory("TestDir1");
            dir2.CreateSubdirectory("TestDir2");
            dir2.CreateSubdirectory("TestDir3");
            FileStream fs1 = new FileInfo(Path.Combine(dir2.ToString(), "TestFile1")).Create();
            FileStream fs2 = new FileInfo(Path.Combine(dir2.ToString(), "TestFile2")).Create();
            FileStream fs3 = new FileInfo(Path.Combine(dir2.ToString(), "Test1File2")).Create();
            FileStream fs4 = new FileInfo(Path.Combine(dir2.ToString(), "Test1Dir2")).Create();

            //white spaces for search pattern
            strArr = Directory.GetFileSystemEntries(dirName, "           ");
            iCountTestcases++;
            if (strArr.Length != 0)
            {
                Console.WriteLine(dir2.ToString());
                iCountErrors++;
                printerr("Error_24324! Incorrect number of directories returned" + strArr.Length);
            }

            //Search pattern with '?'.
            strArr = Directory.GetFileSystemEntries(dirName, "Test1*");
            iCountTestcases++;
            if (strArr.Length != 2)
            {
                iCountErrors++;
                printerr("Error_24343! Incorrect number of directories returned" + strArr.Length);
            }

            strArr = Directory.GetFileSystemEntries(dir2.Name, "*");
            iCountTestcases++;
            if (strArr.Length != 7)
            {
                iCountErrors++;
                printerr("Error_1yt75! Incorrect number of directories returned" + strArr.Length);
            }

            for (int iLoop = 0; iLoop < strArr.Length; iLoop++)
            {
                strArr[iLoop] = Path.GetFileName(strArr[iLoop]);
            }

            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir1") < 0)
            {
                iCountErrors++;
                printerr("Error_4yg76! Incorrect name==" + strArr[0]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir2") < 0)
            {
                iCountErrors++;
                printerr("Error_1987y! Incorrect name==" + strArr[1]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir3") < 0)
            {
                iCountErrors++;
                printerr("Error_4yt76! Incorrect name==" + strArr[2]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1File2") < 0)
            {
                iCountErrors++;
                printerr("Error_3y775! Incorrect name==" + strArr[3]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1Dir2") < 0)
            {
                iCountErrors++;
                printerr("Error_90885! Incorrect name==" + strArr[4]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile1") < 0)
            {
                iCountErrors++;
                printerr("Error_879by! Incorrect name==" + strArr[5]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile2") < 0)
            {
                iCountErrors++;
                printerr("Error_29894! Incorrect name==" + strArr[6]);
            }

            fs1.Dispose();
            fs2.Dispose();
            fs3.Dispose();
            fs4.Dispose();

            // [] Search criteria beginning with '*'

            strArr = Directory.GetFileSystemEntries(dir2.Name, "*2");
            iCountTestcases++;
            if (strArr.Length != 4)
            {
                iCountErrors++;
                printerr("Error_8019x! Incorrect number of files==" + strArr.Length);
            }

            for (int iLoop = 0; iLoop < strArr.Length; iLoop++)
            {
                strArr[iLoop] = Path.GetFileName(strArr[iLoop]);
            }

            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1Dir2") < 0)
            {
                iCountErrors++;
                printerr("Error_247yg! Incorrect name==" + strArr[0]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir2") < 0)
            {
                iCountErrors++;
                printerr("Error_24gy7! Incorrect name==" + strArr[1]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1File2") < 0)
            {
                iCountErrors++;
                printerr("Error_167yb! Incorrect name==" + strArr[2]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestFile2") < 0)
            {
                iCountErrors++;
                printerr("Error_49yb7! Incorrect name==" + strArr[3]);
            }

            strArr = Directory.GetFileSystemEntries(dir2.Name, "*Dir2");
            iCountTestcases++;
            if (strArr.Length != 2)
            {
                iCountErrors++;
                printerr("Error_948yv! Incorrect number of files==" + strArr.Length);
            }
            for (int iLoop = 0; iLoop < strArr.Length; iLoop++)
            {
                strArr[iLoop] = Path.GetFileName(strArr[iLoop]);
            }

            iCountTestcases++;
            if (Array.IndexOf(strArr, "Test1Dir2") < 0)
            {
                iCountErrors++;
                printerr("Error_247yg! Incorrect name==" + strArr[0]);
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "TestDir2") < 0)
            {
                iCountErrors++;
                printerr("Error_24gy7! Incorrect name==" + strArr[1]);
            }

            // [] Search criteria Beginning and ending with '*'

            new FileInfo(Path.Combine(dir2.FullName, "AAABB")).Create();
            Directory.CreateDirectory(Path.Combine(dir2.FullName, "aaabbcc"));

            strArr = Directory.GetFileSystemEntries(dir2.Name, "*BB*");

            iCountTestcases++;
            if (strArr.Length != (Interop.IsWindows ? 2 : 1))
            {
                iCountErrors++;
                printerr("Error_4y190! Incorrect number of files==" + strArr.Length);
            }
            for (int iLoop = 0; iLoop < strArr.Length; iLoop++)
            {
                strArr[iLoop] = Path.GetFileName(strArr[iLoop]);
            }

            if (Interop.IsWindows)
            {
                iCountTestcases++;
                if (Array.IndexOf(strArr, "aaabbcc") < 0)
                {
                    iCountErrors++;
                    printerr("Error_956yb! Incorrect name==" + strArr[0]);
                }
            }
            iCountTestcases++;
            if (Array.IndexOf(strArr, "AAABB") < 0)
            {
                iCountErrors++;
                printerr("Error_48yg7! Incorrect name==" + strArr[1]);
            }

            // [] Should not search on fullpath
            // [] Search Criteria without match should return empty array

            strLoc = "Loc_2301";
            FileInfo   f   = new FileInfo(Path.Combine(dir2.Name, "TestDir1", "Test.tmp"));
            FileStream fs6 = f.Create();
            strArr = Directory.GetFileSystemEntries(dir2.Name, Path.Combine("TestDir1", "*"));
            iCountTestcases++;
            if (strArr.Length != 1)
            {
                iCountErrors++;
                printerr("Error_28gyb! Incorrect number of files");
            }
            fs6.Dispose();

            //if(Directory.Exists(dirName))
            //	Directory.Delete(dirName, true);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            printerr("Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        ////  Finish Diagnostics

        if (iCountErrors != 0)
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
        }

        Assert.Equal(0, iCountErrors);
    }
Beispiel #5
0
    public static void runTest()
    {
        int    iCountErrors    = 0;
        int    iCountTestcases = 0;
        String strLoc          = "Loc_000oo";
        String strValue        = String.Empty;

        string dirName = Path.Combine(TestInfo.CurrentDirectory, Path.GetRandomFileName());

        Directory.CreateDirectory(dirName);

        try
        {
            DirectoryInfo  dir = null;
            FileAttributes diratt;

            new DirectoryInfo(dirName).Attributes = new FileAttributes();

            // [] Invalid value

            strLoc = "Loc_09t77";

            dir = new DirectoryInfo(dirName);
            iCountTestcases++;
            try
            {
                dir.Attributes = ~FileAttributes.ReadOnly;
                iCountErrors++;
                printerr("Error_78t59! Expected exception not thrown");
            }
            catch (ArgumentException)
            {
            }
            catch (Exception exc)
            {
                iCountErrors++;
                printerr("Error_97678! Incorrect exception thrown, exc==" + exc.ToString());
            }

            // [] Set the ReadOnly attribute

            strLoc = "Loc_039ux";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.ReadOnly;
            diratt         = dir.Attributes;
            iCountTestcases++;
            if ((diratt & (FileAttributes.ReadOnly | FileAttributes.Directory)) != (FileAttributes.ReadOnly | FileAttributes.Directory))
            {
                iCountErrors++;
                printerr("Error_2989d! Incorrect directory attribute set");
            }
            dir.Attributes = new FileAttributes();

            // [] Set hidden only

            strLoc = "Loc_209cu";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.Hidden;
            diratt         = dir.Attributes;
            iCountTestcases++;
#if TEST_WINRT  // WinRT doesn't support hidden
            if ((diratt & (FileAttributes.Hidden | FileAttributes.Directory)) != (FileAttributes.Directory))
            {
#else
            if ((diratt & (FileAttributes.Hidden | FileAttributes.Directory)) != (FileAttributes.Hidden | FileAttributes.Directory) && Interop.IsWindows) // setting Hidden not supported on Unix
            {
#endif
                iCountErrors++;
                printerr("Error_3091h! Incorrect direcotory attribute set");
            }
            dir.Attributes = new FileAttributes();

            // [] Set hidden and readonly

            strLoc = "Loc_390uv";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.Hidden | FileAttributes.ReadOnly;
            diratt         = dir.Attributes;
            iCountTestcases++;
#if !TEST_WINRT  // WinRT doesn't support hidden
            diratt = dir.Attributes;
            iCountTestcases++;
            if ((int)(diratt & FileAttributes.Hidden) == 0 && Interop.IsWindows) // setting Hidden not supported on Unix
            {
                iCountErrors++;
                printerr("Error_20x97! Hidden attribute not set");
            }
#endif
            iCountTestcases++;
            if ((int)(diratt & FileAttributes.ReadOnly) == 0)
            {
                iCountErrors++;
                printerr("Error_1990c! ReadOnly attribute not set");
            }
            dir.Attributes = new FileAttributes();

            // [] Set system

            strLoc = "Loc_8gy0b";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.System;
            diratt         = dir.Attributes;
            iCountTestcases++;
#if TEST_WINRT  // WinRT doesn't support system
            if ((diratt & (FileAttributes.System | FileAttributes.Directory)) != (FileAttributes.Directory))
            {
#else
            if ((diratt & (FileAttributes.System | FileAttributes.Directory)) != (FileAttributes.System | FileAttributes.Directory) && Interop.IsWindows) // setting System not supported on Unix
            {
#endif
                iCountErrors++;
                printerr("Error_7t87y! System attribute not set");
            }
            dir.Attributes = new FileAttributes();

            // [] set archive

            strLoc = "Loc_29d88";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.Archive;
            diratt         = dir.Attributes;
            iCountTestcases++;
#if TEST_WINRT  // WinRT doesn't support archive
            if ((diratt & (FileAttributes.Archive | FileAttributes.Directory)) != (FileAttributes.Directory))
            {
#else
            if ((diratt & (FileAttributes.Archive | FileAttributes.Directory)) != (FileAttributes.Archive | FileAttributes.Directory) && Interop.IsWindows) // setting Archive not supported on Unix
            {
#endif
                iCountErrors++;
                printerr("Error_f487b! System attribute not set");
            }
            dir.Attributes = new FileAttributes();

            // [] Encrypted can't be set on directory

            strLoc = "Loc_t78yg";

            /*			dir = new DirectoryInfo(".");
             *          dir.Attributes = FileAttributes.Encrypted;
             *          diratt = dir.Attributes;
             *          iCountTestcases++;
             *          if(diratt != FileAttributes.Directory) {
             *              iCountErrors++;
             *              printerr( "Error_09828! System attribute not set");
             *          }
             *          dir.Attributes = new FileAttributes();                   */

            // [] Normal can't be set on directory

            strLoc = "Loc_90v77";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.Normal;
            diratt         = dir.Attributes;
            iCountTestcases++;
            if ((diratt & FileAttributes.Directory) == 0)
            {
                iCountErrors++;
                printerr("Error_2t09b! System attribute not set");
            }
            dir.Attributes = new FileAttributes();


            /*              // [] Temporary can't be set on directory
             *
             *         strLoc = "Loc_99g94";
             *
             *         dir = new DirectoryInfo(".");
             *         iCountTestcases++;
             *         try {
             *             dir.Attributes = FileAttributes.Temporary;
             *             iCountErrors++;
             *             printerr( "Error_247tb! Expected exception not thrown");
             *         } catch (ArgumentException aexc) {
             *         } catch (Exception exc) {
             *             iCountErrors++;
             *             printerr( "Error_758bh! Incorrect exception thrown, exc=="+exc.ToString());
             *         }
             *         dir.Attributes = new FileAttributes();   */


            // [] Sparsefile can't be set on directory

            strLoc = "Loc_8gy0b";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.SparseFile;
            diratt         = dir.Attributes;
            iCountTestcases++;
            if ((diratt & (FileAttributes.Directory)) == 0)
            {
                iCountErrors++;
                printerr("Error_1300g! SparseFile attribute not set");
            }
            dir.Attributes = new FileAttributes();


            // [] ReparsePoint can't be set on directory


            strLoc = "Loc_9180c";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.ReparsePoint;
            diratt         = dir.Attributes;
            iCountTestcases++;
            if ((diratt & (FileAttributes.Directory)) == 0)
            {
                iCountErrors++;
                printerr("Error_0199c! ReparsePoint attribute not set");
            }
            dir.Attributes = new FileAttributes();

            // [] Compressed can't be set on directory


            strLoc = "Loc_0200d";

            dir            = new DirectoryInfo(dirName);
            dir.Attributes = FileAttributes.Compressed;
            diratt         = dir.Attributes;
            iCountTestcases++;
            if ((diratt & (FileAttributes.Directory)) == 0)
            {
                iCountErrors++;
                printerr("Error_9010c! Compressed attribute not set");
            }
            dir.Attributes = new FileAttributes();

            // [] Offline
            iCountTestcases++;

            /* Does not work on FAT filesystems
             *          strLoc = "Loc_109tg";
             *
             *          dir = new DirectoryInfo(".");
             *          dir.Attributes = FileAttributes.Offline;
             *          diratt = dir.Attributes;
             *          iCountTestcases++;
             *          if(diratt != (FileAttributes.Offline|FileAttributes.Directory)) {
             *              iCountErrors++;
             *              printerr( "Error_010vy! Offline attribute not set");
             *          }
             *          dir.Attributes = new FileAttributes();
             *
             *
             *          // [] NotContectIndexed
             *
             *          strLoc = "Loc_t0698";
             *
             *          dir = new DirectoryInfo(".");
             *          dir.Attributes = FileAttributes.NotContentIndexed;
             *          diratt = dir.Attributes;
             *          iCountTestcases++;
             *          if(diratt != (FileAttributes.NotContentIndexed|FileAttributes.Directory)) {
             *              iCountErrors++;
             *              printerr( "Error_23047! NotContentIndexed attribute not set");
             *          }
             *          dir.Attributes = new FileAttributes();
             */
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine("Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        ////  Finish Diagnostics
        if (iCountErrors != 0)
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
        }

        FailSafeDirectoryOperations.DeleteDirectory(dirName, true);
        Assert.Equal(0, iCountErrors);
    }
Beispiel #6
0
    public static void runTest()
    {
        int    iCountErrors    = 0;
        int    iCountTestcases = 0;
        String strLoc          = "Loc_000oo";
        String strValue        = String.Empty;
        string dirName         = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName());

        Directory.CreateDirectory(dirName);


        try
        {
            DirectoryInfo dir = null;


            // [] Do the current dir


            strLoc = "Loc_909d9";

            dir = new DirectoryInfo(dirName);
            iCountTestcases++;
            if (!dir.ToString().Equals(Path.GetFileName(dirName)))
            {
                iCountErrors++;
                printerr("Error_209xu! Incorrect Directory returned , dir==" + dir.ToString());
                Console.WriteLine(dirName);
                Console.WriteLine(dir == null);
                Console.WriteLine(dir);
            }
            // [] Root drive

            strLoc = "Loc_20u9x";

            dir = new DirectoryInfo(Path.GetPathRoot(Directory.GetCurrentDirectory()));
            iCountTestcases++;
            if (!dir.ToString().Equals(Path.GetPathRoot(Directory.GetCurrentDirectory())))
            {
                iCountErrors++;
                printerr("Error_2098x! Incorrect dir returned==" + dir.ToString());
            }

            string testDir = Path.Combine(dirName, "TestDir");
            Directory.CreateDirectory(testDir);
            dir = new DirectoryInfo(testDir);
            iCountTestcases++;

            if (!dir.FullName.Equals(testDir))
            {
                iCountErrors++;
                printerr("Error_298yx! Incorrect dir constructed, dir==" + dir.ToString());
            }
            dir.Delete();

            // [] Whitespace string

            strLoc = "Loc_298yb";

            if (Interop.IsWindows) // whitespace-only names are valid on Unix
            {
                iCountTestcases++;
                try
                {
                    dir = new DirectoryInfo("      ");
                    dir.Create();
                    iCountErrors++;
                    printerr("Error_09rux! Expected exception not thrown, dir==" + dir.ToString());
                }
                catch (ArgumentException)
                {
                }
                catch (Exception exc)
                {
                    iCountErrors++;
                    printerr("Bug 14866 Error_4577c! Incorrect exception thrown, exc==" + exc.ToString());
                }
            }

            // [] Go for same dir

            strLoc = "Loc_949gg";

            dir = new DirectoryInfo(".");
            iCountTestcases++;
            if (!dir.FullName.Equals(Directory.GetCurrentDirectory()))
            {
                iCountErrors++;
                printerr("Error_299xu! Incorrect dir constructed, dir==" + dir.ToString());
            }

            // [] go one dir up

            strLoc = "Loc_9937a";

            dir = new DirectoryInfo("..");
            iCountTestcases++;
            if (!dir.FullName.Equals(Path.GetDirectoryName(Directory.GetCurrentDirectory())))
            {
                iCountErrors++;
                printerr("Error_298xy! Incorrect dir returned, dir==" + dir.ToString());
            }
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine("Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==" + exc_general.ToString());
        }
        ////  Finish Diagnostics
        if (iCountErrors != 0)
        {
            Console.WriteLine("FAiL! " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString());
        }

        FailSafeDirectoryOperations.DeleteDirectory(dirName, true);
        Assert.Equal(0, iCountErrors);
    }