Example #1
0
        private void GridTests_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            DataGridViewRow row    = GridTests.Rows[e.RowIndex];
            GTestResult     result = row.DataBoundItem as GTestResult;

            if (result == null || result.Disabled != 1 || result.Errors.Count <= 0)
            {
                return;
            }
            foreach (DataGridViewCell c in row.Cells)
            {
                if (result.Disabled == 1)
                {
                    c.Style.ForeColor = Color.Gray;
                    if (string.IsNullOrEmpty(c.ToolTipText))
                    {
                        c.ToolTipText = "Disabled";
                    }
                }
                else if (result.Errors.Count > 0)
                {
                    c.Style.ForeColor = Color.Red;
                }
            }
        }
Example #2
0
 private void GridTests_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 2)
     {
         DataGridViewRow row = GridTests.Rows[e.RowIndex];
         if (row.Cells[2].Value == null || (string)row.Cells[2].Value == "")
         {
             return;
         }
         GTestResult test    = (GTestResult)row.DataBoundItem;
         TestFailure failure = TestPackage.GetTestFailureWindow();
         failure.ShowTest(test.Name, test.Failures);
     }
 }
Example #3
0
        public string GetGTestFilter()
        {
            string filterString = "";

            if (GridTests.Rows.Count != 0)
            {
                foreach (DataGridViewRow row in GridTests.Rows)
                {
                    GTestResult test = (GTestResult)row.DataBoundItem;
                    if (test.TestRan)
                    {
                        if (filterString == "")
                        {
                            filterString = test.Fullname;
                        }
                        else
                        {
                            filterString += "*" + test.Fullname;
                        }
                    }
                }
            }
            return(filterString);
        }
Example #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);
            }
        }
Example #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);
            }
        }