override public bool TestGetCustomAttributes(ParameterInfo param) { Util.print("\n\n" + this.GetType().ToString() + " - TestGetCustomAttributes() started."); Util.print("For ParamInfo on: " + param.Member.GetType().ToString() + "\n"); string strLoc = "L_000"; Attribute[] attrs = null; try { do { iCountTestcases++; strLoc = "L_001"; if (param == null) { iCountErrors++; Util.printerr("E_75yhg - param == null"); return(false); } iCountTestcases++; strLoc = "L_001.2"; attrs = Attribute.GetCustomAttributes(param, true); if (attrs == null) { iCountErrors++; Util.printerr("E_gfh4 - attrs == null"); return(false); } iCountTestcases++; strLoc = "L_001.3"; if (param.Member is System.Reflection.ConstructorInfo) { if (attrs.Length != (iCountTotalAttrs - 2)) { iCountErrors++; Util.printerr("E_4_fk23 - attrs.Length != iCountTotalAttrs-2"); Util.print("Expected: " + (iCountTotalAttrs - 2) + ";Returned: " + attrs.Length); } } else if (attrs.Length != iCountTotalAttrs) { iCountErrors++; Util.printerr("E_jhd3 - attrs.Length Failed!"); Util.print("Expected: " + iCountTotalAttrs + "; Returned: " + attrs.Length); } iCountTestcases++; strLoc = "L_001.3"; TestAttributes(attrs, param.Member); } while (false); } catch (Exception exc_runTest) { ++iCountErrors; Util.printerr("Err_888un! - Uncaught Exception caught in TestGetCustomAttributes(); strLoc == " + strLoc); Util.printexc(exc_runTest); Util.print(exc_runTest.StackTrace); } if (iCountErrors == 0) { return(true); } else { return(false); } }
public bool RunTest() { print(strPath + strTest + " RunTest() started."); string strLoc = "L_000"; MyClass myclass = new MyClass("myclass"); MyClass2 myclass2 = new MyClass2("myclass2"); ParameterInfo param = null; ParameterInfo param2 = null; Attribute[] attrs = null; Type type = null; Type type2 = null; try { strLoc = "L_200_001"; iCountTestcases++; strLoc = "L_200_002"; type = myclass.GetType(); param = type.GetMethod("MyMethod").GetParameters() [0]; if (param == null) { iCountErrors++; Util.printerr("E_200_75yhg - param == null"); } iCountTestcases++; strLoc = "L_200_002.1"; try { attrs = Attribute.GetCustomAttributes(param, null, true); iCountErrors++; Util.printerr("E_200_oi32 - Should 've thrown ArgNullExc"); } catch (ArgumentException) { } iCountTestcases++; strLoc = "L_200_002.1.2"; try { attrs = Attribute.GetCustomAttributes((ParameterInfo)null, typeof(ClassLib_Attributes.CA_AMfalse_INfalse), true); iCountErrors++; Util.printerr("E_200_oi322 - Should 've thrown ArgNullExc"); } catch (ArgumentException) { } type = myclass.GetType(); iCountTestcases++; strLoc = "L_200_003.4"; param = type.GetConstructor(new Type [] { typeof(String) }).GetParameters() [0]; myclass.TestGetCustomAttributes(param); iCountTestcases++; strLoc = "L_200_003.5"; param = type.GetMethod("MyMethod").GetParameters() [0]; myclass.TestGetCustomAttributes(param); type2 = myclass2.GetType(); iCountTestcases++; strLoc = "L_2_200_003.4"; param2 = type2.GetConstructor(new Type [] { typeof(String) }).GetParameters() [0]; myclass2.TestGetCustomAttributes(param2); iCountTestcases++; strLoc = "L_2_200_003.5"; param2 = type2.GetMethod("MyMethod").GetParameters() [0]; myclass2.TestGetCustomAttributes(param2); } catch (Exception exc_runTest) { ++myclass2.iCountErrors; printerr("Err_888un! - Uncaught Exception caught in runTest(); strLoc == " + strLoc); printexc(exc_runTest); print(exc_runTest.StackTrace); } iCountErrors = myclass.iCountErrors + myclass2.iCountErrors; iCountTestcases = myclass.iCountTestcases + myclass2.iCountTestcases; if (iCountErrors == 0) { return(true); } else { print("Related Bugs: " + strBug); print("FAiL! " + strPath + strTest + " iCountErrors==" + iCountErrors.ToString()); return(false); } }
override public bool TestAttributes(Attribute[] attrs, MemberInfo mem) { string strLoc = "L_000"; String str = null; try { do { if (Util.DEBUG > 0) { Console.WriteLine("Number of attrs {0}", attrs.Length); } for (int i = 0; i < attrs.Length; i++) { iCountTestcases++; strLoc = "L_001.3.2"; str = attrs[i].ToString(); if (Util.DEBUG > 1) { Console.WriteLine("{0} : {1}\n\n", i, str); } iCountTestcases++; strLoc = "L_001.4"; if (attrs[i] is ClassLib_Attributes.CA_AMfalse_INfalse) { ClassLib_Attributes.CA_AMfalse_INfalse attr = (ClassLib_Attributes.CA_AMfalse_INfalse)attrs[i]; if (attr.name.Equals("CA_AMfalse_INfalse2")) { iCountTestcases++; strLoc = "L_001.5"; if (!caAmfInf2.Equals(attr)) { iCountErrors++; Util.printerr("E_8d2p- caAmfInf2.Equals FAiLed!"); } } else { iCountErrors++; Util.printerr("E_iu2h- UnExpected attr.name! - " + attr.name); } } else if (attrs[i] is ClassLib_Attributes.CA_AMfalse_INtrue) { ClassLib_Attributes.CA_AMfalse_INtrue attr = (ClassLib_Attributes.CA_AMfalse_INtrue)attrs[i]; if (attr.name.Equals("CA_AMfalse_INtrue2")) { iCountTestcases++; strLoc = "L_11_001.5"; if (!caAmfInt2.Equals(attr)) { iCountErrors++; Util.printerr("E_11_8d2p- caAmfInt2.Equals FAiLed!"); } } else { iCountErrors++; Util.printerr("E_11_iu2h- UnExpected attr.name! - " + attr.name); } } else if (attrs[i] is ClassLib_Attributes.CA_AMtrue_INtrue) { ClassLib_Attributes.CA_AMtrue_INtrue attr = (ClassLib_Attributes.CA_AMtrue_INtrue)attrs[i]; if (!(mem is System.Reflection.ConstructorInfo)) { if (attr.name.Equals("CA_AMtrue_INtrue")) { iCountTestcases++; strLoc = "L_12_001.5"; if (!caAmtInt.Equals(attr)) { iCountErrors++; Util.printerr("E_12_8d2p5- caAmtInt.Equals FAiLed!"); } } else if (attr.name.Equals("CA_AMtrue_INtrue2")) { iCountTestcases++; strLoc = "L_12_001.6"; if (!caAmtInt2.Equals(attr)) { iCountErrors++; Util.printerr("E_12_8d2p6- caAmtInt2.Equals FAiLed!"); } } else if (attr.name.Equals("CA_AMtrue_INtrue3")) { iCountTestcases++; strLoc = "L_12_001.6.2"; if (!caAmtInt3.Equals(attr)) { iCountErrors++; Util.printerr("E_12_dj2o - caAmtInt3.Equals FAiLed!"); } } else { iCountErrors++; Util.printerr("E_12_8dh2 - UnExpected attr.name! - " + attr.name); } } else if (attr.name.Equals("CA_AMtrue_INtrue3")) { iCountTestcases++; strLoc = "L_12_001.7"; if (!caAmtInt3.Equals(attr)) { iCountErrors++; Util.printerr("E_12_8d2p7- caAmtInt3.Equals FAiLed!"); } } else { iCountErrors++; Util.printerr("E_12_iu2h- UnExpected attr.name! - " + attr.name); } } else if (attrs[i] is ClassLib_Attributes.CA_AMtrue_INfalse) { ClassLib_Attributes.CA_AMtrue_INfalse attr = (ClassLib_Attributes.CA_AMtrue_INfalse)attrs[i]; if (attr.name.Equals("CA_AMtrue_INfalse3")) { iCountTestcases++; strLoc = "L_13_001.5"; if (!caAmtInf3.Equals(attr)) { iCountErrors++; Util.printerr("E_13_8d2p- caAmtInf3.Equals FAiLed!"); } } else { iCountErrors++; Util.printerr("E_13_iu2h- UnExpected attr.name! - " + attr.name); } } else { iCountErrors++; Util.printerr("E_iu2h- UnExpected attr type! - " + attrs[i].GetType().ToString()); } } } while (false); } catch (Exception exc_runTest) { ++iCountErrors; Util.printerr("Err_482un! - Uncaught Exception caught in TestAttributes(); strLoc == " + strLoc); Util.printexc(exc_runTest); Util.print(exc_runTest.StackTrace); } if (iCountErrors == 0) { return(true); } else { return(false); } }