Esempio n. 1
0
        public void Truncate()
        {
            IClob testSubject = NewTestSubject();

            if (testSubject.CanWrite)
            {
                long len = testSubject.Length;

                for (int i = (int)len; i >= 0; i--)
                {
                    testSubject.Truncate(i);

                    Assert.AreEqual(i, testSubject.Length);
                }
            }

            testSubject = NewTestSubject();

            try
            {
                testSubject.Truncate(-1);

                Assert.Fail("successful invocation of Truncate(len) with len < 0");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }

            try
            {
                testSubject.Truncate(testSubject.Length + 10);

                Assert.Fail("successful invocation of Truncate(len) "
                            + "with len > testSubject.Length");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }
        }
Esempio n. 2
0
        public void Free()
        {
            IClob testSubject = NewTestSubject();

            long length = testSubject.Length;

            Assert.AreEqual(LobCharsLength, length);

            try
            {
                testSubject.Wrap("5678");

                Assert.Fail("successful invocation of Wrap(object) before Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            testSubject.Free();

            try
            {
                Stream stream = testSubject.GetAsciiStream();

                Assert.Fail("successful invocation of GetAsciiStream() after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                TextReader reader = testSubject.GetCharacterStream();

                Assert.Fail("successful invocation of GetCharactertream() after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                string chars = testSubject.GetSubString(0L, (int)length);

                Assert.Fail("successful invocation of GetSubString(long,int) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                long len = testSubject.Length;

                Assert.Fail("successful invocation of Length property after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                long pos = testSubject.Position("234", 1);

                Assert.Fail("successful invocation of Position(string,long) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                long pos = testSubject.Position(new JdbcClob("234"), 1);

                Assert.Fail("successful invocation of Position(IClob,long) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                Stream stream = testSubject.SetAsciiStream(1);

                Assert.Fail("successful invocation of SetAsciiStream(long) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                TextWriter writer = testSubject.SetCharacterStream(1);

                Assert.Fail("successful invocation of SetCharacterStream(long) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                testSubject.SetString(1, "234");

                Assert.Fail("successful invocation of SetString(long,string) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                testSubject.SetString(1, "234", 0, 3);

                Assert.Fail("successful invocation of SetString(long,string,int,int) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                testSubject.Truncate(0);

                Assert.Fail("successful invocation of Truncate(long) after Free()");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(InvalidOperationException), ex);
            }

            try
            {
                testSubject.Wrap("1234");
            }
            catch (Exception ex)
            {
                Assert.Fail("Wrap(object) raised exception after Free(): " + ex.Message);
            }
        }