Example #1
0
        public void SetString()
        {
            IClob testSubject = NewTestSubject();

            if (testSubject.CanWrite)
            {
                testSubject.SetString(1, "123");
                testSubject.SetString(1, "123", 0, 3);
            }

            try
            {
                testSubject.SetString(0, "123");

                Assert.Fail("successful invocation of SetString(pos,str) with pos too small (<1)");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }

            try
            {
                testSubject.SetString(LobCharsLength + 1, "123");

                Assert.Fail("successful invocation of SetChars(pos,str) with "
                            + "pos too large (> LobCharsLength)");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }

            try
            {
                testSubject.SetString(1, null);

                Assert.Fail("successful invocation of SetString(pos,str) with null str");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }

            try
            {
                testSubject.SetString(1, "123", -1, 3);

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

            try
            {
                testSubject.SetString(1, "123", 4, 3);

                Assert.Fail("successful invocation of SetString(pos,str,offs,len) "
                            + "with offs > str.length");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }

            try
            {
                testSubject.SetString(1, "123", 0, -1);

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

            try
            {
                testSubject.SetString(1, "123", 0, 4);

                Assert.Fail("successful invocation of SetString(pos,str,offs,len) "
                            + "with len > str.length");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }
        }
Example #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);
            }
        }