Exemplo n.º 1
0
        /// <summary>
        /// Creates list of features user-friendly names.
        /// </summary>
        /// <param name="features">list of features.</param>
        /// <returns></returns>
        static string GetFeaturesString(this IList <Feature> features)
        {
            string feature;

            if (features.Count > 0)
            {
                StringBuilder sb = new StringBuilder(FeaturesHelper.GetDisplayName(features[0]));
                for (int i = 1; i < features.Count; i++)
                {
                    sb.AppendFormat(", {0}", FeaturesHelper.GetDisplayName(features[i]));
                }
                feature = sb.ToString();
            }
            else
            {
                feature = "UNDEFINED";
            }
            return(feature);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates requirement description for TestInfo (e.g. requirement level and required features)
        /// given.
        /// </summary>
        /// <param name="testInfo">Test information.</param>
        /// <returns>Requirement description.</returns>
        public static string GetRequirementString(this TestInfo testInfo)
        {
            string info = string.Empty;

            switch (testInfo.RequirementLevel)
            {
            case RequirementLevel.Must:
            {
                info = "MUST";
            }
            break;

            case RequirementLevel.ConditionalMust:
            {
                List <Feature> toBeSupported   = new List <Feature>();
                List <Feature> toBeImplemented = new List <Feature>();

                toBeSupported.AddRange(testInfo.RequiredFeatures.Where(f => FeaturesHelper.FeatureRealization(f) == FeaturesHelper.FeatureRealizationType.Supported));
                toBeImplemented.AddRange(testInfo.RequiredFeatures.Where(f => FeaturesHelper.FeatureRealization(f) == FeaturesHelper.FeatureRealizationType.Implemented));

                string supportedFeatures   = toBeSupported.GetFeaturesString();
                string implementedFeatures = toBeImplemented.GetFeaturesString();

                if (toBeImplemented.Count == 0)
                {
                    info = string.Format("MUST IF SUPPORTED ({0})", supportedFeatures);
                }
                else
                {
                    if (toBeSupported.Count == 0)
                    {
                        info = string.Format("MUST IF IMPLEMENTED ({0})", implementedFeatures);
                    }
                    else
                    {
                        if (toBeImplemented.Contains(Feature.PTZAbsoluteOrRelative))
                        {
                            List <Feature> toBeImplementedLite =
                                toBeImplemented.Where(f => f != Feature.PTZAbsoluteOrRelative).ToList();

                            implementedFeatures = toBeImplementedLite.GetFeaturesString();

                            info = string.Format("MUST IF SUPPORTED ({0}) AND IMPLEMENTED ({1}) AND IMPLEMENTED ({2})",
                                                 supportedFeatures,
                                                 implementedFeatures,
                                                 FeaturesHelper.GetDisplayName(Feature.PTZAbsoluteOrRelative));
                        }
                        else
                        {
                            info = string.Format("MUST IF SUPPORTED ({0}) AND IMPLEMENTED ({1})",
                                                 supportedFeatures,
                                                 implementedFeatures);
                        }
                    }
                }
            };
                break;

            case RequirementLevel.ConditionalShould:
            {
                List <Feature> toBeSupported   = new List <Feature>();
                List <Feature> toBeImplemented = new List <Feature>();

                toBeSupported.AddRange(testInfo.RequiredFeatures.Where(f => FeaturesHelper.FeatureRealization(f) == FeaturesHelper.FeatureRealizationType.Supported));
                toBeImplemented.AddRange(testInfo.RequiredFeatures.Where(f => FeaturesHelper.FeatureRealization(f) == FeaturesHelper.FeatureRealizationType.Implemented));

                string supportedFeatures   = toBeSupported.GetFeaturesString();
                string implementedFeatures = toBeImplemented.GetFeaturesString();

                if (toBeImplemented.Count == 0)
                {
                    info = string.Format("SHOULD IF SUPPORTED ({0})", supportedFeatures);
                }
                else
                {
                    if (toBeSupported.Count == 0)
                    {
                        info = string.Format("SHOULD IF IMPLEMENTED ({0})", implementedFeatures);
                    }
                    else
                    {
                        if (toBeImplemented.Contains(Feature.PTZAbsoluteOrRelative))
                        {
                            List <Feature> toBeImplementedLite =
                                toBeImplemented.Where(f => f != Feature.PTZAbsoluteOrRelative).ToList();

                            implementedFeatures = toBeImplementedLite.GetFeaturesString();

                            info = string.Format("SHOULD IF SUPPORTED ({0}) AND IMPLEMENTED ({1}) AND IMPLEMENTED ({2})",
                                                 supportedFeatures,
                                                 implementedFeatures,
                                                 FeaturesHelper.GetDisplayName(Feature.PTZAbsoluteOrRelative));
                        }
                        else
                        {
                            info = string.Format("SHOULD IF SUPPORTED ({0}) AND IMPLEMENTED ({1})",
                                                 supportedFeatures,
                                                 implementedFeatures);
                        }
                    }
                }
            };
                break;

            case RequirementLevel.Should:
            {
                info = "SHOULD";
            }
            break;

            case RequirementLevel.Optional:
            {
                info = "OPTIONAL";
            }
            break;
            }
            return(info);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds report summary.
        /// </summary>
        private void BuildSummary()
        {
            List <TestInfo> requiredTests = new List <TestInfo>();
            List <TestInfo> optionalTests = new List <TestInfo>();
            List <TestInfo> shouldIfTests = new List <TestInfo>();

            // sort tests
            foreach (TestInfo info in _log.Tests)
            {
                bool bAdd = true;

                foreach (Service service in info.Services)
                {
                    if (!_log.DeviceEnvironment.Services.Contains(service))
                    {
                        bAdd = false;
                        break;
                    }
                }

                if (!bAdd)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("Don't run: {0} {1}", info.Order, info.Name));
                    continue;
                }

                switch (info.RequirementLevel)
                {
                case RequirementLevel.Must:
                {
                    requiredTests.Add(info);
                }
                break;

                case RequirementLevel.ConditionalMust:
                case RequirementLevel.ConditionalShould:
                {
                    foreach (Feature feature in info.RequiredFeatures)
                    {
                        if (feature == Feature.PTZAbsoluteOrRelative)
                        {
                            if (!_log.DeviceEnvironment.Features.Contains(Feature.PTZAbsolute) &&
                                !_log.DeviceEnvironment.Features.Contains(Feature.PTZRelative))
                            {
                                bAdd = false;
                                System.Diagnostics.Debug.WriteLine(string.Format("Don't run: {0} {1}", info.Order, info.Name));
                                break;
                            }
                        }
                        else
                        {
                            if (!_log.DeviceEnvironment.Features.Contains(feature))
                            {
                                bAdd = false;
                                System.Diagnostics.Debug.WriteLine(string.Format("Don't run: {0} {1}", info.Order, info.Name));
                                break;
                            }
                        }
                    }
                    if (bAdd)
                    {
                        if (info.RequirementLevel == RequirementLevel.ConditionalMust)
                        {
                            requiredTests.Add(info);
                        }
                        else
                        {
                            shouldIfTests.Add(info);
                        }
                    }
                }
                break;

                case RequirementLevel.Optional:
                case RequirementLevel.Should:
                {
                    optionalTests.Add(info);
                }
                break;
                } // switch
            }

            _document.NewPage();
            int testCount, optional_Skipped, mandatory_Skipped;
            int testsRan, testsPassed, testsFailed;

            int optional_Failed;

            testCount = requiredTests.Count + shouldIfTests.Count + optionalTests.Count;

            testsRan    = _log.TestResults.Count;
            testsPassed =
                _log.TestResults.Where(KV => KV.Value.Log.TestStatus == TestStatus.Passed || KV.Value.Log.TestStatus == TestStatus.NotSupported).
                Count();
            testsFailed = _log.TestResults.Where(KV => KV.Value.Log.TestStatus == TestStatus.Failed).
                          Count();

            optional_Skipped = 0;
            foreach (TestInfo info in optionalTests)
            {
                if (!_log.TestResults.ContainsKey(info))
                {
                    optional_Skipped++;
                }
            }
            foreach (TestInfo info in shouldIfTests)
            {
                if (!_log.TestResults.ContainsKey(info))
                {
                    optional_Skipped++;
                }
            }

            optional_Failed = _log.TestResults.Where(KV =>
                                                     KV.Value.Log.TestStatus == TestStatus.Failed &&
                                                     KV.Key.RequirementLevel == RequirementLevel.Optional).
                              Count();

            mandatory_Skipped = 0;
            foreach (TestInfo info in requiredTests)
            {
                if (!_log.TestResults.ContainsKey(info))
                {
                    mandatory_Skipped++;
                }
            }

            Paragraph p0 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 16)));

            p0.Add("ONVIF Test Summary\n");
            p0.Alignment = Element.ALIGN_CENTER;
            _document.Add(p0);

            if (mandatory_Skipped > 0)
            {
                Paragraph p1 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 16)));
                p1.Add("THIS IS NOT A VALID ONVIF CONFORMANCE TEST\n\n");
                p1.Alignment = Element.ALIGN_CENTER;
                _document.Add(p1);
            }

            Paragraph p2 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 12)));

            p2.Add(String.Format("Test Count: {0}\n", testCount));
            p2.Add(String.Format("Mandatory Tests Skipped: {0}\n", mandatory_Skipped));
            p2.Add(String.Format("Optional Tests Skipped: {0}\n", optional_Skipped));
            p2.Add(String.Format("Tests Executed: {0}\n", testsRan));
            p2.Add(String.Format("Tests Passed:  {0}\n", testsPassed));
            p2.Add(String.Format("Tests Failed:  {0}\n", testsFailed));

            if (optional_Failed > 0)
            {
                p2.Add(String.Format("Optional Tests Failed: {0}\n", optional_Failed));
            }

            p2.Add("\n");
            _document.Add(p2);

            // Device types
            Paragraph p30 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 12)));

            p30.Add("Device types selected: ");

            DeviceType[] types = new DeviceType[] { DeviceType.NVT, DeviceType.NVS, DeviceType.NVD, DeviceType.NVA };

            bool   bFirst  = true;
            string current = string.Empty;

            foreach (DeviceType type in types)
            {
                if ((type & _log.DeviceEnvironment.DeviceTypes) != 0)
                {
                    current += bFirst ? type.ToString() : string.Format(", {0}", type.ToString());
                    bFirst   = false;
                }
            }
            p30.Add(string.Format("{0}\n", current));
            _document.Add(p30);

            // Services
            Paragraph p33 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 12)));

            current = string.Empty;
            bFirst  = true;
            foreach (Service service in _log.DeviceEnvironment.Services)
            {
                current += bFirst ? service.ToString() : string.Format(", {0}", service.ToString());
                bFirst   = false;
            }
            p33.Add(string.Format("Services selected: {0}", current));
            _document.Add(p33);

            // Features
            Paragraph p35 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 12)));

            p35.Add("Features selected: ");

            List <string> features = FeaturesHelper.SelectedFeatures(_log);

            foreach (string featureString in features)
            {
                p35.Add(string.Format("{0}\n", featureString));
            }
            _document.Add(p35);

            //
            // Settings:
            //

            Paragraph pTimeouts = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 12)));

            pTimeouts.Add("Timeouts: \n");
            pTimeouts.Add(string.Format("Message Timeout: {0}\n", _log.DeviceEnvironment.Timeouts.Message));
            pTimeouts.Add(string.Format("Reboot Timeout: {0}\n", _log.DeviceEnvironment.Timeouts.Reboot));
            pTimeouts.Add(string.Format("Time between tests: {0}\n", _log.DeviceEnvironment.Timeouts.InterTests));
            _document.Add(pTimeouts);

            Paragraph pAccount = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 12)));

            pAccount.Add(string.Format("Account: {0}", _log.DeviceEnvironment.Credentials.UserName));
            _document.Add(pAccount);

            // if not all mandatory tests were run this is not a valid conformance test
            if (mandatory_Skipped > 0)
            {
                Paragraph p5 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 16)));
                p5.Add("NOT ALL TESTS RUN, NOT A VALID ONVIF CONFORMANCE TEST\n");
                p5.Alignment = Element.ALIGN_CENTER;
                _document.Add(p5);
            }

            bool passed = true;

            if (_log.TestResults.Where(KV => KV.Value.Log.TestStatus == TestStatus.Failed).
                Count() > 0)
            {
                // any test FAILED
                passed = false;
            }
            else
            {
                // only optional, should, shouldIf can be skipped
                if (mandatory_Skipped > 0)
                {
                    passed = false;
                }
            }

            // Summary
            Paragraph p6 = new Paragraph(new Chunk("\n", FontFactory.GetFont(FontFactory.TIMES, 16)));

            if (passed)
            {
                p6.Add("TEST PASSED\n");
            }
            else
            {
                p6.Add("TEST FAILED\n");
            }
            p6.Alignment = Element.ALIGN_CENTER;
            _document.Add(p6);
        }