private void Validate_NOTIFY() { ManualResetEvent M = new ManualResetEvent(false); // Check to see if received all the NOTIFY packets NotifyTable.Clear(); ASocket2.Begin(); M.Reset(); StartCountDown(0, Cache); M.WaitOne(Cache * 1000, false); AbortCountDown(); ASocket2.OnReceive -= new AsyncSocket.OnReceiveHandler(ReceiveSink2); if (NotifyTable.ContainsKey("upnp:rootdevice")) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<upnp:rootdevice>> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<upnp:rootdevice>> MISSING/LATE"); } ValidateNotifyTable(TestDevice); if (NOTIFY == UPnPTestStates.Pass) { Results.Add("Notifications OK"); } else { Results.Add("One ore more NOTIFY packets were MISSING"); } SetState("Notifications", NOTIFY); }
public void SetError(UPnPTestStates severity) { if ((int)severity > (int)this.WorstError) { this.WorstError = severity; } }
private void OnStateChangedSink(DeviceScriptorInterface sender, StateEventStruct StateInfo) { UPnPTestStates ReportedState = GetEquivalentUPnPTestState(StateInfo.States); for (int i = 0; i < TestList.Count; i++) { if (StateInfo.ScriptName == ((string [])TestList[i])[0]) { if (ReportedState > states[i]) { states[i] = ReportedState; SetState(StateInfo.ScriptName, ReportedState); } } } }
public virtual void Reset() { if (Countdown == null) { Countdown = new System.Timers.Timer(1000); Countdown.Elapsed += new System.Timers.ElapsedEventHandler(this.CountdownSink); } state = UPnPTestStates.Ready; for (int i = 0; i < states.Length; ++i) { states[i] = UPnPTestStates.Ready; } progress = 0; packets.Clear(); enabled = true; log = ""; result = ""; }
public override void Start(UPnPDevice device) { UPnPDevice d = device; while (d.ParentDevice != null) { d = d.ParentDevice; } TestDevice = d; ASocket = new AsyncSocket(4096); ASocket.Attach(new IPEndPoint(TestDevice.InterfaceToHost, 0), System.Net.Sockets.ProtocolType.Udp); ASocket.SetTTL(4); ASocket.AddMembership((IPEndPoint)ASocket.LocalEndPoint, IPAddress.Parse("239.255.255.250")); ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(ReceiveSink); ASocket.Begin(); ASocket2 = new AsyncSocket(4096); ASocket2.Attach(new IPEndPoint(TestDevice.InterfaceToHost, 1900), System.Net.Sockets.ProtocolType.Udp); ASocket2.SetTTL(2); ASocket2.AddMembership((IPEndPoint)ASocket.LocalEndPoint, IPAddress.Parse("239.255.255.250")); ASocket2.OnReceive += new AsyncSocket.OnReceiveHandler(ReceiveSink2); Validate_MSEARCH_RESPONSETIME(); Validate_NOTIFY(); Validate_DISCOVERY(); UPnPTestStates RetState = UPnPTestStates.Pass; if (NOTIFY == UPnPTestStates.Failed || DISCOVERY == UPnPTestStates.Failed) { RetState = UPnPTestStates.Failed; } else { if (NOTIFY == UPnPTestStates.Warn || DISCOVERY == UPnPTestStates.Warn || MX == UPnPTestStates.Warn) { RetState = UPnPTestStates.Warn; } } state = RetState; }
private void grabTestInfo(XmlElement testElement) { string name = testElement.GetAttribute("name"); string state = testElement.GetAttribute("state"); string result = testElement.GetAttribute("result"); string description = testElement.GetAttribute("description"); Results.Add(result); TestList.Add(new string[] { name, description }); UPnPTestStates[] oldStates = states; states = new UPnPTestStates[TestList.Count]; states[oldStates.Length] = Util.StringToUPnPTestStates(state); for (int i = 0; i < oldStates.Length; ++i) { states[i] = oldStates[i]; } }
public static string UPnPTestStatesToString(UPnPTestStates s) { switch (s) { case UPnPTestStates.Failed: return("Failed"); case UPnPTestStates.Pass: return("Pass"); case UPnPTestStates.Ready: return("Ready"); case UPnPTestStates.Running: return("Running"); case UPnPTestStates.Warn: return("Warn"); } return(""); }
private void ValidateNotifyTable(UPnPDevice d) { foreach (UPnPDevice ed in d.EmbeddedDevices) { ValidateNotifyTable(ed); } if (NotifyTable.ContainsKey(d.DeviceURN)) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<" + d.DeviceURN + ">> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<" + d.DeviceURN + ">> MISSING/LATE"); } if (NotifyTable.ContainsKey("uuid:" + d.UniqueDeviceName)) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<uuid:" + d.UniqueDeviceName + ">> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<uuid:" + d.UniqueDeviceName + ">> MISSING/LATE"); } foreach (UPnPService s in d.Services) { if (NotifyTable.ContainsKey(s.ServiceURN)) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<" + s.ServiceURN + ">> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<" + s.ServiceURN + ">> MISSING/LATE"); } } }
public void SetState(string TestName, UPnPTestStates NewState) { if (TestName == GroupName) { state = NewState; return; } int i = 0; foreach (string s in this.TestNames) { if (s == TestName) { states[i] = NewState; if (this.OnStateChanged != null) { OnStateChanged(this, null); } break; } ++i; } }
public void SetState(string TestName, UPnPTestStates NewState) { if (TestName == GroupName) { state = NewState; return; } int i = 0; foreach (string s in this.TestNames) { if (s == TestName) { states[i] = NewState; if (this.OnStateChanged != null) OnStateChanged(this, null); break; } ++i; } }
public void SetError(UPnPTestStates severity) { if ((int)severity > (int)this.WorstError) { this.WorstError = severity; } }
public void CompareResultsAgainstExpected(CdsBrowseSearchResults br, IList expectedResults, ref UPnPTestStates state, CdsSubTestArgument arg, BrowseInput input, bool strictOrder) { if (br.WorstError >= UPnPTestStates.Failed) { throw new TerminateEarly("\"" + this.Name + "\" is terminating early because " +input.PrintBrowseParams()+ " returned with an error or had problems with the DIDL-Lite."); } else { if (br.MediaObjects.Count != expectedResults.Count) { throw new TerminateEarly("\""+this.Name+"\" did a " +input.PrintBrowseParams()+ " and it should have returned "+expectedResults.Count+ " media objects. DIDL-Lite contained " +br.MediaObjects.Count+ " media objects. DIDL-Lite => " + br.Result); } bool warnResults = false; for (int i=0; i < br.MediaObjects.Count; i++) { IUPnPMedia gotThis = (IUPnPMedia) br.MediaObjects[i]; IUPnPMedia expectedMedia = (IUPnPMedia) expectedResults[i]; if (gotThis.ID == expectedMedia.ID) { //arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\""+this.Name+"\" did a " +input.PrintBrowseParams()+ " and encountered no errors in the results."); } else { bool failed = false; if ((input.SortCriteria == null) || (input.SortCriteria == "")) { failed = true; } else { // Use this sorter to test for value-equality in situations where the expected order didn't match. // We need to do this because two media objects may be value-equivalent according to a sorting // algorithm, in which case there's no way to really distinguish what order they should be in. IMediaSorter sorter2 = new MediaSorter(false, input.SortCriteria); int cmp = sorter2.Compare(gotThis, expectedMedia); if (cmp != 0) { arg.TestGroup.AddEvent(LogImportance.Medium, this.Name, "\""+this.Name+"\" found media object ID=\""+gotThis.ID+"\" when it expected to find \""+expectedMedia.ID+"\" and they are not equal in their sorted order."); warnResults = true; } else { if (strictOrder == false) { arg.TestGroup.AddEvent(LogImportance.Low, this.Name, "\""+this.Name+"\" found media object ID=\""+gotThis.ID+"\" when it expected to find \""+expectedMedia.ID+"\" but since they are effectively value-equivalent, the ordering is OK."); } else { failed = true; } } } if (failed) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("\"{0}\" did a {1} and the order of object ID's in the result conflicts with previous browse requests."); msg.AppendFormat("\r\n\r\nReceived objects in order by ID: "); int z = 0; foreach (IUPnPMedia em in br.MediaObjects) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.Append("\r\n\r\nThe expected order by ID is: "); z = 0; foreach (IUPnPMedia em in expectedResults) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.AppendFormat(".\r\n\r\nDIDL-Lite ==> {0}", br.Result); throw new TerminateEarly(msg.ToString()); } } } if (warnResults == false) { arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\""+this.Name+"\" did a " +input.PrintBrowseParams()+ " and encountered no errors or warnings in the results."); } else { StringBuilder msg = new StringBuilder(); msg.AppendFormat("WARNING: \"{0}\" did a {1} and \r\nreceived results in the following order by ID: ", this.Name, input.PrintBrowseParams()); int z = 0; foreach (IUPnPMedia em in br.MediaObjects) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.Append("\r\n\r\nThe expected order by ID is: "); z = 0; foreach (IUPnPMedia em in expectedResults) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.AppendFormat(".\r\n\r\nDIDL-Lite ==> {0}", br.Result); // warn state = UPnPTestStates.Warn; arg._TestGroup.AddEvent(LogImportance.Medium, this.Name, msg.ToString()); } } }
public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_BrowseFilterRangeSort(); this._TestState = UPnPTestStates.Running; arg._TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" started."); // get the results from the prerequisite tests CdsResult_BrowseFilter FILTER_RESULTS = null; CdsResult_BrowseRange RANGE_RESULTS = null; CdsResult_BrowseSortCriteria SORT_RESULTS = null; try { foreach (ISubTest preTest in otherSubTests) { if (preTest.Name == this.PRE_FILTER.Name) { FILTER_RESULTS = preTest.Details as CdsResult_BrowseFilter; } else if (preTest.Name == this.PRE_RANGE.Name) { RANGE_RESULTS = preTest.Details as CdsResult_BrowseRange; } else if (preTest.Name == this.PRE_SORT.Name) { SORT_RESULTS = preTest.Details as CdsResult_BrowseSortCriteria; } } if (FILTER_RESULTS == null) { throw new TestException(this._Name + " requires that the \"" + this.PRE_FILTER.Name + "\" test be run as a prerequisite. The results from that test cannot be obtained.", otherSubTests); } if (RANGE_RESULTS == null) { throw new TestException(this._Name + " requires that the \"" + this.PRE_RANGE.Name + "\" test be run as a prerequisite. The results from that test cannot be obtained.", otherSubTests); } if (SORT_RESULTS == null) { throw new TestException(this._Name + " requires that the \"" + this.PRE_SORT.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_FILTER.Name + "\" and \"" + this.PRE_RANGE + "\" and \"" + this.PRE_SORT + "\" tests be run before. An error occurred when attempting to obtain the results of those prerequisites.", otherSubTests, e); } UPnPTestStates state = this._TestState; CdsResult_BrowseAll BROWSE_ALL = FILTER_RESULTS.BrowseAllResults; if (BROWSE_ALL.LargestContainer == null) { throw new TestException(new Cds_BrowseAll().Name + " failed to find the container with the most child objects. " + this._Name + " requires this value.", BROWSE_ALL); } if (BROWSE_ALL.MostMetadata == null) { throw new TestException(new Cds_BrowseAll().Name + " failed to find the media object with the most metadata. " + this._Name + " requires this value.", BROWSE_ALL); } if (SORT_RESULTS.SortFields == null) { throw new TestException(new Cds_BrowseAll().Name + " failed to find the sortable fields. " + this._Name + " requires this value.", SORT_RESULTS); } int max = Math.Max(FILTER_RESULTS.Filters.Count, BROWSE_ALL.LargestContainer.ChildCount); max = Math.Max(max, SORT_RESULTS.SortFields.Count); this._Details.ExpectedTotalBrowseRequests = max + 1; this._Details.TotalBrowseRequests = 0; this._ExpectedTestingTime = this._Details.ExpectedTotalBrowseRequests * 900; arg.ActiveTests.UpdateTimeAndProgress(this._Details.TotalBrowseRequests * 900); state = UPnPTestStates.Pass; for (int i = 0; i <= max; i++) { ArrayList filterList = new ArrayList(); for (int j = 0; j < i; j++) { if (j < FILTER_RESULTS.Filters.Count) { filterList.Add(FILTER_RESULTS.Filters[j]); } else { break; } } string filterSettings = Cds_BrowseTest.GetCSVString(filterList); uint range = (uint)i; if (range > BROWSE_ALL.LargestContainer.ChildCount) { range = (uint)BROWSE_ALL.LargestContainer.ChildCount; } ArrayList sortList = new ArrayList(); for (int j = 0; j < i; j++) { if (j < SORT_RESULTS.SortFields.Count) { sortList.Add(SORT_RESULTS.SortFields[j]); } else { break; } } BrowseInput input = new BrowseInput(); input.ObjectID = BROWSE_ALL.LargestContainer.ID; input.BrowseFlag = CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag.BROWSEDIRECTCHILDREN; input.Filter = filterSettings; input.RequestedCount = range; input.SortCriteria = Cds_BrowseSortCriteria.GetSortCriteriaString(sortList, i); input.StartingIndex = 0; this._ExpectedTestingTime = (max) * 900; arg.ActiveTests.UpdateTimeAndProgress(this._Details.TotalBrowseRequests * 900); CdsBrowseSearchResults br = Cds_BrowseTest.Browse(input, this, arg, CDS, _Details); MediaContainer original = (MediaContainer)BROWSE_ALL.LargestContainer; uint ignored; IList expectedResults; expectedResults = original.BrowseSorted(0, input.RequestedCount, new MediaSorter(true, input.SortCriteria), out ignored); try { if (br.WorstError <= UPnPTestStates.Warn) { if (br.MediaObjects.Count != expectedResults.Count) { throw new TerminateEarly(input.PrintBrowseParams() + " returned DIDL-Lite that declared " + br.MediaObjects.Count + " media objects but test expected " + expectedResults.Count.ToString() + " media objects as found in a prerequisite test."); } bool warnOrder = false; for (int ri = 0; ri < br.MediaObjects.Count; ri++) { IUPnPMedia resultObj = (IUPnPMedia)br.MediaObjects[ri]; IUPnPMedia originalObj = (IUPnPMedia)expectedResults[ri]; if (resultObj.ID != originalObj.ID) { warnOrder = true; } foreach (string propName in resultObj.Properties.PropertyNames) { if (filterList.Contains(propName) == false) { if ( (propName != T[_DC.title]) && (propName != T[_UPNP.Class]) ) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("\"" + this.Name + "\" is terminating early because {0} returned DIDL-Lite with \"{1}\" metadata when it should not have done so.", input.PrintBrowseParams(), propName); throw new TerminateEarly(msg.ToString()); } } } } int expectedCount = i; if ((i == 0) || (i > BROWSE_ALL.LargestContainer.ChildCount)) { expectedCount = BROWSE_ALL.LargestContainer.ChildCount; } if (br.MediaObjects.Count != expectedCount) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("\"{0}\" did a {1} and the DIDL-Lite result only has {2} media objects when {3} media objects were expected.", this.Name, input.PrintBrowseParams(), br.MediaObjects.Count, expectedCount); msg.AppendFormat(".\r\nDIDL-Lite ==> {0}", br.Result); throw new TerminateEarly(msg.ToString()); } if (warnOrder) { /* * ArrayList missingResults = new ArrayList(); * * foreach (IUPnPMedia em in expectedResults) * { * bool found = false; * foreach (IUPnPMedia fm in br.MediaObjects) * { * if (em.ID == fm.ID) * { * found = true; * break; * } * } * * if (found == false) * { * missingResults.Add(em); * } * } * * if (missingResults.Count > 0) * { * state = UPnPTestStates.Failed; * StringBuilder msg = new StringBuilder(); * msg.AppendFormat("\"{0}\" did a {1} and the result is missing media objects.", this.Name, input.PrintBrowseParams()); * msg.Append("\r\nExpected order of IDs: "); * int z = 0; * foreach (IUPnPMedia em in expectedResults) * { * if (z > 0) * { * msg.Append(","); * } * msg.AppendFormat("\"{0}\"", em.ID); * z++; * } * msg.Append("\r\nDIDL-Lite result's order of IDs: "); * z = 0; * foreach (IUPnPMedia em in br.MediaObjects) * { * if (z > 0) * { * msg.Append(","); * } * msg.AppendFormat("\"{0}\"", em.ID); * z++; * } * msg.AppendFormat(".\r\nDIDL-Lite ==> {0}", br.Result); * throw new TerminateEarly(msg.ToString()); * } * else */ { StringBuilder msg = new StringBuilder(); msg.AppendFormat("WARNING: \"{0}\" did a {1} and got items in a different order. Target CDS either has an error in its sorting logic, or sorting logic intentionally deviates from test.", this.Name, input.PrintBrowseParams()); msg.Append("\r\nExpected order of IDs: "); int z = 0; foreach (IUPnPMedia em in expectedResults) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.Append("\r\nDIDL-Lite result's order of IDs: "); z = 0; foreach (IUPnPMedia em in br.MediaObjects) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.AppendFormat(".\r\nDIDL-Lite ==> {0}", br.Result); arg._TestGroup.AddEvent(LogImportance.Medium, this.Name, msg.ToString()); state = UPnPTestStates.Warn; } } } else { throw new TerminateEarly("\"" + this.Name + "\" is terminating early because " + input.PrintBrowseParams() + " returned with an error or had problems with the DIDL-Lite."); } } catch (TerminateEarly te) { arg._TestGroup.AddEvent(LogImportance.Critical, this.Name, "\"" + this.Name + "\" terminating early. Reason ==> " + te.Message); state = UPnPTestStates.Failed; break; } } // 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, this.Name + " finished."); return(this._TestState); }
private void Validate_DISCOVERY() { //Test all types of M-SEARCH, both valid and invalid MSEARCHTable.Clear(); ASocket.OnReceive -= new AsyncSocket.OnReceiveHandler(ReceiveSink); ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(MSEARCHSink); HTTPMessage rq = new HTTPMessage(); byte[] rbuf; IPEndPoint d = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900); rq.Directive = "M-SEARCH"; rq.DirectiveObj = "*"; rq.AddTag("MX", "5"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "ssdp:all"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(0, 91); MRE.WaitOne(8000, false); AbortCountDown(); if (MSEARCHTable.ContainsKey("upnp:rootdevice")) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ssdp:all / upnp:rootdevice>> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<ssdp:all / upnp:rootdevice>> MISSING"); } foreach (HTTPMessage m in MSEARCH(TestDevice)) { if (MSEARCHTable.ContainsKey(m.GetTag("ST").Trim())) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ssdp:all / " + m.GetTag("ST").Trim() + ">> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<ssdp:all / " + m.GetTag("ST").Trim() + ">> MISSING"); } } // Test MSEARCH upnp:rootdevice, and others MSEARCHTable.Clear(); rq.AddTag("ST", "upnp:rootdevice"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); foreach (HTTPMessage m in MSEARCH(TestDevice)) { this.sample2 += "\r\n\r\n" + m.StringPacket; ASocket.Send(m.RawPacket, 0, m.RawPacket.Length, d); } MRE.Reset(); StartCountDown(8, 91); MRE.WaitOne(8000, false); AbortCountDown(); ASocket.OnReceive -= new AsyncSocket.OnReceiveHandler(MSEARCHSink); if (MSEARCHTable.ContainsKey("upnp:rootdevice")) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<upnp:rootdevice>> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<upnp:rootdevice>> MISSING"); } foreach (HTTPMessage m in MSEARCH(TestDevice)) { if (MSEARCHTable.ContainsKey(m.GetTag("ST").Trim())) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<" + m.GetTag("ST").Trim() + ">> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<" + m.GetTag("ST").Trim() + ">> MISSING"); } } // Test Invalid MSEARCHes string ST = ""; MSEARCHTable.Clear(); ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(BadMSEARCHSink); rq = new HTTPMessage(); rq.Directive = "M-SEARCH"; rq.DirectiveObj = "*"; rq.AddTag("MX", "2"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "uuid:___" + TestDevice.UniqueDeviceName + "___"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(16, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<NonExistent UDN>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<NonExistent UDN>> OK"); } MSEARCHTable.Clear(); ST = TestDevice.DeviceURN; int i = ST.LastIndexOf(":"); if (i == -1) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "Can't parse DeviceURN"); return; } ST = ST.Substring(0, i); ST = ST + ":" + ((int)(int.Parse(TestDevice.Version) + 5)).ToString(); rq.AddTag("ST", ST); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(21, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Existing Device Type, Bad Version>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Existing Device Type, Bad Version>> OK"); } MSEARCHTable.Clear(); UPnPService _S = FetchAService(TestDevice); ST = _S.ServiceURN; ST = ST.Substring(0, ST.LastIndexOf(":")); ST = ST + ":" + ((int)(int.Parse(_S.Version) + 5)).ToString(); rq.AddTag("ST", ST); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(26, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Existing Service Type, Bad Version>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Existing Service Type, Bad Version>> OK"); } // Test MSEARCH No * MSEARCHTable.Clear(); rq = new HTTPMessage(); rq.Directive = "M-SEARCH"; rq.DirectiveObj = ""; rq.AddTag("MX", "2"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "upnp:rootdevice"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(31, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No *>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No *>> OK"); } MSEARCHTable.Clear(); rq.DirectiveObj = "/"; rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(36, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Not *>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Not *>> OK"); } MSEARCHTable.Clear(); rq = new HTTPMessage(); rq.Directive = "M-SEARCH"; rq.DirectiveObj = ""; rq.AddTag("MX", "2"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "upnp:rootdevice"); rq.Version = "1.0"; rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(41, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Version = 1.0>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Version = 1.0>> OK"); } MSEARCHTable.Clear(); rq.DirectiveObj = "*"; rq.Version = ""; rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(46, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No Version>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No Version>> OK"); } MSEARCHTable.Clear(); rq.Version = "1.1"; rq.RemoveTag("MAN"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(51, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No MAN>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No MAN>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MAN", "\"ssdp:discover\""); rq.RemoveTag("MX"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(56, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No MX>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No MX>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", ""); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(61, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<MX Empty>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<MX Empty>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", "Z"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(66, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<MX Not Integer>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<MX Not Integer>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", "-1"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(71, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<MX Negative>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<MX Negative>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", "2"); rq.RemoveTag("ST"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(76, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No ST>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No ST>> OK"); } MSEARCHTable.Clear(); rq.AddTag("ST", ""); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(81, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<ST Empty>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ST Empty>> OK"); } MSEARCHTable.Clear(); rq.AddTag("ST", "ABCDEFG"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(86, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<ST Invalid>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ST Invalid>> OK"); } SetState("Discovery", DISCOVERY); if (DISCOVERY == UPnPTestStates.Pass) { Results.Add("Discovery mechanism OK"); } else { Results.Add("Discovery mechanism is not behaving correctly"); } }
public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_BrowseFilter(); this._TestState = UPnPTestStates.Running; arg._TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" started."); // get the results from the BrowseAll test CdsResult_BrowseAll PRE = null; try { foreach (ISubTest preTest in otherSubTests) { if (preTest.Name == this.PRE_BROWSEALL.Name) { PRE = preTest.Details as CdsResult_BrowseAll; break; } } if (PRE == 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); } } catch (Exception e) { throw new TestException(this._Name + " requires that the \"" + this.PRE_BROWSEALL.Name + "\" test be run before. An error occurred when attempting to obtain the results of a prerequisite.", otherSubTests, e); } _Details.BrowseAllResults = PRE; if (PRE.MostMetadata == null) { throw new TestException(this.PRE_BROWSEALL.Name + " failed to find a media object with the most metadata. " + this._Name + " requires this value.", PRE); } if (PRE.MostMetadata.Properties.Count != PRE.MostMetadata.Properties.PropertyNames.Count) { throw new TestException(this.Name + " has conflicting reports for the number of metadata properties. " + PRE.MostMetadata.Properties.Count + "/" + PRE.MostMetadata.Properties.PropertyNames.Count, PRE.MostMetadata.Properties); } IUPnPMedia MM = PRE.MostMetadata; if (MM == null) { string skippedMsg = "\"" + this.Name + "\" skipped because the tested content hierarchy does not have a media object with at least one resource and has an ID!=\"0\""; arg.TestGroup.AddEvent(LogImportance.Critical, this.Name, skippedMsg); arg.TestGroup.AddResult(skippedMsg); return(UPnPTestStates.Ready); } IMediaContainer MC = PRE.MostMetadata.Parent; if (MC == null) { throw new TestException(this.Name + " has MostMetadata.Parent == null", PRE.MostMetadata); } int numProps = MM.Properties.Count; int numChildren = MC.ChildCount; // we browse for "res" and each possible res@attribute numProps += (2 * MediaResource.GetPossibleAttributes().Count) + 2; _Details.NumberOfProperties = numProps; _Details.ExpectedTotalBrowseRequests = 0; int inc = numProps / 4; if (inc == 0) { inc = 1; } for (int nProps = 0; nProps < numProps; nProps++) { for (int iProp = 0; iProp < numProps; iProp += inc) { _Details.ExpectedTotalBrowseRequests++; } } _Details.ExpectedTotalBrowseRequests *= 2; int maxTime = 90 * _Details.ExpectedTotalBrowseRequests; this._ExpectedTestingTime = maxTime; // browse metadata with various filter settings // browsedirectchildren with various filter settings UPnPTestStates state = this._TestState; CdsBrowseSearchResults test1 = TestFiltersBrowseMetadata(MM, CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag.BROWSEMETADATA, this, arg, CDS, _Details); if (test1.WorstError > state) { state = test1.WorstError; } CdsBrowseSearchResults test2 = TestFiltersBrowseMetadata(MM, CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag.BROWSEDIRECTCHILDREN, this, arg, CDS, _Details); if (test2.WorstError > state) { state = test2.WorstError; } // 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); }
public override void Start(UPnPDevice device) { UPnPTestStates Master = UPnPTestStates.Pass; TestDevice = device; UPnPDevice d = device; UPnPService[] services = d.GetServices(CpConnectionManager.SERVICE_NAME); if (services == null || services.Length == 0) { enabled = false; return; } CM = new CpConnectionManager(services[0]); string SOURCE = ""; string SINK = ""; DText parser = new DText(); StartCountDown(0, 90); try { CM.Sync_GetProtocolInfo(out SOURCE, out SINK); } catch (UPnPInvokeException) { Results.Add("Connection Handler Test was aborted because GetProtocolInfo FAILED"); SetState("Connection Handling", UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } AbortCountDown(); parser.ATTRMARK = ","; parser.MULTMARK = ":"; bool OK = true; if (ConnectionManagerEventsTest() == false) { Results.Add("Connection Handler Test was aborted because of invalid/missing events"); SetState("Connection Handling", UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } if (SINK != "") { parser[0] = SINK; TotalTime = parser.DCOUNT() * 120; CurrentTime = 0; for (int i = 1; i <= parser.DCOUNT(); ++i) { if (parser.DCOUNT(i) != 4) { // Invalid Format OK = false; AddEvent(LogImportance.Critical, "Connection Handling", " Protocol Info String [" + parser[i] + "] is not in a valid format"); } } if (OK) { AddEvent(LogImportance.Remark, "Connection Handling", " Protocol Info Strings are in the correct format"); } else { Results.Add("Connection Handler Test was aborted because of invalid Protocol Info Strings"); SetState("Connection Handling", UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } if (CM.HasAction_PrepareForConnection) { for (int i = 1; i <= parser.DCOUNT(); ++i) { if (PrepareForConnectionTest_SINK(parser[i]) == false) { OK = false; } } } } if (OK) { Results.Add("Connection Handler Test PASSED"); SetState("Connection Handling", UPnPTestStates.Pass); } else { Results.Add("Connection Handler Test FAILED"); SetState("Connection Handling", UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } OK = true; UPnPService[] _AVT = d.GetServices(CpAVTransport.SERVICE_NAME); if (_AVT.Length != 0) { // AVT Tests AVT = new CpAVTransport(_AVT[0]); if (!Test_AVTransport_LastChange()) { OK = false; } } if (OK) { Results.Add("Event Formatting PASSED"); SetState("Event Formatting", UPnPTestStates.Pass); } else { Results.Add("Event Formatting FAILED"); SetState("Event Formatting", UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } OK = true; _AVT = d.GetServices(CpAVTransport.SERVICE_NAME); if (_AVT.Length != 0) { // AVT Tests AVT = new CpAVTransport(_AVT[0]); if (!Test_AVTransport_StateVariables()) { OK = false; } } if (OK) { Results.Add("StateVariable Values NOT TESTED (Not implemented)"); SetState("StateVariable Values", UPnPTestStates.Pass); } else { Results.Add("StateVariable Values FAILED"); SetState("StateVariable Values", UPnPTestStates.Failed); Master = UPnPTestStates.Failed; } // this.HTTP_ScenarioTest(); state = Master; }
private void Validate_MSEARCH_RESPONSETIME() { AddMessage(0, "Testing Notifications"); HTTPMessage r = new HTTPMessage(); r.Directive = "M-SEARCH"; r.DirectiveObj = "*"; r.AddTag("MX", "10"); r.AddTag("ST", "uuid:" + TestDevice.UniqueDeviceName); r.AddTag("Host", "239.255.255.250:1900"); r.AddTag("MAN", "\"ssdp:discover\""); byte[] buf = r.RawPacket; IPEndPoint dest = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900); Cache = -1; MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(0, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(15, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(30, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(45, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(60, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(75, 90); MRE.WaitOne(15000, false); AbortCountDown(); double s = 0; try { s = DPA.StandardDeviation.TotalSeconds; } catch (DivideByZeroException) {} if (s < (double)1.50) { AddEvent(LogImportance.Medium, "M-SEARCH, MX Value", "WARNING: Device not choosing Random interval based on MX value <<Standard Deviation: " + s.ToString() + ">>"); Results.Add("M-SEARCH Response time not choosing Random interval based on MX value"); MX = UPnPTestStates.Warn; SetState("MX Value", UPnPTestStates.Warn); } else { MX = UPnPTestStates.Pass; AddEvent(LogImportance.Remark, "M-SEARCH, MX Value", "Random MX interval: <<Standard Deviation: " + s.ToString() + ">> OK"); Results.Add("M-SEARCH Response time OK"); SetState("MX Value", UPnPTestStates.Pass); } }
private void ValidateNotifyTable(UPnPDevice d) { foreach (UPnPDevice ed in d.EmbeddedDevices) { ValidateNotifyTable(ed); } if (NotifyTable.ContainsKey(d.DeviceURN)) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<" + d.DeviceURN + ">> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<" + d.DeviceURN + ">> MISSING/LATE"); } if (NotifyTable.ContainsKey("uuid:" + d.UniqueDeviceName)) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<uuid:" + d.UniqueDeviceName + ">> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<uuid:" + d.UniqueDeviceName + ">> MISSING/LATE"); } foreach (UPnPService s in d.Services) { if (NotifyTable.ContainsKey(s.ServiceURN)) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<" + s.ServiceURN + ">> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<" + s.ServiceURN + ">> MISSING/LATE"); } } }
public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_BrowseRange(); this._TestState = UPnPTestStates.Running; // get the results from the BrowseAll test CdsResult_BrowseAll PRE = null; try { foreach (ISubTest preTest in otherSubTests) { if (preTest.Name == this.PRE_BROWSEALL.Name) { PRE = preTest.Details as CdsResult_BrowseAll; break; } } if (PRE == 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); } } catch (Exception e) { throw new TestException(this._Name + " requires that the \"" + this.PRE_BROWSEALL.Name + "\" test be run before. An error occurred when attempting to obtain the results of a prerequisite.", otherSubTests, e); } _Details.BrowseAllResults = PRE; if (PRE.LargestContainer == null) { throw new TestException(this.PRE_BROWSEALL.Name + " failed to find the container with the most child objects. " + this._Name + " requires this value.", PRE); } if (PRE.Root == null) { throw new TestException(this.PRE_BROWSEALL.Name + " failed to find the root container. " + this._Name + " requires this value.", PRE); } //calculate expected test time //int maxC = PRE.LargestContainer.ChildCount + 1; //int rootC = PRE.Root.ChildCount + 1; //_Details.ExpectedTotalBrowseRequests = (maxC * maxC) + (rootC * rootC); _Details.ExpectedTotalBrowseRequests = CalculateExpectedBrowseRequests(PRE.LargestContainer) + CalculateExpectedBrowseRequests(PRE.Root); int maxTime = 300 * _Details.ExpectedTotalBrowseRequests; this._ExpectedTestingTime = maxTime; arg.ActiveTests.UpdateTimeAndProgress(0); // test the root container arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" started testing root container."); CdsBrowseSearchResults rootResults = TestContainerRanges(PRE.Root, this, arg, CDS, _Details); arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" finished testing root container."); UPnPTestStates state = this._TestState; if (state < rootResults.WorstError) { state = rootResults.WorstError; } //test largest container arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" started testing containerID=\"" + PRE.LargestContainer.ID + "\"."); CdsBrowseSearchResults cResults = TestContainerRanges(PRE.LargestContainer, this, arg, CDS, _Details); arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" finished testing containerID=\"" + PRE.LargestContainer.ID + "\"."); if (state < cResults.WorstError) { state = cResults.WorstError; } // finish up logging this._TestState = state; if (this._TestState >= UPnPTestStates.Warn) { arg._TestGroup.AddEvent(LogImportance.High, this.Name, "\"" + this.Name + "\" expects all Browse requests to succeed. A CDS should not return errors caused by [(StartingIndex + RequestedCount) >= container.ChildCount] because control points cannot assume a particular range. For leniency, the test will pass with warnings for CDS implementations that return an error when (StartingIndex >= container.ChildCount)."); } 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); } } return(this._TestState); }
public void CompareResultsAgainstExpected(CdsBrowseSearchResults br, IList expectedResults, ref UPnPTestStates state, CdsSubTestArgument arg, BrowseInput input, bool strictOrder) { if (br.WorstError >= UPnPTestStates.Failed) { throw new TerminateEarly("\"" + this.Name + "\" is terminating early because " + input.PrintBrowseParams() + " returned with an error or had problems with the DIDL-Lite."); } else { if (br.MediaObjects.Count != expectedResults.Count) { throw new TerminateEarly("\"" + this.Name + "\" did a " + input.PrintBrowseParams() + " and it should have returned " + expectedResults.Count + " media objects. DIDL-Lite contained " + br.MediaObjects.Count + " media objects. DIDL-Lite => " + br.Result); } bool warnResults = false; for (int i = 0; i < br.MediaObjects.Count; i++) { IUPnPMedia gotThis = (IUPnPMedia)br.MediaObjects[i]; IUPnPMedia expectedMedia = (IUPnPMedia)expectedResults[i]; if (gotThis.ID == expectedMedia.ID) { //arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\""+this.Name+"\" did a " +input.PrintBrowseParams()+ " and encountered no errors in the results."); } else { bool failed = false; if ((input.SortCriteria == null) || (input.SortCriteria == "")) { failed = true; } else { // Use this sorter to test for value-equality in situations where the expected order didn't match. // We need to do this because two media objects may be value-equivalent according to a sorting // algorithm, in which case there's no way to really distinguish what order they should be in. IMediaSorter sorter2 = new MediaSorter(false, input.SortCriteria); int cmp = sorter2.Compare(gotThis, expectedMedia); if (cmp != 0) { arg.TestGroup.AddEvent(LogImportance.Medium, this.Name, "\"" + this.Name + "\" found media object ID=\"" + gotThis.ID + "\" when it expected to find \"" + expectedMedia.ID + "\" and they are not equal in their sorted order."); warnResults = true; } else { if (strictOrder == false) { arg.TestGroup.AddEvent(LogImportance.Low, this.Name, "\"" + this.Name + "\" found media object ID=\"" + gotThis.ID + "\" when it expected to find \"" + expectedMedia.ID + "\" but since they are effectively value-equivalent, the ordering is OK."); } else { failed = true; } } } if (failed) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("\"{0}\" did a {1} and the order of object ID's in the result conflicts with previous browse requests."); msg.AppendFormat("\r\n\r\nReceived objects in order by ID: "); int z = 0; foreach (IUPnPMedia em in br.MediaObjects) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.Append("\r\n\r\nThe expected order by ID is: "); z = 0; foreach (IUPnPMedia em in expectedResults) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.AppendFormat(".\r\n\r\nDIDL-Lite ==> {0}", br.Result); throw new TerminateEarly(msg.ToString()); } } } if (warnResults == false) { arg.TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" did a " + input.PrintBrowseParams() + " and encountered no errors or warnings in the results."); } else { StringBuilder msg = new StringBuilder(); msg.AppendFormat("WARNING: \"{0}\" did a {1} and \r\nreceived results in the following order by ID: ", this.Name, input.PrintBrowseParams()); int z = 0; foreach (IUPnPMedia em in br.MediaObjects) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.Append("\r\n\r\nThe expected order by ID is: "); z = 0; foreach (IUPnPMedia em in expectedResults) { if (z > 0) { msg.Append(","); } msg.AppendFormat("\"{0}\"", em.ID); z++; } msg.AppendFormat(".\r\n\r\nDIDL-Lite ==> {0}", br.Result); // warn state = UPnPTestStates.Warn; arg._TestGroup.AddEvent(LogImportance.Medium, this.Name, msg.ToString()); } } }
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); }
private void Validate_DISCOVERY() { //Test all types of M-SEARCH, both valid and invalid MSEARCHTable.Clear(); ASocket.OnReceive -= new AsyncSocket.OnReceiveHandler(ReceiveSink); ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(MSEARCHSink); HTTPMessage rq = new HTTPMessage(); byte[] rbuf; IPEndPoint d = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900); rq.Directive = "M-SEARCH"; rq.DirectiveObj = "*"; rq.AddTag("MX", "5"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "ssdp:all"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(0, 91); MRE.WaitOne(8000, false); AbortCountDown(); if (MSEARCHTable.ContainsKey("upnp:rootdevice")) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ssdp:all / upnp:rootdevice>> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<ssdp:all / upnp:rootdevice>> MISSING"); } foreach (HTTPMessage m in MSEARCH(TestDevice)) { if (MSEARCHTable.ContainsKey(m.GetTag("ST").Trim())) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ssdp:all / " + m.GetTag("ST").Trim() + ">> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<ssdp:all / " + m.GetTag("ST").Trim() + ">> MISSING"); } } // Test MSEARCH upnp:rootdevice, and others MSEARCHTable.Clear(); rq.AddTag("ST", "upnp:rootdevice"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); foreach (HTTPMessage m in MSEARCH(TestDevice)) { this.sample2 += "\r\n\r\n" + m.StringPacket; ASocket.Send(m.RawPacket, 0, m.RawPacket.Length, d); } MRE.Reset(); StartCountDown(8, 91); MRE.WaitOne(8000, false); AbortCountDown(); ASocket.OnReceive -= new AsyncSocket.OnReceiveHandler(MSEARCHSink); if (MSEARCHTable.ContainsKey("upnp:rootdevice")) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<upnp:rootdevice>> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<upnp:rootdevice>> MISSING"); } foreach (HTTPMessage m in MSEARCH(TestDevice)) { if (MSEARCHTable.ContainsKey(m.GetTag("ST").Trim())) { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<" + m.GetTag("ST").Trim() + ">> OK"); } else { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Discovery", "MSEARCH <<" + m.GetTag("ST").Trim() + ">> MISSING"); } } // Test Invalid MSEARCHes string ST = ""; MSEARCHTable.Clear(); ASocket.OnReceive += new AsyncSocket.OnReceiveHandler(BadMSEARCHSink); rq = new HTTPMessage(); rq.Directive = "M-SEARCH"; rq.DirectiveObj = "*"; rq.AddTag("MX", "2"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "uuid:___" + TestDevice.UniqueDeviceName + "___"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(16, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<NonExistent UDN>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<NonExistent UDN>> OK"); } MSEARCHTable.Clear(); ST = TestDevice.DeviceURN; int i = ST.LastIndexOf(":"); if (i == -1) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "Can't parse DeviceURN"); return; } ST = ST.Substring(0, i); ST = ST + ":" + ((int)(int.Parse(TestDevice.Version) + 5)).ToString(); rq.AddTag("ST", ST); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(21, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Existing Device Type, Bad Version>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Existing Device Type, Bad Version>> OK"); } MSEARCHTable.Clear(); UPnPService _S = FetchAService(TestDevice); ST = _S.ServiceURN; ST = ST.Substring(0, ST.LastIndexOf(":")); ST = ST + ":" + ((int)(int.Parse(_S.Version) + 5)).ToString(); rq.AddTag("ST", ST); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(26, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Existing Service Type, Bad Version>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Existing Service Type, Bad Version>> OK"); } // Test MSEARCH No * MSEARCHTable.Clear(); rq = new HTTPMessage(); rq.Directive = "M-SEARCH"; rq.DirectiveObj = ""; rq.AddTag("MX", "2"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "upnp:rootdevice"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(31, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No *>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No *>> OK"); } MSEARCHTable.Clear(); rq.DirectiveObj = "/"; rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(36, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Not *>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Not *>> OK"); } MSEARCHTable.Clear(); rq = new HTTPMessage(); rq.Directive = "M-SEARCH"; rq.DirectiveObj = ""; rq.AddTag("MX", "2"); rq.AddTag("Host", "239.255.255.250:1900"); rq.AddTag("MAN", "\"ssdp:discover\""); rq.AddTag("ST", "upnp:rootdevice"); rq.Version = "1.0"; rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(41, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<Version = 1.0>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<Version = 1.0>> OK"); } MSEARCHTable.Clear(); rq.DirectiveObj = "*"; rq.Version = ""; rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(46, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No Version>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No Version>> OK"); } MSEARCHTable.Clear(); rq.Version = "1.1"; rq.RemoveTag("MAN"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(51, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No MAN>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No MAN>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MAN", "\"ssdp:discover\""); rq.RemoveTag("MX"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(56, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No MX>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No MX>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", ""); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(61, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<MX Empty>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<MX Empty>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", "Z"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(66, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<MX Not Integer>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<MX Not Integer>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", "-1"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(71, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<MX Negative>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<MX Negative>> OK"); } MSEARCHTable.Clear(); rq.AddTag("MX", "2"); rq.RemoveTag("ST"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(76, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<No ST>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<No ST>> OK"); } MSEARCHTable.Clear(); rq.AddTag("ST", ""); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(81, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<ST Empty>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ST Empty>> OK"); } MSEARCHTable.Clear(); rq.AddTag("ST", "ABCDEFG"); rbuf = rq.RawPacket; ASocket.Send(rbuf, 0, rbuf.Length, d); MRE.Reset(); StartCountDown(86, 91); MRE.WaitOne(5000, false); AbortCountDown(); if (MSEARCHTable.Count != 0) { DISCOVERY = UPnPTestStates.Failed; AddEvent(LogImportance.High, "Discovery", "MSEARCH <<ST Invalid>> Unexpected Response"); } else { AddEvent(LogImportance.Remark, "Discovery", "MSEARCH <<ST Invalid>> OK"); } SetState("Discovery", DISCOVERY); if (DISCOVERY == UPnPTestStates.Pass) { Results.Add("Discovery mechanism OK"); } else { Results.Add("Discovery mechanism is not behaving correctly"); } }
public void RunQueue() { Arg.TestGroup.state = UPnPTestStates.Running; UPnPService[] services = Arg.Device.Services; UPnPServiceWatcher[] watchers = new UPnPServiceWatcher[services.Length]; for (int i = 0; i < services.Length; i++) { //watchers[i] = new UPnPServiceWatcher(services[i], null, new UPnPServiceWatcher.SniffPacketHandler(this.SniffPacketSink)); } foreach (ISubTest sub in Q.Values) { Arg.TestGroup.SetState(sub.Name, UPnPTestStates.Running); bool cont = true; foreach (SubTest pre1 in sub.Prerequisites) { pre1.CalculateExpectedTestingTime(Q.Values, Arg); ISubTest pre = null; foreach (ISubTest pre2 in Q.Values) { if (pre2.Name == pre1.Name) { pre = pre2; } } if ( (! (pre.TestState == UPnPTestStates.Pass) || (pre.TestState == UPnPTestStates.Warn) ) ) { cont = false; } } this.UpdateTimeAndProgress(0); if (cont) { UPnPTestStates result = sub.Run(Q.Values, Arg); Arg.TestGroup.SetState(sub.Name, result); if (sub.TestState != result) { throw new ApplicationException("Test state does not match the set value."); } } this.UpdateTimeAndProgress(0); } UPnPTestStates MasterResult = UPnPTestStates.Pass; foreach (ISubTest done in Q.Values) { if (done.TestState > MasterResult) { MasterResult = done.TestState; break; } } for (int i = 0; i < services.Length; i++) { //watchers[i].OnSniffPacket -= new UPnPServiceWatcher.SniffPacketHandler(this.SniffPacketSink); } Arg.TestGroup.state = MasterResult; }
private void Validate_NOTIFY() { ManualResetEvent M = new ManualResetEvent(false); // Check to see if received all the NOTIFY packets NotifyTable.Clear(); ASocket2.Begin(); M.Reset(); StartCountDown(0, Cache); if (Cache == -1) { M.WaitOne(-1, false); } else { M.WaitOne(Cache * 1000, false); } AbortCountDown(); ASocket2.OnReceive -= new AsyncSocket.OnReceiveHandler(ReceiveSink2); if (NotifyTable.ContainsKey("upnp:rootdevice")) { AddEvent(LogImportance.Remark, "Notifications", "NOTIFY <<upnp:rootdevice>> OK"); } else { NOTIFY = UPnPTestStates.Failed; AddEvent(LogImportance.Critical, "Notifications", "NOTIFY <<upnp:rootdevice>> MISSING/LATE"); } ValidateNotifyTable(TestDevice); if (NOTIFY == UPnPTestStates.Pass) { Results.Add("Notifications OK"); } else { Results.Add("One ore more NOTIFY packets were MISSING"); } SetState("Notifications", NOTIFY); }
public static string UPnPTestStatesToString(UPnPTestStates s) { switch(s) { case UPnPTestStates.Failed: return "Failed"; case UPnPTestStates.Pass: return "Pass"; case UPnPTestStates.Ready: return "Ready"; case UPnPTestStates.Running: return "Running"; case UPnPTestStates.Warn: return "Warn"; } return ""; }
public override UPnPTestStates Run(ICollection otherSubTests, CdsSubTestArgument arg) { // init basic stuff CpContentDirectory CDS = this.GetCDS(arg._Device); _Details = new CdsResult_BrowseAll(); // set up a queue of containers to browse, starting with root container Queue C = new Queue(); _Details.Root = new MediaContainer(); _Details.Root.ID = "0"; _Details.AllObjects.Add(_Details.Root); _Details.TotalContainers = 1; _Details.TotalItems = 0; C.Enqueue(_Details.Root); // if we have containers to browse, do so this._TestState = UPnPTestStates.Running; UPnPTestStates testResult = UPnPTestStates.Ready; arg._TestGroup.AddEvent(LogImportance.Remark, this.Name, "\"" + this.Name + "\" started."); while (C.Count > 0) { IMediaContainer c = (IMediaContainer)C.Dequeue(); this._ExpectedTestingTime = _Details.ExpectedTotalBrowseRequests * 30; arg.ActiveTests.UpdateTimeAndProgress(_Details.TotalBrowseRequests * 30); // // get the container's metadata // IUPnPMedia metadata; CdsBrowseSearchResults results = GetContainerMetadataAndValidate(c.ID, CDS, this, arg, _Details, out metadata); testResult = results.WorstError; if (testResult > UPnPTestStates.Warn) { arg._TestGroup.AddEvent(LogImportance.Critical, this.Name, this.Name + " terminating because container metadata could not be obtained or the metadata was not CDS-compliant."); testResult = UPnPTestStates.Failed; this._TestState = testResult; return(this._TestState); } if (metadata != null) { try { c.UpdateObject(metadata); c.Tag = results.UpdateID; } catch (Exception e) { UpdateObjectError uoe = new UpdateObjectError(); uoe.UpdateThis = c; uoe.Metadata = metadata; throw new TestException("Critical error updating metadata of a container using UpdateObject()", uoe, e); } } else { string reason = "\"" + this.Name + "\" terminating because container metadata could not be cast into object form."; arg._TestGroup.AddEvent(LogImportance.Critical, this.Name, reason); arg._TestGroup.AddResult("\"" + this.Name + "\" test failed. " + reason); testResult = UPnPTestStates.Failed; this._TestState = testResult; return(this._TestState); } // // Now get the container's children // ArrayList children = new ArrayList(); try { children = GetContainerChildrenAndValidate(c, CDS, this, arg, _Details, C); if ((_Details.LargestContainer == null) || (children.Count > _Details.LargestContainer.ChildCount)) { _Details.LargestContainer = c; } } catch (TerminateEarly te) { string reason = "\"" + this.Name + "\" terminating early. Reason => " + te.Message; arg._TestGroup.AddEvent(LogImportance.Critical, this.Name, reason); arg._TestGroup.AddResult("\"" + this.Name + "\" test failed. " + reason); testResult = UPnPTestStates.Failed; this._TestState = testResult; return(this._TestState); } } if (testResult >= UPnPTestStates.Failed) { throw new TestException("Execution should not reach this code if testResult is WARN or worse.", testResult); } if (testResult == UPnPTestStates.Ready) { throw new TestException("We should not return Ready state.", testResult); } StringBuilder sb = new StringBuilder(); sb.Append("\"" + this._Name + "\" test finished"); if (testResult == UPnPTestStates.Warn) { sb.Append(" with warnings"); } sb.AppendFormat(" and found {0}/{1}/{2} TotalObjects/TotalContainers/TotalItems.", _Details.AllObjects.Count, _Details.TotalContainers, _Details.TotalItems); arg.TestGroup.AddResult(sb.ToString()); arg._TestGroup.AddEvent(LogImportance.Remark, this.Name, this.Name + " completed."); this._TestState = testResult; if (this._TestState <= UPnPTestStates.Warn) { if (_Details.TotalBrowseRequests != _Details.ExpectedTotalBrowseRequests) { throw new TestException("TotalBrowseRequests=" + _Details.TotalBrowseRequests.ToString() + " ExpectedTotal=" + _Details.ExpectedTotalBrowseRequests.ToString(), _Details); } } return(this._TestState); }
private void Validate_MSEARCH_RESPONSETIME() { AddMessage(0, "Testing Notifications"); HTTPMessage r = new HTTPMessage(); r.Directive = "M-SEARCH"; r.DirectiveObj = "*"; r.AddTag("MX", "10"); r.AddTag("ST", "uuid:" + TestDevice.UniqueDeviceName); r.AddTag("Host", "239.255.255.250:1900"); r.AddTag("MAN", "\"ssdp:discover\""); byte[] buf = r.RawPacket; IPEndPoint dest = new IPEndPoint(IPAddress.Parse("239.255.255.250"), 1900); Cache = -1; MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(0, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(15, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(30, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(45, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(60, 90); MRE.WaitOne(15000, false); AbortCountDown(); MRE.Reset(); StartTime = DateTime.Now; ASocket.Send(buf, 0, buf.Length, dest); StartCountDown(75, 90); MRE.WaitOne(15000, false); AbortCountDown(); double s = 0; try { s = DPA.StandardDeviation.TotalSeconds; } catch (DivideByZeroException) {} if (s < (double)1.50) { AddEvent(LogImportance.Medium, "M-SEARCH, MX Value", "WARNING: Device not choosing Random interval based on MX value <<Standard Deviation: " + s.ToString() + ">>"); Results.Add("M-SEARCH Response time not choosing Random interval based on MX value"); MX = UPnPTestStates.Warn; SetState("MX Value", UPnPTestStates.Warn); } else { MX = UPnPTestStates.Pass; AddEvent(LogImportance.Remark, "M-SEARCH, MX Value", "Random MX interval: <<Standard Deviation: " + s.ToString() + ">> OK"); Results.Add("M-SEARCH Response time OK"); SetState("MX Value", UPnPTestStates.Pass); } }
private int getImageIndexForUPnPTestState(UPnPTestStates state) { switch (state) { case UPnPTestStates.Failed: return 10; case UPnPTestStates.Pass: return 12; case UPnPTestStates.Warn: return 11; default: return 8; } }
private void grabTestInfo(XmlElement testElement) { string name = testElement.GetAttribute("name"); string state = testElement.GetAttribute("state"); string result = testElement.GetAttribute("result"); string description = testElement.GetAttribute("description"); Results.Add(result); TestList.Add(new string[] {name, description}); UPnPTestStates[] oldStates = states; states = new UPnPTestStates[TestList.Count]; states[oldStates.Length] = Util.StringToUPnPTestStates(state); for(int i=0;i<oldStates.Length;++i) { states[i] = oldStates[i]; } }