public virtual void TestInCoreLimit_SwitchOnCopy()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer
                                                                                  .DEFAULT_IN_CORE_LIMIT * 2);
            try
            {
                ByteArrayInputStream @in = new ByteArrayInputStream(test, TemporaryBuffer.DEFAULT_IN_CORE_LIMIT
                                                                    , test.Length - TemporaryBuffer.DEFAULT_IN_CORE_LIMIT);
                b.Write(test, 0, TemporaryBuffer.DEFAULT_IN_CORE_LIMIT);
                b.Copy(@in);
                b.Close();
                NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
                }
            }
            finally
            {
                b.Destroy();
            }
        }
        public virtual void TestOneBlock_BulkWrite()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.Block
                                                                                  .SZ);
            try
            {
                b.Write(test, 0, 2);
                b.Write(test, 2, 4);
                b.Write(test, 6, test.Length - 6 - 2);
                b.Write(test, test.Length - 2, 2);
                b.Close();
                NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
                }
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #3
0
		public virtual void TestOneByte()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			byte test = unchecked((byte)new TestRng(Sharpen.Extensions.GetTestName()).NextInt
				());
			try
			{
				b.Write(test);
				b.Close();
				NUnit.Framework.Assert.AreEqual(1, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(1, r.Length);
					NUnit.Framework.Assert.AreEqual(test, r[0]);
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(1, r.Length);
					NUnit.Framework.Assert.AreEqual(test, r[0]);
				}
			}
			finally
			{
				b.Destroy();
			}
		}
        public virtual void TestOneBlockAndHalf_Copy()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.Block
                                                                                  .SZ * 3 / 2);
            try
            {
                ByteArrayInputStream @in = new ByteArrayInputStream(test);
                b.Write(@in.Read());
                b.Copy(@in);
                b.Close();
                NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
                }
            }
            finally
            {
                b.Destroy();
            }
        }
        public virtual void TestOneByte()
        {
            TemporaryBuffer b    = new TemporaryBuffer.LocalFile();
            byte            test = unchecked ((byte)new TestRng(Sharpen.Extensions.GetTestName()).NextInt
                                                  ());

            try
            {
                b.Write(test);
                b.Close();
                NUnit.Framework.Assert.AreEqual(1, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(1, r.Length);
                    NUnit.Framework.Assert.AreEqual(test, r[0]);
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(1, r.Length);
                    NUnit.Framework.Assert.AreEqual(test, r[0]);
                }
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #6
0
        public virtual void TestRandomWrites()
        {
            TemporaryBuffer b   = new TemporaryBuffer.LocalFile();
            TestRng         rng = new TestRng(Sharpen.Extensions.GetTestName());
            int             max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;

            byte[] expect = new byte[max];
            try
            {
                int  written = 0;
                bool onebyte = true;
                while (written < max)
                {
                    if (onebyte)
                    {
                        byte v = unchecked ((byte)rng.NextInt());
                        b.Write(v);
                        expect[written++] = v;
                    }
                    else
                    {
                        int    len = Math.Min(rng.NextInt() & 127, max - written);
                        byte[] tmp = rng.NextBytes(len);
                        b.Write(tmp, 0, len);
                        System.Array.Copy(tmp, 0, expect, written, len);
                        written += len;
                    }
                    onebyte = !onebyte;
                }
                NUnit.Framework.Assert.AreEqual(expect.Length, written);
                b.Close();
                NUnit.Framework.Assert.AreEqual(expect.Length, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(expect.Length, r.Length);
                    for (int i = 0; i < expect.Length; i++)
                    {
                        Assert.AreEqual(expect[i], r[i]);
                    }
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(expect.Length, r.Length);
                    for (int i = 0; i < expect.Length; i++)
                    {
                        Assert.AreEqual(expect[i], r[i]);
                    }
                }
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #7
0
 public virtual void TestDestroyWhileOpen()
 {
     TemporaryBuffer b = new TemporaryBuffer.LocalFile();
     try
     {
         b.Write(new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT
              * 2));
     }
     finally
     {
         b.Destroy();
     }
 }
        public virtual void TestDestroyWhileOpen()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            try
            {
                b.Write(new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.DEFAULT_IN_CORE_LIMIT
                                                                                * 2));
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #9
0
		public virtual void TestEmpty()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			try
			{
				b.Close();
				NUnit.Framework.Assert.AreEqual(0, b.Length());
				byte[] r = b.ToByteArray();
				NUnit.Framework.Assert.IsNotNull(r);
				NUnit.Framework.Assert.AreEqual(0, r.Length);
			}
			finally
			{
				b.Destroy();
			}
		}
        public virtual void TestEmpty()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            try
            {
                b.Close();
                NUnit.Framework.Assert.AreEqual(0, b.Length());
                byte[] r = b.ToByteArray();
                NUnit.Framework.Assert.IsNotNull(r);
                NUnit.Framework.Assert.AreEqual(0, r.Length);
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #11
0
        public virtual void TestOneBlockAndHalf_SingleWrite()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.Block
                                                                                  .SZ * 3 / 2);
            try
            {
                for (int i = 0; i < test.Length; i++)
                {
                    b.Write(test[i]);
                }
                b.Close();
                NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    for (int i = 0; i < test.Length; i++)
                    {
                        Assert.AreEqual(test[i], r[i]);
                    }
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    for (int i = 0; i < test.Length; i++)
                    {
                        Assert.AreEqual(test[i], r[i]);
                    }
                }
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #12
0
        public virtual void TestInCoreLimit_SwitchBeforeAppendByte()
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer
                                                                                  .DEFAULT_IN_CORE_LIMIT * 3);
            try
            {
                b.Write(test, 0, test.Length - 1);
                b.Write(test[test.Length - 1]);
                b.Close();
                NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
                {
                    byte[] r = b.ToByteArray();
                    NUnit.Framework.Assert.IsNotNull(r);
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    for (int i = 0; i < test.Length; i++)
                    {
                        Assert.AreEqual(test[i], r[i]);
                    }
                }
                {
                    ByteArrayOutputStream o = new ByteArrayOutputStream();
                    b.WriteTo(o, null);
                    o.Close();
                    byte[] r = o.ToByteArray();
                    NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
                    for (int i = 0; i < test.Length; i++)
                    {
                        Assert.AreEqual(test[i], r[i]);
                    }
                }
            }
            finally
            {
                b.Destroy();
            }
        }
