Пример #1
0
        public void Test_Write()
        {
            TestDataType data;
            FileStream   file;

            /*
             * Test null file stream
             */
            data = new TestDataType(0);
            try
            {
                data.Write(null, 0);
            }
            catch (ArgumentNullException ex)
            {
                /* Passes if this exception is caught */
                Assert.AreEqual(1, 1);
            }

            /*
             * Try to write from a negative actual offset
             */
            file = new FileStream(TestHelper.EmptyFile, FileMode.Open);
            data = new TestDataType(-4);

            try
            {
                data.Read(file, 0);

                /* Fail if this is reached */
                Assert.AreEqual(1, 0);
            }
            catch (InvalidOperationException ex)
            {
                /* Pass if this exception is caught */
                Assert.AreEqual(1, 1);
            }

            file.Close();
        }
Пример #2
0
        public void Test_readFile()
        {
            FileStream   file;
            TestDataType data;

            /*
             * Test null file stream
             */
            data = new TestDataType(0);
            try
            {
                data.Read(null, 0);
            }
            catch (ArgumentNullException ex)
            {
                /* Passes if this exception is caught */
                Assert.AreEqual(1, 1);
            }

            /*
             * Try to read from a negative actual offset
             */
            file = new FileStream(TestHelper.EmptyFile, FileMode.Open);
            data = new TestDataType(-4);

            try
            {
                data.Read(file, 0);

                /* Fail if this is reached */
                Assert.AreEqual(1, 0);
            }
            catch (InvalidOperationException ex)
            {
                /* Pass if this exception is caught */
                Assert.AreEqual(1, 1);
            }

            file.Close();

            /*
             * Try to read past end of file
             */
            file = new FileStream(TestHelper.EmptyFile, FileMode.Open);
            data = new TestDataType(0);

            try
            {
                data.Read(file, 0);

                /* Fail if this is reached */
                Assert.AreEqual(1, 0);
            }
            catch (Exception ex)
            {
                /* Pass if this exception is caught */
                Assert.AreEqual(1, 1);
            }

            /*
             * Valid read tests are handled by classes that inherit DataType.
             */
        }