示例#1
0
        public void CompileTaskGetStandardStringTest()
        {
            // create default compile task
            var sourceCodeFilePath = Helper.CreateFileForCompilation("my incorrect code", this.compiler.Extension);

            var compileTask = new CompileTask(this.compiler, sourceCodeFilePath);
            var result = compileTask.Execute();

            Assert.AreEqual(result, false);
            Assert.AreEqual(string.IsNullOrEmpty(compileTask.StandardError), false);
            Assert.AreEqual(string.IsNullOrEmpty(compileTask.StandardOutput), false);
        }
示例#2
0
        public string Compile(string source, string language, string[] input, string[] output, int timelimit, int memorylimit)
        {
             // remove after testing
            const string CompilerDirectory = "Compilers";
            var compilers = new Compilers(CompilerDirectory);
            compilers.Load();
            //----

            if (string.IsNullOrEmpty(language))
                throw new Exception("Bad language name");

            source = HttpUtility.UrlDecode(source);
            Compiler currentCompiler = compilers.GetCompiler(language);

            if (currentCompiler == null)
                throw new Exception("Can't find compiler with such name");

            string compileFilePath = Classes.Helper.CreateFileForCompilation(source, currentCompiler.Extension);

            var compileTask = new CompileTask(currentCompiler, compileFilePath);

            if (!compileTask.Execute())
                return "CompilationError";

            var executeFilePath = Path.ChangeExtension(compileFilePath, currentCompiler.CompiledExtension);

            for (int i = 0; i < input.Length; i++)
            {
                var currentStatus = Tester.Test(executeFilePath, input[i], output[i], timelimit, memorylimit);

                if (currentStatus.TestResult != "Accepted")
                {
                    currentStatus.TestResult = currentStatus.TestResult + " Test: " + i;
                    return currentStatus.TestResult;
                }
            }

            return "Accepted";
        }