Ejemplo n.º 1
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";
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public void ClearTest()
 {
     var target = new Compilers("Directory");
     Assert.AreEqual(target.Count, 0);
     target.AddCompiler(new Compiler());
     Assert.AreEqual(target.Count, 1);
     target.Clear();
     Assert.AreEqual(target.Count, 0);
 }
Ejemplo n.º 5
0
        public void AddCompilerTest()
        {
            var compilersDirectory = "Directory";
            Compilers target;

            try
            {
                target = new Compilers(compilersDirectory);
                target.AddCompiler(null);
                Assert.AreEqual(false, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                target = new Compilers(compilersDirectory);
                Assert.AreEqual(target.Count, 0);
                target.AddCompiler(new Compiler());
                Assert.AreEqual(target.Count, 1);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
Ejemplo n.º 6
0
        public void LoadTest()
        {
            var compilers = new Compilers("EmptyCompiler");
            compilers.Load();
            Assert.AreEqual(compilers.Count, 0);

            compilers = new Compilers("Compilers");
            compilers.Load();
            Assert.AreEqual(compilers.Count, 4);
        }
Ejemplo n.º 7
0
 public void AddInvalidCompilerTest()
 {
     //create compilers with bad path
     var compilers = new Compilers("NoFolderCompilers");
     //try to initialize them
     compilers.Load();
    //there is no Assert, because in this test we are expecting an exception.
 }
Ejemplo n.º 8
0
        public void ParseTest()
        {
            var correctXmlFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Compilers\CPP8\CPP8.xml");
            var incorrectXmlFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Compilers\CsSharp\CSharp.xml");

            var compilers = new Compilers("Compilers");
            var privateObject = new PrivateObject(compilers, new PrivateType(typeof(Compilers)));

            // incorrect xml file
            try
            {
                privateObject.Invoke("Parse", incorrectXmlFilePath);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            // correct xml file
            try
            {
                Assert.AreNotEqual(null, privateObject.Invoke("Parse", correctXmlFilePath));
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
Ejemplo n.º 9
0
        public void CompilersParseBadXmlTest()
        {
            var incorrectXmlFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Compilers\CSharp\CSharp.xml");
            try
            {
              var tempCompilers = new Compilers("Compilers");
              var privateObject = new PrivateObject(tempCompilers, new PrivateType(typeof(Compilers)));

              privateObject.Invoke("Parse", incorrectXmlFilePath);
            }
            catch (Exception)
            {
              Assert.AreEqual(true, true);
            }
        }
Ejemplo n.º 10
0
 public void AddDuplicateCompilerTest()
 {
   //creating Compilers from compilers folder
   var firstCompilers = new Compilers("Compilers");
   //initialization
   firstCompilers.Load();
   //trying to add compiler of CPP8 which actually is in Compilers right now !
   firstCompilers.AddCompiler(firstCompilers.GetCompiler("CPP8"));
   //compilers must be unique. same compiler can not be added, thats why test fails yet.
   Assert.AreEqual(firstCompilers.Count,4);
 }
Ejemplo n.º 11
0
        public void ParseTest()
        {
            var correctXmlFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Compilers\CPP8\CPP8.xml");

            // TODO: check it
            var compilersArr = new Compilers("Compilers");
            var privateObject = new PrivateObject(compilersArr, new PrivateType(typeof(Compilers)));

            Assert.AreNotEqual(null, privateObject.Invoke("Parse", correctXmlFilePath));
        }
Ejemplo n.º 12
0
 public void AddInvalidCompilerTest()
 {
     //create compilers with bad path
     var compilers = new Compilers("NoFolderCompilers");
     //try to initialize them
     compilers.Load();
 }
Ejemplo n.º 13
0
 public void AddDuplicateCompilerTest()
 {
   var firstCompilers = new Compilers("Compilers");
   firstCompilers.Load();
   firstCompilers.AddCompiler(firstCompilers.GetCompiler("CPP8"));
   //compilers must be unique. same compiler can not be added.
   Assert.AreEqual(firstCompilers.Count,4);
 }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
 public void CompilersConstructorTest()
 {
     var compilersArr = new Compilers(null);
 }
Ejemplo n.º 16
0
        public void LoadTest()
        {
            Compilers compilers;

            // empty compiler folder
            try
            {
                compilers = new Compilers("EmptyCompiler");
                compilers.Load();
                Assert.AreEqual(compilers.Count, 0);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }

            // compiler folder with bad information
            try
            {
                compilers = new Compilers("BadCompilers");
                compilers.Load();
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            // compiler folder with correct information
            try
            {
                compilers = new Compilers("Compilers");
                compilers.Load();
                Assert.AreEqual(compilers.Count, 5);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
Ejemplo n.º 17
0
 public void CompilerConstructorTest()
 {
     var target = new Compilers("Directory");
     Assert.AreNotEqual(target.GetCompilers(), null);
 }
Ejemplo n.º 18
0
        public void CompilersConstructorTest()
        {
            string compilersDirectory = null;
            Compilers target;

            try
            {
                target = new Compilers(compilersDirectory);
                Assert.AreEqual(true, false);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, true);
            }

            try
            {
                compilersDirectory = "Directory";
                target = new Compilers(compilersDirectory);
                Assert.AreEqual(true, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(true, false);
            }
        }
Ejemplo n.º 19
0
 protected void Application_Start(object sender, EventArgs e)
 {
     compilers = new Compilers(CompilerDirectory);
     compilers.Load();
 }