Dispose() защищенный Метод

protected Dispose ( bool disposing ) : void
disposing bool
Результат void
Пример #1
0
        /**
         * Tears down the fixture, for example, close a network connection. This
         * method is called after a test is executed.
         */
        public override void TearDown()
        {
            try
            {
                br.Dispose();
            }
#pragma warning disable 168
            catch (Exception e)
#pragma warning restore 168
            {
            }
        }
Пример #2
0
 public void Test_Close()
 {
     // Test for method void java.io.BufferedReader.close()
     try
     {
         br = new BufferedCharFilter(new StringReader(testString));
         br.Dispose();
         br.Read();
         fail("Read on closed stream");
     }
     catch (Exception x) when(x.IsIOException())
     {
         return;
     }
 }
Пример #3
0
        public void Test_Close()
        {
            // Test for method void java.io.BufferedReader.close()
            try
            {
                br = new BufferedCharFilter(new StringReader(testString));
                br.Dispose();
                br.Read();
                fail("Read on closed stream");
            }
#pragma warning disable 168
            catch (IOException x)
#pragma warning restore 168
            {
                return;
            }
        }
Пример #4
0
        public void Test_Read_CII_Exception()
        {
            br = new BufferedCharFilter(new StringReader(testString));
            char[] nullCharArray = null;
            char[] charArray     = testString.toCharArray();

            try
            {
                br.Read(nullCharArray, -1, -1);

                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(nullCharArray, -1, 0);

                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(nullCharArray, 0, -1);

                fail("should throw NullPointerException");
            }
#pragma warning disable 168
            catch (NullReferenceException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(nullCharArray, 0, 0);

                fail("should throw NullPointerException");
            }
#pragma warning disable 168
            catch (NullReferenceException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(nullCharArray, 0, 1);

                fail("should throw NullPointerException");
            }
#pragma warning disable 168
            catch (NullReferenceException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(charArray, -1, -1);

                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(charArray, -1, 0);

                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
                // expected
            }

            br.Read(charArray, 0, 0);
            br.Read(charArray, 0, charArray.Length);
            br.Read(charArray, charArray.Length, 0);

            try
            {
                br.Read(charArray, charArray.Length + 1, 0);

                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
                //expected
            }

            try
            {
                br.Read(charArray, charArray.Length + 1, 1);

                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
                //expected
            }

            br.Dispose();

            try
            {
                br.Read(nullCharArray, -1, -1);

                fail("should throw IOException");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(charArray, -1, 0);

                fail("should throw IOException");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // expected
            }

            try
            {
                br.Read(charArray, 0, -1);

                fail("should throw IOException");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // expected
            }
        }
Пример #5
0
        public void Test_ReadCII()
        {
            char[]             ca    = new char[2];
            BufferedCharFilter toRet = new BufferedCharFilter(new StreamReader(
                                                                  new MemoryStream(new byte[0])));

            /* Null buffer should throw NPE even when len == 0 */
            try
            {
                toRet.Read(null, 1, 0);

                fail("null buffer reading zero bytes should throw NPE");
            }
#pragma warning disable 168
            catch (NullReferenceException e)
#pragma warning restore 168
            {
                //expected
            }

            try
            {
                toRet.Dispose();
            }
            catch (IOException e)
            {
                fail("unexpected 1: " + e);
            }

            try
            {
                toRet.Read(null, 1, 0);

                fail("null buffer reading zero bytes on closed stream should throw IOException");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                //expected
            }

            /* Closed reader should throw IOException reading zero bytes */
            try
            {
                toRet.Read(ca, 0, 0);

                fail("Reading zero bytes on a closed reader should not work");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // expected
            }

            /*
             * Closed reader should throw IOException in preference to index out of
             * bounds
             */
            try
            {
                // Read should throw IOException before
                // ArrayIndexOutOfBoundException
                toRet.Read(ca, 1, 5);

                fail("IOException should have been thrown");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // expected
            }

            // Test to ensure that a drained stream returns 0 at EOF
            toRet = new BufferedCharFilter(new StreamReader(

                                               new MemoryStream(new byte[2])));
            try
            {
                assertEquals("Emptying the reader should return two bytes", 2,
                             toRet.Read(ca, 0, 2));

                // LUCENENET specific: end of stream should be 0 in .NET
                assertEquals("EOF on a reader should be 0", 0, toRet.Read(ca, 0,
                                                                          2));
                //assertEquals("EOF on a reader should be -1", -1, toRet.Read(ca, 0,
                //        2));

                assertEquals("Reading zero bytes at EOF should work", 0, toRet
                             .Read(ca, 0, 0));
            }
            catch (IOException ex)
            {
                fail("Unexpected IOException : " + ex.ToString());
            }

            // Test for method int java.io.BufferedReader.read(char [], int, int)
            try
            {
                char[] buf = new char[testString.Length];
                br = new BufferedCharFilter(new StringReader(testString));
                br.Read(buf, 50, 500);

                assertTrue("Chars read improperly", new string(buf, 50, 500)
                           .Equals(testString.Substring(0, 500 - 0), StringComparison.Ordinal));
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                fail("Exception during read test");
            }

            BufferedCharFilter bufin = new BufferedCharFilter(new ReaderAnonymousInnerClassHelper());

            //BufferedCharFilter bufin = new BufferedCharFilter(new Reader() {
            //            int size = 2, pos = 0;

            //char[] contents = new char[size];

            //public int read()
            //{
            //				if (pos >= size)
            //					throw new IOException("Read past end of data");
            //				return contents[pos++];
            //			}

            //			public int read(char[] buf, int off, int len) throws IOException
            //{
            //				if (pos >= size)
            //					throw new IOException("Read past end of data");
            //int toRead = len;
            //				if (toRead > (size - pos))
            //					toRead = size - pos;
            //				System.arraycopy(contents, pos, buf, off, toRead);
            //				pos += toRead;
            //				return toRead;
            //			}

            //			public boolean ready() throws IOException
            //{
            //				return size - pos > 0;
            //}

            //public void close()
            //{
            //}
            //		});
            try
            {
                bufin.Read();
                int result = bufin.Read(new char[2], 0, 2);

                assertTrue("Incorrect result: " + result, result == 1);
            }
            catch (IOException e)
            {
                fail("Unexpected: " + e);
            }

            //regression for HARMONY-831
            try
            {
                new BufferedCharFilter(new StringReader(""), 9).Read(new char[] { }, 7, 0);
                fail("should throw IndexOutOfBoundsException");
            }
#pragma warning disable 168
            catch (ArgumentOutOfRangeException e)
#pragma warning restore 168
            {
            }

            // Regression for HARMONY-54
            char[]             ch     = { };
            BufferedCharFilter reader = new BufferedCharFilter(new StringReader(new string(ch)));
            try
            {
                // Check exception thrown when the reader is open.
                reader.Read(null, 1, 0);
                fail("Assert 0: NullPointerException expected");
            }
#pragma warning disable 168
            catch (NullReferenceException e)
#pragma warning restore 168
            {
                // Expected
            }

            // Now check IOException is thrown in preference to
            // NullPointerexception when the reader is closed.
            reader.Dispose();
            try
            {
                reader.Read(null, 1, 0);
                fail("Assert 1: IOException expected");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // Expected
            }

            try
            {
                // And check that the IOException is thrown before
                // ArrayIndexOutOfBoundException
                reader.Read(ch, 0, 42);
                fail("Assert 2: IOException expected");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // expected
            }
        }
