예제 #1
0
        /// <summary>Resets this to an empty buffer. </summary>
        public virtual void  Reset()
        {
            currentBuffer      = null;
            currentBufferIndex = -1;
            bufferPosition     = 0;
            bufferStart        = 0;
            bufferLength       = 0;

            file.SetLength(0);
        }
예제 #2
0
        /// <summary>Resets this to an empty buffer. </summary>
        public virtual void  Reset()
        {
            try
            {
                Seek(0);
            }
            catch (System.IO.IOException e)
            {
                // should never happen
                throw new System.SystemException(e.ToString());
            }

            file.SetLength(0);
        }
예제 #3
0
 /// <summary>Simulates a crash of OS or machine by overwriting
 /// unsynced files.
 /// </summary>
 public virtual void  Crash()
 {
     lock (this)
     {
         crashed   = true;
         openFiles = new System.Collections.Hashtable();
         System.Collections.IEnumerator it = unSyncedFiles.GetEnumerator();
         unSyncedFiles = new System.Collections.Hashtable();
         int count = 0;
         while (it.MoveNext())
         {
             System.String name = (System.String)((System.Collections.DictionaryEntry)it.Current).Value;
             RAMFile       file = (RAMFile)fileMap_ForNUnit[name];
             if (count % 3 == 0)
             {
                 DeleteFile(name, true);
             }
             else if (count % 3 == 1)
             {
                 // Zero out file entirely
                 int numBuffers = file.NumBuffers();
                 for (int i = 0; i < numBuffers; i++)
                 {
                     byte[] buffer = file.GetBuffer(i);
                     for (int j = 0; j < buffer.Length; j++)
                     {
                         buffer[j] = (byte)0;
                     }
                 }
             }
             else if (count % 3 == 2)
             {
                 // Truncate the file:
                 file.SetLength(file.GetLength() / 2);
             }
             count++;
         }
     }
 }