public void TestAddCondition() { string firstPath = Path.Combine(TestSupport.CreatedFilesDirectory, "first.xml"); string secondPath = Path.Combine(TestSupport.CreatedFilesDirectory, "second.xml"); TestCasesRootContainer tcrc = new TestCasesRootContainer(); tcrc.TestCasesRoot.Save(firstPath); SelectedValuesByConditionsAndActions selValues = new SelectedValuesByConditionsAndActions(); selValues.CollectValues(tcrc.TestCasesRoot); selValues.Check(tcrc.TestCasesRoot); string newConditionName = "new condition " + DateTime.Now.ToString("F"); int conditionCount = tcrc.TestCasesRoot.Conditions.Count; tcrc.TestCasesRoot.AppendCondition(ConditionObject.Create(newConditionName, new ObservableCollection <EnumValue>() { new EnumValue("new test", "new value") })); TestUtils.CheckTestCasesAndConditionsAndActions(tcrc.TestCasesRoot); Assert.That(tcrc.TestCasesRoot.Conditions.Count == conditionCount + 1); Assert.That(tcrc.TestCasesRoot.Conditions.Last().Name.Equals(newConditionName)); Assert.That(tcrc.ConditionChangeCount == 2); Assert.That(tcrc.ActionChangeCount == 0); selValues.AppendCondition(tcrc.TestCasesRoot.TestCases.Count); selValues.Check(tcrc.TestCasesRoot); tcrc.TestCasesRoot.Save(secondPath); // only for manual check of testcase //TestSupport.CompareFile(firstPath, secondPath); }
public void TestInsertCondition(InsertPosition insertPosition) { string firstPath = Path.Combine(TestSupport.CreatedFilesDirectory, "first.xml"); string secondPath = Path.Combine(TestSupport.CreatedFilesDirectory, "second.xml"); TestCasesRootContainer tcrc = new TestCasesRootContainer(); tcrc.TestCasesRoot.Save(firstPath); SelectedValuesByConditionsAndActions selValues = new SelectedValuesByConditionsAndActions(); selValues.CollectValues(tcrc.TestCasesRoot); selValues.Check(tcrc.TestCasesRoot); int indexWhereToInsert = TestUtils.CalculateIndex(tcrc.TestCasesRoot.Conditions, insertPosition); string newConditionName = "new condition " + DateTime.Now.ToString("F"); int conditionCount = tcrc.TestCasesRoot.Conditions.Count; tcrc.TestCasesRoot.InsertCondition(indexWhereToInsert, ConditionObject.Create(newConditionName, new ObservableCollection <EnumValue>() { new EnumValue("new test", "new value") })); TestUtils.CheckTestCasesAndConditionsAndActions(tcrc.TestCasesRoot); Assert.That(conditionCount == 3); // adjust last testcase on failue Assert.That(tcrc.TestCasesRoot.Conditions.Count == conditionCount + 1); Assert.That(tcrc.TestCasesRoot.Conditions[indexWhereToInsert].Name.Equals(newConditionName)); Assert.That(tcrc.ConditionChangeCount == 2); Assert.That(tcrc.ActionChangeCount == 0); selValues.InsertCondition(insertPosition, tcrc.TestCasesRoot.TestCases.Count); selValues.Check(tcrc.TestCasesRoot); tcrc.TestCasesRoot.Save(secondPath); // only for manual check of testcase //TestSupport.CompareFile(firstPath, secondPath); }
public void TestCalculationEnumValues(int count, int defaultIndex, int invalidIndex, int dontCareIndex, int expectedResult) { var condition = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", count, defaultIndex, invalidIndex, dontCareIndex)); long result = TestCasesRoot.CalculateEnumValuesWithoutDontCareAndInvalid(condition); Assert.That(result == expectedResult); }
public void CreateAllTestCases1() { TestCasesRoot tcr = new TestCasesRoot(); tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-1", 4, 0, 0, 3))); CreateAllTestCases(tcr, 2); }
internal void Check(ConditionObject co) { Assert.That(co.TestValues.Count == Values.Count); for (int idx = 0; idx < Values.Count; idx++) { Values[idx].Check(co.TestValues[idx]); } }
internal void Collect(ConditionObject condition) { Assert.That(condition.DataType == ValueDataType.Enumeration); Values = new List <SelectedValue>(); foreach (ValueObject value in condition.TestValues) { Values.Add(new SelectedValue(value)); } }
public void CreateAllTestCases4() { TestCasesRoot tcr = new TestCasesRoot(); tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-1", 4, 0, 0, 3))); tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-2", 4, 0, 0, 3))); tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-3", 1, 0, 0, -1))); tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-4", 4, 0, 0, -1))); CreateAllTestCases(tcr, 2 * 2 * 3); }
internal void Check(TestCasesRoot testCasesRoot) { Assert.That(testCasesRoot.Conditions.Count == ConditionValues.Count); for (int idx = 0; idx < testCasesRoot.Conditions.Count; idx++) { ConditionObject co = testCasesRoot.Conditions[idx]; ConditionValues[idx].Check(co); } Assert.That(testCasesRoot.Actions.Count == ActionValues.Count); for (int idx = 0; idx < testCasesRoot.Actions.Count; idx++) { ActionObject co = testCasesRoot.Actions[idx]; ActionValues[idx].Check(co); } }
/// <summary> /// Feld Hinzufügen und Fenster entsprechend schließen. /// </summary> private void AddField() { var cg = tp.cbFieldsToChoose.Text; ConditionObject k = new ConditionObject { Feld = cg }; Playlists.GetPlaylists[lbPlaylist.SelectedIndex].PlaylistConditionGroups[lbConditionList.SelectedIndex].Add(k); Functions.PlaylistChanged = true; lbFelder.ItemsSource = null; lbFelder.ItemsSource = Playlists.GetPlaylists[lbPlaylist.SelectedIndex].PlaylistConditionGroups[lbConditionList.SelectedIndex] .FieldNamesList; lbFelder.SelectedIndex = (Playlists.GetPlaylists[lbPlaylist.SelectedIndex].PlaylistConditionGroups[lbConditionList.SelectedIndex] .FieldNamesList.Count - 1); tp.Close(); tbFeld.Focus(); }
public void TestCalculationConditions() { TestCasesRoot tcr = new TestCasesRoot(); int expectedResult = 0; long result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); expectedResult = 4; tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 4, 0, 0, 3))); tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 4, 0, 0, 3))); result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); // 2 invalids var cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 6, 0, 0, 3)); cond.EnumValues[5].IsInvalid = true; tcr.Conditions.Add(cond); expectedResult *= 3; result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 2, 0, 0, 1)); tcr.Conditions.Add(cond); result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 1, 0, 0, 0)); tcr.Conditions.Add(cond); result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 0, 0, 0, 0)); tcr.Conditions.Add(cond); result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 2, 0, -1, -1)); tcr.Conditions.Add(cond); expectedResult *= 2; result = tcr.CalculatePossibleCombinations(); Assert.That(result == expectedResult); }
public void CompareTestCases2Test(int selected11, int selected12, int selected13, int selected21, int selected22, int selected23, bool unique1, bool unique2, int expectedCoveredCount) { TestCasesRoot tcr = new TestCasesRoot(); var enum1 = TestCasesRoot.CreateSampleEnum("enum1", 6, 0, 0, 5); var enum2 = TestCasesRoot.CreateSampleEnum("enum2", 6, 0, 0, 5); var enum3 = TestCasesRoot.CreateSampleEnum("enum3", 6, 0, 0, 5); tcr.Conditions.Add(ConditionObject.Create("enum1", enum1)); tcr.Conditions.Add(ConditionObject.Create("enum2", enum2)); tcr.Conditions.Add(ConditionObject.Create("enum3", enum3)); List <ValueObject> conditions1 = new List <ValueObject>(); conditions1.Add(new ValueObject(enum1, selected11)); conditions1.Add(new ValueObject(enum2, selected12)); conditions1.Add(new ValueObject(enum3, selected13)); List <ValueObject> conditions2 = new List <ValueObject>(); conditions2.Add(new ValueObject(enum1, selected21)); conditions2.Add(new ValueObject(enum2, selected22)); conditions2.Add(new ValueObject(enum3, selected23)); TestCase tc1 = tcr.InsertTestCase(); tc1.SetValues(tcr, conditions1, new List <ValueObject>()); TestCase tc2 = tcr.InsertTestCase(); tc2.SetValues(tcr, conditions2, new List <ValueObject>()); Trace.WriteLine(tc1); Trace.WriteLine(tc2); bool isEqual = tc1.TestSettingIsEqual(tc2); Assert.That(TestCase.UpdateUniqueness(tc1, tc2) == (unique1 && unique2)); long count = tcr.CalculateNumberOfUniqueCoveredTestCases(); Assert.That(tc1.TestCaseIsUnique == unique1); Assert.That(tc2.TestCaseIsUnique == unique2); Assert.That(count == expectedCoveredCount); }
/** * Queries whether any threads are waiting on the given condition * associated with this synchronizer. Note that because timeouts * and interrupts may occur at any time, a <tt>true</tt> return * does not guarantee that a future <tt>signal</tt> will awaken * any threads. This method is designed primarily for use in * monitoring of the system state. * * @param condition the condition * @return <tt>true</tt> if there are any waiting threads * @throws ThreadStateException if exclusive synchronization * is not held * @throws IllegalArgumentException if the given condition is * not associated with this synchronizer * @throws NullPointerException if the condition is null */ public bool HasWaiters(ConditionObject condition) { if (!Owns(condition)) { throw new ArgumentException("Not owner"); } return condition.HasWaiters; }
/** * Queries whether the given ConditionObject * uses this synchronizer as its lock. * * @param condition the condition * @return <tt>true</tt> if owned * @throws NullPointerException if the condition is null */ public bool Owns(ConditionObject condition) { if (condition == null) { throw new NullReferenceException(); } return condition.IsOwnedBy(this); }
public void CalculateUniqueTestCasesWithDontCare(int id, int[] values, int expectedCombinations, int expectedCoveredTestCases, double expectedCovarage) { string testOutputPath = Path.Combine(TestSupport.CreatedFilesDirectory, "TestOutput.txt"); string testSettingPath = Path.Combine(TestSupport.CreatedFilesDirectory, "TestSetting.txt"); TestCasesRoot tcr = new TestCasesRoot(); List <List <ValueObject> > listOfValueLists = new List <List <ValueObject> >(); var enum1 = TestCasesRoot.CreateSampleEnum("enum1", 4, 0, 0, 3); var enum2 = TestCasesRoot.CreateSampleEnum("enum2", 4, 0, 0, 3); var enum3 = TestCasesRoot.CreateSampleEnum("enum3", 6, 0, 0, 5); tcr.Conditions.Add(ConditionObject.Create("name", enum1)); tcr.Conditions.Add(ConditionObject.Create("name", enum2)); tcr.Conditions.Add(ConditionObject.Create("name", enum3)); for (int idx1 = 0; idx1 < 3; idx1++) { for (int idx2 = 0; idx2 < 4; idx2++) { for (int idx3 = 0; idx3 < 6; idx3++) { listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, idx1), new ValueObject(enum2, idx2), new ValueObject(enum3, idx3), }); } } } listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 5), }); for (int idx = 0; idx < listOfValueLists.Count; idx++) { List <ValueObject> condList = listOfValueLists[idx]; File.AppendAllText(testOutputPath, String.Format("{0:d2} {1} {2} {3}" + Environment.NewLine, idx, condList[0].SelectedValue.ToTestString(), condList[1].SelectedValue.ToTestString(), condList[2].SelectedValue.ToTestString())); } for (int idx = 0; idx < values.Length; idx++) { //TestCase tc = new TestCase(String.Format("tc {0:d2}", idx), listOfValueLists[values[idx]], new List<ValueObject>()); //tcr.TestCases.Add(tc); TestCase tc = tcr.InsertTestCase(); tc.SetValues(tcr, listOfValueLists[values[idx]], new List <ValueObject>()); //File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, tc)); } Statistics stat = tcr.CalculateStatistics(); for (int idx = 0; idx < tcr.TestCases.Count; idx++) { File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, tcr.TestCases[idx])); } File.AppendAllText(testSettingPath, Environment.NewLine + Environment.NewLine); ExpandTestCases expand = new ExpandTestCases(); var resultList = expand.Expand(tcr); foreach (TestCase testCase in resultList) { File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, testCase)); } Assert.That(stat.CoveredTestCases == expectedCoveredTestCases); Assert.That(stat.PossibleCombinations == expectedCombinations); Assert.That(stat.Coverage.Equals(expectedCovarage)); }
public void CalculateUniqueTestCases(int id, int[] values, int expectedResult) { TestCasesRoot tcr = new TestCasesRoot(); List <List <ValueObject> > listOfValueLists = new List <List <ValueObject> >(); var enum1 = TestCasesRoot.CreateSampleEnum("enum1", 4, 0, 0, -1); var enum2 = TestCasesRoot.CreateSampleEnum("enum2", 4, 0, 0, 1); var enum3 = TestCasesRoot.CreateSampleEnum("enum3", 6, 0, 0, -1); tcr.Conditions.Add(ConditionObject.Create("name", enum1)); tcr.Conditions.Add(ConditionObject.Create("name", enum2)); tcr.Conditions.Add(ConditionObject.Create("name", enum3)); //0 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2), }); //2 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 2), new ValueObject(enum2, 3), new ValueObject(enum3, 3), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 2), new ValueObject(enum2, 3), new ValueObject(enum3, 3), }); //4 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 3), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 3), }); //6 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 2), new ValueObject(enum3, 3), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 2), new ValueObject(enum3, 3), }); //8 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 4), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 4), }); //10 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 5), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 5), }); //12 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 3), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 3), }); //14 not valid for unique count listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 0), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 0), }); //16 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2), }); //18 listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2), }); listOfValueLists.Add(new List <ValueObject>() { new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2), }); List <TestCase> testCases = new List <TestCase>(); for (int idx = 0; idx < values.Length; idx++) { TestCase tc = tcr.InsertTestCase(); tc.SetValues(tcr, listOfValueLists[values[idx]], new List <ValueObject>()); //TestCase tc = new TestCase(String.Format("tc {0:d2} {1:d2}", idx, values[idx]), listOfValueLists[values[idx]], new List<ValueObject>()); //testCases.Add(tc); //Trace.WriteLine(tc); } long result = tcr.CalculateNumberOfUniqueCoveredTestCases(); Assert.That(result == expectedResult); }
/// <summary> /// Returns an estimate of the number of threads waiting on the given condition /// associated with this synchronizer. Note that because timeouts and interrupts /// may occur at any time, the estimate serves only as an upper bound on the actual /// number of waiters. This method is designed for use in monitoring of the /// system state, not for synchronization control. /// </summary> /// <returns> /// the estimated number of waiting threads /// </returns> /// <param name='condition'> /// The Condition to retrienve to wait queue length. /// </param> /// <exception cref='ThreadStateException'> /// If the exclusive synchronization is not held. /// </exception> /// <exception cref='ArgumentException'> /// if the given condition is not associated with this synchronizer /// </exception> /// <exception cref='NullReferenceException'> /// If the supplied condition is null. /// </exception> public int GetWaitQueueLength(ConditionObject condition) { if (!Owns(condition)) { throw new ArgumentException("Not owner"); } return condition.WaitQueueLength; }
/// <summary> /// Returns a collection containing those threads that may be waiting on the /// given condition associated with this synchronizer. Because the actual /// set of threads may change dynamically while constructing this result, /// the returned collection is only a best-effort estimate. The elements /// of the returned collection are in no particular order. /// </summary> /// <exception cref='ArgumentException'> /// Is thrown when the given condition is not associated with this synchronizer. /// </exception> /// <exception cref='ThreadStateException'> /// Is thrown when exclusive synchronization is not held. /// </exception> /// <exception cref='NullReferenceException'> /// Is thrown when the Condition object passed is null. /// </exception> public Collection<Thread> GetWaitingThreads(ConditionObject condition) { if (!Owns(condition)) { throw new ArgumentException("Not owner"); } return condition.WaitingThreads; }
public static void CheckTestCasesAndConditionsAndActions(TestCasesRoot tcr) { int testCasesCount = tcr.TestCases.Count; int conditionsCount = tcr.Conditions.Count; int actionsCount = tcr.Actions.Count; for (int testCaseIndex = 0; testCaseIndex < tcr.TestCases.Count; testCaseIndex++) { TestCase tc = tcr.TestCases[testCaseIndex]; Assert.That(tc.Conditions.Count == conditionsCount); Assert.That(tc.Actions.Count == actionsCount); var actionCol = tcr.ActionTable.Columns[testCaseIndex + 1]; Assert.That(tc.Name.Equals(actionCol.Caption)); var conditionCol = tcr.ConditionTable.Columns[testCaseIndex + 1]; Assert.That(tc.Name.Equals(conditionCol.Caption)); for (int conditionIndex = 0; conditionIndex < tcr.Conditions.Count; conditionIndex++) { ConditionObject co = tcr.Conditions[conditionIndex]; Assert.That(co.TestValues.Count == testCasesCount); Assert.That(tc.Conditions[conditionIndex].ConditionOrActionParent.Equals(co)); ValueObject tcValueObject = tc.Conditions[conditionIndex]; ValueObject condValueObject = tcr.Conditions[conditionIndex].TestValues[testCaseIndex]; Assert.That(tcValueObject == condValueObject); Assert.That(tcValueObject.EnumValues == condValueObject.EnumValues); } for (int actionIndex = 0; actionIndex < tcr.Actions.Count; actionIndex++) { ActionObject co = tcr.Actions[actionIndex]; Assert.That(co.TestValues.Count == testCasesCount); Assert.That(tc.Actions[actionIndex].ConditionOrActionParent.Equals(co)); ValueObject tcValueObject = tc.Actions[actionIndex]; ValueObject actionValueObject = tcr.Actions[actionIndex].TestValues[testCaseIndex]; Assert.That(tcValueObject == actionValueObject); Assert.That(tcValueObject.EnumValues == actionValueObject.EnumValues); } } Assert.That(tcr.ConditionTable.Columns.Count == tcr.TestCases.Count + 1); Assert.That(tcr.ConditionTable.Columns.Count == tcr.TestCases.Count + 1); Assert.That(tcr.ActionTable.Columns.Count == tcr.TestCases.Count + 1); Assert.That(tcr.ActionTable.Columns.Count == tcr.TestCases.Count + 1); for (int rowIndex = 0; rowIndex < tcr.ConditionTable.Rows.Count; rowIndex++) { DataRow rowView = tcr.ConditionTable.Rows[rowIndex]; Assert.That(rowView.ItemArray.Length == tcr.TestCases.Count + 1); Assert.That(rowView[0] is ConditionObject); Assert.That(rowView[0] == tcr.Conditions[rowIndex]); for (int colIndex = 1; colIndex < tcr.ConditionTable.Columns.Count; colIndex++) { ValueObject vo = rowView[colIndex] as ValueObject; TestCase tc = tcr.TestCases[colIndex - 1]; Assert.That(vo == tc.Conditions[rowIndex]); } } for (int rowIndex = 0; rowIndex < tcr.ActionTable.Rows.Count; rowIndex++) { DataRow rowView = tcr.ActionTable.Rows[rowIndex]; Assert.That(rowView.ItemArray.Length == tcr.TestCases.Count + 1); Assert.That(rowView[0] is ActionObject); Assert.That(rowView[0] == tcr.Actions[rowIndex]); for (int colIndex = 1; colIndex < tcr.ActionTable.Columns.Count; colIndex++) { ValueObject vo = rowView[colIndex] as ValueObject; TestCase tc = tcr.TestCases[colIndex - 1]; Assert.That(vo == tc.Actions[rowIndex]); } } }