public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); Console.WriteLine(); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; ConstructorInfo[] cons = null; Object[] arrVntInitialValues; Int32 iValue; Type tpName = null; MemberInfo[] members = null; Object[] arrVntData = null; Object objValue = null; baloney bal1 = null; Int16 shtValue; bool fCreatedSuccesfully; StringBuilder sbldr1 = null; Int32 iCheck; Module mdClassLib = null; Type[] arrTpClassLib = null; Type[] arrTpPopularValutTypes = {typeof(Int16), typeof(Int32), typeof(Int64), typeof(UInt16), typeof(UInt32), typeof(UInt64), typeof(SByte), typeof(Byte), typeof(Double), typeof(Single) }; try { do { strLoc = "Loc_435cd"; iValue = 10; tpName = iValue.GetType(); members = FormatterServices.GetSerializableMembers(tpName); arrVntData = FormatterServices.GetObjectData(iValue, members); iCountTestcases++; if(arrVntData.Length!=1) { iCountErrors++; Console.WriteLine("Err_743cd! Int32 has more members than before, " + arrVntData.Length.ToString()); } iCountTestcases++; if((int)arrVntData[0] != iValue) { iCountErrors++; Console.WriteLine("Err_4692fd! wrong value returned, " + arrVntData[0].ToString()); } for(int i=0; i<arrTpPopularValutTypes.Length;i++) { strLoc = "Loc_0467cvd_" + i.ToString(); arrVntInitialValues = new Object[1]; arrVntInitialValues[0] = (i+10).ToString(); objValue = arrTpPopularValutTypes[i].InvokeMember("Parse", BindingFlags.InvokeMethod, null, null, arrVntInitialValues); members = FormatterServices.GetSerializableMembers(arrTpPopularValutTypes[i]); arrVntData = FormatterServices.GetObjectData(objValue, members); iCountTestcases++; if(arrVntData.Length!=1) { iCountErrors++; Console.WriteLine("Err_863xw! " + arrTpPopularValutTypes[i].Name + " has more members than before, " + arrVntData.Length.ToString()); } iCheck = ((IConvertible)arrVntData[0]).ToInt32(null); iCountTestcases++; if(iCheck != (i+10)) { iCountErrors++; Console.WriteLine("Err_395fd! " + arrTpPopularValutTypes[i].Name + " member value is different than before, " + arrVntData[0].ToString()); } } strLoc = "Loc_02547cs"; mdClassLib = typeof(String).Module; arrTpClassLib = mdClassLib.GetTypes(); for(int i=0; i<arrTpClassLib.Length;i++) { if(!arrTpClassLib[i].IsPublic || !arrTpClassLib[i].IsSerializable) continue; try { members = FormatterServices.GetSerializableMembers(arrTpClassLib[i]); fCreatedSuccesfully = false; try { cons = arrTpClassLib[i].GetConstructors(); for(int j=0; j<cons.Length; j++){ if(cons[j].IsPublic && cons[j].GetParameters().Length==0) { objValue = Activator.CreateInstance(arrTpClassLib[i]); fCreatedSuccesfully=true; break; } } }catch(Exception){fCreatedSuccesfully=false;} if(fCreatedSuccesfully){ iCountTestcases++; arrVntData = FormatterServices.GetObjectData(objValue, members); } } catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_846qm! Unexpected exception thrown for the type, " + arrTpClassLib[i].FullName + ", " + ex.ToString()); } } try { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(null, members); iCountErrors++; Console.WriteLine("Err_935vd! We were expecting this to throw!"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_935fd! Unexpected exception thrown, " + ex.ToString()); } try { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(new Object(), null); iCountErrors++; Console.WriteLine("Err_106vs! We were expecting this to throw!"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_720cxa! Unexpected exception thrown, " + ex.ToString()); } strLoc = "Loc_639vf"; iValue = 20; shtValue = 30; members = FormatterServices.GetSerializableMembers(shtValue.GetType()); try{ arrVntData = FormatterServices.GetObjectData(iValue, members); } catch(ArgumentException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_934cs! Wrong Exception thrown, " + ex.ToString()); } strLoc = "Loc_0256fd"; iValue = 20; sbldr1 = new StringBuilder("Hello"); members = FormatterServices.GetSerializableMembers(sbldr1.GetType()); try { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(iValue, members); iCountErrors++; Console.WriteLine("Err_9357vs! We were expecting this to throw!"); } catch(ArgumentException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_934cs! Wrong Exception thrown, " + ex.ToString()); } bal1 = new baloney(); members = FormatterServices.GetSerializableMembers(bal1.GetType()); arrVntData = FormatterServices.GetObjectData(bal1, members); iCountTestcases++; if(arrVntData.Length!=2) { iCountErrors++; Console.WriteLine("Err_9e5fd! baloney has more members than before, " + arrVntData.Length.ToString()); } iCountTestcases++; if(!arrVntData[0].ToString().Equals("Hello World")) { iCountErrors++; Console.WriteLine("Err_036cs! baloney's member value is different than before, " + arrVntData[0].ToString()); } iCountTestcases++; if((int)arrVntData[1] != 20) { iCountErrors++; Console.WriteLine("Err_302xs! baloney's member value is different than before, " + arrVntData[1].ToString()); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); Console.WriteLine(); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; Int32 iValue = 0; Object objValue = null; MemberInfo[] members = null; Object[] data = null; try { do { members = FormatterServices.GetSerializableMembers(iValue.GetType()); data = new Object[members.Length]; data[0] = 10; objValue = FormatterServices.GetUninitializedObject(iValue.GetType()); iValue = (Int32)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountTestcases++; if(iValue != 10) { iCountErrors++; Console.WriteLine("Err_753dw! Wrong Value returned," + iValue.ToString()); } data[0] = "Hello World"; try { iCountTestcases++; iValue = (Int32)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_045fcd! Excepion not thrown"); } catch(ArgumentException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_369sq! Wrong excepion thrown, " + ex.ToString()); } baloney bal = new baloney(); members = FormatterServices.GetSerializableMembers(bal.GetType()); data = new Object[members.Length]; for(int i=0; i<members.Length; i++) { if(members[i].Name.Equals("str_Humpty")) { data[i] = "Anything"; } else if(members[i].Name.Equals("i_spy")) { data[i] = 3; } else { Console.WriteLine("i scream"); } } objValue = FormatterServices.GetUninitializedObject(bal.GetType()); baloney bal1 = (baloney)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountTestcases++; if(!bal1.str_Humpty.Equals("Anything")) { iCountErrors++; Console.WriteLine("Err_9564fd! Wrong Value returned," + bal1.str_Humpty); } iCountTestcases++; if(bal1.i_spy!=3) { iCountErrors++; Console.WriteLine("Err_863cd! Wrong Value returned," + bal1.i_spy.ToString()); } try { iCountTestcases++; FormatterServices.PopulateObjectMembers(null, members, data); iCountErrors++; Console.WriteLine("Err_058fd! Excepion not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_105ds! Wrong excepion thrown, " + ex.ToString()); } try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, null, data); iCountErrors++; Console.WriteLine("Err_9662dsd! Excepion not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_937sd! Wrong excepion thrown, " + ex.ToString()); } try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, members, null); iCountErrors++; Console.WriteLine("Err_1057ds! Excepion not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_0572ds! Wrong excepion thrown, " + ex.ToString()); } members = FormatterServices.GetSerializableMembers(iValue.GetType()); data = new Object[3]; data[0] = 10; objValue = FormatterServices.GetUninitializedObject(iValue.GetType()); try { iCountTestcases++; iValue = (Int32)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_054xs! Excepion not thrown"); } catch(ArgumentException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_1067fs! Wrong excepion thrown, " + ex.ToString()); } members = FormatterServices.GetSerializableMembers(iValue.GetType()); members[0] = null; data = new Object[1]; data[0] = 10; objValue = FormatterServices.GetUninitializedObject(iValue.GetType()); try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_935cd! Excepion not thrown"); } catch(ArgumentNullException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_105xs! Wrong excepion thrown, " + ex.ToString()); } members = typeof(Guid).GetConstructors(); data = new Object[members.Length]; for(int i=0; i< data.Length; i++){ data[i] = i + 10; } objValue = FormatterServices.GetUninitializedObject(typeof(Guid)); try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_046fcsd! Excepion not thrown"); } catch(SerializationException){} catch(Exception ex) { iCountErrors++; Console.WriteLine("Err_9453cdf! Wrong excepion thrown, " + ex.ToString()); } } while (false); } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.StackTrace); } if ( iCountErrors == 0 ) { Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString()); return true; } else { Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); Console.WriteLine(); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; Int32 iValue = 0; Object objValue = null; MemberInfo[] members = null; Object[] data = null; try { do { members = FormatterServices.GetSerializableMembers(iValue.GetType()); data = new Object[members.Length]; data[0] = 10; objValue = FormatterServices.GetUninitializedObject(iValue.GetType()); iValue = (Int32)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountTestcases++; if (iValue != 10) { iCountErrors++; Console.WriteLine("Err_753dw! Wrong Value returned," + iValue.ToString()); } data[0] = "Hello World"; try { iCountTestcases++; iValue = (Int32)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_045fcd! Excepion not thrown"); } catch (ArgumentException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_369sq! Wrong excepion thrown, " + ex.ToString()); } baloney bal = new baloney(); members = FormatterServices.GetSerializableMembers(bal.GetType()); data = new Object[members.Length]; for (int i = 0; i < members.Length; i++) { if (members[i].Name.Equals("str_Humpty")) { data[i] = "Anything"; } else if (members[i].Name.Equals("i_spy")) { data[i] = 3; } else { Console.WriteLine("i scream"); } } objValue = FormatterServices.GetUninitializedObject(bal.GetType()); baloney bal1 = (baloney)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountTestcases++; if (!bal1.str_Humpty.Equals("Anything")) { iCountErrors++; Console.WriteLine("Err_9564fd! Wrong Value returned," + bal1.str_Humpty); } iCountTestcases++; if (bal1.i_spy != 3) { iCountErrors++; Console.WriteLine("Err_863cd! Wrong Value returned," + bal1.i_spy.ToString()); } try { iCountTestcases++; FormatterServices.PopulateObjectMembers(null, members, data); iCountErrors++; Console.WriteLine("Err_058fd! Excepion not thrown"); } catch (ArgumentNullException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_105ds! Wrong excepion thrown, " + ex.ToString()); } try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, null, data); iCountErrors++; Console.WriteLine("Err_9662dsd! Excepion not thrown"); } catch (ArgumentNullException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_937sd! Wrong excepion thrown, " + ex.ToString()); } try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, members, null); iCountErrors++; Console.WriteLine("Err_1057ds! Excepion not thrown"); } catch (ArgumentNullException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_0572ds! Wrong excepion thrown, " + ex.ToString()); } members = FormatterServices.GetSerializableMembers(iValue.GetType()); data = new Object[3]; data[0] = 10; objValue = FormatterServices.GetUninitializedObject(iValue.GetType()); try { iCountTestcases++; iValue = (Int32)FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_054xs! Excepion not thrown"); } catch (ArgumentException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_1067fs! Wrong excepion thrown, " + ex.ToString()); } members = FormatterServices.GetSerializableMembers(iValue.GetType()); members[0] = null; data = new Object[1]; data[0] = 10; objValue = FormatterServices.GetUninitializedObject(iValue.GetType()); try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_935cd! Excepion not thrown"); } catch (ArgumentNullException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_105xs! Wrong excepion thrown, " + ex.ToString()); } members = typeof(Guid).GetConstructors(); data = new Object[members.Length]; for (int i = 0; i < data.Length; i++) { data[i] = i + 10; } objValue = FormatterServices.GetUninitializedObject(typeof(Guid)); try { iCountTestcases++; FormatterServices.PopulateObjectMembers(objValue, members, data); iCountErrors++; Console.WriteLine("Err_046fcsd! Excepion not thrown"); } catch (SerializationException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_9453cdf! Wrong excepion thrown, " + ex.ToString()); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==\n" + exc_general.StackTrace); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases.ToString()); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString() + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer); Console.WriteLine(); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; ConstructorInfo[] cons = null; Object[] arrVntInitialValues; Int32 iValue; Type tpName = null; MemberInfo[] members = null; Object[] arrVntData = null; Object objValue = null; baloney bal1 = null; Int16 shtValue; bool fCreatedSuccesfully; StringBuilder sbldr1 = null; Int32 iCheck; Module mdClassLib = null; Type[] arrTpClassLib = null; Type[] arrTpPopularValutTypes = { typeof(Int16), typeof(Int32), typeof(Int64), typeof(UInt16), typeof(UInt32), typeof(UInt64), typeof(SByte), typeof(Byte), typeof(Double), typeof(Single) }; try { do { strLoc = "Loc_435cd"; iValue = 10; tpName = iValue.GetType(); members = FormatterServices.GetSerializableMembers(tpName); arrVntData = FormatterServices.GetObjectData(iValue, members); iCountTestcases++; if (arrVntData.Length != 1) { iCountErrors++; Console.WriteLine("Err_743cd! Int32 has more members than before, " + arrVntData.Length.ToString()); } iCountTestcases++; if ((int)arrVntData[0] != iValue) { iCountErrors++; Console.WriteLine("Err_4692fd! wrong value returned, " + arrVntData[0].ToString()); } for (int i = 0; i < arrTpPopularValutTypes.Length; i++) { strLoc = "Loc_0467cvd_" + i.ToString(); arrVntInitialValues = new Object[1]; arrVntInitialValues[0] = (i + 10).ToString(); objValue = arrTpPopularValutTypes[i].InvokeMember("Parse", BindingFlags.InvokeMethod, null, null, arrVntInitialValues); members = FormatterServices.GetSerializableMembers(arrTpPopularValutTypes[i]); arrVntData = FormatterServices.GetObjectData(objValue, members); iCountTestcases++; if (arrVntData.Length != 1) { iCountErrors++; Console.WriteLine("Err_863xw! " + arrTpPopularValutTypes[i].Name + " has more members than before, " + arrVntData.Length.ToString()); } iCheck = ((IConvertible)arrVntData[0]).ToInt32(null); iCountTestcases++; if (iCheck != (i + 10)) { iCountErrors++; Console.WriteLine("Err_395fd! " + arrTpPopularValutTypes[i].Name + " member value is different than before, " + arrVntData[0].ToString()); } } strLoc = "Loc_02547cs"; mdClassLib = typeof(String).Module; arrTpClassLib = mdClassLib.GetTypes(); for (int i = 0; i < arrTpClassLib.Length; i++) { if (!arrTpClassLib[i].IsPublic || !arrTpClassLib[i].IsSerializable) { continue; } try { members = FormatterServices.GetSerializableMembers(arrTpClassLib[i]); fCreatedSuccesfully = false; try { cons = arrTpClassLib[i].GetConstructors(); for (int j = 0; j < cons.Length; j++) { if (cons[j].IsPublic && cons[j].GetParameters().Length == 0) { objValue = Activator.CreateInstance(arrTpClassLib[i]); fCreatedSuccesfully = true; break; } } }catch (Exception) { fCreatedSuccesfully = false; } if (fCreatedSuccesfully) { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(objValue, members); } } catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_846qm! Unexpected exception thrown for the type, " + arrTpClassLib[i].FullName + ", " + ex.ToString()); } } try { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(null, members); iCountErrors++; Console.WriteLine("Err_935vd! We were expecting this to throw!"); } catch (ArgumentNullException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_935fd! Unexpected exception thrown, " + ex.ToString()); } try { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(new Object(), null); iCountErrors++; Console.WriteLine("Err_106vs! We were expecting this to throw!"); } catch (ArgumentNullException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_720cxa! Unexpected exception thrown, " + ex.ToString()); } strLoc = "Loc_639vf"; iValue = 20; shtValue = 30; members = FormatterServices.GetSerializableMembers(shtValue.GetType()); try{ arrVntData = FormatterServices.GetObjectData(iValue, members); } catch (ArgumentException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_934cs! Wrong Exception thrown, " + ex.ToString()); } strLoc = "Loc_0256fd"; iValue = 20; sbldr1 = new StringBuilder("Hello"); members = FormatterServices.GetSerializableMembers(sbldr1.GetType()); try { iCountTestcases++; arrVntData = FormatterServices.GetObjectData(iValue, members); iCountErrors++; Console.WriteLine("Err_9357vs! We were expecting this to throw!"); } catch (ArgumentException) {} catch (Exception ex) { iCountErrors++; Console.WriteLine("Err_934cs! Wrong Exception thrown, " + ex.ToString()); } bal1 = new baloney(); members = FormatterServices.GetSerializableMembers(bal1.GetType()); arrVntData = FormatterServices.GetObjectData(bal1, members); iCountTestcases++; if (arrVntData.Length != 2) { iCountErrors++; Console.WriteLine("Err_9e5fd! baloney has more members than before, " + arrVntData.Length.ToString()); } iCountTestcases++; if (!arrVntData[0].ToString().Equals("Hello World")) { iCountErrors++; Console.WriteLine("Err_036cs! baloney's member value is different than before, " + arrVntData[0].ToString()); } iCountTestcases++; if ((int)arrVntData[1] != 20) { iCountErrors++; Console.WriteLine("Err_302xs! baloney's member value is different than before, " + arrVntData[1].ToString()); } } while (false); } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy! strLoc==" + strLoc + ", exc_general==\n" + exc_general); } if (iCountErrors == 0) { Console.WriteLine("paSs. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases.ToString()); return(true); } else { Console.WriteLine("FAiL! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors.ToString() + " , BugNums?: " + s_strActiveBugNums); return(false); } }