TestGetCustomAttribute_Type() public method

public TestGetCustomAttribute_Type ( MemberInfo mem ) : bool
mem System.Reflection.MemberInfo
return bool
        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.TestGetCustomAttribute_Type(param);
                iCountTestcases++;
                strLoc = "L_200_003.5";
                param  = type.GetMethod("MyMethod").GetParameters() [0];
                myclass.TestGetCustomAttribute_Type(param);
                type2 = myclass2.GetType();
                iCountTestcases++;
                strLoc = "L_2_200_003.4";
                param2 = type2.GetConstructor(new Type [] { typeof(String) }).GetParameters() [0];
                myclass2.TestGetCustomAttribute_Type(param2);
                iCountTestcases++;
                strLoc = "L_2_200_003.5";
                param2 = type2.GetMethod("MyMethod").GetParameters() [0];
                myclass2.TestGetCustomAttribute_Type(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);
            }
        }
 public bool RunTest()
   {
   print (strPath + strTest + "  RunTest() started.");
   string strLoc="L_000";
   MyClass myclass = new MyClass ();
   MyClass2 myclass2 = new MyClass2 ();
   MemberInfo mem = null;
   MemberInfo mem2 = null;
   Attribute attr = null;
   Type type = null;
   Type type2 = null;
   try  
     {
     strLoc="L_200_001";
     iCountTestcases++;
     strLoc="L_200_002";
     type = myclass.GetType ();
     mem = type.GetMethod ("MyMethod");
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_200_75yhg - mem == null");
     }
     iCountTestcases++;
     strLoc="L_200_002.1";
     try {
     attr = Attribute.GetCustomAttribute (mem, null, true);
     iCountErrors++;
     Util.printerr ("E_200_oi32 - Should 've thrown ArgNullExc");
     }
     catch (ArgumentException ) {
     }
     iCountTestcases++;
     strLoc="L_200_002.1.2";
     try {
     attr = Attribute.GetCustomAttribute ((MemberInfo) null, typeof (ClassLib_Attributes.CA_AMfalse_INfalse), true);
     iCountErrors++;
     Util.printerr ("E_200_oi322 - Should 've thrown ArgNullExc");
     }
     catch (ArgumentException ) {
     }
     iCountTestcases++;
     strLoc="L_200_002.5";
     type = myclass.GetType ();
     mem = type;
     myclass.TestGetCustomAttribute_Type (mem);
     iCountTestcases++;
     strLoc="L_200_003.4";
     mem = type.GetConstructor (Type.EmptyTypes);
     myclass.TestGetCustomAttribute_Type (mem);
     iCountTestcases++;
     strLoc="L_200_003.5";
     mem = type.GetMethod ("MyMethod");
     myclass.TestGetCustomAttribute_Type (mem);
     iCountTestcases++;
     strLoc="L_200_004.5";
     mem = type.GetField ("MyField");
     myclass.TestGetCustomAttribute_Type (mem);
     iCountTestcases++;
     strLoc="L_200_005.5";
     mem = type.GetProperty ("MyProp");
     myclass.TestGetCustomAttribute_Type (mem);
     iCountTestcases++;
     strLoc="L_2_200_002.5";
     type2 = myclass2.GetType ();
     mem2 = type2;
     myclass2.TestGetCustomAttribute_Type (mem2);
     iCountTestcases++;
     strLoc="L_2_200_003.4";
     mem2 = type2.GetConstructor (Type.EmptyTypes);
     myclass2.TestGetCustomAttribute_Type (mem2);
     iCountTestcases++;
     strLoc="L_2_200_003.5";
     mem2 = type2.GetMethod ("MyMethod");
     myclass2.TestGetCustomAttribute_Type (mem2);
     iCountTestcases++;
     strLoc="L_2_200_004.5";
     mem2 = type2.GetField ("MyField");
     myclass2.TestGetCustomAttribute_Type (mem2);
     iCountTestcases++;
     strLoc="L_2_200_005.5";
     mem2 = type2.GetProperty ("MyProp");
     myclass2.TestGetCustomAttribute_Type (mem2);
     }
   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;
   }
   }
 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.TestGetCustomAttribute_Type (param);
     iCountTestcases++;
     strLoc="L_200_003.5";
     param = type.GetMethod ("MyMethod").GetParameters () [0];
     myclass.TestGetCustomAttribute_Type (param);
     type2 = myclass2.GetType ();
     iCountTestcases++;
     strLoc="L_2_200_003.4";
     param2 = type2.GetConstructor (new Type [] {typeof (String)}).GetParameters () [0];
     myclass2.TestGetCustomAttribute_Type (param2);
     iCountTestcases++;
     strLoc="L_2_200_003.5";
     param2 = type2.GetMethod ("MyMethod").GetParameters () [0];
     myclass2.TestGetCustomAttribute_Type (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;
   }
   }