Пример #6
0
        public void Test_MarkI()
        {
            // Test for method void java.io.BufferedReader.mark(int)
            char[] buf = null;
            br = new BufferedCharFilter(new StringReader(testString));
            br.Skip(500);
            br.Mark(1000);
            br.Skip(250);
            br.Reset();
            buf = new char[testString.Length];
            br.Read(buf, 0, 500);

            assertTrue("Failed to set mark properly", testString.Substring(500,
                                                                           1000 - 500).Equals(new string(buf, 0, 500), StringComparison.Ordinal));

            try
            {
                br = new BufferedCharFilter(new StringReader(testString), 800);
                br.Skip(500);
                br.Mark(250);
                br.Read(buf, 0, 1000);
                br.Reset();

                fail("Failed to invalidate mark properly");
            }
#pragma warning disable 168
            catch (IOException x)
#pragma warning restore 168
            {
                // Expected
            }

            char[] chars = new char[256];
            for (int i = 0; i < 256; i++)
            {
                chars[i] = (char)i;
            }
            BufferedCharFilter @in = new BufferedCharFilter(new StringReader(new String(
                                                                                 chars)), 12);

            @in.Skip(6);
            @in.Mark(14);
            @in.Read(new char[14], 0, 14);
            @in.Reset();

            assertTrue("Wrong chars", @in.Read() == (char)6 &&
                       @in.Read() == (char)7);

            @in = new BufferedCharFilter(new StringReader(new String(chars)), 12);
            @in.Skip(6);
            @in.Mark(8);
            @in.Skip(7);
            @in.Reset();

            assertTrue("Wrong chars 2", @in.Read() == (char)6 &&
                       @in.Read() == (char)7);

            BufferedCharFilter br2 = new BufferedCharFilter(new StringReader("01234"), 2);
            br2.Mark(3);
            char[] carray = new char[3];
            int    result = br2.read(carray);
            assertEquals(3, result);
            assertEquals("Assert 0:", '0', carray[0]);
            assertEquals("Assert 1:", '1', carray[1]);
            assertEquals("Assert 2:", '2', carray[2]);
            assertEquals("Assert 3:", '3', br2.Read());

            br2 = new BufferedCharFilter(new StringReader("01234"), 2);
            br2.Mark(3);
            carray = new char[4];
            result = br2.read(carray);
            assertEquals("Assert 4:", 4, result);
            assertEquals("Assert 5:", '0', carray[0]);
            assertEquals("Assert 6:", '1', carray[1]);
            assertEquals("Assert 7:", '2', carray[2]);
            assertEquals("Assert 8:", '3', carray[3]);
            assertEquals("Assert 9:", '4', br2.Read());
            assertEquals("Assert 10:", -1, br2.Read());

            BufferedCharFilter reader = new BufferedCharFilter(new StringReader("01234"));
            reader.Mark(int.MaxValue);
            reader.Read();
            reader.Dispose();
        }