Beispiel #13
0
 private string[] ExtractFileLines(Encoding[] csGuess)
 {
     TemporaryBuffer[] tmp = new TemporaryBuffer[GetParentCount() + 1];
     try
     {
         for (int i = 0; i < tmp.Length; i++)
         {
             tmp[i] = new TemporaryBuffer.LocalFile();
         }
         foreach (HunkHeader h in GetHunks())
         {
             h.ExtractFileLines(tmp);
         }
         string[] r = new string[tmp.Length];
         for (int i_1 = 0; i_1 < tmp.Length; i_1++)
         {
             Encoding cs = csGuess != null ? csGuess[i_1] : null;
             if (cs == null)
             {
                 cs = Constants.CHARSET;
             }
             r[i_1] = RawParseUtils.Decode(cs, tmp[i_1].ToByteArray());
         }
         return r;
     }
     catch (IOException ioe)
     {
         throw new RuntimeException(JGitText.Get().cannotConvertScriptToText, ioe);
     }
     finally
     {
         foreach (TemporaryBuffer b in tmp)
         {
             if (b != null)
             {
                 b.Destroy();
             }
         }
     }
 }
		public virtual void TestInCoreLimit_SwitchBeforeAppendByte()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer
				.DEFAULT_IN_CORE_LIMIT * 3);
			try
			{
				b.Write(test, 0, test.Length - 1);
				b.Write(test[test.Length - 1]);
				b.Close();
				NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					for (int i = 0; i < test.Length; i ++)
						Assert.AreEqual (test[i], r[i]);
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					for (int i = 0; i < test.Length; i ++)
						Assert.AreEqual (test[i], r[i]);
				}
			}
			finally
			{
				b.Destroy();
			}
		}
