t_checkup.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_checkup                                                      *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *******************************************************************************
00007 * Copyright (c) 1993-$now By Author.  This program is free software; you can  *
00008 * redistribute it and/or modify it under the terms of the GNU General Public  *
00009 * License as published by the Free Software Foundation; either version 2 of   *
00010 * the License or (at your option) any later version.  This is online at:      *
00011 *     http://www.fsf.org/copyleft/gpl.html                                    *
00012 * Please send any updates to: fred@gruntose.com                               *
00013 \*****************************************************************************/
00014 
00015 #include "checkup.h"
00016 
00017 #include <basis/function.h>
00018 #include <basis/guards.h>
00019 #include <basis/istring.h>
00020 #include <basis/portable.h>
00021 #include <basis/version_record.h>
00022 #include <opsystem/application_shell.h>
00023 #include <loggers/console_logger.h>
00024 #include <data_struct/static_memory_gremlin.h>
00025 
00026 #include <stdio.h>
00027 
00028 using namespace portable;
00029 using namespace system_checkup;
00030 
00031 class checkup_on_OS : public application_shell
00032 {
00033 public:
00034   checkup_on_OS() : application_shell(static_class_name()) {}
00035   IMPLEMENT_CLASS_NAME("checkup_on_OS");
00036   virtual int execute();
00037 };
00038 
00039 class burpee
00040 {
00041 public:
00042   burpee() : my_string(new istring) { *my_string = "balrog"; }
00043   virtual ~burpee() {
00044     WHACK(my_string);
00045     if (my_string) deadly_error("burpee", "whack test", "whack failed");
00046   }
00047 
00048 private:
00049   istring *my_string;
00050 };
00051 
00053 
00054 class florba : public burpee
00055 {
00056 public:
00057   florba() : burpee(), second_string(new istring)
00058       { *second_string = "loquacious"; }
00059   virtual ~florba() {
00060     WHACK(second_string); 
00061     if (second_string) deadly_error("florba", "whack test", "whack failed");
00062   }
00063 
00064 private:
00065   istring *second_string;
00066 };
00067 
00069 
00070 struct testing_file_struct : public FILE {};
00071 
00072 // NOTE: an important part of this test program is running it under something
00073 // like boundschecker to ensure that there are no memory leaks caused by
00074 // invoking WHACK.  apparently diab 3 is unable to implement WHACK correctly.
00075 
00076 int checkup_on_OS::execute()
00077 {
00078   // let's see what this system is called.
00079   log(istring("The name of this software system is: ")
00080       + software_product_name());
00081 
00082   // and what this program is called.
00083   log(istring("The application is called: ") + portable::application_name());
00084 
00085   // turn the "if 0" into "if 1" below if you want to test scoping.
00086 #if 0
00087   //testing new compiler's ansi c++ compliance.
00088   for (int q = 0; q < 19823; q++) {
00089     int treno = q;
00090     int malfoy = treno * 3;
00091     log(isprintf("%d", malfoy));
00092   }
00093   //this should be an error.  the scope of q should be within the loop and
00094   //not outside of it.
00095   if (q > 19824) {
00096     log("some kind of weirdness happened.");
00097   }
00098   //end test.
00099 #endif
00100 
00101   // test that the WHACK function operates properly.
00102   burpee *chunko = new burpee;
00103   florba *lorkas = new florba;
00104   burpee *alias = lorkas;
00105 
00106   WHACK(chunko);
00107   WHACK(alias);
00108   if (chunko) deadly_error("chunko", "whack test", "whack failed");
00109   if (alias) deadly_error("lorkas", "whack test", "whack failed");
00110 
00111   if (sizeof(testing_file_struct) != sizeof(FILE))
00112     deadly_error("test_checkup", "struct size test",
00113         "sizeof testing_file_struct and sizeof FILE differ");
00114 
00115   // now do the crucial tests on the OS, platform, compiler, etc.
00116   istring message;
00117   if (check_system_characteristics())
00118     message = istring(class_name()) + ":: the required characteristics "
00119         "seem present.";
00120   else
00121     message = istring(class_name()) + ":: at least one required "
00122         "characteristic is absent!!";
00123 
00124 #ifdef __WIN32__
00125   known_operating_systems os = determine_OS();
00126   if (os == WIN_95)
00127     printf("This is windows 95.\n");
00128   else if (os == WIN_NT)
00129     printf("This is windows NT.\n");
00130   else if (os == WIN_2K)
00131     printf("This is windows 2000.\n");
00132   else if (os == WIN_XP)
00133     printf("This is windows XP.\n");
00134   else 
00135     printf("This OS is unknown.\n");
00136 #endif
00137 
00138   version os_ver = portable::get_OS_version();
00139   printf("The stated OS version number is: %s\n", os_ver.text_form().s());
00140 
00141   guards::alert_message(message.s());
00142   return 0;
00143 }
00144 
00145 HOOPLE_MAIN(checkup_on_OS, )
00146 

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