예제 #1
0
        private static void TestWeirdPaths()
        {
            // null path
            String nullPath = null;

            TestWeirdPathIter(nullPath, "nullPath", new ArgumentNullException());

            // empty path
            String emptyPath = "";

            TestWeirdPathIter(emptyPath, "emptyPath", new ArgumentException());

            // whitespace-only path
            char[] whitespacePathChars = { (char)0x9, (char)0xA };
            String whitespacePath      = new String(whitespacePathChars);

            TestWeirdPathIter(whitespacePath, "whitespacePath", new ArgumentException());

            // try to test a path that doesn't exist. Skip if can't find an unused drive
            if (Interop.IsWindows)
            {
                String pathNotExists = null;
                String unusedDrive   = EnumerableUtils.GetUnusedDrive();
                if (unusedDrive != null)
                {
                    pathNotExists = Path.Combine(unusedDrive, "temp", "dir");
                }
                if (pathNotExists != null)
                {
                    TestWeirdPathIter(pathNotExists, "pathNotExists", new DirectoryNotFoundException());
                }
            }

            // file (not dir) name. If we try to do GetFiles, GetDirs, etc in a file (not dir) we get IOException
            String filePath = null;

            foreach (String s in s_utils.expected_Files_Deep)
            {
                if (s != null)
                {
                    filePath = s;
                    break;
                }
            }
            TestWeirdPathIter(filePath, "pathIsFile", new IOException());

            // PathTooLong
            String longPath = Path.Combine(new String('a', IOInputs.MaxDirectory), "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");

            TestWeirdPathIter(longPath, "pathTooLong", new PathTooLongException());

            // path invalid chars
            String invalidCharPath = "temp" + Path.DirectorySeparatorChar + "fsd\0sdsds";

            TestWeirdPathIter(invalidCharPath, "invalidCharPath", new ArgumentException());
        }
