00001 #include "config.h" 00002 00003 #include <iostream> 00004 #include <string> 00005 #include <cassert> 00006 00007 #ifdef HAVE_UNISTD_H 00008 #include <unistd.h> 00009 #endif 00010 00011 #include <errno.h> 00012 00013 #include "asserts.h" 00014 #include "types.h" 00015 #include "error.h" 00016 #include "estring.h" 00017 #include "fs.h" 00018 #include "tstamp.h" 00019 #include "rconfig.h" 00020 #include "test-rconfig-setup.h" 00021 00022 #define ERR_OUT(e) std::cerr << e; 00023 // #define ERR_OUT(e) 00024 00025 void test(void) 00026 { 00027 char const * argv[256] = { 0 }; 00028 int argc = 0; 00029 bool thrown = false; 00030 00031 argv[argc++] = "<program>"; 00032 argv[argc++] = "--archive"; 00033 00034 config.default_file("./test-rconfig.dir/old-log-files.dir/file-1.conf"); 00035 config.default_logdir("./test-rconfig.dir/log.dir"); 00036 try { 00037 config.init(argc, argv); 00038 } 00039 catch(error e) { 00040 ERR_OUT(e); 00041 thrown = true; 00042 } 00043 catch(...) { 00044 assert(0); 00045 } 00046 assert(!thrown); 00047 assert(config.delete_old_log_files() == false); 00048 assert(config.delete_old_report_files() == false); 00049 00050 config.clear(); 00051 00052 config.default_file("./test-rconfig.dir/old-log-files.dir/file-2.conf"); 00053 config.default_logdir("./test-rconfig.dir/log.dir"); 00054 try { 00055 config.init(argc, argv); 00056 } 00057 catch(error e) { 00058 ERR_OUT(e); 00059 thrown = true; 00060 } 00061 catch(...) { 00062 assert(0); 00063 } 00064 assert(!thrown); 00065 assert(config.delete_old_log_files() == true); 00066 assert(config.delete_old_report_files() == false); 00067 00068 config.clear(); 00069 00070 config.default_file("./test-rconfig.dir/old-log-files.dir/file-3.conf"); 00071 config.default_logdir("./test-rconfig.dir/log.dir"); 00072 try { 00073 config.init(argc, argv); 00074 } 00075 catch(error e) { 00076 ERR_OUT(e); 00077 thrown = true; 00078 } 00079 catch(...) { 00080 assert(0); 00081 } 00082 assert(!thrown); 00083 assert(config.delete_old_log_files() == false); 00084 assert(config.delete_old_report_files() == true); 00085 00086 config.clear(); 00087 00088 config.default_file("./test-rconfig.dir/old-log-files.dir/file-4.conf"); 00089 config.default_logdir("./test-rconfig.dir/log.dir"); 00090 try { 00091 config.init(argc, argv); 00092 } 00093 catch(error e) { 00094 ERR_OUT(e); 00095 thrown = true; 00096 } 00097 catch(...) { 00098 assert(0); 00099 } 00100 assert(!thrown); 00101 assert(config.delete_old_log_files() == true); 00102 assert(config.delete_old_report_files() == true); 00103 } 00104 00105 int main(int argc, char const * argv[]) 00106 { 00107 cleanup(); 00108 setup(); 00109 try { 00110 test(); 00111 } 00112 catch(error e) { 00113 std::cerr << e; 00114 assert(0); 00115 } 00116 catch(...) { 00117 std::cerr << err_unknown; 00118 assert(0); 00119 } 00120 cleanup(); 00121 return(0); 00122 } 00123