public bool runTest() { //////////// Global Variables used for all tests int iCountErrors = 0; int iCountTestcases = 0; MyCollectionBase mycol; Foo f, newF; string expectedExceptionMessage; try { do { ///////////////////////// START TESTS //////////////////////////// /////////////////////////////////////////////////////////////////// //[] Vanilla Add iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Add(f); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_4072ayps OnInsertComplete was never called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_0181salh Item was added"); } //[] Add where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnValidateThrow = true; expectedExceptionMessage = "OnValidate"; f = new Foo(); try { mycol.Add(f); iCountErrors++; Console.WriteLine("Err_1570pyqa Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_2708apsa Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCalled) { iCountErrors++; Console.WriteLine("Err_56707awwaps OnInsert was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_2708apsa Expected Empty Collection actual {0} elements", mycol.Count); } //[] Add where OnInsert throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertThrow = true; expectedExceptionMessage = "OnInsert"; f = new Foo(); try { mycol.Add(f); iCountErrors++; Console.WriteLine("Err_35208asdo Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_30437sfdah Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_370asjhs OnInsertComplete was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_3y07aza Expected Empty Collection actual {0} elements", mycol.Count); } //[] Add where OnInsertComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertCompleteThrow = true; expectedExceptionMessage = "OnInsertComplete"; f = new Foo(); try { mycol.Add(f); iCountErrors++; Console.WriteLine("Err_2548ashz Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_2708alkw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_3680ahksd Expected Empty Collection actual {0} elements", mycol.Count); } /******* Insert ******************************************************************************************/ //[] Vanilla Insert iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Insert(0, f); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_270ash OnInsertComplete was never called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_208anla Item was added"); } //[] Insert where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnValidateThrow = true; expectedExceptionMessage = "OnValidate"; f = new Foo(); try { mycol.Insert(0, f); iCountErrors++; Console.WriteLine("Err_270ahsw Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_48708awhoh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCalled) { iCountErrors++; Console.WriteLine("Err_3708anw OnInsert was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_707j2awn Expected Empty Collection actual {0} elements", mycol.Count); } //[] Insert where OnInsert throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertThrow = true; expectedExceptionMessage = "OnInsert"; f = new Foo(); try { mycol.Insert(0, f); iCountErrors++; Console.WriteLine("Err_70378sanw Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_7302nna Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_1270jqna OnInsertComplete was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_2707nqnq Expected Empty Collection actual {0} elements", mycol.Count); } //[] Insert where OnInsertComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertCompleteThrow = true; expectedExceptionMessage = "OnInsertComplete"; f = new Foo(); try { mycol.Insert(0, f); iCountErrors++; Console.WriteLine("Err_27087nqlkha Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_270hy1na Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_270978aw Expected Empty Collection actual {0} elements", mycol.Count); } /************** Remove ***************************************************************************************************************/ //[] Vanilla Remove iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Add(f); mycol.Remove(f); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnRemoveCompleteCalled) { iCountErrors++; Console.WriteLine("Err_348awq OnRemoveComplete was never called"); } else if (-1 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_0824answ Item was not removed"); } //[] Remove where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); expectedExceptionMessage = "OnValidate"; f = new Foo(); try { mycol.Add(f); mycol.OnValidateThrow = true; mycol.Remove(f); iCountErrors++; Console.WriteLine("Err_08207hnas Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_87082aspz Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnRemoveCalled) { iCountErrors++; Console.WriteLine("Err_7207snmqla OnRemove was called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_7270pahnz Element was actually removed {0}", mycol.IndexOf(f)); } //[] Remove where OnRemove throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnRemoveThrow = true; expectedExceptionMessage = "OnRemove"; f = new Foo(); try { mycol.Add(f); mycol.Remove(f); iCountErrors++; Console.WriteLine("Err_7708aqyy Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_08281naws Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnRemoveCompleteCalled) { iCountErrors++; Console.WriteLine("Err_10871aklsj OnRemoveComplete was called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_2081aslkjs Element was actually removed {0}", mycol.IndexOf(f)); } //[] Remove where OnRemoveComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnRemoveCompleteThrow = true; expectedExceptionMessage = "OnRemoveComplete"; f = new Foo(); try { mycol.Add(f); mycol.Remove(f); iCountErrors++; Console.WriteLine("Err_10981nlskj Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_20981askjs Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_20909assfd Element was actually removed {0}", mycol.IndexOf(f)); } /******************* Clear ************************************************************************************************/ //[] Vanilla Clear iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Add(f); mycol.Clear(); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnClearCompleteCalled) { iCountErrors++; Console.WriteLine("Err_2136sdf OnClearComplete was never called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_9494aswa Items were not Cleared"); } //[] Clear where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); expectedExceptionMessage = "OnValidate"; f = new Foo(); mycol.Add(f); mycol.OnValidateThrow = true; mycol.Clear(); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnClearCompleteCalled) { iCountErrors++; Console.WriteLine("Err_6549asff OnClearComplete was not called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_4649awajm Items were Cleared"); } //[] Clear where OnClear throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnClearThrow = true; expectedExceptionMessage = "OnClear"; f = new Foo(); try { mycol.Add(f); mycol.Clear(); iCountErrors++; Console.WriteLine("Err_9444sjpjnException was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_78941joaException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnClearCompleteCalled) { iCountErrors++; Console.WriteLine("Err_94944awfuu OnClearComplete was called"); } else if (1 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_6498 Items were not Cleared"); } //[] Clear where OnClearComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnClearCompleteThrow = true; expectedExceptionMessage = "OnClearComplete"; f = new Foo(); try { mycol.Add(f); mycol.Clear(); iCountErrors++; Console.WriteLine("Err_64977awad Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_0877asaw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_1081lkajs Items were not Cleared"); } /**************************** Set ***********************************************************************************************************************/ //[] Vanilla Set iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(1, "1"); newF = new Foo(2, "2"); mycol.Add(f); mycol[0] = newF; if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnSetCompleteCalled) { iCountErrors++; Console.WriteLine("Err_1698asdf OnSetComplete was never called"); } else if (-1 != mycol.IndexOf(f) || 0 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_9494safs Item was not Set"); } //[] Set where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); expectedExceptionMessage = "OnValidate"; f = new Foo(1, "1"); newF = new Foo(2, "2"); try { mycol.Add(f); mycol.OnValidateThrow = true; mycol[0] = newF; iCountErrors++; Console.WriteLine("Err_611awwa Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnSetCalled) { iCountErrors++; Console.WriteLine("Err_94887jio OnSet was called"); } else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", mycol.IndexOf(f)); } //[] Set where OnSet throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnSetThrow = true; expectedExceptionMessage = "OnSet"; f = new Foo(1, "1"); newF = new Foo(2, "2"); try { mycol.Add(f); mycol[0] = newF; iCountErrors++; Console.WriteLine("Err_61518haiosd Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnSetCompleteCalled) { iCountErrors++; Console.WriteLine("Err_6548dasfs OnSetComplete was called"); } else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_2797sah Element was actually Set {0}", mycol.IndexOf(f)); } //[] Set where OnSetComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnSetCompleteThrow = true; expectedExceptionMessage = "OnSetComplete"; f = new Foo(1, "1"); newF = new Foo(2, "2"); try { mycol.Add(f); mycol[0] = newF; iCountErrors++; Console.WriteLine("Err_56498hkashException was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_64198ahihos Element was actually Set {0}", mycol.IndexOf(f)); } /////////////////////////////////////////////////////////////////// /////////////////////////// END TESTS ///////////////////////////// } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); } //// Finish Diagnostics if (iCountErrors == 0) { return true; } else { return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; MyCollectionBase mycol1; MyCollectionBase mycol2; Foo f1; Foo[] arrF1; IEnumerator enu1; Int32 iCount; Object obj1; try { do { iCountTestcases++; iCountTestcases++; strLoc = "Loc_001oo"; mycol1 = new MyCollectionBase(); if(mycol1.Count!=0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for(int i=0; i<100; i++) mycol1.Add(new Foo()); if(mycol1.Count!=100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } iCountTestcases++; strLoc = "Loc_002oo"; mycol1 = new MyCollectionBase(); for(int i=0; i<100; i++) mycol1.Add(new Foo(i, i.ToString())); arrF1 = new Foo[100]; mycol1.CopyTo(arrF1, 0); for(int i=0; i<100; i++) { if((arrF1[i].IValue != i) || (arrF1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); for(int i=0; i<100; i++) mycol1.Add(new Foo(i, i.ToString())); arrF1 = new Foo[100]; try { mycol1.CopyTo(arrF1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch(ArgumentException) { } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrF1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch(ArgumentException) { } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } iCountTestcases++; arrF1 = new Foo[200]; mycol1.CopyTo(arrF1, 100); for(int i=0; i<100; i++) { if((arrF1[100+i].IValue != i) || (arrF1[100+i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } iCountTestcases++; mycol1 = new MyCollectionBase(); for(int i=0; i<100; i++) mycol1.Add(new Foo(i, i.ToString())); enu1 = mycol1.GetEnumerator(); try { f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount=0; while( enu1.MoveNext() ) { f1 = (Foo)enu1.Current; if((f1.IValue != iCount) || (f1.SValue!= iCount.ToString()) ) { iCountErrors++; Console.WriteLine("Err_87543! does not match, " + f1.IValue); } iCount++; } if(iCount!=100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } try { f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_438fsfd! Exception not thrown"); } catch(InvalidOperationException) { } catch(Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } strLoc = "Loc_004oo"; iCountTestcases++; mycol1 = new MyCollectionBase(); if(((ICollection)mycol1).IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + ((ICollection)mycol1).IsSynchronized); } iCountTestcases++; strLoc = "Loc_005oo"; mycol1 = new MyCollectionBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if(obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyCollectionBase(); for(int i=0; i<100; i++) mycol1.Add(new Foo(i, i.ToString())); for(int i=0; i<100; i++) { if((mycol1[i].IValue != i) || (mycol1[i].SValue!= i.ToString()) ) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } if((mycol1.IndexOf(new Foo(i, i.ToString()))!= i) ) { iCountErrors++; Console.WriteLine("Err_205sg_" + i + "! Expected value not returned"); } } for(int i=99; i>=0; i--) { mycol1.RemoveAt(0); if((mycol1.Count != (i)) ) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } if(i>=50) { if((!mycol1.Contains(new Foo(i, i.ToString()))) ) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } else { if((mycol1.Contains(new Foo(i, i.ToString()))) ) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyCollectionBase(); if(((IList)mycol1).IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + ((IList)mycol1).IsFixedSize); } if(((IList)mycol1).IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + ((IList)mycol1).IsReadOnly); } for(int i=0; i<100; i++) { mycol1.Insert(i, new Foo(i, i.ToString())); if(!(mycol1.Contains(new Foo(i, i.ToString()))) ) { iCountErrors++; Console.WriteLine("Err_753sg_" + i + "! Expected value not returned"); } } for(int i=0; i<100; i++) { mycol1.Remove(new Foo(i, i.ToString())); if((mycol1.Contains(new Foo(i, i.ToString()))) ) { iCountErrors++; Console.WriteLine("Err_2085sg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); for(int i=0; i<100; i++) mycol1.Add(new Foo(i, i.ToString())); mycol1.Clear(); if(mycol1.Count!=0) { iCountErrors++; Console.WriteLine("Err_847tfgdg! Expected value not returned, " + mycol1.Count); } mycol1 = new MyCollectionBase(); for(int i=0; i<100; i++) mycol1.Add(new Foo(i, i.ToString())); for(int i=0, j=100; i<100; i++, j--) mycol1[i] = new Foo(j, j.ToString()); for(int i=0, j=100; i<100; i++, j--) { if((mycol1.IndexOf(new Foo(j, j.ToString()))!= i) ) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); mycol1.Add(new Foo()); } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; MyCollectionBase mycol1; MyCollectionBase mycol2; Foo f1; Foo[] arrF1; IEnumerator enu1; Int32 iCount; Object obj1; try { do { iCountTestcases++; iCountTestcases++; strLoc = "Loc_001oo"; mycol1 = new MyCollectionBase(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for (int i = 0; i < 100; i++) { mycol1.Add(new Foo()); } if (mycol1.Count != 100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } iCountTestcases++; strLoc = "Loc_002oo"; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } arrF1 = new Foo[100]; mycol1.CopyTo(arrF1, 0); for (int i = 0; i < 100; i++) { if ((arrF1[i].IValue != i) || (arrF1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } arrF1 = new Foo[100]; try { mycol1.CopyTo(arrF1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrF1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } iCountTestcases++; arrF1 = new Foo[200]; mycol1.CopyTo(arrF1, 100); for (int i = 0; i < 100; i++) { if ((arrF1[100 + i].IValue != i) || (arrF1[100 + i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } enu1 = mycol1.GetEnumerator(); try { f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; while (enu1.MoveNext()) { f1 = (Foo)enu1.Current; if ((f1.IValue != iCount) || (f1.SValue != iCount.ToString())) { iCountErrors++; Console.WriteLine("Err_87543! does not match, " + f1.IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } try { f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_438fsfd! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } strLoc = "Loc_004oo"; iCountTestcases++; mycol1 = new MyCollectionBase(); if (((ICollection)mycol1).IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + ((ICollection)mycol1).IsSynchronized); } iCountTestcases++; strLoc = "Loc_005oo"; mycol1 = new MyCollectionBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if (obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } for (int i = 0; i < 100; i++) { if ((mycol1[i].IValue != i) || (mycol1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } if ((mycol1.IndexOf(new Foo(i, i.ToString())) != i)) { iCountErrors++; Console.WriteLine("Err_205sg_" + i + "! Expected value not returned"); } } for (int i = 99; i >= 0; i--) { mycol1.RemoveAt(0); if ((mycol1.Count != (i))) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } if (i >= 50) { if ((!mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } else { if ((mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } } strLoc = "Loc_006oo"; iCountTestcases++; mycol1 = new MyCollectionBase(); if (((IList)mycol1).IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + ((IList)mycol1).IsFixedSize); } if (((IList)mycol1).IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + ((IList)mycol1).IsReadOnly); } for (int i = 0; i < 100; i++) { mycol1.Insert(i, new Foo(i, i.ToString())); if (!(mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_753sg_" + i + "! Expected value not returned"); } } for (int i = 0; i < 100; i++) { mycol1.Remove(new Foo(i, i.ToString())); if ((mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_2085sg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } mycol1.Clear(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_847tfgdg! Expected value not returned, " + mycol1.Count); } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } for (int i = 0, j = 100; i < 100; i++, j--) { mycol1[i] = new Foo(j, j.ToString()); } for (int i = 0, j = 100; i < 100; i++, j--) { if ((mycol1.IndexOf(new Foo(j, j.ToString())) != i)) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); mycol1.Add(new Foo()); } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
/// <summary> /// Clears out all the items in the stack /// </summary> public void Clear() { _theStackList.Clear(); }
public bool runTest() { //////////// Global Variables used for all tests int iCountErrors = 0; int iCountTestcases = 0; MyCollectionBase mycol1; MyCollectionBase mycol2; Foo f1; Foo[] arrF1; IEnumerator enu1; Int32 iCount; Object obj1; try { do { ///////////////////////// START TESTS //////////////////////////// /////////////////////////////////////////////////////////////////// //[]CollectionBase implements IList (which means both ICollection and IEnumerator as well :-() //To test this class, we will implement our own strongly typed CollectionBase and call its methods iCountTestcases++; //[] Count property iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for (int i = 0; i < 100; i++) { mycol1.Add(new Foo()); } if (mycol1.Count != 100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } //[]this[int index] argument checking iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo()); } try { Object o = mycol1[-1]; iCountErrors++; Console.WriteLine("Err_0823afds Expected CollectionBase[-1] to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } try { Object o = mycol1[100]; iCountErrors++; Console.WriteLine("Err_8094sadd Expected CollectionBase[100] with only 100 elements to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } try { mycol1[-1] = new Foo(); iCountErrors++; Console.WriteLine("Err_2773apnn Expected CollectionBase[-1] to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } try { mycol1[100] = new Foo(); iCountErrors++; Console.WriteLine("Err_3402hnxz Expected CollectionBase[100] with only 100 elements to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } //[]CopyTo iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } arrF1 = new Foo[100]; mycol1.CopyTo(arrF1, 0); for (int i = 0; i < 100; i++) { if ((arrF1[i].IValue != i) || (arrF1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } //Argument checking mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } arrF1 = new Foo[100]; try { mycol1.CopyTo(arrF1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrF1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } iCountTestcases++; arrF1 = new Foo[200]; mycol1.CopyTo(arrF1, 100); for (int i = 0; i < 100; i++) { if ((arrF1[100 + i].IValue != i) || (arrF1[100 + i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } //[]GetEnumerator iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } enu1 = mycol1.GetEnumerator(); //Calling current should throw here try { //Calling current should throw here f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; while (enu1.MoveNext()) { f1 = (Foo)enu1.Current; if ((f1.IValue != iCount) || (f1.SValue != iCount.ToString())) { iCountErrors++; Console.WriteLine("Err_87543! does not match, " + f1.IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } //Calling current should throw here try { //Calling current should throw here f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_438fsfd! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //[]IsSynchronized iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + ((ICollection)mycol1).IsSynchronized); } //[]IsReadOnly iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_2508aszp! Expected value not returned, " + mycol1.IsReadOnly); } //[]IsFixedSize iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_0803puj! Expected value not returned, " + mycol1.IsFixedSize); } //[]SyncRoot - SyncRoot should be the reference to the underlying collection, not to MyCollectionBase iCountTestcases++; mycol1 = new MyCollectionBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if (obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } //End of ICollection and IEnumerator methods //Now to IList methods //[]Add, this, Contains, RemoveAt, IndexOf iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } for (int i = 0; i < 100; i++) { if ((mycol1[i].IValue != i) || (mycol1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } if ((mycol1.IndexOf(new Foo(i, i.ToString())) != i)) { iCountErrors++; Console.WriteLine("Err_205sg_" + i + "! Expected value not returned"); } } for (int i = 99; i >= 0; i--) { mycol1.RemoveAt(0); if ((mycol1.Count != (i))) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } //WE have removed the first half by the time the counter comes there if (i >= 50) { if ((!mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } else { if ((mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } } //[]Rest of the IList methods: this-set, Remove, Insert, Clear, IsFixedSize, IsReadOnly iCountTestcases++; mycol1 = new MyCollectionBase(); if (((IList)mycol1).IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + ((IList)mycol1).IsFixedSize); } if (((IList)mycol1).IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + ((IList)mycol1).IsReadOnly); } for (int i = 0; i < 100; i++) { mycol1.Insert(i, new Foo(i, i.ToString())); if (!(mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_753sg_" + i + "! Expected value not returned"); } } for (int i = 0; i < 100; i++) { mycol1.Remove(new Foo(i, i.ToString())); if ((mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_2085sg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } mycol1.Clear(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_847tfgdg! Expected value not returned, " + mycol1.Count); } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) { mycol1.Add(new Foo(i, i.ToString())); } for (int i = 0, j = 100; i < 100; i++, j--) { mycol1[i] = new Foo(j, j.ToString()); } for (int i = 0, j = 100; i < 100; i++, j--) { if ((mycol1.IndexOf(new Foo(j, j.ToString())) != i)) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); mycol1.Add(new Foo()); /////////////////////////////////////////////////////////////////// /////////////////////////// END TESTS ///////////////////////////// } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); } //// Finish Diagnostics if (iCountErrors == 0) { return(true); } else { return(false); } }
public bool runTest() { //////////// Global Variables used for all tests int iCountErrors = 0; int iCountTestcases = 0; MyCollectionBase mycol; Foo f, newF; string expectedExceptionMessage; try { do { ///////////////////////// START TESTS //////////////////////////// /////////////////////////////////////////////////////////////////// //[] Vanilla Add iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Add(f); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_4072ayps OnInsertComplete was never called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_0181salh Item was added"); } //[] Add where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnValidateThrow = true; expectedExceptionMessage = "OnValidate"; f = new Foo(); try { mycol.Add(f); iCountErrors++; Console.WriteLine("Err_1570pyqa Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_2708apsa Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCalled) { iCountErrors++; Console.WriteLine("Err_56707awwaps OnInsert was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_2708apsa Expected Empty Collection actual {0} elements", mycol.Count); } //[] Add where OnInsert throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertThrow = true; expectedExceptionMessage = "OnInsert"; f = new Foo(); try { mycol.Add(f); iCountErrors++; Console.WriteLine("Err_35208asdo Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_30437sfdah Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_370asjhs OnInsertComplete was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_3y07aza Expected Empty Collection actual {0} elements", mycol.Count); } //[] Add where OnInsertComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertCompleteThrow = true; expectedExceptionMessage = "OnInsertComplete"; f = new Foo(); try { mycol.Add(f); iCountErrors++; Console.WriteLine("Err_2548ashz Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_2708alkw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_3680ahksd Expected Empty Collection actual {0} elements", mycol.Count); } /******* Insert ******************************************************************************************/ //[] Vanilla Insert iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Insert(0, f); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_270ash OnInsertComplete was never called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_208anla Item was added"); } //[] Insert where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnValidateThrow = true; expectedExceptionMessage = "OnValidate"; f = new Foo(); try { mycol.Insert(0, f); iCountErrors++; Console.WriteLine("Err_270ahsw Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_48708awhoh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCalled) { iCountErrors++; Console.WriteLine("Err_3708anw OnInsert was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_707j2awn Expected Empty Collection actual {0} elements", mycol.Count); } //[] Insert where OnInsert throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertThrow = true; expectedExceptionMessage = "OnInsert"; f = new Foo(); try { mycol.Insert(0, f); iCountErrors++; Console.WriteLine("Err_70378sanw Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_7302nna Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnInsertCompleteCalled) { iCountErrors++; Console.WriteLine("Err_1270jqna OnInsertComplete was called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_2707nqnq Expected Empty Collection actual {0} elements", mycol.Count); } //[] Insert where OnInsertComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnInsertCompleteThrow = true; expectedExceptionMessage = "OnInsertComplete"; f = new Foo(); try { mycol.Insert(0, f); iCountErrors++; Console.WriteLine("Err_27087nqlkha Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_270hy1na Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_270978aw Expected Empty Collection actual {0} elements", mycol.Count); } /************** Remove ***************************************************************************************************************/ //[] Vanilla Remove iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Add(f); mycol.Remove(f); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnRemoveCompleteCalled) { iCountErrors++; Console.WriteLine("Err_348awq OnRemoveComplete was never called"); } else if (-1 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_0824answ Item was not removed"); } //[] Remove where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); expectedExceptionMessage = "OnValidate"; f = new Foo(); try { mycol.Add(f); mycol.OnValidateThrow = true; mycol.Remove(f); iCountErrors++; Console.WriteLine("Err_08207hnas Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_87082aspz Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnRemoveCalled) { iCountErrors++; Console.WriteLine("Err_7207snmqla OnRemove was called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_7270pahnz Element was actually removed {0}", mycol.IndexOf(f)); } //[] Remove where OnRemove throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnRemoveThrow = true; expectedExceptionMessage = "OnRemove"; f = new Foo(); try { mycol.Add(f); mycol.Remove(f); iCountErrors++; Console.WriteLine("Err_7708aqyy Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_08281naws Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnRemoveCompleteCalled) { iCountErrors++; Console.WriteLine("Err_10871aklsj OnRemoveComplete was called"); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_2081aslkjs Element was actually removed {0}", mycol.IndexOf(f)); } //[] Remove where OnRemoveComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnRemoveCompleteThrow = true; expectedExceptionMessage = "OnRemoveComplete"; f = new Foo(); try { mycol.Add(f); mycol.Remove(f); iCountErrors++; Console.WriteLine("Err_10981nlskj Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_20981askjs Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.IndexOf(f)) { iCountErrors++; Console.WriteLine("Err_20909assfd Element was actually removed {0}", mycol.IndexOf(f)); } /******************* Clear ************************************************************************************************/ //[] Vanilla Clear iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(); mycol.Add(f); mycol.Clear(); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnClearCompleteCalled) { iCountErrors++; Console.WriteLine("Err_2136sdf OnClearComplete was never called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_9494aswa Items were not Cleared"); } //[] Clear where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); expectedExceptionMessage = "OnValidate"; f = new Foo(); mycol.Add(f); mycol.OnValidateThrow = true; mycol.Clear(); if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnClearCompleteCalled) { iCountErrors++; Console.WriteLine("Err_6549asff OnClearComplete was not called"); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_4649awajm Items were Cleared"); } //[] Clear where OnClear throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnClearThrow = true; expectedExceptionMessage = "OnClear"; f = new Foo(); try { mycol.Add(f); mycol.Clear(); iCountErrors++; Console.WriteLine("Err_9444sjpjnException was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_78941joaException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnClearCompleteCalled) { iCountErrors++; Console.WriteLine("Err_94944awfuu OnClearComplete was called"); } else if (1 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_6498 Items were not Cleared"); } //[] Clear where OnClearComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnClearCompleteThrow = true; expectedExceptionMessage = "OnClearComplete"; f = new Foo(); try { mycol.Add(f); mycol.Clear(); iCountErrors++; Console.WriteLine("Err_64977awad Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_0877asaw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.Count) { iCountErrors++; Console.WriteLine("Err_1081lkajs Items were not Cleared"); } /**************************** Set ***********************************************************************************************************************/ //[] Vanilla Set iCountTestcases++; mycol = new MyCollectionBase(); f = new Foo(1, "1"); newF = new Foo(2, "2"); mycol.Add(f); mycol[0] = newF; if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (!mycol.OnSetCompleteCalled) { iCountErrors++; Console.WriteLine("Err_1698asdf OnSetComplete was never called"); } else if (-1 != mycol.IndexOf(f) || 0 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_9494safs Item was not Set"); } //[] Set where Validate throws iCountTestcases++; mycol = new MyCollectionBase(); expectedExceptionMessage = "OnValidate"; f = new Foo(1, "1"); newF = new Foo(2, "2"); try { mycol.Add(f); mycol.OnValidateThrow = true; mycol[0] = newF; iCountErrors++; Console.WriteLine("Err_611awwa Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnSetCalled) { iCountErrors++; Console.WriteLine("Err_94887jio OnSet was called"); } else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", mycol.IndexOf(f)); } //[] Set where OnSet throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnSetThrow = true; expectedExceptionMessage = "OnSet"; f = new Foo(1, "1"); newF = new Foo(2, "2"); try { mycol.Add(f); mycol[0] = newF; iCountErrors++; Console.WriteLine("Err_61518haiosd Exception was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (mycol.OnSetCompleteCalled) { iCountErrors++; Console.WriteLine("Err_6548dasfs OnSetComplete was called"); } else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_2797sah Element was actually Set {0}", mycol.IndexOf(f)); } //[] Set where OnSetComplete throws iCountTestcases++; mycol = new MyCollectionBase(); mycol.OnSetCompleteThrow = true; expectedExceptionMessage = "OnSetComplete"; f = new Foo(1, "1"); newF = new Foo(2, "2"); try { mycol.Add(f); mycol[0] = newF; iCountErrors++; Console.WriteLine("Err_56498hkashException was not thrown"); } catch (Exception e) { if (expectedExceptionMessage != e.Message) { iCountErrors++; Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message); } } if (mycol.IsError) { iCountErrors++; Console.WriteLine(mycol.ErrorMsg); } else if (0 != mycol.IndexOf(f) || -1 != mycol.IndexOf(newF)) { iCountErrors++; Console.WriteLine("Err_64198ahihos Element was actually Set {0}", mycol.IndexOf(f)); } /////////////////////////////////////////////////////////////////// /////////////////////////// END TESTS ///////////////////////////// } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); } //// Finish Diagnostics if (iCountErrors == 0) { return(true); } else { return(false); } }
public bool runTest() { //////////// Global Variables used for all tests int iCountErrors = 0; int iCountTestcases = 0; MyCollectionBase mycol1; MyCollectionBase mycol2; Foo f1; Foo[] arrF1; IEnumerator enu1; Int32 iCount; Object obj1; try { do { ///////////////////////// START TESTS //////////////////////////// /////////////////////////////////////////////////////////////////// //[]CollectionBase implements IList (which means both ICollection and IEnumerator as well :-() //To test this class, we will implement our own strongly typed CollectionBase and call its methods iCountTestcases++; //[] Count property iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count); } for (int i = 0; i < 100; i++) mycol1.Add(new Foo()); if (mycol1.Count != 100) { iCountErrors++; Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count); } //[]this[int index] argument checking iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo()); try { Object o = mycol1[-1]; iCountErrors++; Console.WriteLine("Err_0823afds Expected CollectionBase[-1] to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } try { Object o = mycol1[100]; iCountErrors++; Console.WriteLine("Err_8094sadd Expected CollectionBase[100] with only 100 elements to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } try { mycol1[-1] = new Foo(); iCountErrors++; Console.WriteLine("Err_2773apnn Expected CollectionBase[-1] to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } try { mycol1[100] = new Foo(); iCountErrors++; Console.WriteLine("Err_3402hnxz Expected CollectionBase[100] with only 100 elements to throw ArgumentOutOfRangeException"); } catch (ArgumentOutOfRangeException) { } //[]CopyTo iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo(i, i.ToString())); arrF1 = new Foo[100]; mycol1.CopyTo(arrF1, 0); for (int i = 0; i < 100; i++) { if ((arrF1[i].IValue != i) || (arrF1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } //Argument checking mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo(i, i.ToString())); arrF1 = new Foo[100]; try { mycol1.CopyTo(arrF1, 50); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } try { mycol1.CopyTo(arrF1, -1); iCountErrors++; Console.WriteLine("Err_2075dfgv! Exception not thrown"); } catch (ArgumentException) { } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name); } iCountTestcases++; arrF1 = new Foo[200]; mycol1.CopyTo(arrF1, 100); for (int i = 0; i < 100; i++) { if ((arrF1[100 + i].IValue != i) || (arrF1[100 + i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned"); } } //[]GetEnumerator iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo(i, i.ToString())); enu1 = mycol1.GetEnumerator(); //Calling current should throw here try { //Calling current should throw here f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_87543! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } iCount = 0; while (enu1.MoveNext()) { f1 = (Foo)enu1.Current; if ((f1.IValue != iCount) || (f1.SValue != iCount.ToString())) { iCountErrors++; Console.WriteLine("Err_87543! does not match, " + f1.IValue); } iCount++; } if (iCount != 100) { iCountErrors++; Console.WriteLine("Err_87543! doesnot match"); } //Calling current should throw here try { //Calling current should throw here f1 = (Foo)enu1.Current; iCountErrors++; Console.WriteLine("Err_438fsfd! Exception not thrown"); } catch (InvalidOperationException) { } catch (Exception ex) { Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name); } //[]IsSynchronized iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.IsSynchronized) { iCountErrors++; Console.WriteLine("Err_275eg! Expected value not returned, " + ((ICollection)mycol1).IsSynchronized); } //[]IsReadOnly iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.IsReadOnly) { iCountErrors++; Console.WriteLine("Err_2508aszp! Expected value not returned, " + mycol1.IsReadOnly); } //[]IsFixedSize iCountTestcases++; mycol1 = new MyCollectionBase(); if (mycol1.IsFixedSize) { iCountErrors++; Console.WriteLine("Err_0803puj! Expected value not returned, " + mycol1.IsFixedSize); } //[]SyncRoot - SyncRoot should be the reference to the underlying collection, not to MyCollectionBase iCountTestcases++; mycol1 = new MyCollectionBase(); obj1 = mycol1.SyncRoot; mycol2 = mycol1; if (obj1 != mycol2.SyncRoot) { iCountErrors++; Console.WriteLine("Err_9745sg! Expected value not returned"); } //End of ICollection and IEnumerator methods //Now to IList methods //[]Add, this, Contains, RemoveAt, IndexOf iCountTestcases++; mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo(i, i.ToString())); for (int i = 0; i < 100; i++) { if ((mycol1[i].IValue != i) || (mycol1[i].SValue != i.ToString())) { iCountErrors++; Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned"); } if ((mycol1.IndexOf(new Foo(i, i.ToString())) != i)) { iCountErrors++; Console.WriteLine("Err_205sg_" + i + "! Expected value not returned"); } } for (int i = 99; i >= 0; i--) { mycol1.RemoveAt(0); if ((mycol1.Count != (i))) { iCountErrors++; Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned"); } //WE have removed the first half by the time the counter comes there if (i >= 50) { if ((!mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } else { if ((mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_975wg_" + i + "! Expected value not returned"); } } } //[]Rest of the IList methods: this-set, Remove, Insert, Clear, IsFixedSize, IsReadOnly iCountTestcases++; mycol1 = new MyCollectionBase(); if (((IList)mycol1).IsFixedSize) { iCountErrors++; Console.WriteLine("Err_9753sfg! Expected value not returned, " + ((IList)mycol1).IsFixedSize); } if (((IList)mycol1).IsReadOnly) { iCountErrors++; Console.WriteLine("Err_834sg! Expected value not returned, " + ((IList)mycol1).IsReadOnly); } for (int i = 0; i < 100; i++) { mycol1.Insert(i, new Foo(i, i.ToString())); if (!(mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_753sg_" + i + "! Expected value not returned"); } } for (int i = 0; i < 100; i++) { mycol1.Remove(new Foo(i, i.ToString())); if ((mycol1.Contains(new Foo(i, i.ToString())))) { iCountErrors++; Console.WriteLine("Err_2085sg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo(i, i.ToString())); mycol1.Clear(); if (mycol1.Count != 0) { iCountErrors++; Console.WriteLine("Err_847tfgdg! Expected value not returned, " + mycol1.Count); } mycol1 = new MyCollectionBase(); for (int i = 0; i < 100; i++) mycol1.Add(new Foo(i, i.ToString())); for (int i = 0, j = 100; i < 100; i++, j--) mycol1[i] = new Foo(j, j.ToString()); for (int i = 0, j = 100; i < 100; i++, j--) { if ((mycol1.IndexOf(new Foo(j, j.ToString())) != i)) { iCountErrors++; Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned"); } } mycol1 = new MyCollectionBase(); mycol1.Add(new Foo()); /////////////////////////////////////////////////////////////////// /////////////////////////// END TESTS ///////////////////////////// } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString()); } //// Finish Diagnostics if (iCountErrors == 0) { return true; } else { return false; } }