private void TestParseParentListArgumentException(String props, int offset) { try { HmdParser.ParseParentList(props, ref offset); Assert.Fail("Expected an ArgumentException, but didn't get one"); } catch (ArgumentException e) { Console.WriteLine("Expected Exception: \"{0}\"", e.Message); } }
private void TestParseParentList(String props, int offset, params String[] expectedParents) { int parentLength = expectedParents.Length; HmdParentReference[] actualParents = HmdParser.ParseParentList(props, ref offset); Assert.AreEqual(actualParents.Length, parentLength); Boolean [] actualParentalreadyMatchd = new Boolean[parentLength]; int lowestNonMatchedParent = 0; for (int i = 0; i < parentLength; i++) { Boolean expectedParentFound = false; for (int j = lowestNonMatchedParent; j < parentLength; j++) { if (actualParents[j].IDLowerCase.Equals(expectedParents[i], StringComparison.CurrentCultureIgnoreCase)) { if (actualParentalreadyMatchd[j]) { throw new InvalidOperationException("Found the same parent twice...what??"); } actualParentalreadyMatchd[j] = true; if (j == lowestNonMatchedParent) { lowestNonMatchedParent++; while (lowestNonMatchedParent < parentLength && actualParentalreadyMatchd[lowestNonMatchedParent]) { lowestNonMatchedParent++; } } expectedParentFound = true; break; } } if (!expectedParentFound) { Assert.Fail(String.Format("The expected parent \"{0}\" was not found in the actual parents", expectedParents[i])); } } }