Skip to content

Commit

Permalink
v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ReignOfComputer committed May 13, 2019
1 parent fd15f9a commit 740c427
Show file tree
Hide file tree
Showing 15 changed files with 1,178 additions and 1 deletion.
25 changes: 25 additions & 0 deletions JavaTestCenter.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.106
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaTestCenter", "JavaTestCenter\JavaTestCenter.csproj", "{45794E0B-BEAF-4A4F-9A0D-408A75B48651}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45794E0B-BEAF-4A4F-9A0D-408A75B48651}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C16A067E-5194-4C7A-9774-474D21E7DA1F}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions JavaTestCenter/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
394 changes: 394 additions & 0 deletions JavaTestCenter/Form1.Designer.cs

Large diffs are not rendered by default.

133 changes: 133 additions & 0 deletions JavaTestCenter/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
}
}
}
Loading

0 comments on commit 740c427

Please sign in to comment.