Пример #1
0
    public static bool ErrorTest(Stream s)
    {
        Console.WriteLine("  (09)  Error test on stream: " + s.GetType( ).Name);
        //	Test EndRead & EndWrite's Type safety
        byte[]            bytes = new byte[0];
        IAsyncResult      asyncResult;
        BogusIAsyncResult bogus = new BogusIAsyncResult( );

        if (s.CanRead)
        {
            asyncResult = s.BeginRead(bytes, 0, 0, null, null);                                                                     /*	BeginRead	*/
            try
            {
                s.EndWrite(asyncResult);                                                                                                        /*	EndWrite	*/
                throw new Exception("EndWrite with an asyncResult from BeginRead should have thrown!");
            }
            catch (ArgumentException)    {       }
        }
        if (s.CanWrite)
        {
            asyncResult = s.BeginWrite(bytes, 0, 0, null, null);                                                                      /*	BeginWrite	*/
            try
            {
                s.EndRead(asyncResult);                                                                                                         /*	EndRead		*/
                throw new Exception("EndRead with an asyncResult from BeginWrite should have thrown!");
            }
            catch (ArgumentException)    {       }
            //	Verify EndWrite doesn't allow using the same asyncResult twice.
            s.EndWrite(asyncResult);                                                                                                            /*	EndWrite	*/
            try
            {
                s.EndWrite(asyncResult);                                                                                                        /*	EndWrite	*/
                throw new Exception("Exception EndWrite was called twice w/ same IAsyncResult from "
                                    + s.GetType( ).Name + ", but didn't throw!");
            }
            catch (InvalidOperationException)    {       }
        }
        try
        {
            s.EndRead(bogus);                                                                                                                           /*	EndRead		*/
            throw new Exception("EndRead with a bogus IAsyncResult object should have thrown!");
        }
        catch (ArgumentException)        {       }
        try
        {
            s.EndWrite(bogus);                                                                                                                          /*	EndWrite	*/
            throw new Exception("EndWrite with a bogus IAsyncResult object should have thrown!");
        }
        catch (ArgumentException)        {       }
        return(true);
    }
Пример #2
0
 public static bool ErrorTest(Stream s) 
 {
     Console.WriteLine("  (09)  Error test on stream: "+s.GetType( ).Name);
     //	Test EndRead & EndWrite's Type safety
     byte[]				bytes		= new byte[0];
     IAsyncResult		asyncResult;
     BogusIAsyncResult	bogus		= new BogusIAsyncResult( );
     if(s.CanRead) 
     {
         asyncResult = s.BeginRead(bytes,0,0,null,null);									/*	BeginRead	*/ 
         try 
         {
             s.EndWrite(asyncResult);													/*	EndWrite	*/ 
             throw new Exception("EndWrite with an asyncResult from BeginRead should have thrown!");
         }
         catch(ArgumentException)	{	}
     }
     if(s.CanWrite) 
     {
         asyncResult=s.BeginWrite(bytes,0,0,null,null);									/*	BeginWrite	*/ 
         try 
         {
             s.EndRead(asyncResult);														/*	EndRead		*/ 
             throw new Exception("EndRead with an asyncResult from BeginWrite should have thrown!");
         }
         catch(ArgumentException)	{	}
         //	Verify EndWrite doesn't allow using the same asyncResult twice.
         s.EndWrite(asyncResult);														/*	EndWrite	*/ 
         try 
         {
             s.EndWrite(asyncResult);													/*	EndWrite	*/ 
             throw new Exception("Exception EndWrite was called twice w/ same IAsyncResult from "
                 +s.GetType( ).Name+", but didn't throw!");
         }
         catch(InvalidOperationException)	{	}
     }
     try 
     {
         s.EndRead(bogus);																/*	EndRead		*/ 
         throw new Exception("EndRead with a bogus IAsyncResult object should have thrown!");
     }
     catch(ArgumentException)	{	}
     try 
     {
         s.EndWrite(bogus);																/*	EndWrite	*/ 
         throw new Exception("EndWrite with a bogus IAsyncResult object should have thrown!");
     }
     catch(ArgumentException)	{	}
     return true;
 }