Exemple #1
0
        public CompileTask(Compiler compiler, string sourceFilePath)
        {
            if (compiler == null)
                throw new Exception("Compiler can't be null");

            if (!File.Exists(sourceFilePath))
                throw new FileNotFoundException("Can't find such file", sourceFilePath);

            this.sourceFilePath = sourceFilePath;
            this.compiler = compiler;
            this.standardOutput = string.Empty;
            this.standardError = string.Empty;
        }
Exemple #2
0
        private Compiler Parse(string xmlFilePath)
        {
            var compiler = new Compiler();
            var xmlReader = new XmlTextReader(xmlFilePath);
            xmlReader.Read();

            while (xmlReader.Read())
            {
                switch (xmlReader.Name)
                {
                    case "name":
                        {
                            compiler.Name = xmlReader.ReadElementContentAsString();
                        }
                        break;

                    case "location":
                        {
                            compiler.Location = Path.Combine(
                                AppDomain.CurrentDomain.BaseDirectory, xmlReader.ReadElementContentAsString());
                        }
                        break;

                    case "extension":
                        {
                            compiler.Extension = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
                        }
                        break;
                    case "arguments":
                        {
                            compiler.Arguments = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
                        }
                        break;
                    case "compiledExtension":
                        {
                            compiler.CompiledExtension = xmlReader.ReadElementContentAsString().TrimEnd().TrimStart();
                        }
                        break;
                    case "needShortName":
                        {
                            compiler.IsNeedShortPath = xmlReader.ReadElementContentAsBoolean();
                        }
                        break;
                }
            }

            if (compiler.Extension == string.Empty || compiler.Name == string.Empty || compiler.Location == string.Empty || compiler.CompiledExtension == string.Empty || compiler.Arguments == string.Empty)
                throw new Exception("Bad xml information about compiler");

            return compiler;
        }
Exemple #3
0
        public void GetCompilersTest()
        {
            var newCompiler = new Compiler { Name = "CPP" };
            var resultList = this.compilers.GetCompilers();

            Assert.AreEqual(resultList.Count, 0);

            this.compilers.AddCompiler(newCompiler);
            resultList = this.compilers.GetCompilers();

            Assert.AreEqual(resultList.Count, 1);

            this.compilers.Clear();
        }
Exemple #4
0
        public void CompilersContainsTest()
        {
            Assert.AreEqual(this.compilers.Count, 0);
            var newCompiler = new Compiler { Name = "CPP" };
            this.compilers.AddCompiler(newCompiler);

            var result = this.compilers.Contains("CPP");
            Assert.AreEqual(true, result);

            result = this.compilers.Contains("BadCompilerName");
            Assert.AreEqual(result, false);

            this.compilers.Clear();
        }
Exemple #5
0
        public void CompilersGetCompilerTest()
        {
            Assert.AreEqual(this.compilers.Count, 0);
            var result = this.compilers.GetCompiler("CPP");
            Assert.AreEqual(null, result);

            var newCompiler = new Compiler { Name = "CPP" };
            this.compilers.AddCompiler(newCompiler);

            result = this.compilers.GetCompiler("CPP");

            Assert.AreNotEqual(result, null);
            Assert.AreEqual("CPP", result.Name);

            result = this.compilers.GetCompiler("BadName");
            Assert.AreEqual(result, null);

            this.compilers.Clear();
        }
        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);
        }
        public void TestTest()
        {
            // 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 filePath = Helper.CreateFileForCompilation(
                CompileServiceLanguageSourceCode.CPPCorrectSourceCode, compiler.Extension);
            string output, error;
            var result = compiler.Compile(filePath, out output, out error);
            if (result)
            {
                filePath = Path.ChangeExtension(filePath, compiler.CompiledExtension);
                Status testingResult;

                // check file path
                try
                {
                    Tester.Test("badFilePath", string.Empty, string.Empty, 1, 1);
                    Assert.AreEqual(true, false);
                }
                catch (Exception)
                {
                    Assert.AreEqual(true, true);
                }

                // check correct timelimit
                try
                {
                    Tester.Test(filePath, string.Empty, string.Empty, -5, 1);
                    Assert.AreEqual(true, false);
                }
                catch (Exception)
                {
                    Assert.AreEqual(true, true);
                }

                // check correct memorylimit
                try
                {
                    Tester.Test(filePath, string.Empty, string.Empty, 1, -5);
                    Assert.AreEqual(true, false);
                }
                catch (Exception)
                {
                    Assert.AreEqual(true, true);
                }

                // test with correct parameters
                try
                {
                    testingResult = Tester.Test(filePath, string.Empty, string.Empty, 10000, 3000);
                    Assert.AreEqual("Accepted", testingResult.TestResult);
                }
                catch (Exception)
                {
                    Assert.AreEqual(true, false);
                }
            }
        }
        public void CompileTest()
        {
            // 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 filePath = Helper.CreateFileForCompilation(
                CompileServiceLanguageSourceCode.CPPCorrectSourceCode, compiler.Extension);
            string output, error;
            bool result=true;
            try
            {
                result = compiler.Compile("BadFileName", out output, out error);
                result = false;
            }
            catch (Exception)
            {
                Assert.AreEqual(true,result);
            }
            result = compiler.Compile(filePath, out output, out error);

            try
            {
                result = compiler.Compile(filePath, out output, out error);
            }
            catch (Exception)
            {
              result = false;
            }
             Assert.AreEqual(true, result);
            // remove file
            try
            {
              File.Delete(filePath);
            }
            catch (Exception)
            {
              Assert.AreEqual(true, false);
            }
        }
        public void GetCompilersTest()
        {
            var target = new Compilers("Directory");
            var newCompiler = new Compiler();
            newCompiler.Name = "CPP";
            var resultList = target.GetCompilers();
            Assert.AreEqual(resultList.Count, 0);

            target.AddCompiler(newCompiler);
            resultList = target.GetCompilers();
            Assert.AreEqual(resultList.Count, 1);
        }
        public void GetCompilerTest()
        {
            var target = new Compilers("Directory");
            Assert.AreEqual(target.Count, 0);
            var newCompiler = new Compiler();
            newCompiler.Name = "CPP";
            target.AddCompiler(newCompiler);
            var result = target.GetCompiler("CPP");
            Assert.AreNotEqual(result, null);
            Assert.AreEqual("CPP", result.Name);

            result = target.GetCompiler("BadName");
            Assert.AreEqual(result, null);
        }
        public void ContainsTest()
        {
            var target = new Compilers("Directory");
            Assert.AreEqual(target.Count, 0);
            var newCompiler = new Compiler();
            newCompiler.Name = "CPP";
            target.AddCompiler(newCompiler);
            var result = target.Contains("CPP");
            Assert.AreEqual(true, result);

            result = target.Contains("BadCompilerName");
            Assert.AreEqual(result, false);
        }
Exemple #12
0
        public void AddCompiler(Compiler newCompiler)
        {
            if (newCompiler == null)
                throw new Exception("Compiler is null");

            this.compilers.Add(newCompiler);
        }