-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
133 lines (116 loc) · 5.04 KB
/
Form1.cs
File metadata and controls
133 lines (116 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
namespace JavaTestCenter
{
public partial class JavaTestCenter : Form
{
OpenFileDialog ofd = new OpenFileDialog();
public JavaTestCenter()
{
InitializeComponent();
}
private void Button_Run_Click(object sender, EventArgs e)
{
TextBox_Process.Text = "";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.WorkingDirectory = TextBox_Directory.Text;
p.StartInfo.FileName = "javac";
p.StartInfo.Arguments = ((RadioButton_CP.Checked) ? "-cp . " + TextBox_JavaFile.Text : (RadioButton_D.Checked) ? "-d . *.java" : TextBox_JavaFile.Text);
TextBox_Process.Text += "javac " + ((RadioButton_CP.Checked) ? "-cp . " + TextBox_JavaFile.Text : (RadioButton_D.Checked) ? "-d . *.java" : TextBox_JavaFile.Text) + " [Compiling...]";
try
{
p.Start();
p.WaitForExit();
p.StartInfo.FileName = "java";
p.StartInfo.Arguments = TextBox_JavaFile.Text.Replace(".java", "");
TextBox_Process.Text += Environment.NewLine + "java " + TextBox_JavaFile.Text.Replace(".java", "") + " [Running...]";
p.Start();
StreamWriter sw = p.StandardInput;
foreach (string line in TextBox_Input.Lines)
{
sw.WriteLine(line);
}
sw.Close();
p.WaitForExit();
string error = p.StandardError.ReadToEnd();
if (error.Length > 0)
{
MessageBox.Show("Error occurred: " + Environment.NewLine + error);
}
string output = p.StandardOutput.ReadToEnd();
TextBox_OutputActual.Text = output.Trim();
if (TextBox_Output.Text.Length > 0)
{
if (TextBox_OutputActual.Lines.Length != TextBox_Output.Lines.Length)
{
TextBox_OutputActual.Text += Environment.NewLine + "Match: NO - Line count different.";
return;
}
else
{
int count = 0;
int compareCount = TextBox_OutputActual.Lines.Length;
TextBox_OutputActual.Text += Environment.NewLine + Environment.NewLine;
for (int i = 0; i < compareCount; i++)
{
if (!TextBox_OutputActual.Lines[i].Equals(TextBox_Output.Lines[i]))
{
count++;
TextBox_OutputActual.Text += "Line " + i + ":" + Environment.NewLine + "Expected \"" + TextBox_Output.Lines[i] + "\" got \"" + TextBox_OutputActual.Lines[i] + "\"." + Environment.NewLine;
}
}
if (count == 0)
{
TextBox_OutputActual.Text += Environment.NewLine + "Match: YES";
}
else
{
TextBox_OutputActual.Text += Environment.NewLine + "Match: NO - " + count + " lines different.";
}
}
}
TextBox_Process.Text += " [Done.]";
}
catch (Exception)
{
TextBox_Process.Text += " [Error.]";
MessageBox.Show("Error: Verify Java is in PATH.");
}
}
private void Button_JavaFile_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
ofd.Filter = "JAVA (*.java)|*.java";
if (ofd.ShowDialog() == DialogResult.OK)
{
TextBox_JavaFile.Text = Path.GetFileName(ofd.FileName);
TextBox_Directory.Text = ofd.FileName.Substring(0, ofd.FileName.LastIndexOf("\\") + 1);
}
}
private void Button_Input_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] lines = File.ReadAllLines(ofd.FileName);
TextBox_Input.Text = String.Join(Environment.NewLine, lines);
}
}
private void Button_Output_Click(object sender, EventArgs e)
{
ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] lines = File.ReadAllLines(ofd.FileName);
TextBox_Output.Text = String.Join(Environment.NewLine, lines);
}
}
}
}