Ejemplo n.º 1
0
        private void CboFilter_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_gTestRunner.TestsInRunner.Count == 0)
            {
                return;
            }

            GTestResultCollection resultCollection = _gTestRunner.TestsInRunner.Count == 1 ? _gTestRunner.TestsInRunner.First().Value : _gTestRunner.TestsInRunner[((ConfiguredProject)cboProject.SelectedItem).TestExe];
            BindingSource         boundTests       = new BindingSource();

            if (cboFilter.Text == Resources.FilterByAllTestsText)
            {
                TimeTakenForTests    = resultCollection.TotalTime;
                NumberOfFailingTests = resultCollection.TotalNumberOfFailures;
                NumberOfPassingTests = resultCollection.TotalNumberOfTests - resultCollection.TotalNumberOfFailures;
                NumberOfTests        = resultCollection.TotalNumberOfTests;
                foreach (GTestSuite suite in resultCollection.TestResults)
                {
                    foreach (var test in suite.Results)
                    {
                        boundTests.Add(test);
                    }
                }
                if (NumberOfPassingTests == 0 && NumberOfFailingTests == 0)
                {
                    picPass.Image = Resources.TestNotRun;
                }
                else
                {
                    picPass.Image = NumberOfFailingTests == 0 ? Resources.TestPassed : Resources.TestFail;
                }
            }
            else
            {
                foreach (GTestSuite suite in resultCollection.TestResults)
                {
                    if (suite.Name == cboFilter.Text)
                    {
                        TimeTakenForTests    = suite.Time;
                        NumberOfFailingTests = suite.NumberOfFailures;
                        NumberOfPassingTests = suite.NumberOfTests - suite.NumberOfFailures;
                        NumberOfTests        = suite.NumberOfTests;
                        if (NumberOfPassingTests == 0 && NumberOfFailingTests == 0)
                        {
                            picPass.Image = Resources.TestNotRun;
                        }
                        else
                        {
                            picPass.Image = NumberOfFailingTests == 0 ? Resources.TestPassed : Resources.TestFail;
                        }
                        foreach (var test in suite.Results)
                        {
                            boundTests.Add(test);
                        }
                        break;
                    }
                }
            }
            GridTests.DataSource = boundTests;
        }
