Exemple #1
0
        static MFTestResults TestMemberFunctions()
        {
            bool retVal = true;

            sbyte initVal = 10;

            TestNonStaticFunctions objWithFields = new TestNonStaticFunctions(initVal);

            // Test that all members initialized to initVal.
            if (!objWithFields.TestIfMembersEqual(initVal))
            {
                Log.Comment("Failed in Constructor of TestNonStaticFunctions");
                retVal = false;
            }
            // This function adds 20 to all fields.
            objWithFields.IncreaseAllMembers(20);
            initVal += 20;

            if (!objWithFields.TestIfMembersEqual(initVal))
            {
                Log.Comment("Failed in IncreaseAllMembers");
                retVal = false;
            }

            // Test retrieval of member varialbes through function with reference parameters:
            char   char_var   = '0';
            sbyte  sbyte_var  = 0;
            short  short_var  = 0;
            int    int_var    = 0;
            long   long_var   = 0;
            bool   bool_var   = false;
            byte   byte_var   = 0;
            ushort ushort_var = 0;
            uint   uint_var   = 0;
            ulong  ulong_var  = 0;
            float  float_var  = 0;
            double double_var = 0;

            //
            // Retrieve member vars
            //
            objWithFields.RetrieveMemberVariables
                (ref char_var, ref sbyte_var, ref short_var,
                ref int_var, ref long_var, ref bool_var,
                ref byte_var, ref ushort_var, ref uint_var, ref ulong_var, ref float_var, ref double_var);

            if (objWithFields.char_data != char_var ||
                objWithFields.sbyte_data != sbyte_var ||
                objWithFields.short_data != short_var ||
                objWithFields.int_data != int_var ||
                objWithFields.long_data != long_var ||
                objWithFields.bool_data != bool_var ||
                objWithFields.byte_data != byte_var ||
                objWithFields.ushort_data != ushort_var ||
                objWithFields.uint_data != uint_var ||
                objWithFields.ulong_data != ulong_var ||
                objWithFields.float_data != float_var ||
                objWithFields.double_data != double_var
                )
            {
                retVal = false;
                Log.Comment("Failed in test of passing variables by reference in non-static member function");
            }
            else
            {
                Log.Comment("Success in test of passing variables by reference in non-static member functiona");
            }



            // Validates setting and retrieval of properties.
            if (objWithFields.prop_double_data != objWithFields.double_data)
            {
                retVal = false;
                Log.Comment("Failed in retrieval of prop_double_data");
            }
            else
            {
                Log.Comment("Success in retrieval of prop_double_data");
            }

            double testDoubleVal = 123.456;

            objWithFields.prop_double_data = testDoubleVal;
            if (testDoubleVal != objWithFields.double_data)
            {
                retVal = false;
                Log.Comment("Failed in setting of prop_double_data");
            }
            else
            {
                Log.Comment("Success in setting of prop_double_data");
            }

            if (retVal)
            {
                Log.Comment("Success in testing of non-static member function\n");
            }
            return(retVal ? MFTestResults.Pass : MFTestResults.Fail);
        }
        static MFTestResults TestMemberFunctions()
        {
            bool retVal = true;

            sbyte initVal = 10; 

            TestNonStaticFunctions objWithFields = new TestNonStaticFunctions( initVal );

            // Test that all members initialized to initVal.
            if ( !objWithFields.TestIfMembersEqual( initVal ) )
            {
                Log.Comment( "Failed in Constructor of TestNonStaticFunctions" );
                retVal = false;
            }
            // This function adds 20 to all fields.
            objWithFields.IncreaseAllMembers( 20 );
            initVal += 20;

            if ( !objWithFields.TestIfMembersEqual( initVal ) )
            {
                Log.Comment( "Failed in IncreaseAllMembers" );
                retVal = false;
            }

            // Test retrieval of member varialbes through function with reference parameters:
            char char_var = '0';    
            sbyte sbyte_var = 0;  
            short short_var = 0;    
            int int_var = 0;     
            long  long_var = 0;
            bool bool_var = false;  
            byte byte_var = 0;    
            ushort ushort_var = 0;  
            uint uint_var = 0;   
            ulong ulong_var = 0;
            float float_var = 0;    
            double double_var = 0;
            //
            // Retrieve member vars
            //
            objWithFields.RetrieveMemberVariables
                (ref char_var, ref sbyte_var, ref short_var, 
                 ref int_var, ref long_var, ref bool_var, 
                 ref byte_var, ref ushort_var, ref uint_var, ref ulong_var, ref float_var, ref double_var);

            if ( objWithFields.char_data      != char_var   ||
                 objWithFields.sbyte_data     != sbyte_var  ||
                 objWithFields.short_data     != short_var  ||
                 objWithFields.int_data       != int_var    ||
                 objWithFields.long_data      != long_var   ||
                 objWithFields.bool_data      != bool_var   ||
                 objWithFields.byte_data      != byte_var   ||
                 objWithFields.ushort_data    != ushort_var ||
                 objWithFields.uint_data      != uint_var   ||
                 objWithFields.ulong_data     != ulong_var  ||
                 objWithFields.float_data     != float_var  ||
                 objWithFields.double_data    != double_var 
                )
            {
                retVal = false;
                Log.Comment("Failed in test of passing variables by reference in non-static member function" );
            }
            else
            {
                Log.Comment("Success in test of passing variables by reference in non-static member functiona");
            }
 
            
            
            // Validates setting and retrieval of properties.
            if( objWithFields.prop_double_data != objWithFields.double_data )
            {
                retVal = false;
                Log.Comment( "Failed in retrieval of prop_double_data" );
            }
            else
            {
                Log.Comment( "Success in retrieval of prop_double_data" );
            }

            double testDoubleVal = 123.456;
            objWithFields.prop_double_data = testDoubleVal;
            if( testDoubleVal != objWithFields.double_data )
            {
                retVal = false;
                Log.Comment( "Failed in setting of prop_double_data" );
            }
            else
            {
                Log.Comment( "Success in setting of prop_double_data" );
            }

            if ( retVal )
            {
                Log.Comment( "Success in testing of non-static member function\n" );
            }
            return retVal ? MFTestResults.Pass : MFTestResults.Fail;
        }