コード例 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Test Unit (local) name.</param>
        /// <param name="parent">Parent/Owner Test Unit of this instance.</param>
        protected TestUnit(string name, TestUnit parent)
        {
            this.Id = null;
            this.Name = name;
            this.Parent = parent;

            if (parent != null)
            {
                parent.AddChild(this);
            }
        }
コード例 #2
0
        /// <summary>
        /// Helper function which aids in the implementation of QualifiedNameBuilder(TestUnit) constructor
        /// </summary>
        /// <param name="root">The test unit which is to be listed</param>
        private void Initialize(TestUnit root)
        {
            if (root == null)
            {
                return;
            }

            Initialize(root.Parent);

            this.Push(root);
        }
コード例 #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Test Unit (local) name.</param>
        /// <param name="parent">Parent/Owner Test Unit of this instance.</param>
        protected TestUnit(string name, TestUnit parent)
        {
            this.Id = null;
            this.Name = name;
            this.Parent = parent;
            this.Labels = Enumerable.Empty<string>();

            if (parent != null)
            {
                parent.AddChild(this);
            }
        }
コード例 #4
0
        /// <summary>
        /// Parses a general test result information from the provided node.
        /// </summary>
        /// <param name="node">The XPathNavigator pointing to a TestUnit node.</param>
        /// <param name="unit">The test unit for which the test results are related to.</param>
        /// <param name="collection">The TestResultCollection which will host the result.</param>
        private static TestResult ParseTestResult(XPathNavigator node, TestUnit unit, TestResultCollection collection)
        {
            TestResult result = new TestResult(collection);

            result.Unit = unit;
            result.Result = ParseResultType(node.GetAttribute(Xml.Result, string.Empty));

            result.AssertionsPassed = uint.Parse(node.GetAttribute(Xml.AssertionsPassed, string.Empty), CultureInfo.InvariantCulture);
            result.AssertionsFailed = uint.Parse(node.GetAttribute(Xml.AssertionsFailed, string.Empty), CultureInfo.InvariantCulture);
            result.ExpectedFailures = uint.Parse(node.GetAttribute(Xml.ExpectedFailures, string.Empty), CultureInfo.InvariantCulture);

            return result;
        }
コード例 #5
0
 /// <summary>
 /// Adds a child to this TestUnit
 /// </summary>
 /// <param name="unit">The unit to add as a child</param>
 public virtual void AddChild(TestUnit unit)
 {
     throw new InvalidOperationException();
 }
コード例 #6
0
 public override void AddChild(TestUnit unit)
 {
     this._children.Add(unit);
 }
コード例 #7
0
 /// <summary>
 /// Constructor. Initializes this qualified name based on the provided TestUnit.
 /// </summary>
 /// <param name="root">The TestUnit from which this qualified name is to be initialized.</param>
 public QualifiedNameBuilder(TestUnit root)
     : this()
 {
     Initialize(root);
 }
コード例 #8
0
        public void Visit(TestSuite testSuite)
        {
            Assert.That(this.ExpectedUnit, Is.TypeOf<TestSuite>());
            Assert.That(testSuite.Children.Count(), Is.EqualTo(this.ExpectedUnit.Children.Count()));

            VerifyTestUnit(testSuite, this.ExpectedUnit);

            var expectedChild = Sort(this.ExpectedUnit.Children).GetEnumerator();

            foreach (TestUnit child in Sort(testSuite.Children))
            {
                expectedChild.MoveNext();
                this.ExpectedUnit = expectedChild.Current;
                child.Apply(this);
                this.ExpectedUnit = this.ExpectedUnit.Parent;
            }
        }
コード例 #9
0
            private bool Check(TestUnit unit)
            {
                bool match = (unit.FullyQualifiedName == this.FullyQualifiedName);

                if (match)
                {
                    this.Unit = unit;
                }

                return match;
            }
コード例 #10
0
 /// <summary>
 /// States the number of test suites for the provided test unit (including itself)
 /// </summary>
 /// <param name="root">The root test unit from which to start enumerating test suites</param>
 /// <returns>The number of test suites for the provided test unit</returns>
 private uint GetTestSuiteCount(TestUnit root)
 {
     TestSuiteCounter counter = new TestSuiteCounter();
     root.Apply(counter);
     return counter.Count;
 }
