private void btn_Run_Code_Click(object sender, EventArgs e)
        {
            if (selectedProblem == null)
            {
                MessageBox.Show("当前未选择题目");
                return;
            }
            PHPRunner runner = new PHPRunner();

            //selectedProblem.InputSample = "1 2";
            //selectedProblem.Problemcode = "<?php echo $_GET['a']; echo $_GET['b'];";
            if (this.problemcode.Text == "")
            {
                MessageBox.Show("请输入解答代码!");
                return;
            }
            runner.Code = this.problemcode.Text;
            if (selectedProblem.InputSample != "" || selectedProblem.InputSample != null)
            {
                string[] parameters = selectedProblem.InputSample.Split(' ');
                for (int i = 0; i < parameters.Length; i++)
                {
                    runner.QueryString += "parameter" + i + "=" + parameters[i] + "&";

                    //runner.Code = runner.Code.Replace(Regex.Match(runner.Code,"\\$_GET\\[\\S*\\]$").Value, "$_GET['parameter"+i+"']");
                }
                MatchCollection mc = Regex.Matches(runner.Code, "\\$_GET\\[\\S*\\]");
                int             j  = 0;
                foreach (Match m in mc)
                {
                    //MessageBox.Show(m.Value);
                    runner.Code = runner.Code.Replace(m.Value, "$_GET['parameter" + j + "']");
                    j++;
                }
                //runner.Code =  runner.Code.Replace("$_GET['a']", "$_GET['parameter0']");
                // runner.Code = runner.Code.Replace("$_GET['b']", "$_GET['parameter1']");
                runner.QueryString = runner.QueryString.Substring(0, runner.QueryString.Length - 1);
            }

            String res = runner.run();

            Browser_output.Text           = res;
            Answer_tabControl.SelectedTab = Browse_Output;
            if (res == selectedProblem.OutputSample)
            {
                this.Main_TreeView.SelectedNode.ImageIndex = 1;
                selectedProblem.Status = 1;
                MessageBox.Show("Accept");
                ProblemList.UpdateStatus(selectedProblem);
            }
            else
            {
                this.Main_TreeView.SelectedNode.ImageIndex = 2;
                selectedProblem.Status = -1;
                MessageBox.Show("WrongAnswer");
                ProblemList.UpdateStatus(selectedProblem);
            }
            this.Browser_output.Text = res;
            this.Main_TreeView.Invalidate();
        }
예제 #2
0
        public void RunTest()
        {
            PHPRunner phpRunner = new PHPRunner();

            phpRunner.Code = "echo 'hello';";
            Assert.AreEqual("hello", phpRunner.run());
        }
예제 #3
0
        public void PostTest()
        {
            PHPRunner phpRunner = new PHPRunner();

            //phpRunner.SetCommandPath("../../../php");
            phpRunner.Code     = "echo $_POST['who'];";
            phpRunner.PostData = "who=casper";
            Assert.AreEqual("casper", phpRunner.run());
        }
예제 #4
0
        public void ServerTest()
        {
            PHPRunner phpRunner = new PHPRunner();

            //phpRunner.SetCommandPath("../../../php");
            phpRunner.Code        = "echo $_SERVER['QUERY_STRING'];";
            phpRunner.QueryString = "who=casper";
            // phpRunner.PostData = "who=casper";
            Assert.AreEqual("who=casper", phpRunner.run());
        }
예제 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            PHPRunner php = new PHPRunner();

            php.Code = "<?php\n" + this.SourceCode.Text;
            string result = php.run();

            if (result == structureOfProblem.OutputSample)
            {
                MessageBox.Show("Accepted!");
            }
            else
            {
                MessageBox.Show("Wrong answer");
            }
        }
        private void btn_Run_Answer_Click(object sender, EventArgs e)
        {
            if (selectedProblem == null)
            {
                MessageBox.Show("当前未选择题目");
                return;
            }
            PHPRunner runner = new PHPRunner();

            //selectedProblem.InputSample = "1 2";
            //selectedProblem.Problemcode = "<?php echo $_GET['a']; echo $_GET['b'];";
            runner.Code = selectedProblem.Problemcode;
            if (selectedProblem.InputSample != "" || selectedProblem.InputSample != null)
            {
                string[] parameters = selectedProblem.InputSample.Split(' ');
                for (int i = 0; i < parameters.Length; i++)
                {
                    runner.QueryString += "parameter" + i + "=" + parameters[i] + "&";

                    //runner.Code = runner.Code.Replace(Regex.Match(runner.Code,"\\$_GET\\[\\S*\\]$").Value, "$_GET['parameter"+i+"']");
                }
                MatchCollection mc = Regex.Matches(runner.Code, "\\$_GET\\[\\S*\\]");
                int             j  = 0;
                foreach (Match m in mc)
                {
                    //MessageBox.Show(m.Value);
                    runner.Code = runner.Code.Replace(m.Value, "$_GET['parameter" + j + "']");
                    j++;
                }
                //runner.Code =  runner.Code.Replace("$_GET['a']", "$_GET['parameter0']");
                // runner.Code = runner.Code.Replace("$_GET['b']", "$_GET['parameter1']");
                runner.QueryString = runner.QueryString.Substring(0, runner.QueryString.Length - 1);
            }

            String res = runner.run();

            StandarOutputrichTextBox.Text  = res;
            Problem_tabControl.SelectedTab = Standard_Answer_Output_Browse;
        }