TestGetCustomAttributes() public méthode

public TestGetCustomAttributes ( MemberInfo mem ) : bool
mem System.Reflection.MemberInfo
Résultat 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.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);
            }
        }
 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[] attrs = null;
   Attribute[] attrs2 = null;
   Type type = null;
   Type type2 = null;
   try  
     {
     strLoc="L_100_001";
     iCountTestcases++;
     strLoc="L_100_001.4";
     try {
     attrs = Attribute.GetCustomAttributes ((MemberInfo) null, true);
     iCountErrors++;
     Util.printerr ("E_100_duo21 - Should 've thrown ArgNullExc");
     }
     catch (ArgumentException ) {
     }
     iCountTestcases++;
     strLoc="L_100_001.4.2";
     type = myclass.GetType();
     mem = type.GetMethod ("TestGetCustomAttributes");
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_jkjs - mem == null");
     }
     iCountTestcases++;
     strLoc="L_100_001.5";
     attrs = Attribute.GetCustomAttributes (mem, true);
     if (attrs == null) {
     iCountErrors++;
     Util.printerr ("E_100_iudo - attrs == null");
     return false;
     }
     iCountTestcases++;
     strLoc="L_100_001.6";
     if (attrs.Length != 0+1) {
     iCountErrors++;
     Util.printerr ("E_100_f3fw - attrs.Length != 1");
     Util.print (attrs.Length);
     }
     iCountTestcases++;
     strLoc="L_2_100_001.4.2";
     type2 = myclass2.GetType();
     mem2 = type2.GetMethod ("TestGetCustomAttributes");
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_jkjs - mem2 == null");
     }
     iCountTestcases++;
     strLoc="L_2_100_001.5";
     attrs2 = Attribute.GetCustomAttributes (mem2, true);
     if (attrs2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_iudo - attrs2 == null");
     return false;
     }
     iCountTestcases++;
     strLoc="L_2_100_001.6";
     if (attrs2.Length != 0+1) {
     iCountErrors++;
     Util.printerr ("E_2_100_f3fw - attrs2.Length != 1");
     Util.print (attrs2.Length);
     }
     iCountTestcases++;
     strLoc="L_100_001.7";
     type = myclass.GetType();
     mem = type;
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_skj2 - mem == null");
     }
     else {
     myclass.TestGetCustomAttributes (mem);
     iCountTestcases++;
     strLoc="L_100_001.7.2";
     myclass.TestGetCustomAttributes2 (mem);
     }
     iCountTestcases++;
     strLoc="L_100_001.8";
     mem = type.GetConstructor (Type.EmptyTypes);
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_001.8_skj2 - mem == null");
     }
     else {
     myclass.TestGetCustomAttributes (mem);
     iCountTestcases++;
     strLoc="L_100_001.8.2";
     myclass.TestGetCustomAttributes2 (mem);
     }
     iCountTestcases++;
     strLoc="L_100_002";
     mem = type.GetMethod ("MyMethod");
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_002_skj2 - mem == null");
     }
     else {
     myclass.TestGetCustomAttributes (mem);
     iCountTestcases++;
     strLoc="L_100_002.7.2";
     myclass.TestGetCustomAttributes2 (mem);
     }
     iCountTestcases++;
     strLoc="L_100_003";
     mem = type.GetField ("MyField");
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_003_skj2 - mem == null");
     }
     else {
     myclass.TestGetCustomAttributes (mem);
     iCountTestcases++;
     strLoc="L_100_003.7.2";
     myclass.TestGetCustomAttributes2 (mem);
     }
     iCountTestcases++;
     strLoc="L_100_004";
     mem = type.GetProperty ("MyProp");
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_004_skj2 - mem == null");
     }
     else {
     myclass.TestGetCustomAttributes (mem);
     iCountTestcases++;
     strLoc="L_100_004.7.2";
     myclass.TestGetCustomAttributes2 (mem);
     }
     iCountTestcases++;
     strLoc="L_100_005";
     mem = type.GetEvent ("MyEvent");
     if (mem == null) {
     iCountErrors++;
     Util.printerr ("E_100_005_skj2 - mem == null");
     }
     else {
     myclass.TestGetCustomAttributes (mem);
     iCountTestcases++;
     strLoc="L_100_005.7.2";
     myclass.TestGetCustomAttributes2 (mem);
     }
     iCountTestcases++;
     strLoc="L_2_100_001.7";
     type2 = myclass2.GetType();
     mem2 = type2;
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_skj2 - mem2 == null");
     }
     else {
     myclass2.TestGetCustomAttributes (mem2);
     iCountTestcases++;
     strLoc="L_2_100_001.7.2";
     myclass2.TestGetCustomAttributes2 (mem2);
     }
     iCountTestcases++;
     strLoc="L_2_100_001.8";
     mem2 = type2.GetConstructor (Type.EmptyTypes);
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_001.8_skj2 - mem2 == null");
     }
     else {
     myclass2.TestGetCustomAttributes (mem2);
     iCountTestcases++;
     strLoc="L_2_100_001.8.2";
     myclass2.TestGetCustomAttributes2 (mem2);
     }
     iCountTestcases++;
     strLoc="L_2_100_002";
     mem2 = type2.GetMethod ("MyMethod");
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_002_skj2 - mem2 == null");
     }
     else {
     myclass2.TestGetCustomAttributes (mem2);
     iCountTestcases++;
     strLoc="L_2_100_002.7.2";
     myclass2.TestGetCustomAttributes2 (mem2);
     }
     iCountTestcases++;
     strLoc="L_2_100_003";
     mem2 = type2.GetField ("MyField",BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly);
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_003_skj2 - mem2 == null");
     }
     else {
     myclass2.TestGetCustomAttributes (mem2);
     iCountTestcases++;
     strLoc="L_2_100_003.7.2";
     myclass2.TestGetCustomAttributes2 (mem2);
     }
     iCountTestcases++;
     strLoc="L_2_100_004";
     mem2 = type2.GetProperty ("MyProp");
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_004_skj2 - mem2 == null");
     }
     else {
     myclass2.TestGetCustomAttributes (mem2);
     iCountTestcases++;
     strLoc="L_2_100_004.7.2";
     myclass2.TestGetCustomAttributes2 (mem2);
     }
     iCountTestcases++;
     strLoc="L_2_100_005";
     mem2 = type2.GetEvent ("MyEvent");
     if (mem2 == null) {
     iCountErrors++;
     Util.printerr ("E_2_100_005_skj2 - mem2 == null");
     }
     else {
     myclass2.TestGetCustomAttributes (mem2);
     iCountTestcases++;
     strLoc="L_2_100_005.7.2";
     myclass2.TestGetCustomAttributes2 (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;
   }
   }
