Exemplo n.º 1
0
        public void open_Object()
        {
            var fileName        = "test.txt";
            var fileContents_1  = "someText";
            var fileContents_2  = "someText2";
            var expectedSha1_1  = "61447cbfe08f98ece3b0491e9e111bcb3188d79a";
            var expectedSha1_2  = "6b384b15fbeecdd9747f35ff3ce3db4de86c72a4";

            //Before writing fileContents_1
            Assert.IsNull   (nGit.open_Object(expectedSha1_1));
            Assert.IsNull   (nGit.open_Object(expectedSha1_2));

            nGit.file_Create(fileName, fileContents_1);
            nGit.add_and_Commit_using_Status();

            //After writing fileContents_1
            Assert.IsNotNull(nGit.open_Object(expectedSha1_1));
            Assert.IsNull   (nGit.open_Object(expectedSha1_2));

            var objectLoader = nGit.open_Object(expectedSha1_1);

            Assert.NotNull(objectLoader);

            //check content
            var bytes1 = objectLoader.bytes();
            var bytes2 = objectLoader.stream().bytes();
            Assert.AreEqual(bytes1.ascii(), fileContents_1);
            Assert.AreEqual(bytes2.ascii(), fileContents_1);

            //write fileContents_2
            nGit.file_Create(fileName, fileContents_2);
            nGit.add_and_Commit_using_Status();

            //After writing fileContents_2
            Assert.IsNotNull(nGit.open_Object(expectedSha1_1));
            Assert.IsNotNull(nGit.open_Object(expectedSha1_2));

            //Test exception handing
            Assert.IsNull(nGit.open_Object(null));
            Assert.IsNull(nGit.open_Object(expectedSha1_2.replace("6", "1")));
            Assert.IsNull(nGit.open_Object(expectedSha1_2.replace("6", "-")));
            Assert.IsNull ((null as ObjectLoader).stream());
            Assert.IsEmpty((null as ObjectLoader).bytes());
            Assert.IsEmpty((null as ObjectStream).bytes());

            var badObjectStream = new ObjectStream.SmallStream(0, null);
            Assert.IsEmpty(badObjectStream.bytes());

            var badObjectLoader = new ObjectLoader.SmallObject(0, null);
            Assert.IsEmpty(badObjectLoader.bytes());
        }
        public virtual void TestSmallObjectLoader()
        {
            byte[]       act = GetRng().NextBytes(512);
            ObjectLoader ldr = new ObjectLoader.SmallObject(Constants.OBJ_BLOB, act);

            NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, ldr.GetType());
            NUnit.Framework.Assert.AreEqual(act.Length, ldr.GetSize());
            NUnit.Framework.Assert.IsFalse(ldr.IsLarge(), "not is large");
            NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes());
            NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes(1));
            NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes(int.MaxValue));
            byte[] copy = ldr.GetBytes();
            NUnit.Framework.Assert.AreNotSame(act, copy);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
            copy = ldr.GetBytes(1);
            NUnit.Framework.Assert.AreNotSame(act, copy);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
            copy = ldr.GetBytes(int.MaxValue);
            NUnit.Framework.Assert.AreNotSame(act, copy);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
            ObjectStream @in = ldr.OpenStream();

            NUnit.Framework.Assert.IsNotNull(@in, "has stream");
            NUnit.Framework.Assert.IsTrue(@in is ObjectStream.SmallStream, "is small stream");
            NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, @in.GetType());
            NUnit.Framework.Assert.AreEqual(act.Length, @in.GetSize());
            NUnit.Framework.Assert.AreEqual(act.Length, @in.Available());
            NUnit.Framework.Assert.IsTrue(@in.MarkSupported(), "mark supported");
            copy = new byte[act.Length];
            NUnit.Framework.Assert.AreEqual(act.Length, @in.Read(copy));
            NUnit.Framework.Assert.AreEqual(0, @in.Available());
            NUnit.Framework.Assert.AreEqual(-1, @in.Read());
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
            ByteArrayOutputStream tmp = new ByteArrayOutputStream();

            ldr.CopyTo(tmp);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, tmp.ToByteArray()), "same content"
                                          );
        }
Exemplo n.º 3
0
		public virtual void TestSmallObjectLoader()
		{
			byte[] act = GetRng().NextBytes(512);
			ObjectLoader ldr = new ObjectLoader.SmallObject(Constants.OBJ_BLOB, act);
			NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, ldr.GetType());
			NUnit.Framework.Assert.AreEqual(act.Length, ldr.GetSize());
			NUnit.Framework.Assert.IsFalse(ldr.IsLarge(), "not is large");
			NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes());
			NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes(1));
			NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes(int.MaxValue));
			byte[] copy = ldr.GetBytes();
			NUnit.Framework.Assert.AreNotSame(act, copy);
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
			copy = ldr.GetBytes(1);
			NUnit.Framework.Assert.AreNotSame(act, copy);
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
			copy = ldr.GetBytes(int.MaxValue);
			NUnit.Framework.Assert.AreNotSame(act, copy);
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
			ObjectStream @in = ldr.OpenStream();
			NUnit.Framework.Assert.IsNotNull(@in, "has stream");
			NUnit.Framework.Assert.IsTrue(@in is ObjectStream.SmallStream, "is small stream");
			NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, @in.GetType());
			NUnit.Framework.Assert.AreEqual(act.Length, @in.GetSize());
			NUnit.Framework.Assert.AreEqual(act.Length, @in.Available());
			NUnit.Framework.Assert.IsTrue(@in.MarkSupported(), "mark supported");
			copy = new byte[act.Length];
			NUnit.Framework.Assert.AreEqual(act.Length, @in.Read(copy));
			NUnit.Framework.Assert.AreEqual(0, @in.Available());
			NUnit.Framework.Assert.AreEqual(-1, @in.Read());
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
			ByteArrayOutputStream tmp = new ByteArrayOutputStream();
			ldr.CopyTo(tmp);
			NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, tmp.ToByteArray()), "same content"
				);
		}