t_portable.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : test_portable                                                     *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *  Purpose:                                                                   *
00007 *                                                                             *
00008 *    Checks out some methods in the low-level portable support.               *
00009 *                                                                             *
00010 *******************************************************************************
00011 * Copyright (c) 2003-$now By Author.  This program is free software; you can  *
00012 * redistribute it and/or modify it under the terms of the GNU General Public  *
00013 * License as published by the Free Software Foundation; either version 2 of   *
00014 * the License or (at your option) any later version.  This is online at:      *
00015 *     http://www.fsf.org/copyleft/gpl.html                                    *
00016 * Please send any updates to: fred@gruntose.com                               *
00017 \*****************************************************************************/
00018 
00019 #include <basis/function.h>
00020 #include <basis/guards.h>
00021 #include <basis/log_base.h>
00022 #include <basis/portable.h>
00023 #include <data_struct/static_memory_gremlin.h>
00024 #include <loggers/console_logger.h>
00025 #include <opsystem/application_shell.h>
00026 
00027 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00028 
00029 class test_portable : public application_shell
00030 {
00031 public:
00032   test_portable() : application_shell(class_name()) {}
00033 
00034   IMPLEMENT_CLASS_NAME("test_portable");
00035 
00036   virtual int execute();
00037 
00038   void show_time();
00039 };
00040 
00041 void test_portable::show_time()
00042 {
00043   u_int up = portable::system_uptime();
00044   log(isprintf("system uptime: %d ms or %f seconds\nor %f "
00045       "minutes or %f hours\nor %f days.", up,
00046       double(up) / 1000.0, double(up) / 1000.0 / 60.0,
00047       double(up) / 1000.0 / 60.0 / 60.0,
00048       double(up) / 1000.0 / 60.0 / 60.0 / 24.0));
00049 }
00050 
00051 int test_portable::execute()
00052 {
00053   FUNCDEF("execute");
00054   istring application_name = portable::application_name();
00055   log(istring("app name is ") + application_name);
00056   istring prod = software_product_name();
00057   log(istring("product name is ") + prod);
00058 
00059   show_time();
00060   log("sleeping 12.3 seconds.");
00061   portable::sleep_ms(12300);
00062   show_time();
00063 
00064   log("");
00065   guards::alert_message("portable support works for those functions tested.");
00066   return 0;
00067 }
00068 
00069 // NOTE: leave the main function alone; we do not want argc and argv to be
00070 //       set for this test.
00071 
00072 HOOPLE_STARTUP_CODE;
00073 
00074 int main(int formal(argc), char *formal(argv)[])
00075 {
00076   test_portable to_run;
00077   return to_run.execute();
00078 }
00079 
00080 

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