Example #4
0
        public bool RunTest()
        {
            print(strPath + strTest + "  RunTest() started.");
            string     strLoc   = "L_000";
            MyClass    myclass  = new MyClass();
            MyClass2   myclass2 = new MyClass2();
            MemberInfo mem      = null;
            MemberInfo mem2     = null;
            Attribute  attr     = null;
            Type       type     = null;
            Type       type2    = null;

            try
            {
                strLoc = "L_200_001";
                iCountTestcases++;
                strLoc = "L_200_002";
                type   = myclass.GetType();
                mem    = type.GetMethod("MyMethod");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_200_75yhg - mem == null");
                }
                iCountTestcases++;
                strLoc = "L_200_002.1";
                try {
                    attr = Attribute.GetCustomAttribute(mem, null, true);
                    iCountErrors++;
                    Util.printerr("E_200_oi32 - Should 've thrown ArgNullExc");
                }
                catch (ArgumentException) {
                }
                iCountTestcases++;
                strLoc = "L_200_002.1.2";
                try {
                    attr = Attribute.GetCustomAttribute((MemberInfo)null, typeof(ClassLib_Attributes.CA_AMfalse_INfalse), true);
                    iCountErrors++;
                    Util.printerr("E_200_oi322 - Should 've thrown ArgNullExc");
                }
                catch (ArgumentException) {
                }
                iCountTestcases++;
                strLoc = "L_200_002.5";
                type   = myclass.GetType();
                mem    = type;
                myclass.TestGetCustomAttribute_Type(mem);
                iCountTestcases++;
                strLoc = "L_200_003.4";
                mem    = type.GetConstructor(Type.EmptyTypes);
                myclass.TestGetCustomAttribute_Type(mem);
                iCountTestcases++;
                strLoc = "L_200_003.5";
                mem    = type.GetMethod("MyMethod");
                myclass.TestGetCustomAttribute_Type(mem);
                iCountTestcases++;
                strLoc = "L_200_004.5";
                mem    = type.GetField("MyField");
                myclass.TestGetCustomAttribute_Type(mem);
                iCountTestcases++;
                strLoc = "L_200_005.5";
                mem    = type.GetProperty("MyProp");
                myclass.TestGetCustomAttribute_Type(mem);
                iCountTestcases++;
                strLoc = "L_2_200_002.5";
                type2  = myclass2.GetType();
                mem2   = type2;
                myclass2.TestGetCustomAttribute_Type(mem2);
                iCountTestcases++;
                strLoc = "L_2_200_003.4";
                mem2   = type2.GetConstructor(Type.EmptyTypes);
                myclass2.TestGetCustomAttribute_Type(mem2);
                iCountTestcases++;
                strLoc = "L_2_200_003.5";
                mem2   = type2.GetMethod("MyMethod");
                myclass2.TestGetCustomAttribute_Type(mem2);
                iCountTestcases++;
                strLoc = "L_2_200_004.5";
                mem2   = type2.GetField("MyField");
                myclass2.TestGetCustomAttribute_Type(mem2);
                iCountTestcases++;
                strLoc = "L_2_200_005.5";
                mem2   = type2.GetProperty("MyProp");
                myclass2.TestGetCustomAttribute_Type(mem2);
            }
            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);
            }
        }