-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved three test methods from main project into test project
- Loading branch information
Showing
3 changed files
with
107 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace RtfDomParser.Tests | ||
{ | ||
internal static class Helper | ||
{ | ||
/// <summary> | ||
/// Test to generate a little rtf document | ||
/// </summary> | ||
/// <param name="w">RTF text writer</param> | ||
internal static void TestBuildRTF(RTFWriter w) | ||
{ | ||
w.Encoding = System.Text.Encoding.GetEncoding(936); | ||
// write header | ||
w.WriteStartGroup(); | ||
w.WriteKeyword("rtf1"); | ||
w.WriteKeyword("ansi"); | ||
w.WriteKeyword("ansicpg" + w.Encoding.CodePage); | ||
// wirte font table | ||
w.WriteStartGroup(); | ||
w.WriteKeyword("fonttbl"); | ||
w.WriteStartGroup(); | ||
w.WriteKeyword("f0"); | ||
w.WriteText("Arial;"); | ||
w.WriteEndGroup(); | ||
w.WriteStartGroup(); | ||
w.WriteKeyword("f1"); | ||
w.WriteText("Times New Roman;"); | ||
w.WriteEndGroup(); | ||
w.WriteEndGroup(); | ||
// write color table | ||
w.WriteStartGroup(); | ||
w.WriteKeyword("colortbl"); | ||
w.WriteText(";"); | ||
w.WriteKeyword("red0"); | ||
w.WriteKeyword("green0"); | ||
w.WriteKeyword("blue255"); | ||
w.WriteText(";"); | ||
w.WriteEndGroup(); | ||
// write content | ||
w.WriteKeyword("qc"); // set alignment center | ||
w.WriteKeyword("f0"); // set font | ||
w.WriteKeyword("fs30"); // set font size | ||
w.WriteText("This is the first paragraph text "); | ||
w.WriteKeyword("cf1"); // set text color | ||
w.WriteText("Arial "); | ||
w.WriteKeyword("cf0"); // set default color | ||
w.WriteKeyword("f1"); // set font | ||
w.WriteText("Align center ABC12345"); | ||
w.WriteKeyword("par"); // new paragraph | ||
w.WriteKeyword("pard"); // clear format | ||
w.WriteKeyword("f1"); // set font | ||
w.WriteKeyword("fs20"); // set font size | ||
w.WriteKeyword("cf1"); | ||
w.WriteText("This is the secend paragraph Arial left alignment ABC12345"); | ||
// finish | ||
w.WriteEndGroup(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.IO; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
|
||
namespace RtfDomParser.Tests | ||
{ | ||
[TestFixture] | ||
public class RtfTest | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Defaults.FontName = System.Windows.Forms.Control.DefaultFont.Name; | ||
} | ||
|
||
/// <summary> | ||
/// Test generate rtf file | ||
/// after execute this function you can open c:\a.rtf | ||
/// </summary> | ||
[Test] | ||
public void TestWriteFile() | ||
{ | ||
string file = Path.GetFullPath("a.rtf"); | ||
RTFWriter w = new RTFWriter(file); | ||
Helper.TestBuildRTF(w); | ||
w.Close(); | ||
System.Windows.Forms.MessageBox.Show($"OK, you can open file {file} now."); | ||
} | ||
|
||
/// <summary> | ||
/// Test generate rtf text and copy to windows clipboard | ||
/// after execute this function , you can paste rtf text in MS Word | ||
/// </summary> | ||
[Test] | ||
[RequiresThread(ApartmentState.STA)] | ||
public void TestClipboard() | ||
{ | ||
System.IO.StringWriter myStr = new System.IO.StringWriter(); | ||
RTFWriter w = new RTFWriter(myStr); | ||
Helper.TestBuildRTF(w); | ||
w.Close(); | ||
System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject(); | ||
data.SetData(System.Windows.Forms.DataFormats.Rtf, myStr.ToString()); | ||
System.Windows.Forms.Clipboard.SetDataObject(data, true); | ||
System.Windows.Forms.MessageBox.Show("OK, you can paste words in MS Word."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters