コード例 #1
0
        public void GenerateFileForCompilationTest()
        {
            Settings          settings = FunctionContainer.CreateDefaultSetting();
            CompilationTester compilationTester = new CompilationTester(settings);
            string            source, programPath;
            Language          language;

            //language tests
            source      = CompileServiceLanguageSourceCode.CSCorrectSourceCode;
            language    = Language.CSharp3;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            source      = CompileServiceLanguageSourceCode.CPPCorrectSourceCode;
            language    = Language.VC8;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            source      = CompileServiceLanguageSourceCode.JavaCorrectSourceCode;
            language    = Language.Java6;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            source      = CompileServiceLanguageSourceCode.DelphiCorrectSourceCode;
            language    = Language.Delphi7;
            programPath = compilationTester.GenerateFileForCompilation(source, language);
            Assert.AreEqual(true, CompileServiceHelper.ValidatePath(programPath));

            //incorrect source
            source   = "";
            language = Language.CSharp3;
            try
            {
                programPath = compilationTester.GenerateFileForCompilation(source, language);
                Assert.AreEqual(false, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            //incorrect compiler
            settings.Compilers = new List <Compiler>();
            compilationTester  = new CompilationTester(settings);
            source             = "";
            language           = Language.CSharp3;
            try
            {
                programPath = compilationTester.GenerateFileForCompilation(source, language);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }
コード例 #2
0
ファイル: RunnerTest.cs プロジェクト: nbl852003/iudico
        public void ExecuteIncorrectParametersTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            string            exeString;
            Program           program = FunctionContainer.CreateProgram("", 10000, 100000);
            Result            result;

            try
            {
                //-----------CS-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSCorrectSourceCode,
                                                                Language.CSharp3);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "2";
                program.OutputTest = "23";
                program.Language   = Language.CSharp3;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);

                //-----------CPP-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CPPCorrectSourceCode,
                                                                Language.VC8);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "2";
                program.OutputTest = "23";
                program.Language   = Language.VC8;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);

                //-----------Java-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.JavaCorrectSourceCode,
                                                                Language.Java6);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "2";
                program.OutputTest = "23";
                program.Language   = Language.Java6;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);

                //-----------Delphi-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiCorrectSourceCode,
                                                                Language.Delphi7);
                exeString          = Path.ChangeExtension(programPath, "exe");
                program.InputTest  = "";
                program.OutputTest = " world!";
                program.Language   = Language.Delphi7;
                result             = Runner.Execute(exeString, program);
                Assert.AreNotEqual(result.ProgramStatus, Status.Accepted);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
コード例 #3
0
        public void DelphiIncorrectCodeCompileTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            CompileResult     result;

            try
            {
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiIncorrectSourceCode,
                                                                Language.Delphi7);
                result = Compiler.Delphi7Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
コード例 #4
0
        public void GeneralCompileTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            CompileResult     result;

            try
            {
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSCorrectSourceCode,
                                                                Language.CSharp3);
                result = Compiler.DotNet3Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            // bad input parameters
            try
            {
                result = Compiler.DotNet3Compiler.Compile(null);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                result = Compiler.DotNet3Compiler.Compile("");
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }
コード例 #5
0
ファイル: CompilerTest.cs プロジェクト: nbl852003/iudico
        public void CompileTest()
        {
            CompilationTester tester = new CompilationTester(FunctionContainer.CreateDefaultSetting());
            string            programPath;
            CompileResult     result;

            #region CorrectLangugeSource

            try
            {
                //-----------CS-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSCorrectSourceCode,
                                                                Language.CSharp3);
                result = Compiler.DotNet3Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);

                //-----------CPP-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CPPCorrectSourceCode,
                                                                Language.VC8);
                result = Compiler.VC8Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);

                //-----------Java-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.JavaCorrectSourceCode,
                                                                Language.Java6);
                result = Compiler.Java6Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);

                //-----------Delphi-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiCorrectSourceCode,
                                                                Language.Delphi7);
                result = Compiler.Delphi7Compiler.Compile(programPath);
                CompileServiceHelper.ValidateCorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            #endregion

            #region IncorrectLangugeSource

            try
            {
                //-----------CS-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CSIncorrectSourceCode,
                                                                Language.CSharp3);
                result = Compiler.DotNet3Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);

                //-----------CPP-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.CPPIncorrectSourceCode,
                                                                Language.VC8);
                result = Compiler.VC8Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);

                //-----------Java-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.JavaIncorrectSourceCode,
                                                                Language.Java6);
                result = Compiler.Java6Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);

                //-----------Delphi-----------
                programPath = tester.GenerateFileForCompilation(CompileServiceLanguageSourceCode.DelphiIncorrectSourceCode,
                                                                Language.Delphi7);
                result = Compiler.Delphi7Compiler.Compile(programPath);
                CompileServiceHelper.ValidateIncorrectCompilationResult(result);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            #endregion

            // bad input parameters
            try
            {
                result = Compiler.DotNet3Compiler.Compile(null);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                result = Compiler.DotNet3Compiler.Compile("");
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }
        }