| 1 |
using System; |
| 2 |
using System.Collections.Generic; |
| 3 |
using System.ComponentModel; |
| 4 |
using System.Data; |
| 5 |
using System.Drawing; |
| 6 |
using System.Linq; |
| 7 |
using System.Text; |
| 8 |
using System.Windows.Forms; |
| 9 |
using System.Diagnostics; |
| 10 |
using System.Reflection; |
| 11 |
using nft.framework; |
| 12 |
|
| 13 |
namespace nft.test |
| 14 |
{ |
| 15 |
public partial class TestLauncher : Form |
| 16 |
{ |
| 17 |
public TestLauncher() { |
| 18 |
InitializeComponent(); |
| 19 |
listEntryView.statusLabel = lblInfo; |
| 20 |
listener = new MyTracer(tbLog); |
| 21 |
} |
| 22 |
|
| 23 |
protected MyTracer listener; |
| 24 |
public TraceListener TraceListener { |
| 25 |
get { return listener; } |
| 26 |
} |
| 27 |
|
| 28 |
protected bool init = false; |
| 29 |
protected override void OnShown(EventArgs e) { |
| 30 |
base.OnShown(e); |
| 31 |
if (!init) { |
| 32 |
init = true; |
| 33 |
// TODO: カスタム属性をつけたメソッドを集められないか? |
| 34 |
Assembly[] a = new Assembly[] { Assembly.GetExecutingAssembly(), typeof(TestUtil).Assembly }; |
| 35 |
LoadAssemblies(a); |
| 36 |
listEntryView.AdjustColumns(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
private ProgressForm progressForm = null; |
| 41 |
protected void LoadAssemblies(Assembly[] array) { |
| 42 |
if (progressForm != null) { |
| 43 |
if (!progressForm.Disposing && !progressForm.IsDisposed) { |
| 44 |
progressForm.Close(); |
| 45 |
} |
| 46 |
progressForm.Dispose(); |
| 47 |
} |
| 48 |
progressForm = new ProgressForm(); |
| 49 |
progressForm.Assemblies = array; |
| 50 |
progressForm.ShowDialog(this); |
| 51 |
progressForm.Dispose(); |
| 52 |
} |
| 53 |
|
| 54 |
public void AddTestEntry(TestInfo info) { |
| 55 |
//info.Run(); |
| 56 |
listEntryView.AddTestInfo(info); |
| 57 |
} |
| 58 |
|
| 59 |
#region context menu event handlers |
| 60 |
private void btnReverseCheck_Click(object sender, EventArgs e) { |
| 61 |
listEntryView.ReverseCheckAll(); |
| 62 |
} |
| 63 |
|
| 64 |
private void btnRunChcked_Click(object sender, EventArgs e) { |
| 65 |
listEntryView.RunCheckedEntries(); |
| 66 |
} |
| 67 |
|
| 68 |
private void cmenuReverseCheck_Click(object sender, EventArgs e) { |
| 69 |
listEntryView.ReverseCheckSelected(); |
| 70 |
} |
| 71 |
|
| 72 |
private void cmenuUncheck_Click(object sender, EventArgs e) { |
| 73 |
listEntryView.SetCheckSelected(false); |
| 74 |
} |
| 75 |
|
| 76 |
private void cmenuCheck_Click(object sender, EventArgs e) { |
| 77 |
listEntryView.SetCheckSelected(true); |
| 78 |
} |
| 79 |
|
| 80 |
private void cmenuRun_Click(object sender, EventArgs e) { |
| 81 |
listEntryView.RunSelectedEntries(); |
| 82 |
} |
| 83 |
#endregion |
| 84 |
|
| 85 |
private void listEntryView_DoubleClick(object sender, MouseEventArgs e) { |
| 86 |
if ((Control.ModifierKeys & Keys.Alt) == Keys.Alt) { |
| 87 |
ListViewItem item = listEntryView.HitTest(e.Location).Item; |
| 88 |
if (item != null) { |
| 89 |
item.Checked = !item.Checked; |
| 90 |
JumpToLastLog(item); |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
protected void JumpToLastLog(ListViewItem item) { |
| 96 |
if (item != null) { |
| 97 |
string log = listEntryView.StartLogText(item); |
| 98 |
int x = tbLog.Text.LastIndexOf(log); |
| 99 |
if (x >= 0) { |
| 100 |
tbLog.Focus(); |
| 101 |
tbLog.Select(x, log.Length); |
| 102 |
tbLog.ScrollToCaret(); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
public class MyTracer : TraceListener |
| 109 |
{ |
| 110 |
readonly TextBox tbOutput; |
| 111 |
|
| 112 |
public MyTracer(TextBox outbox) { |
| 113 |
tbOutput = outbox; |
| 114 |
} |
| 115 |
|
| 116 |
public override void Write(string message) { |
| 117 |
tbOutput.AppendText(message); |
| 118 |
} |
| 119 |
|
| 120 |
public override void WriteLine(string message) { |
| 121 |
tbOutput.AppendText(message); |
| 122 |
tbOutput.AppendText(System.Environment.NewLine); |
| 123 |
} |
| 124 |
} |
| 125 |
} |