} // static Exercise method private static void RealWorldTests ( StreamWriter pswReport ) { const string MSG_BEGIN = @"{0}Begin RealWorldTests{0}"; const string MSG_DONE = @"{0}RealWorldTests Done{0}"; const string MSG_FLAG_STACK = @" New s_aenmStackTraceDisp value = {0} ({1,3})"; const string MSG_FLAG_SUBSYSTEM = @" New s_aenmAppSubsystem value = {0} ({1,3})"; const string MSG_FLAG_EVENTLOGGING = @" New s_aenmLoggingState value = {0} ({1,3})"; const string MSG_OPTION_FLAGS_DISP = @" Test Case {0,3} OptionFlags {1,3} = {2,3}"; const string MSG_OPTIONS_ANTE = @"Ante"; const string MSG_OPTIONS_POST = @"Post"; const string REPORT_HEADINGS = "StackTraceDisposition\tOutputDestination\tEventLogging\tInitialFlags\tFinalFlags"; const string REPORT_DETAIL_LINE = "{0,3}\t{1,3}\t{2,3}\t{3,3}\t{4,3}"; Console.WriteLine ( MSG_BEGIN , Environment.NewLine ); pswReport.WriteLine ( REPORT_HEADINGS ); OutputOptions enmFlags = OutputOptions.Method | OutputOptions.Source; uint uintCase = StandardConstants.ZERO; foreach ( OutputOptions enmStackDisp in s_aenmStackTraceDisp ) { // Stack tracing is either ON or OFF. Console.WriteLine ( MSG_FLAG_STACK , enmStackDisp , ( byte ) enmStackDisp ); foreach ( OutputOptions enmSubsystem in s_aenmAppSubsystem ) { // ExceptionLogger.Subsystem collapses to one of only three values. Console.WriteLine ( MSG_FLAG_SUBSYSTEM , enmSubsystem , ( byte ) enmSubsystem ); foreach ( OutputOptions enmEventLogUsage in s_aenmLoggingState ) { // Event logging is either ON or OFF. Console.WriteLine ( MSG_FLAG_EVENTLOGGING , enmEventLogUsage , ( byte ) enmEventLogUsage ); // ---------------------------------------------------- // From this point forward, the code is identical with // the test code that brought this matter to my // attention. // ---------------------------------------------------- Console.WriteLine ( MSG_OPTION_FLAGS_DISP , ++uintCase , MSG_OPTIONS_ANTE , enmFlags ); OutputOptions enmInitialFlags = enmFlags; BitArray32 b32Flags = new BitArray32 ( ( UInt32 ) enmFlags ); if ( ( enmSubsystem & OutputOptions.StandardError ) == OutputOptions.StandardError ) b32Flags.BitOn ( ( int ) BitArray32.BitNumber ( ( UInt32 ) OutputOptions.StandardError ) ); else b32Flags.BitOff ( ( int ) BitArray32.BitNumber ( ( UInt32 ) OutputOptions.StandardError ) ); if ( ( enmStackDisp & OutputOptions.Stack ) == OutputOptions.Stack ) b32Flags.BitOn ( ( int ) BitArray32.BitNumber ( ( UInt32 ) OutputOptions.Stack ) ); else b32Flags.BitOff ( ( int ) BitArray32.BitNumber ( ( UInt32 ) OutputOptions.Stack ) ); if ( ( enmEventLogUsage & OutputOptions.EventLog ) == OutputOptions.EventLog ) b32Flags.BitOn ( ( int ) BitArray32.BitNumber ( ( UInt32 ) OutputOptions.EventLog ) ); else b32Flags.BitOff ( ( int ) BitArray32.BitNumber ( ( UInt32 ) OutputOptions.EventLog ) ); enmFlags = ( OutputOptions ) ( ( UInt32 ) b32Flags ); Console.WriteLine ( MSG_OPTION_FLAGS_DISP , uintCase , MSG_OPTIONS_POST , enmFlags ); pswReport.WriteLine ( REPORT_DETAIL_LINE , new object [ ] { ( byte ) enmStackDisp , // Token 0 = StackTraceDisposition ( byte ) enmSubsystem , // Token 1 = OutputDestination ( byte ) enmEventLogUsage , // Token 2 = EventLogging ( byte ) enmInitialFlags , // Token 3 = InitialFlags ( byte ) enmFlags // Token 4 = FinalFlags } ); } // foreach ( OutputOptions enmStackDisp in s_aenmStackTraceDisp ) } // foreach ( OutputOptions enmSubsystem in s_aenmAppSubsystem ) } // foreach ( OutputOptions enmEventLogUsage in s_aenmLoggingState ) Console.WriteLine ( MSG_DONE , Environment.NewLine ); } // private static void RealWorldTests
}; // s_aint64Examples public static void Exercise ( string pstrReportFileName ) { const string HEXADECIMAL_8 = @"X8"; const string BITMASK_FORMAT_STRING = "G"; int intTestNbr = TestBit32ArrayToStringOverload ( ); TestBitArrayRulers ( ref intTestNbr ); TestBitMaskAndRuler ( ref intTestNbr ); Console.WriteLine ( @"Begin BitArray32TestStand Exercises" ); Console.WriteLine ( @"{1} Test # {0} - Display public constants.{1}" , ++intTestNbr , Environment.NewLine ); Console.WriteLine ( " Bit 1 = {0} (Individual bits: {1})" , // Format control string BitArray32.BIT_01.ToString ( HEXADECIMAL_8 ) , // Format Item 0 = Bit as hexadecimal integer BitArray32.FormatIntegerAsBitArray ( // Format Item 1 = Bit as array of bits BitArray32.BIT_01 , // Specify the same bit, raw. BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); // This should be passing a value of 1. Console.WriteLine ( @" Bit 2 = {0} (Individual bits: {1})" , BitArray32.BIT_02.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_02 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 3 = {0} (Individual bits: {1})" , BitArray32.BIT_03.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_03 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 4 = {0} (Individual bits: {1})" , BitArray32.BIT_04.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_04 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 5 = {0} (Individual bits: {1})" , BitArray32.BIT_05.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_05 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 6 = {0} (Individual bits: {1})" , BitArray32.BIT_06.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_06 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 7 = {0} (Individual bits: {1})" , BitArray32.BIT_07.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_07 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 8 = {0} (Individual bits: {1})" , BitArray32.BIT_08.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_08 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 9 = {0} (Individual bits: {1})" , BitArray32.BIT_09.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_09 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 10 = {0} (Individual bits: {1})" , BitArray32.BIT_10.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_10 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 11 = {0} (Individual bits: {1})" , BitArray32.BIT_11.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_11 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 12 = {0} (Individual bits: {1})" , BitArray32.BIT_12.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_12 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 13 = {0} (Individual bits: {1})" , BitArray32.BIT_13.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_13 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 14 = {0} (Individual bits: {1})" , BitArray32.BIT_14.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_14 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 15 = {0} (Individual bits: {1})" , BitArray32.BIT_15.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_15 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 16 = {0} (Individual bits: {1})" , BitArray32.BIT_16.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_16 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 17 = {0} (Individual bits: {1})" , BitArray32.BIT_17.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_17 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 18 = {0} (Individual bits: {1})" , BitArray32.BIT_18.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_18 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 19 = {0} (Individual bits: {1})" , BitArray32.BIT_19.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_19 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 20 = {0} (Individual bits: {1})" , BitArray32.BIT_20.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_20 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 21 = {0} (Individual bits: {1})" , BitArray32.BIT_21.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_21 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 22 = {0} (Individual bits: {1})" , BitArray32.BIT_22.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_22 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 23 = {0} (Individual bits: {1})" , BitArray32.BIT_23.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_23 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 24 = {0} (Individual bits: {1})" , BitArray32.BIT_24.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_24 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 25 = {0} (Individual bits: {1})" , BitArray32.BIT_25.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_25 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 26 = {0} (Individual bits: {1})" , BitArray32.BIT_26.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_26 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 27 = {0} (Individual bits: {1})" , BitArray32.BIT_27.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_27 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 28 = {0} (Individual bits: {1})" , BitArray32.BIT_28.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_28 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 29 = {0} (Individual bits: {1})" , BitArray32.BIT_29.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_29 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 30 = {0} (Individual bits: {1})" , BitArray32.BIT_30.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_30 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 31 = {0} (Individual bits: {1})" , BitArray32.BIT_31.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_31 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" Bit 32 = {0} (Individual bits: {1})" , BitArray32.BIT_32.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_32 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" BIT_NBR_MIN = {0} (Individual bits: {1})" , BitArray32.BIT_NBR_MIN , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_NBR_MIN , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" BIT_NBR_MAX = {0} (Individual bits: {1})" , BitArray32.BIT_NBR_MAX , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_NBR_MAX , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) ); Console.WriteLine ( @" OFF = {0}" , BitArray32.OFF ); Console.WriteLine ( @" ON = {0}" , BitArray32.ON ); Console.WriteLine ( @"{1} Test # {0} - Default Constructor.{1}" , ++intTestNbr , Environment.NewLine ); BitArray32 Mask1 = new BitArray32 ( ); Console.WriteLine ( @" Initial value of default BitArray32 = {0} (Individual bits: {1})" , Mask1.ToString ( BITMASK_FORMAT_STRING ) , Mask1.ToString ( "B4" ) ); Mask1.BitOn ( 10 ); Console.WriteLine ( @" Bit 10 was turned ON. Mask1 = {0} (Individual bits: {1})" , Mask1.ToString ( BITMASK_FORMAT_STRING ) , Mask1.ToString ( "B4" ) ); Console.WriteLine ( @"{1} Test # {0} - First overloaded Constructor.{1}" , ++intTestNbr , Environment.NewLine ); BitArray32 Mask2 = new BitArray32 ( BitArray32.BIT_07 ); // ---------------------------------------------------------------- // The following statement writes a two-line ruler above the area // where the next three statements will display bit masks. Since // this group prints beneath the ruler, it eschews the spacing in // favor of the compact format that aligns correctly with the // ruler. // ---------------------------------------------------------------- Console.WriteLine ( "{2} {0}{2} {1}" , BitArray32.GetRulerTens ( BitArray32.BitCount.Count32 , BitArray32.BitDisplayOrder.HighBitToLowBit ) , BitArray32.GetRulerUnits ( BitArray32.BitCount.Count32 , BitArray32.BitDisplayOrder.HighBitToLowBit ) , Environment.NewLine ); Console.WriteLine ( @" Initial value of Overloaded BitArray32 = {0} (Individual bits: {1})" , Mask2.ToString ( BITMASK_FORMAT_STRING ) , Mask2.ToString ( "H" ) ); Mask2.BitOn ( 10 ); Console.WriteLine ( @" Bit 10 was turned ON. Mask2 = {0} (Individual bits: {1})" , Mask2.ToString ( BITMASK_FORMAT_STRING ) , Mask2.ToString ( "H" ) ); Mask2.BitOff ( 7 ); Console.WriteLine ( @" Bit 7 was turned OFF. Mask2 = {0} (Individual bits: {1})" , Mask2.ToString ( BITMASK_FORMAT_STRING ) , Mask2.ToString ( "H" ) ); if ( Mask2.IsBitOn ( 10 ) ) Console.WriteLine ( @" Bit 10 is ON" ); else Console.WriteLine ( @" Bit 10 is OFF" ); if ( Mask2.IsBitOn ( 7 ) ) Console.WriteLine ( @" Bit 7 is ON" ); else Console.WriteLine ( @" Bit 7 is OFF" ); if ( Mask2.IsBitOff ( 10 ) ) Console.WriteLine ( @" Bit 10 is OFF" ); else Console.WriteLine ( @" Bit 10 is NOT OFF" ); if ( Mask2.IsBitOff ( 7 ) ) Console.WriteLine ( @" Bit 7 is OFF" ); else Console.WriteLine ( @" Bit 7 is NOT OFF" ); StreamWriter swReport = null; try { swReport = new StreamWriter ( pstrReportFileName , StandardConstants.FILE_OUT_CREATE , System.Text.Encoding.ASCII ); RealWorldTests ( swReport ); } catch ( Exception ex ) { Console.WriteLine ( ex.Message ); } finally { // Clean up the StreamWriter. if ( swReport != null ) { swReport.Close ( ); swReport.Dispose ( ); swReport = null; } // if ( swReport != null ) } // One way or another, the StreamWriter got cleaned up. Console.WriteLine ( "{0}End BitArray32TestStand Exercises{0}" , Environment.NewLine ); } // static Exercise method