/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into a string.</summary>
		/// <remarks>
		/// Serializes an <code>XMPMeta</code>-object as RDF into a string.
		/// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a
		/// string to ensure the correctness of &quot;exact packet size&quot;.
		/// </remarks>
		/// <param name="xmp">a metadata implementation object</param>
		/// <param name="options">
		/// Options to control the serialization (see
		/// <see cref="Com.Adobe.Xmp.Options.SerializeOptions"/>
		/// ).
		/// </param>
		/// <returns>Returns a string containing the serialized RDF.</returns>
		/// <exception cref="Com.Adobe.Xmp.XMPException">on serializsation errors.</exception>
		public static string SerializeToString(XMPMetaImpl xmp, SerializeOptions options)
		{
			// forces the encoding to be UTF-16 to get the correct string length
			options = options != null ? options : new SerializeOptions();
			options.SetEncodeUTF16BE(true);
			ByteArrayOutputStream @out = new ByteArrayOutputStream(2048);
			Serialize(xmp, @out, options);
			try
			{
				return @out.ToString(options.GetEncoding());
			}
			catch (UnsupportedEncodingException)
			{
				// cannot happen as UTF-8/16LE/BE is required to be implemented in
				// Java
				return @out.ToString();
			}
		}
Пример #2
0
		public virtual void TestDiffModified()
		{
			Write(new FilePath(db.WorkTree, "test.txt"), "test");
			FilePath folder = new FilePath(db.WorkTree, "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			OutputStream @out = new ByteArrayOutputStream();
			IList<DiffEntry> entries = git.Diff().SetOutputStream(@out).Call();
			NUnit.Framework.Assert.AreEqual(1, entries.Count);
			NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
				());
			NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
			NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
			string actual = @out.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
Пример #3
0
		public virtual void TestDiff()
		{
			Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
			FilePath folder = new FilePath(db.Directory.GetParent(), "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os));
			df.SetRepository(db);
			df.SetPathFilter(PathFilter.Create("folder"));
			DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
			FileTreeIterator newTree = new FileTreeIterator(db);
			df.Format(oldTree, newTree);
			df.Flush();
			string actual = os.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
Пример #4
0
			public override void Run()
			{
				HttpClient httpclient = new DefaultHttpClient();
				HttpResponse response;
				string responseString = null;
				try
				{
					response = httpclient.Execute(new HttpGet(pathToDoc.ToExternalForm()));
					StatusLine statusLine = response.GetStatusLine();
					NUnit.Framework.Assert.IsTrue(statusLine.GetStatusCode() == HttpStatus.ScOk);
					if (statusLine.GetStatusCode() == HttpStatus.ScOk)
					{
						ByteArrayOutputStream @out = new ByteArrayOutputStream();
						response.GetEntity().WriteTo(@out);
						@out.Close();
						responseString = @out.ToString();
						NUnit.Framework.Assert.IsTrue(responseString.Contains(doc1Id));
						Log.D(ReplicationTest.Tag, "result: " + responseString);
					}
					else
					{
						response.GetEntity().GetContent().Close();
						throw new IOException(statusLine.GetReasonPhrase());
					}
				}
				catch (ClientProtocolException e)
				{
					NUnit.Framework.Assert.IsNull("Got ClientProtocolException: " + e.GetLocalizedMessage
						(), e);
				}
				catch (IOException e)
				{
					NUnit.Framework.Assert.IsNull("Got IOException: " + e.GetLocalizedMessage(), e);
				}
				httpRequestDoneSignal.CountDown();
			}
Пример #5
0
 public virtual void TestDiffWithPrefixes()
 {
     Write(new FilePath(db.WorkTree, "test.txt"), "test");
     Git git = new Git(db);
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("Initial commit").Call();
     Write(new FilePath(db.WorkTree, "test.txt"), "test change");
     OutputStream @out = new ByteArrayOutputStream();
     git.Diff().SetOutputStream(@out).SetSourcePrefix("old/").SetDestinationPrefix("new/"
         ).Call();
     string actual = @out.ToString();
     string expected = "diff --git old/test.txt new/test.txt\n" + "index 30d74d2..4dba797 100644\n"
          + "--- old/test.txt\n" + "+++ new/test.txt\n" + "@@ -1 +1 @@\n" + "-test\n" + "\\ No newline at end of file\n"
          + "+test change\n" + "\\ No newline at end of file\n";
     NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
 }
Пример #6
0
 public virtual void TestDiffWithNegativeLineCount()
 {
     Write(new FilePath(db.WorkTree, "test.txt"), "0\n1\n2\n3\n4\n5\n6\n7\n8\n9");
     Git git = new Git(db);
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("Initial commit").Call();
     Write(new FilePath(db.WorkTree, "test.txt"), "0\n1\n2\n3\n4a\n5\n6\n7\n8\n9");
     OutputStream @out = new ByteArrayOutputStream();
     git.Diff().SetOutputStream(@out).SetContextLines(1).Call();
     string actual = @out.ToString();
     string expected = "diff --git a/test.txt b/test.txt\n" + "index f55b5c9..c5ec8fd 100644\n"
          + "--- a/test.txt\n" + "+++ b/test.txt\n" + "@@ -4,3 +4,3 @@\n" + " 3\n" + "-4\n"
          + "+4a\n" + " 5\n";
     NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
 }
Пример #7
0
 public virtual void TestDiffTwoCommits()
 {
     Write(new FilePath(db.WorkTree, "test.txt"), "test");
     FilePath folder = new FilePath(db.WorkTree, "folder");
     folder.Mkdir();
     Write(new FilePath(folder, "folder.txt"), "folder");
     Git git = new Git(db);
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("Initial commit").Call();
     Write(new FilePath(folder, "folder.txt"), "folder change");
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("second commit").Call();
     Write(new FilePath(folder, "folder.txt"), "second folder change");
     git.Add().AddFilepattern(".").Call();
     git.Commit().SetMessage("third commit").Call();
     // bad filter
     DiffCommand diff = git.Diff().SetShowNameAndStatusOnly(true).SetPathFilter(PathFilter
         .Create("test.txt")).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree(GetTreeIterator
         ("HEAD^"));
     IList<DiffEntry> entries = diff.Call();
     NUnit.Framework.Assert.AreEqual(0, entries.Count);
     // no filter, two commits
     OutputStream @out = new ByteArrayOutputStream();
     diff = git.Diff().SetOutputStream(@out).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree
         (GetTreeIterator("HEAD^"));
     entries = diff.Call();
     NUnit.Framework.Assert.AreEqual(1, entries.Count);
     NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
         ());
     NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
     NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
     string actual = @out.ToString();
     string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
          + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
          "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
     NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
 }