public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { this._TestState = UPnPTestStates.Running; CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_GetSortCapabilities(); _Details.SortCapabilities = null; try { if (CDS != null) { DateTime start = System.DateTime.Now; CDS.Sync_GetSortCapabilities(out _Details.SortCapabilities); this.LogResponseTime(start, _Details, arg); } } catch (UPnPInvokeException ie) { arg.TestGroup.AddResult(this._Name + " test failed because of an invocation error: " + ie.Message); this._TestState = UPnPTestStates.Failed; return(this._TestState); } /* NKIDD - REMOVED BECAUSE EMPTY STRING IS LEGIT * if ((_Details.SortCapabilities == null) || (_Details.SortCapabilities == "")) * { * arg.TestGroup.AddResult(this._Name + " test failed because result was empty or null string."); * this._TestState = UPnPTestStates.Failed; * return this._TestState; * } */ arg._TestGroupState.SortCapabilities = _Details.SortCapabilities; arg.TestGroup.AddResult(this._Name + " test passed. Returned=\"" + _Details.SortCapabilities + "\"."); this._TestState = UPnPTestStates.Pass; return(this._TestState); }
public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { this._TestState = UPnPTestStates.Running; CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_GetSortCapabilities(); _Details.SortCapabilities = null; try { if (CDS != null) { DateTime start = System.DateTime.Now; CDS.Sync_GetSortCapabilities(out _Details.SortCapabilities); this.LogResponseTime(start, _Details, arg); } } catch (UPnPInvokeException ie) { arg.TestGroup.AddResult(this._Name + " test failed because of an invocation error: " + ie.Message); this._TestState = UPnPTestStates.Failed; return this._TestState; } /* NKIDD - REMOVED BECAUSE EMPTY STRING IS LEGIT if ((_Details.SortCapabilities == null) || (_Details.SortCapabilities == "")) { arg.TestGroup.AddResult(this._Name + " test failed because result was empty or null string."); this._TestState = UPnPTestStates.Failed; return this._TestState; } */ arg._TestGroupState.SortCapabilities = _Details.SortCapabilities; arg.TestGroup.AddResult(this._Name + " test passed. Returned=\"" + _Details.SortCapabilities + "\"."); this._TestState = UPnPTestStates.Pass; return this._TestState; }
public override void CalculateExpectedTestingTime(ICollection otherSubTests, ISubTestArgument arg) { // get the results from the prerequisite tests CdsResult_BrowseAll BROWSE_RESULTS = null; CdsResult_GetSortCapabilities SORTCAPS = null; foreach (ISubTest preTest in otherSubTests) { if (preTest.Name == this.PRE_BROWSEALL.Name) { BROWSE_RESULTS = preTest.Details as CdsResult_BrowseAll; } else if (preTest.Name == this.PRE_SORTCAPS.Name) { SORTCAPS = preTest.Details as CdsResult_GetSortCapabilities; } } if (BROWSE_RESULTS == null) { return; } if (SORTCAPS == null) { return; } if (BROWSE_RESULTS.LargestContainer == null) { return; } MediaContainer MC = BROWSE_RESULTS.LargestContainer as MediaContainer; if (MC == null) { return; } ArrayList sortFields = new ArrayList(); if (SORTCAPS.SortCapabilities == "") { } else if (SORTCAPS.SortCapabilities == "*") { sortFields = (ArrayList)BROWSE_RESULTS.PropertyNames.Clone(); } else { sortFields.AddRange(GetSortFields(SORTCAPS.SortCapabilities)); } int fieldCount = sortFields.Count; IList childList = BROWSE_RESULTS.LargestContainer.CompleteList; uint inc = (uint)(childList.Count / 3); int firstInc = (fieldCount / 3); if (firstInc == 0) { firstInc = 1; } int totalBrowses = 0; for (int numFields = 0; numFields < fieldCount; numFields++) { for (int first = 0; first < fieldCount; first += firstInc) { //for (uint i=0; i < childList.Count; i+=inc) { totalBrowses++; } } } //add one for an unsorted browse totalBrowses++; //multiply by 2 because we have 2 rounds to check for consistency in ordered results totalBrowses *= 2; //calculate expected time this._ExpectedTestingTime = totalBrowses * 900; }
public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_BrowseSortCriteria(); this._TestState = UPnPTestStates.Running; arg._TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" started."); // get the results from the prerequisite tests CdsResult_BrowseAll BROWSE_RESULTS = null; CdsResult_GetSortCapabilities SORTCAPS = null; try { foreach (ISubTest preTest in otherSubTests) { if (preTest.Name == this.PRE_BROWSEALL.Name) { BROWSE_RESULTS = preTest.Details as CdsResult_BrowseAll; } else if (preTest.Name == this.PRE_SORTCAPS.Name) { SORTCAPS = preTest.Details as CdsResult_GetSortCapabilities; } } if (BROWSE_RESULTS == null) { throw new TestException(this._Name + " requires that the \"" + this.PRE_BROWSEALL.Name + "\" test be run as a prerequisite. The results from that test cannot be obtained.", otherSubTests); } if (SORTCAPS == null) { throw new TestException(this._Name + " requires that the \"" + this.PRE_SORTCAPS.Name + "\" test be run as a prerequisite. The results from that test cannot be obtained.", otherSubTests); } } catch (Exception e) { throw new TestException(this._Name + " requires that the \"" + this.PRE_BROWSEALL.Name + "\" and \"" + this.PRE_SORTCAPS + "\" tests be run before. An error occurred when attempting to obtain the results of those prerequisites.", otherSubTests, e); } _Details.BrowseAllResults = BROWSE_RESULTS; _Details.SortCapsResults = SORTCAPS; UPnPTestStates state = this._TestState; if (BROWSE_RESULTS.LargestContainer == null) { throw new TestException(this.PRE_BROWSEALL.Name + " failed to find the container with the most child objects. " + this._Name + " requires this value.", BROWSE_RESULTS); } MediaContainer MC = BROWSE_RESULTS.LargestContainer as MediaContainer; if (MC == null) { throw new TestException(this.PRE_BROWSEALL.Name + " has the largest container as type \"" + BROWSE_RESULTS.LargestContainer.GetType().ToString() + "\" when \"" + this.Name + "\" requires \"" + typeof(MediaContainer).ToString() + "\".", BROWSE_RESULTS); } ArrayList sortFields = new ArrayList(); if (SORTCAPS.SortCapabilities == "") { //arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\""+this.Name+"\" has no sorting capabilities."); } else if (SORTCAPS.SortCapabilities == "*") { sortFields = (ArrayList)BROWSE_RESULTS.PropertyNames.Clone(); } else { sortFields.AddRange(GetSortFields(SORTCAPS.SortCapabilities)); } _Details.ExpectedTotalBrowseRequests = 0; _Details.SortFields = sortFields; int fieldCount = sortFields.Count; IList childList = BROWSE_RESULTS.LargestContainer.CompleteList; _Details.ExpectedTotalBrowseRequests = 0; //fieldCount * fieldCount * fieldCount; uint inc = (uint)(childList.Count / 3); int firstInc = (fieldCount / 3); if (firstInc == 0) { firstInc = 1; } for (int numFields = 0; numFields < fieldCount; numFields++) { for (int first = 0; first < fieldCount; first += firstInc) { //for (uint i=0; i < childList.Count; i+=inc) { _Details.ExpectedTotalBrowseRequests++; } } } // add 1 for an unsorted browse _Details.ExpectedTotalBrowseRequests++; //multiply by 2 because we have 2 rounds to check for consistency in ordered results _Details.ExpectedTotalBrowseRequests *= 2; //calculate time this._ExpectedTestingTime = _Details.ExpectedTotalBrowseRequests * 900; arg.ActiveTests.UpdateTimeAndProgress(0); if (state <= UPnPTestStates.Running) { state = UPnPTestStates.Pass; try { ArrayList round2 = new ArrayList(); //perform the standard unsorted browse BrowseInput input = new BrowseInput(); input.BrowseFlag = CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag.BROWSEDIRECTCHILDREN; input.StartingIndex = 0; input.ObjectID = MC.ID; input.RequestedCount = 0; input.Filter = "*"; input.SortCriteria = ""; CdsBrowseSearchResults br = Browse(input, this, arg, CDS, _Details); Round2 r2 = new Round2(); r2.Input = (BrowseInput)input.Clone(); r2.PreviousResult = br; round2.Add(r2); for (int numFields = 0; numFields < fieldCount; numFields++) { for (int first = 0; first < fieldCount; first += firstInc) { ArrayList sortSettings = GetSortSettings(sortFields, first, first); input.SortCriteria = GetSortCriteriaString(sortSettings, numFields + first); arg.ActiveTests.UpdateTimeAndProgress(_Details.TotalBrowseRequests * 900); uint ignored; //use this sorter for to determine the expected order of the media objects IMediaSorter sorter = new MediaSorter(true, input.SortCriteria); IList expectedSorted = MC.BrowseSorted(0, 0, sorter, out ignored); br = Browse(input, this, arg, CDS, _Details); arg.ActiveTests.UpdateTimeAndProgress(_Details.TotalBrowseRequests * 900); this.CompareResultsAgainstExpected(br, expectedSorted, ref state, arg, input, false); r2 = new Round2(); r2.Input = (BrowseInput)input.Clone(); r2.PreviousResult = br; round2.Add(r2); } } //do round2 - check for consistency in results foreach (Round2 r in round2) { br = Browse(r.Input, this, arg, CDS, _Details); arg.ActiveTests.UpdateTimeAndProgress(_Details.TotalBrowseRequests * 900); this.CompareResultsAgainstExpected(br, r.PreviousResult.MediaObjects, ref state, arg, r.Input, true); } } catch (TerminateEarly te) { string reason = "\"" + this.Name + "\" terminating early. Reason => " + te.Message; arg._TestGroup.AddEvent(LogImportance.Critical, this.Name, reason); state = UPnPTestStates.Failed; } } // finish up logging this._TestState = state; StringBuilder sb = new StringBuilder(); sb.AppendFormat("\"{0}\" completed", this.Name); if (this._TestState <= UPnPTestStates.Running) { throw new TestException("\"" + this.Name + "\" must have a pass/warn/fail result.", this._TestState); } switch (this._TestState) { case UPnPTestStates.Pass: sb.Append(" successfully."); break; case UPnPTestStates.Warn: sb.Append(" with warnings."); break; case UPnPTestStates.Failed: sb.Append(" with a failed result."); break; } arg._TestGroup.AddResult(sb.ToString()); if (this._TestState <= UPnPTestStates.Warn) { if (_Details.TotalBrowseRequests != _Details.ExpectedTotalBrowseRequests) { throw new TestException("TotalBrowseRequests=" + _Details.TotalBrowseRequests.ToString() + " ExpectedTotal=" + _Details.ExpectedTotalBrowseRequests.ToString(), _Details); } } arg._TestGroup.AddEvent(LogImportance.Remark, this.Name, sb.ToString()); return(this._TestState); }