Exemple #3
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[] attrs  = null;
            Attribute[] attrs2 = null;
            Type        type   = null;
            Type        type2  = null;

            try
            {
                strLoc = "L_100_001";
                iCountTestcases++;
                strLoc = "L_100_001.4";
                try {
                    attrs = Attribute.GetCustomAttributes((MemberInfo)null, true);
                    iCountErrors++;
                    Util.printerr("E_100_duo21 - Should 've thrown ArgNullExc");
                }
                catch (ArgumentException) {
                }
                iCountTestcases++;
                strLoc = "L_100_001.4.2";
                type   = myclass.GetType();
                mem    = type.GetMethod("TestGetCustomAttributes");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_jkjs - mem == null");
                }
                iCountTestcases++;
                strLoc = "L_100_001.5";
                attrs  = Attribute.GetCustomAttributes(mem, true);
                if (attrs == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_iudo - attrs == null");
                    return(false);
                }
                iCountTestcases++;
                strLoc = "L_100_001.6";
                if (attrs.Length != 0 + 1)
                {
                    iCountErrors++;
                    Util.printerr("E_100_f3fw - attrs.Length != 1");
                    Util.print(attrs.Length);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.4.2";
                type2  = myclass2.GetType();
                mem2   = type2.GetMethod("TestGetCustomAttributes");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_jkjs - mem2 == null");
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.5";
                attrs2 = Attribute.GetCustomAttributes(mem2, true);
                if (attrs2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_iudo - attrs2 == null");
                    return(false);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.6";
                if (attrs2.Length != 0 + 1)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_f3fw - attrs2.Length != 1");
                    Util.print(attrs2.Length);
                }
                iCountTestcases++;
                strLoc = "L_100_001.7";
                type   = myclass.GetType();
                mem    = type;
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_001.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_001.8";
                mem    = type.GetConstructor(Type.EmptyTypes);
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_001.8_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_001.8.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_002";
                mem    = type.GetMethod("MyMethod");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_002_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_002.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_003";
                mem    = type.GetField("MyField");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_003_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_003.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_004";
                mem    = type.GetProperty("MyProp");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_004_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_004.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_005";
                mem    = type.GetEvent("MyEvent");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_005_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_005.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.7";
                type2  = myclass2.GetType();
                mem2   = type2;
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_001.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.8";
                mem2   = type2.GetConstructor(Type.EmptyTypes);
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_001.8_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_001.8.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_002";
                mem2   = type2.GetMethod("MyMethod");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_002_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_002.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_003";
                mem2   = type2.GetField("MyField", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_003_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_003.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_004";
                mem2   = type2.GetProperty("MyProp");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_004_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_004.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_005";
                mem2   = type2.GetEvent("MyEvent");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_005_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_005.7.2";
                    myclass2.TestGetCustomAttributes2(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.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;
   }
   }