コード例 #11
0
 /// <summary>
 /// Asserts test suite details
 /// </summary>
 /// <param name="unit">The test suite to test</param>
 /// <param name="id">The expected Id of the test suite</param>
 /// <param name="parent">The expected parent of the test suite</param>
 private void AssertTestSuite(TestUnit unit, int id, TestUnit parent)
 {
     AssertTestUnit(unit, typeof(TestSuite), id, parent);
 }
コード例 #12
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="expected">The expected root test unit hierarchy which is to be compared against</param>
 private FrameworkEqualityVisitor(TestUnit expected)
 {
     this.ExpectedUnit = expected;
 }
コード例 #13
0
        /// <summary>
        /// Verifies that both test units are equal
        /// </summary>
        /// <param name="actual">The actual TestUnit to be compared against</param>
        /// <param name="expected">The expected TestUnit 'actual' should match</param>
        private static void VerifyTestUnit(TestUnit actual, TestUnit expected)
        {
            Assert.That(actual.Name, Is.EqualTo(expected.Name));
            Assert.That(actual.Id, Is.EqualTo(expected.Id));
            Assert.That(actual.Labels, Is.EquivalentTo(expected.Labels));

            if (expected.Source != null)
            {
                VerifySoureFileInfo(actual.Source, expected.Source);
            }
            else
            {
                Assert.That(actual.Source, Is.Null);
            }
        }
コード例 #14
0
        private static string GetTestResultMessageText(TestUnit unit, LogEntry entry)
        {
            Code.Require(unit, "unit");
            Code.Require(entry, "entry");

            if ((entry is LogEntryStandardOutputMessage) || (entry is LogEntryStandardErrorMessage))
            {
                return entry.Detail.TrimEnd() + Environment.NewLine;
            }

            StringBuilder sb = new StringBuilder();

            if (entry.Source != null)
            {
                AppendSourceInfo(entry.Source, sb);
            }

            sb.Append(entry.ToString().ToLowerInvariant()).
                Append(" in \"").
                Append(unit.Name).
                Append("\"");

            LogEntryMemoryLeak memoryLeak = entry as LogEntryMemoryLeak;
            if (memoryLeak == null)
            {
                sb.Append(": ").Append(entry.Detail.TrimEnd());
            }

            LogEntryException exception = entry as LogEntryException;
            if (exception != null)
            {
                FormatException(exception, sb);
            }

            LogEntryError error = entry as LogEntryError;
            if (error != null)
            {
                FormatError(error, sb);
            }

            if (memoryLeak != null)
            {
                FormatMemoryLeak(memoryLeak, sb);
            }

            // Append NewLine so that log entries are listed one per line
            return sb.Append(Environment.NewLine).ToString();
        }
コード例 #15
0
 /// <summary>
 /// Adds a child to this TestUnit
 /// </summary>
 /// <param name="unit">The unit to add as a child</param>
 public virtual void AddChild(TestUnit unit)
 {
     throw new InvalidOperationException();
 }
コード例 #16
0
        public void Visit(TestSuite testSuite)
        {
            Assert.That(this.ExpectedUnit, Is.TypeOf<TestSuite>());
            Assert.That(testSuite.Children.Count(), Is.EqualTo(this.ExpectedUnit.Children.Count()));

            VerifyTestUnit(testSuite, this.ExpectedUnit);

            foreach (TestUnit child in testSuite.Children)
            {
                this.ExpectedUnit = child;
                child.Apply(this);
                this.ExpectedUnit = child.Parent;
            }

            this.ExpectedUnit = this.ExpectedUnit.Parent;
        }
コード例 #17
0
        /// <summary>
        /// Asserts test case details
        /// </summary>
        /// <param name="unit">The test case to test</param>
        /// <param name="id">The expected Id of the test case</param>
        /// <param name="info">The expected source file information of the test case</param>
        /// <param name="parent">The expected parent of the test case</param>
        private void AssertTestCase(TestUnit unit, int id, SourceFileInfo info, TestUnit parent)
        {
            AssertTestUnit(unit, typeof(TestCase), id, parent);

            TestCase test = ((TestCase) unit);

            Assert.That(test.Children, Is.Empty);

            SourceFileInfo unitInfo = test.Source;

            if (info == null)
            {
                Assert.That(unitInfo, Is.Null);
            }
            else
            {
                Assert.That(unitInfo.File, Is.EqualTo(info.File));
                Assert.That(unitInfo.LineNumber, Is.EqualTo(info.LineNumber));
            }
        }
コード例 #18
0
 public override void AddChild(TestUnit unit)
 {
     this._children.Add(unit);
 }
