t_debugging_console.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_debugging_console                                            *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *  Purpose:                                                                   *
00007 *                                                                             *
00008 *    Exercises the debugging_console object in order to assess if it's        *
00009 *  functioning properly.                                                      *
00010 *                                                                             *
00011 *******************************************************************************
00012 * Copyright (c) 1995-$now By Author.  This program is free software; you can  *
00013 * redistribute it and/or modify it under the terms of the GNU General Public  *
00014 * License as published by the Free Software Foundation; either version 2 of   *
00015 * the License or (at your option) any later version.  This is online at:      *
00016 *     http://www.fsf.org/copyleft/gpl.html                                    *
00017 * Please send any updates to: fred@gruntose.com                               *
00018 \*****************************************************************************/
00019 
00020 #include <basis/chaos.h>
00021 #include <basis/istring.h>
00022 #include <mathematics/averager.cpp>
00023 #include <mechanisms/time_stamp.h>
00024 #include <mfc_ext/debugging_console_window.h>
00025 #include <mfc_ext/tiny_app.cpp>
00026 #include <mfc_ext/tiny_shell.h>
00027 #include <opsystem/event_extensions.h>
00028 #include <data_struct/static_memory_gremlin.h>
00029 #include <textual/string_manipulation.h>
00030 #include <win_ext/debugger.h>
00031 
00032 const int PRINT_TIMER = 37;
00033   // id for timer event.
00034 
00035 const int PRINT_INTERVAL = 10;
00036   // interval we print stuff at.
00037 
00038 //const int RUN_TIME = 7 * MINUTE_ms;
00039 const int RUN_TIME = 30 * SECOND_ms;//temp
00040   // how long the test runs.
00041 
00042 // the constraints on how many random names we string together.
00043 const int MIN_RANDS = 7;
00044 const int MAX_RANDS = 88;
00045 
00046 // these are the limits on how many times we blast the same random string
00047 // out per timer cycle.
00048 const int MIN_REPRINTS = 10;
00049 const int MAX_REPRINTS = 60;
00050 
00051 class test_debugging_console : public tiny_shell
00052 {
00053 public:
00054   test_debugging_console();
00055 
00056   IMPLEMENT_CLASS_NAME("test_debugging_console");
00057 
00058   int execute();
00059     // performs main body of test.
00060 
00061   void OnTimer(u_int wparam);
00062 
00063   DECLARE_MESSAGE_MAP();
00064 
00065   time_stamp _start_time;  // when the test started.
00066   time_stamp _quitting_time;  // when the test should stop.
00067   long _operations;  // how many calls were made.
00068   long _bytes;  // how many bytes were logged total.
00069   averager<double> _log_times;  // the average time a log() call takes.
00070 };
00071 
00072 BEGIN_MESSAGE_MAP(test_debugging_console, tiny_shell)
00073   //{{AFX_MSG_MAP(test_debugging_console)
00074   ON_WM_TIMER()
00075   //}}AFX_MSG_MAP
00076 END_MESSAGE_MAP()
00077 
00078 test_debugging_console::test_debugging_console()
00079 : tiny_shell("Test Debugging Console", "t_debugging_console"),
00080   _operations(0),
00081   _bytes(0)
00082 {}
00083 
00084 int test_debugging_console::execute()
00085 {
00086   SetTimer(PRINT_TIMER, PRINT_INTERVAL, NIL);
00087   // hadn't quite started 'til that timer was set...
00088   _start_time.reset();
00089   _quitting_time.reset(RUN_TIME);
00090   return 0;
00091 }
00092 
00093 void test_debugging_console::OnTimer(u_int wparam)
00094 {
00095   static istring to_print;
00096   to_print.reset();  // clear static guy.
00097   for (int i = 0; i < randomizer().inclusive(MIN_RANDS, MAX_RANDS); i++)
00098     to_print += string_manipulation::make_random_name() + " ";
00099   time_stamp log_start;
00100   int repeats = randomizer().inclusive(MIN_REPRINTS, MAX_REPRINTS);
00101   for (int j = 0; j < repeats; j++) {
00102     log(to_print);
00103     _operations++;
00104   }
00105   time_stamp log_end;
00106   _bytes += repeats * to_print.length();
00107   _log_times.add(log_end.value() - log_start.value(), repeats);
00108   if (time_stamp() > _quitting_time) {
00109     // test is done now.  stop the test driver and report what happened.
00110     KillTimer(wparam);
00111     log("");
00112     log("");
00113     log("test complete:");
00114     log(istring(istring::SPRINTF, "\trun time: %f sec",
00115         (time_stamp().value() - _start_time.value()) / 1000));
00116     log(istring(istring::SPRINTF, "\toperations: %d",
00117         _operations));
00118     log(istring(istring::SPRINTF, "\tbytes logged: %d",
00119         _bytes));
00120     log(istring(istring::SPRINTF, "\taverage log() duration: %f ms",
00121         _log_times.average()));
00122 
00123     event_extensions::poll(200);  // force messages to move through.
00124     istring win_contents;
00125     if (!console().get_contents(win_contents)) {
00126       log("failed to get clipboard!");
00127     } else {
00128 
00129 //temp; doesn't get out since someone keeps it from being printed.  is that
00130 //      the console or log_base or someone enforcing a size limit?
00131 //      log(win_contents);
00132 
00133       log(isprintf("win content was %d characters long.",
00134           win_contents.length()));
00135     }
00136 
00137   }
00138 }
00139 
00140 //hmmm:    CHECK_MFCEX(); how?
00141 
00142 HOOPLE_MAIN(test_debugging_console, )
00143 

Generated on Fri Nov 28 04:29:34 2008 for HOOPLE Libraries by  doxygen 1.5.1