00001 #include "config.h" 00002 00003 #include <iostream> 00004 #include <fstream> 00005 #include <iomanip> 00006 #include <string> 00007 #include <cassert> 00008 00009 #include "asserts.h" 00010 #include "error.h" 00011 #include "fs.h" 00012 #include "vaulter.h" 00013 00014 bool make_dir(const std::string& path) 00015 { 00016 bool thrown; 00017 00018 thrown = false; 00019 try { 00020 mk_dir(path); 00021 } 00022 catch(...) { 00023 thrown = true; 00024 } 00025 00026 return(thrown == false); 00027 } 00028 00029 void setup(void) 00030 { 00031 std::ofstream out; 00032 00033 assert(make_dir("./test-vaulter.dir")); 00034 assert(make_dir("./test-vaulter.dir/group-1")); 00035 assert(make_dir("./test-vaulter.dir/group-1/vault-1")); 00036 assert(make_dir("./test-vaulter.dir/group-1/vault-2")); 00037 assert(make_dir("./test-vaulter.dir/group-1/vault-3")); 00038 assert(make_dir("./test-vaulter.dir/group-1/vault-1/2003-09-15")); 00039 assert(make_dir("./test-vaulter.dir/group-1/vault-2/2003-09-16")); 00040 assert(make_dir("./test-vaulter.dir/group-1/vault-3/2003-09-17")); 00041 assert(make_dir("./test-vaulter.dir/group-1/vault-1/2003-09-18.incomplete")); 00042 assert(make_dir("./test-vaulter.dir/group-1/vault-1/2003-09-18.corrupt")); 00043 assert(make_dir("./test-vaulter.dir/group-1/vault-2/2003-09-19")); 00044 assert(make_dir("./test-vaulter.dir/group-1/vault-3/2003-09-20")); 00045 assert(make_dir("./test-vaulter.dir/group-1/vault-1/2003-09-21")); 00046 assert(make_dir("./test-vaulter.dir/group-1/vault-2/2003-09-22")); 00047 assert(make_dir("./test-vaulter.dir/group-2")); 00048 assert(make_dir("./test-vaulter.dir/group-2/vault-1")); 00049 assert(make_dir("./test-vaulter.dir/group-2/vault-2")); 00050 assert(make_dir("./test-vaulter.dir/group-2/vault-3")); 00051 assert(make_dir("./test-vaulter.dir/group-2/vault-1/2003-09-15")); 00052 assert(make_dir("./test-vaulter.dir/group-2/vault-2/2003-09-16")); 00053 assert(make_dir("./test-vaulter.dir/group-2/vault-3/2003-09-17")); 00054 assert(make_dir("./test-vaulter.dir/group-2/vault-1/2003-09-18")); 00055 assert(make_dir("./test-vaulter.dir/group-2/vault-2/2003-09-19")); 00056 assert(make_dir("./test-vaulter.dir/group-2/vault-3/2003-09-20")); 00057 assert(make_dir("./test-vaulter.dir/group-2/vault-1/2003-09-21")); 00058 assert(make_dir("./test-vaulter.dir/log.dir")); 00059 assert(make_dir("./test-vaulter.dir/log.dir/log-1.dir")); 00060 assert(make_dir("./test-vaulter.dir/log.dir/log-2.dir")); 00061 00062 out.open("./test-vaulter.dir/file-1.conf"); 00063 assert(out.is_open()); 00064 out << "log-dir ./test-vaulter.dir/log.dir/log-1.dir" << std::endl; 00065 out << "vault ./test-vaulter.dir/group-1/*" << std::endl; 00066 out << "vault-selection-behavior round-robin" << std::endl; 00067 out.close(); 00068 00069 assert(make_dir("./test-vaulter.dir/log.dir/log-3.dir")); 00070 assert(make_dir("./test-vaulter.dir/group-3")); 00071 assert(make_dir("./test-vaulter.dir/group-3/vault-1")); 00072 assert(make_dir("./test-vaulter.dir/group-3/vault-1/2006-06-20")); 00073 assert(make_dir("./test-vaulter.dir/group-3/vault-1/2006-06-21")); 00074 assert(make_dir("./test-vaulter.dir/group-3/vault-1/2006-06-22")); 00075 assert(make_dir("./test-vaulter.dir/group-3/vault-1/2006-06-23")); 00076 assert(make_dir("./test-vaulter.dir/group-3/vault-1/2006-06-24")); 00077 00078 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-20.log"); 00079 assert(out.is_open()); 00080 out << "Hello World" << std::endl; 00081 out.close(); 00082 00083 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-20.report"); 00084 assert(out.is_open()); 00085 out << "Hello World" << std::endl; 00086 out.close(); 00087 00088 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-21.relink"); 00089 assert(out.is_open()); 00090 out << "Hello World" << std::endl; 00091 out.close(); 00092 00093 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-22.log"); 00094 assert(out.is_open()); 00095 out << "Hello World" << std::endl; 00096 out.close(); 00097 00098 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-22.report"); 00099 assert(out.is_open()); 00100 out << "Hello World" << std::endl; 00101 out.close(); 00102 00103 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-23.log"); 00104 assert(out.is_open()); 00105 out << "Hello World" << std::endl; 00106 out.close(); 00107 00108 out.open("./test-vaulter.dir/log.dir/log-3.dir/2006-06-23.report"); 00109 assert(out.is_open()); 00110 out << "Hello World" << std::endl; 00111 out.close(); 00112 00113 out.open("./test-vaulter.dir/file-2.conf"); 00114 assert(out.is_open()); 00115 out << "log-dir ./test-vaulter.dir/log.dir/log-3.dir" << std::endl; 00116 out << "delete-old-log-files yes" << std::endl; 00117 out << "vault ./test-vaulter.dir/group-3/*" << std::endl; 00118 out << "vault-selection-behavior round-robin" << std::endl; 00119 out.close(); 00120 00121 out.open("./test-vaulter.dir/file-3.conf"); 00122 assert(out.is_open()); 00123 out << "log-dir ./test-vaulter.dir/log.dir/log-3.dir" << std::endl; 00124 out << "delete-old-report-files yes" << std::endl; 00125 out << "vault ./test-vaulter.dir/group-3/*" << std::endl; 00126 out << "vault-selection-behavior round-robin" << std::endl; 00127 out.close(); 00128 00129 out.open("./test-vaulter.dir/file-4.conf"); 00130 assert(out.is_open()); 00131 out << "log-dir ./test-vaulter.dir/log.dir/log-3.dir" << std::endl; 00132 out << "delete-old-log-files yes" << std::endl; 00133 out << "delete-old-report-files yes" << std::endl; 00134 out << "vault ./test-vaulter.dir/group-3/*" << std::endl; 00135 out << "vault-selection-behavior round-robin" << std::endl; 00136 out.close(); 00137 00138 out.open("./test-vaulter.dir/file-5.conf"); 00139 assert(out.is_open()); 00140 out << "log-dir ./test-vaulter.dir/log.dir/log-3.dir" << std::endl; 00141 out << "vault ./test-vaulter.dir/group-3/*" << std::endl; 00142 out << "vault-selection-behavior round-robin" << std::endl; 00143 out.close(); 00144 } 00145 00146 void cleanup(void) 00147 { 00148 system("rm -fr ./test-vaulter.dir"); 00149 } 00150