Skip to content

Commit 740c427

Browse files
v1.0
1 parent fd15f9a commit 740c427

15 files changed

+1178
-1
lines changed

JavaTestCenter.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.106
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaTestCenter", "JavaTestCenter\JavaTestCenter.csproj", "{45794E0B-BEAF-4A4F-9A0D-408A75B48651}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {C16A067E-5194-4C7A-9774-474D21E7DA1F}
24+
EndGlobalSection
25+
EndGlobal

JavaTestCenter/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>

JavaTestCenter/Form1.Designer.cs

+394
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JavaTestCenter/Form1.cs

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

0 commit comments

Comments
 (0)