Ejemplo n.º 2
0
        public void UpdateTestResult(ConfiguredProject project, GTestResultCollection results)
        {
            Control.updateGTestInfomation(project, results);
            IVsWindowFrame windowFrame = (IVsWindowFrame)Frame;

            windowFrame.Show();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the Ctrl's GUI with the test infomation inside testInfo
        /// </summary>
        public void updateGTestInfomation(ConfiguredProject project, GTestResultCollection testInfo)
        {
            Contract.Requires(testInfo != null);

            UpdateSuitePicture updateSuitePicture = SuitePictureChange;
            Image image;

            AddProject(project);
            NumberOfTests        = testInfo.TotalNumberOfTests;
            NumberOfFailingTests = testInfo.TotalNumberOfFailures;
            NumberOfPassingTests = NumberOfTests - NumberOfFailingTests;
            if (NumberOfPassingTests == 0 && NumberOfFailingTests == 0)
            {
                image = Resources.TestNotRun;
            }
            else
            {
                image = NumberOfFailingTests == 0 ? Resources.TestPassed : Resources.TestFail;
            }

            cboFilter.SetPropertyThreadSafe(() => cboFilter.SelectedIndex, 0);
            TimeTakenForTests = testInfo.TotalTime;
            if (picPass.InvokeRequired)
            {
                picPass.Invoke(updateSuitePicture, new object[] { image });
            }
            else
            {
                updateSuitePicture(image);
            }
            BindingSource bindingSource = new BindingSource();
            UpdateFilter  addFilterItem = AddFilterItem;

            foreach (GTestSuite testSuite in testInfo.GetList())
            {
                if (cboFilter.InvokeRequired)
                {
                    cboFilter.Invoke(addFilterItem, new object[] { testSuite.Name });
                }
                else
                {
                    cboFilter.Items.Add(testSuite.Name);
                }
                foreach (GTestResult test in testSuite.GetList())
                {
                    bindingSource.Add(test);
                }
            }
            SetGridDatasouce datasouce = SetDatasource;

            if (GridTests.InvokeRequired)
            {
                GridTests.Invoke(datasouce, new object[] { bindingSource });
            }
            else
            {
                GridTests.DataSource = bindingSource;
            }
        }
Ejemplo n.º 4
0
        public void ListTests(ConfiguredProject project)
        {
            GTestResultCollection testlist;
            OutputWindowPane      debugOut = TestPackage.GetOutputWindow();
            Process testProcess            = new Process();

            // first try and vaildate as a vaild gtest executable
            _testExeArgs = "--help";
            FileInfo info = new FileInfo(project.TestExe);

            testProcess.StartInfo = new ProcessStartInfo(info.FullName)
            {
                UseShellExecute        = false,
                WindowStyle            = ProcessWindowStyle.Minimized,
                Arguments              = _testExeArgs,
                CreateNoWindow         = true,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                WorkingDirectory       = info.DirectoryName ?? Directory.GetCurrentDirectory()
            };
            //   testProcess.OutputDataReceived += ReadIntoBuffer;
            testProcess.Start();
            string list = testProcess.StandardOutput.ReadLine();

            if (list != Resources.GTestHelpString)
            {
                testProcess.WaitForExit(400);
                if (!testProcess.HasExited)
                {
                    testProcess.Kill();
                }
                if (testProcess.ExitCode != 0 && debugOut != null)
                {
                    debugOut.OutputString("An error occured while attempting to run " + info.Name +
                                          " process exited with " + testProcess.ExitCode);
                }
                return;
            }

            if (debugOut != null)
            {
                debugOut.OutputString("Tests found for " + info.Name + "..loading tests now...");
            }

            _testExeArgs = project.ListTestCommand;
            testProcess.StartInfo.Arguments = _testExeArgs;
            testProcess.Start();
            list = testProcess.StandardOutput.ReadToEnd();
            testProcess.WaitForExit(200);

            if (!TestSets.ContainsKey(project.TestExe))
            {
                testlist = new GTestResultCollection();
                TestSets.Add(project.TestExe, testlist);
            }
            else
            {
                testlist = TestSets[project.TestExe];
            }

            string[] splitList = list.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            GTestSuite suite = null;

            foreach (string t1 in splitList)
            {
                string actualName = t1.Trim(new[] { ' ', '\n', '\r' });
                if (actualName.Contains("."))
                {
                    actualName = actualName.TrimEnd('.');
                    int suiteIndex = testlist.TestResults.FindIndex(t => t.Name == actualName);
                    if (suiteIndex == -1)
                    {
                        suite = new GTestSuite {
                            Name = actualName, NumberOfTests = 0
                        };
                        testlist.TestResults.Add(suite);
                    }
                    else
                    {
                        suite = testlist.TestResults[suiteIndex];
                    }
                    continue;
                }
                if (suite == null)
                {
                    throw new NullReferenceException("ACK THESE BLACKHOLES ARE EVERYWHERE");
                }

                int disabled = 0;
                if (actualName.StartsWith("DISABLED_"))
                {
                    disabled   = 1;
                    actualName = actualName.Replace("DISABLED_", string.Empty);
                }
                GTestResult testResult = suite.Results.Find(t => t.Name == actualName);
                if (testResult == null)
                {
                    testResult = new GTestResult {
                        Name = actualName, Disabled = disabled
                    };
                    suite.Results.Add(testResult);
                    testlist.TotalNumberOfTests++;
                    suite.NumberOfTests++;
                }
            }
            if (OnTestsUpdated != null)
            {
                OnTestsUpdated.Invoke(project, testlist);
            }
        }
Ejemplo n.º 5
0
        private void CheckIfTestsHaveFinished()
        {
            OutputWindowPane debugOut = TestPackage.GetOutputWindow();

            if (debugOut != null)
            {
                debugOut.OutputString(_testProcess.StandardOutput.ReadToEnd());
            }
            _testProcess.WaitForExit(5000);
            if (!_testProcess.HasExited)
            {
                _testProcess.Kill();
            }

            if (_testProcess.ExitCode > 1 || !File.Exists(TestFileName))
            {
                MessageBox.Show(Resources.CommandLineErrorMessage + TestFileName + @" " + _testExeArgs);
                _testProcess.Dispose();
                return;
            }
            _testProcess.Dispose();
            FileStream testFile = File.OpenRead(TestFileName);

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(GTestResultCollection));

            GTestResultCollection newTestData = (GTestResultCollection)xmlSerializer.Deserialize(testFile);
            GTestResultCollection testDataToUpdate;

            if (!TestSets.ContainsKey(_testProcess.StartInfo.FileName))
            {
                testDataToUpdate = newTestData;
                TestSets.Add(_testProcess.StartInfo.FileName, testDataToUpdate);
            }
            else
            {
                testDataToUpdate = TestSets[_testProcess.StartInfo.FileName];
                testDataToUpdate.TotalNumberOfTests    = newTestData.TotalNumberOfTests;
                testDataToUpdate.TotalNumberOfFailures = newTestData.TotalNumberOfFailures;
                testDataToUpdate.TotalNumberOfErrors   = newTestData.TotalNumberOfErrors;
                testDataToUpdate.TotalTime             = newTestData.TotalTime;
            }

            foreach (GTestSuite testSuite in newTestData.TestResults)
            {
                // check if this suite exists in current data.
                GTestSuite suite = testSuite;
                int        currentTestSuiteIndex = testDataToUpdate.TestResults.FindIndex(t => t.Name == suite.Name);
                if (currentTestSuiteIndex == -1)
                {
                    testDataToUpdate.TestResults.Add(testSuite);
                    currentTestSuiteIndex = testDataToUpdate.TestResults.Count - 1;
                }
                else // update suite data
                {
                    GTestSuite currentsuite = testDataToUpdate.TestResults[currentTestSuiteIndex];
                    currentsuite.Time             = testSuite.Time;
                    currentsuite.NumberOfTests    = testSuite.NumberOfTests;
                    currentsuite.NumberOfFailures = testSuite.NumberOfFailures;
                    currentsuite.NumberOfErrors   = testSuite.NumberOfErrors;
                }
                for (int i = 0; i < testSuite.Results.Count; i++)
                {
                    GTestResult test = testSuite.Results[i];
                    //check to see if the test exist in current data
                    string testName = test.Name;
                    bool   disabled = testName.StartsWith("DISABLED_");
                    testName = test.Name.Replace("DISABLED_", "");
                    int currentTestIndex = testDataToUpdate.TestResults[currentTestSuiteIndex].Results.FindIndex(
                        t => t.Name == testName);
                    GTestResult current = null;

                    if (currentTestIndex == -1)
                    {
                        testDataToUpdate.TestResults[currentTestSuiteIndex].Results.Add(test);
                        current = test;
                    }
                    else if (test.TestRan)
                    {
                        current =
                            testDataToUpdate.TestResults[currentTestSuiteIndex].Results[currentTestIndex];
                        current.Errors = test.Errors;
                        current.Status = test.Status;
                        current.Time   = test.Time;
                    }
                    else
                    {
                        current         = testDataToUpdate.TestResults[currentTestSuiteIndex].Results[currentTestIndex];
                        current.TestRan = false;
                    }
                    current.Disabled = disabled ? 1 : 0;
                }
            }

            testFile.Close();
            File.Delete(TestFileName);
            _testsRunning = false;
            if (OnTestsUpdated != null)
            {
                OnTestsUpdated.Invoke(_currentTestsFor, testDataToUpdate);
            }
        }