예제 #2
0
        private static void TestFileExceptions()
        {
            // Create common file and dir names
            String nullFileName   = null;
            String emptyFileName1 = "";
            String emptyFileName2 = " ";
            String longPath       = Path.Combine(new String('a', IOInputs.MaxDirectory), "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "test.txt");

            String notExistsFileName = null;

            if (Interop.IsWindows) // drive labels
            {
                String unusedDrive = EnumerableUtils.GetUnusedDrive();
                if (unusedDrive != null)
                {
                    notExistsFileName = Path.Combine(unusedDrive, Path.Combine("temp", "notExists", "temp.txt")); // just skip otherwise
                }
            }
            String[]             lines    = { "test line 1", "test line 2" };
            IEnumerable <String> contents = (IEnumerable <String>)lines;

            // Read exceptions
            TestReadFileExceptions(nullFileName, "null path", Encoding.UTF8, new ArgumentNullException());
            TestReadFileExceptions(emptyFileName1, "empty path 1", Encoding.UTF8, new ArgumentException());
            if (Interop.IsWindows) // whitespace-only names are valid on Unix
            {
                TestReadFileExceptions(emptyFileName2, "empty path 2", Encoding.UTF8, new ArgumentException());
            }
            TestReadFileExceptions(longPath, "long path", Encoding.UTF8, new PathTooLongException());
            if (notExistsFileName != null)
            {
                TestReadFileExceptions(notExistsFileName, "not exists", Encoding.UTF8, new DirectoryNotFoundException());
            }
            TestReadFileExceptionsWithEncoding("temp.txt", "null encoding", null, new ArgumentNullException(), File.ReadLines, File.ReadLines, "File.ReadLines");

            // Write exceptions
            TestWriteFileExceptions(nullFileName, "null path", contents, Encoding.UTF8, new ArgumentNullException());
            TestWriteFileExceptions(emptyFileName1, "empty path 1", contents, Encoding.UTF8, new ArgumentException());
            if (Interop.IsWindows) // whitespace-only paths are valid on Unix
            {
                TestWriteFileExceptions(emptyFileName2, "empty path 2", contents, Encoding.UTF8, new ArgumentException());
            }
            TestWriteFileExceptions(longPath, "long path", contents, Encoding.UTF8, new PathTooLongException());
            if (notExistsFileName != null)
            {
                TestWriteFileExceptions(notExistsFileName, "not exists", contents, Encoding.UTF8, new DirectoryNotFoundException());
            }
            TestWriteFileExceptions("temp.txt", "null contents", null, Encoding.UTF8, new ArgumentNullException());

            TestWriteFileExceptionsWithEncoding("temp.txt", "null encoding", contents, null, new ArgumentNullException(), File.WriteAllLines, File.WriteAllLines, "File.WriteAllLines");
            TestWriteFileExceptionsWithEncoding("temp.txt", "null encoding", contents, null, new ArgumentNullException(), File.AppendAllLines, File.AppendAllLines, "File.AppendAllLines");
        }
        public static void runTest()
        {
            s_utils = new EnumerableUtils();

            s_utils.CreateTestDirs();

            TestIEnumerator();
            TestClone();

            s_utils.DeleteTestDirs();

            Assert.True(s_utils.Passed);
        }
예제 #4
0
    public void runTest()
    {
        s_utils = new EnumerableUtils();

        s_utils.CreateTestDirs(TestDirectory);

        TestIEnumerator();
        TestClone();

        s_utils.DeleteTestDirs();

        Assert.True(s_utils.Passed);
    }
예제 #5
0
        public void RunTests()
        {
            utils = new EnumerableUtils();

            utils.CreateTestDirs(TestDirectory);

            TestFileAPIs();

            TestFileExceptions();

            utils.DeleteTestDirs();

            Assert.True(utils.Passed);
        }
예제 #6
0
        public void RunTests()
        {
            utils = new EnumerableUtils();

            utils.CreateTestDirs(TestDirectory);

            TestFileAPIs();

            TestFileExceptions();

            utils.DeleteTestDirs();

            Assert.True(utils.Passed);
        }
예제 #7
0
        public static void RunTests()
        {
            s_utils = new EnumerableUtils();

            s_utils.CreateTestDirs();

            TestDirectoryInfoAPIs();

            TestExceptions();

            TestWhileEnumerating();

            s_utils.DeleteTestDirs();

            Assert.True(s_utils.Passed);
        }
        public static void RunTests()
        {
            s_utils = new EnumerableUtils();

            s_utils.CreateTestDirs();

            TestDirectoryInfoAPIs();

            TestExceptions();

            if (Interop.IsWindows) // test currently relies on the explicit order being returned on Windows
            {
                TestWhileEnumerating();
            }

            s_utils.DeleteTestDirs();

            Assert.True(s_utils.Passed);
        }
예제 #9
0
        private static void TestFileExceptions()
        {
            // Create common file and dir names
            String nullFileName   = null;
            String emptyFileName1 = "";
            String emptyFileName2 = " ";
            String longPath       = new String('a', 240) + @"\bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\test.txt";

            String notExistsFileName = null;
            String unusedDrive       = EnumerableUtils.GetUnusedDrive();

            if (unusedDrive != null)
            {
                notExistsFileName = Path.Combine(unusedDrive, @"temp\notExists\temp.txt"); // just skip otherwise
            }
            String[]             lines    = { "test line 1", "test line 2" };
            IEnumerable <String> contents = (IEnumerable <String>)lines;

            // Read exceptions
            TestReadFileExceptions(nullFileName, "null path", Encoding.UTF8, new ArgumentNullException());
            TestReadFileExceptions(emptyFileName1, "empty path 1", Encoding.UTF8, new ArgumentException());
            TestReadFileExceptions(emptyFileName2, "empty path 2", Encoding.UTF8, new ArgumentException());
            TestReadFileExceptions(longPath, "long path", Encoding.UTF8, new PathTooLongException());
            if (notExistsFileName != null)
            {
                TestReadFileExceptions(notExistsFileName, "not exists", Encoding.UTF8, new DirectoryNotFoundException());
            }
            TestReadFileExceptionsWithEncoding("temp.txt", "null encoding", null, new ArgumentNullException(), File.ReadLines, File.ReadLines, "File.ReadLines");

            // Write exceptions
            TestWriteFileExceptions(nullFileName, "null path", contents, Encoding.UTF8, new ArgumentNullException());
            TestWriteFileExceptions(emptyFileName1, "empty path 1", contents, Encoding.UTF8, new ArgumentException());
            TestWriteFileExceptions(emptyFileName2, "empty path 2", contents, Encoding.UTF8, new ArgumentException());
            TestWriteFileExceptions(longPath, "long path", contents, Encoding.UTF8, new PathTooLongException());
            if (notExistsFileName != null)
            {
                TestWriteFileExceptions(notExistsFileName, "not exists", contents, Encoding.UTF8, new DirectoryNotFoundException());
            }
            TestWriteFileExceptions("temp.txt", "null contents", null, Encoding.UTF8, new ArgumentNullException());

            TestWriteFileExceptionsWithEncoding("temp.txt", "null encoding", contents, null, new ArgumentNullException(), File.WriteAllLines, File.WriteAllLines, "File.WriteAllLines");
            TestWriteFileExceptionsWithEncoding("temp.txt", "null encoding", contents, null, new ArgumentNullException(), File.AppendAllLines, File.AppendAllLines, "File.AppendAllLines");
        }
예제 #10
0
        public static void runTest()
        {
            s_utils = new EnumerableUtils();

            s_utils.CreateTestDirs();

            TestDirectoryAPIs();

            TestExceptions();

            if (Interop.IsWindows) // test relies on the explicit order being returned on Windows
            {
                TestWhileEnumerating();
            }

            s_utils.DeleteTestDirs();

            Assert.True(s_utils.Passed);
        }
예제 #11
0
    private static void TestWeirdPathFast(String path, String pathDescription, Exception expectedException, EnumerableUtils.GetFSEsFast0 fseMethod0, EnumerableUtils.GetFSEsFast1 fseMethod1, EnumerableUtils.GetFSEsFast2 fseMethod2, String methodName)
    {
        int failCount = 0;
        String chkptFlag = "chkpt_wpf_";
        try
        {
            IEnumerable<String> dirs1 = fseMethod0(path);
            Console.WriteLine(chkptFlag + "1: didn't throw");
            failCount++;
        }
        catch (Exception e)
        {
            if (e.GetType() != expectedException.GetType())
            {
                failCount++;
                Console.WriteLine(chkptFlag + "2: threw wrong exception");
                Console.WriteLine(e);
            }
        }


        try
        {
            IEnumerable<String> dirs1 = fseMethod1(path, "*");
            Console.WriteLine(chkptFlag + "3: didn't throw");
            failCount++;
        }
        catch (Exception e)
        {
            if (e.GetType() != expectedException.GetType())
            {
                failCount++;
                Console.WriteLine(chkptFlag + "4: threw wrong exception");
                Console.WriteLine(e);
            }
        }

        if (fseMethod2 != null)
        {
            try
            {
                IEnumerable<String> dirs2 = fseMethod2(path, "*", SearchOption.AllDirectories);
                Console.WriteLine(chkptFlag + "5: didn't throw");
                failCount++;
            }
            catch (Exception e)
            {
                if (e.GetType() != expectedException.GetType())
                {
                    failCount++;
                    Console.WriteLine(chkptFlag + "6: threw wrong exception");
                    Console.WriteLine(e);
                }
            }
        }

        String testName = String.Format("TestWeirdPathFast({0})", pathDescription);
        s_utils.PrintTestStatus(testName, methodName, failCount);
    }
예제 #12
0
    private static void TestSearchOptionOutOfRangeFast(EnumerableUtils.GetFSEsFast2 fseMethod, String methodName)
    {
        int failCount = 0;
        String chkptFlag = "chkpt_soorf_";
        try
        {
            IEnumerable<String> dirs1 = fseMethod(s_utils.testDir, "*", (SearchOption)5);
            Console.WriteLine(chkptFlag + "1: didn't throw");
            failCount++;
        }
        catch (ArgumentOutOfRangeException) { } // expected
        catch (Exception e)
        {
            failCount++;
            Console.WriteLine(chkptFlag + "2: threw wrong exception");
            Console.WriteLine(e);
        }

        s_utils.PrintTestStatus("TestSearchOptionOutOfRangeFast", methodName, failCount);
    }
예제 #13
0
    private static void TestSearchPattern(String path, String pattern, String patternDescription, Exception expectedException,
        EnumerableUtils.GetFSEs1 fseMethod1, EnumerableUtils.GetFSEs2 fseMethod2, String methodName)
    {
        int failCount = 0;
        String chkptFlag = "chkpt_nspat_";
        try
        {
            String[] dirs1 = fseMethod1(path, pattern);
            Console.WriteLine(chkptFlag + "1: didn't throw");
            failCount++;
        }
        catch (Exception e)
        {
            if (e.GetType() != expectedException.GetType())
            {
                failCount++;
                Console.WriteLine(chkptFlag + "2: threw wrong exception");
                Console.WriteLine(e);
            }
        }

        if (fseMethod2 != null)
        {
            try
            {
                String[] dirs2 = fseMethod2(path, pattern, SearchOption.AllDirectories);
                Console.WriteLine(chkptFlag + "3: didn't throw");
                failCount++;
            }
            catch (Exception e)
            {
                if (e.GetType() != expectedException.GetType())
                {
                    failCount++;
                    Console.WriteLine(chkptFlag + "4: threw wrong exception");
                    Console.WriteLine(e);
                }
            }
        }

        String testName = String.Format("TestSearchPattern({0})", patternDescription);
        s_utils.PrintTestStatus(testName, methodName, failCount);
    }
예제 #14
0
        private static void TestWriteFileExceptionsWithEncoding(String path, String pathDescription, IEnumerable<String> contents, Encoding encoding, Exception expectedException,
                                                                    EnumerableUtils.WriteFastDelegate1 writeDelegate, EnumerableUtils.WriteFastDelegate2 writeDelegate2, String methodName)
        {
            int failCount = 0;
            String chkptFlag = "chkpt_wfewe_";

            try
            {
                writeDelegate2(path, contents, encoding);
                Console.WriteLine(chkptFlag + "1: didn't throw");
                failCount++;
            }
            catch (Exception e)
            {
                if (e.GetType() != expectedException.GetType())
                {
                    failCount++;
                    Console.WriteLine(chkptFlag + "2: threw wrong exception");
                    Console.WriteLine(e);
                }
            }

            String testName = String.Format("TestWriteFileExceptions_Encoding({0})", pathDescription);
            utils.PrintTestStatus(testName, methodName, failCount);
        }
예제 #15
0
        private static void TestReadFileExceptionsDefaultEncoding(String path, String pathDescription, Exception expectedException,
                                                                    EnumerableUtils.ReadFastDelegate1 readDelegate, EnumerableUtils.ReadFastDelegate2 readDelegate2, String methodName)
        {
            int failCount = 0;
            String chkptFlag = "chkpt_rfede_";

            try
            {
                IEnumerable<String> lines = readDelegate(path);
                Console.WriteLine(chkptFlag + "1: didn't throw");
                failCount++;
            }
            catch (Exception e)
            {
                if (e.GetType() != expectedException.GetType())
                {
                    failCount++;
                    Console.WriteLine(chkptFlag + "2: threw wrong exception");
                    Console.WriteLine(e);
                }
            }

            String testName = String.Format("TestReadFileExceptions({0})", pathDescription);
            utils.PrintTestStatus(testName, methodName, failCount);
        }