Beispiel #15
0
 /// <exception cref="System.IO.IOException"></exception>
 private static byte[] ReadFully(InputStream @is)
 {
     TemporaryBuffer b = new TemporaryBuffer.LocalFile();
     try
     {
         b.Copy(@is);
         b.Close();
         return b.ToByteArray();
     }
     finally
     {
         b.Destroy();
     }
 }
Beispiel #16
0
		public virtual void TestOneBlock_BulkWrite()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.Block
				.SZ);
			try
			{
				b.Write(test, 0, 2);
				b.Write(test, 2, 4);
				b.Write(test, 6, test.Length - 6 - 2);
				b.Write(test, test.Length - 2, 2);
				b.Close();
				NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
				}
			}
			finally
			{
				b.Destroy();
			}
		}
Beispiel #17
0
		public virtual void TestOneBlockAndHalf_Copy()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.Block
				.SZ * 3 / 2);
			try
			{
				ByteArrayInputStream @in = new ByteArrayInputStream(test);
				b.Write(@in.Read());
				b.Copy(@in);
				b.Close();
				NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
				}
			}
			finally
			{
				b.Destroy();
			}
		}
Beispiel #18
0
		public virtual void TestInCoreLimit_SwitchOnCopy()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer
				.DEFAULT_IN_CORE_LIMIT * 2);
			try
			{
				ByteArrayInputStream @in = new ByteArrayInputStream(test, TemporaryBuffer.DEFAULT_IN_CORE_LIMIT
					, test.Length - TemporaryBuffer.DEFAULT_IN_CORE_LIMIT);
				b.Write(test, 0, TemporaryBuffer.DEFAULT_IN_CORE_LIMIT);
				b.Copy(@in);
				b.Close();
				NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(test, r));
				}
			}
			finally
			{
				b.Destroy();
			}
		}
Beispiel #19
0
		public virtual void TestRandomWrites()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			TestRng rng = new TestRng(Sharpen.Extensions.GetTestName());
			int max = TemporaryBuffer.DEFAULT_IN_CORE_LIMIT * 2;
			byte[] expect = new byte[max];
			try
			{
				int written = 0;
				bool onebyte = true;
				while (written < max)
				{
					if (onebyte)
					{
						byte v = unchecked((byte)rng.NextInt());
						b.Write(v);
						expect[written++] = v;
					}
					else
					{
						int len = Math.Min(rng.NextInt() & 127, max - written);
						byte[] tmp = rng.NextBytes(len);
						b.Write(tmp, 0, len);
						System.Array.Copy(tmp, 0, expect, written, len);
						written += len;
					}
					onebyte = !onebyte;
				}
				NUnit.Framework.Assert.AreEqual(expect.Length, written);
				b.Close();
				NUnit.Framework.Assert.AreEqual(expect.Length, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(expect.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(expect, r));
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(expect.Length, r.Length);
					NUnit.Framework.Assert.IsTrue(Arrays.Equals(expect, r));
				}
			}
			finally
			{
				b.Destroy();
			}
		}
		public virtual void TestOneBlockAndHalf_SingleWrite()
		{
			TemporaryBuffer b = new TemporaryBuffer.LocalFile();
			byte[] test = new TestRng(Sharpen.Extensions.GetTestName()).NextBytes(TemporaryBuffer.Block
				.SZ * 3 / 2);
			try
			{
				for (int i = 0; i < test.Length; i++)
				{
					b.Write(test[i]);
				}
				b.Close();
				NUnit.Framework.Assert.AreEqual(test.Length, b.Length());
				{
					byte[] r = b.ToByteArray();
					NUnit.Framework.Assert.IsNotNull(r);
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					for (int i = 0; i < test.Length; i ++)
						Assert.AreEqual (test[i], r[i]);
				}
				{
					ByteArrayOutputStream o = new ByteArrayOutputStream();
					b.WriteTo(o, null);
					o.Close();
					byte[] r = o.ToByteArray();
					NUnit.Framework.Assert.AreEqual(test.Length, r.Length);
					for (int i = 0; i < test.Length; i ++)
						Assert.AreEqual (test[i], r[i]);
				}
			}
			finally
			{
				b.Destroy();
			}
		}