コード例 #19
0
 /// <summary>
 /// Asserts test unit details
 /// </summary>
 /// <param name="unit">The test unit to test</param>
 /// <param name="type">The expected type of the test unit</param>
 /// <param name="id">The expected Id of the test unit</param>
 /// <param name="parent">The expected parent of the test unit</param>
 private void AssertTestUnit(TestUnit unit, Type type, int id, TestUnit parent)
 {
     Assert.That(unit, Is.Not.Null);
     Assert.That(unit, Is.TypeOf(type));
     Assert.That(unit.Id, Is.EqualTo(id));
     Assert.That(unit.Parent, Is.EqualTo(parent));
 }
コード例 #20
0
        private static string GetTestResultMessageText(TestUnit unit, LogEntry entry)
        {
            if ((entry is LogEntryStandardOutputMessage) || (entry is LogEntryStandardErrorMessage))
            {
                return entry.Detail.TrimEnd() + Environment.NewLine;
            }

            StringBuilder sb = new StringBuilder();

            if (entry.Source != null)
            {
                AppendSourceInfo(entry.Source, sb);
            }

            sb.Append(entry.ToString().ToLowerInvariant()).
                Append(" in \"").
                Append(unit.Name).
                Append("\"");

            LogEntryMemoryLeak memoryLeak = entry as LogEntryMemoryLeak;
            if (memoryLeak == null)
            {
                sb.Append(": ").Append(entry.Detail.TrimEnd());
            }

            LogEntryException exception = entry as LogEntryException;
            if (exception != null)
            {
                if (exception.LastCheckpoint != null)
                {
                    sb.Append(Environment.NewLine);
                    AppendSourceInfo(exception.LastCheckpoint, sb);
                    sb.Append("last checkpoint: ").Append(exception.CheckpointDetail);
                }
            }

            if (memoryLeak != null)
            {
                if ((memoryLeak.LeakSourceFilePath != null) && (memoryLeak.LeakSourceFileName != null))
                {
                    sb.Append("source file path leak detected at :").
                        Append(memoryLeak.LeakSourceFilePath).
                        Append(memoryLeak.LeakSourceFileName);
                }

                if (memoryLeak.LeakLineNumber != null)
                {
                    sb.Append(", ").
                        Append("Line number: ").
                        Append(memoryLeak.LeakLineNumber);
                }

                sb.Append(", ").
                    Append("Memory allocation number: ").
                    Append(memoryLeak.LeakMemoryAllocationNumber);

                sb.Append(", ").
                    Append("Leak size: ").
                    Append(memoryLeak.LeakSizeInBytes).
                    Append(" byte");
                
                if (memoryLeak.LeakSizeInBytes > 0)
                {
                     sb.Append('s');
                }

                sb.Append(Environment.NewLine).
                    Append(memoryLeak.LeakLeakedDataContents);
            }

            // Append NewLine so that log entries are listed one per line
            return sb.Append(Environment.NewLine).ToString();
        }
コード例 #21
0
 /// <summary>
 /// Looks up a test unit by fully qualified name
 /// </summary>
 /// <param name="root">The root test unit from which to start searching</param>
 /// <param name="fullyQualifiedName">The fully qualified name of the test unit to look for</param>
 /// <returns>The test unit with the requested fully qualified name or null if it cannot be found</returns>
 private TestUnit Lookup(TestUnit root, string fullyQualifiedName)
 {
     TestUnitLookup lookup = new TestUnitLookup(fullyQualifiedName);
     root.Apply(lookup);
     return lookup.Unit;
 }
コード例 #22
0
        /// <summary>
        /// Pushes the test unit on this structure.
        /// </summary>
        /// <param name="unit">The test unit to push</param>
        /// <returns>this</returns>
        public QualifiedNameBuilder Push(TestUnit unit)
        {
            Utility.Code.Require(unit, "unit");

            return this.Push(unit.Name);
        }
コード例 #23
0
 /// <summary>
 /// Determine the Boost.Test.TestUnit test case for which this BoostTestResult is associated with.
 /// </summary>
 /// <param name="unit">The Boost.Test.TestUnit test case to associate with the generated result</param>
 /// <returns>this</returns>
 public BoostTestResultBuilder For(TestUnit unit)
 {
     this.Unit = unit;
     return this;
 }
コード例 #24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="expected">The expected root test unit hierarchy which is to be compared against</param>
 private FrameworkEqualityVisitor(TestUnit expected, bool respectOrder = true)
 {
     this.ExpectedUnit = expected;
     this.OrderRespected = respectOrder;
 }