Пример #1
0
        public void CompileTaskNullCompilerTest()
        {
            var sourceCodeFilePath =
                Helper.CreateFileForCompilation(
                    CompileServiceLanguageSourceCode.CPPCorrectSourceCode, this.compiler.Extension);

            var compileTask = new CompileTask(null, sourceCodeFilePath);
        }
Пример #2
0
        public void CompileTastConstructorTest()
        {
            var sourceCodeFilePath =
                Helper.CreateFileForCompilation(
                    CompileServiceLanguageSourceCode.CPPCorrectSourceCode, this.compiler.Extension);

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

            File.Delete(sourceCodeFilePath);
        }
Пример #3
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);
        }
Пример #4
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";
        }
Пример #5
0
 public void CompileTaskBadPathTest()
 {
     var compileTask = new CompileTask(this.compiler, "BadFilePath");
 }
Пример #6
0
        public void CompileTaskConstructorTest()
        {
            // create compiler
            var compiler = new Compiler
                {
                    Name = "CPP", 
                    Location = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Compilers\CPP8\Compiler\CL.EXE"), 
                    Extension = "cpp", 
                    Arguments = "/I\"$CompilerDirectory$\" $SourceFilePath$ /link /LIBPATH:\"$CompilerDirectory$\"", 
                    CompiledExtension = "exe", 
                    IsNeedShortPath = true
                };
            var sourceCodeFilePath =
                Helper.CreateFileForCompilation(
                    CompileServiceLanguageSourceCode.CPPCorrectSourceCode, compiler.Extension);

            try
            {
                var compileTask = new CompileTask(null, sourceCodeFilePath);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                var compileTask = new CompileTask(compiler, "BadFilePath");
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                var compileTask = new CompileTask(compiler, sourceCodeFilePath);
                Assert.AreEqual(true, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            File.Delete(sourceCodeFilePath);
        }