00001 #include "config.h"
00002
00003 #include <iostream>
00004 #include <fstream>
00005 #include <iomanip>
00006 #include <string>
00007 #include <cassert>
00008
00009 #include "error.h"
00010 #include "fs.h"
00011 #include "vaulter.h"
00012 #include "test-vaulter-setup.h"
00013
00014 #define ERR_OUT(e) std::cerr << e
00015
00016
00017 void test_vaulter(void)
00018 {
00019 char const * argv[256] = { 0 };
00020 int argc = 0;
00021 bool thrown = false;
00022 subdirectory subdir;
00023
00024 argv[argc++] = "<program>";
00025 argv[argc++] = "--archive";
00026 argv[argc++] = "--timestamp";
00027 argv[argc++] = "2003-09-21";
00028
00029 config.default_file("./test-vaulter.dir/file-2.conf");
00030 try {
00031 config.init(argc, argv);
00032 logger.init();
00033 vaulter.init();
00034 vaulter.select();
00035 vaulter.delete_oldest_archive();
00036
00037 }
00038 catch(error e) {
00039 ERR_OUT(e);
00040 thrown = true;
00041 }
00042 catch(...) {
00043 ERR_OUT(err_unknown);
00044 assert(0);
00045 }
00046 assert(!thrown);
00047 assert(vaulter.deleted_archives().size() == 1);
00048 assert(vaulter.deleted_archives()[0] == "2006-06-20");
00049
00050 subdir.path("./test-vaulter.dir/log.dir/log-3.dir");
00051 assert(find(subdir.begin(),subdir.end(),"2006-06-20.log") == subdir.end());
00052 assert(find(subdir.begin(),subdir.end(),"2006-06-20.report") != subdir.end());
00053 assert(find(subdir.begin(),subdir.end(),"2006-06-21.relink") != subdir.end());
00054 assert(find(subdir.begin(),subdir.end(),"2006-06-22.log") != subdir.end());
00055 assert(find(subdir.begin(),subdir.end(),"2006-06-22.report") != subdir.end());
00056 assert(find(subdir.begin(),subdir.end(),"2006-06-23.log") != subdir.end());
00057 assert(find(subdir.begin(),subdir.end(),"2006-06-23.report") != subdir.end());
00058
00059 config.clear();
00060 logger.clear();
00061 vaulter.clear();
00062
00063 config.default_file("./test-vaulter.dir/file-2.conf");
00064 try {
00065 config.init(argc, argv);
00066 logger.init();
00067 vaulter.init();
00068 vaulter.select();
00069 vaulter.delete_oldest_archive();
00070
00071 }
00072 catch(error e) {
00073 ERR_OUT(e);
00074 thrown = true;
00075 }
00076 catch(...) {
00077 ERR_OUT(err_unknown);
00078 assert(0);
00079 }
00080 assert(!thrown);
00081 assert(vaulter.deleted_archives().size() == 1);
00082 assert(vaulter.deleted_archives()[0] == "2006-06-21");
00083
00084 subdir.path("./test-vaulter.dir/log.dir/log-3.dir");
00085 assert(find(subdir.begin(),subdir.end(),"2006-06-20.log") == subdir.end());
00086 assert(find(subdir.begin(),subdir.end(),"2006-06-20.report") != subdir.end());
00087 assert(find(subdir.begin(),subdir.end(),"2006-06-21.relink") == subdir.end());
00088 assert(find(subdir.begin(),subdir.end(),"2006-06-22.log") != subdir.end());
00089 assert(find(subdir.begin(),subdir.end(),"2006-06-22.report") != subdir.end());
00090 assert(find(subdir.begin(),subdir.end(),"2006-06-23.log") != subdir.end());
00091 assert(find(subdir.begin(),subdir.end(),"2006-06-23.report") != subdir.end());
00092
00093 config.clear();
00094 logger.clear();
00095 vaulter.clear();
00096
00097 config.default_file("./test-vaulter.dir/file-3.conf");
00098 try {
00099 config.init(argc, argv);
00100 logger.init();
00101 vaulter.init();
00102 vaulter.select();
00103 vaulter.delete_oldest_archive();
00104
00105 }
00106 catch(error e) {
00107 ERR_OUT(e);
00108 thrown = true;
00109 }
00110 catch(...) {
00111 ERR_OUT(err_unknown);
00112 assert(0);
00113 }
00114 assert(!thrown);
00115 assert(vaulter.deleted_archives().size() == 1);
00116 assert(vaulter.deleted_archives()[0] == "2006-06-22");
00117
00118 subdir.path("./test-vaulter.dir/log.dir/log-3.dir");
00119 assert(find(subdir.begin(),subdir.end(),"2006-06-20.log") == subdir.end());
00120 assert(find(subdir.begin(),subdir.end(),"2006-06-20.report") != subdir.end());
00121 assert(find(subdir.begin(),subdir.end(),"2006-06-21.relink") == subdir.end());
00122 assert(find(subdir.begin(),subdir.end(),"2006-06-22.log") != subdir.end());
00123 assert(find(subdir.begin(),subdir.end(),"2006-06-22.report") == subdir.end());
00124 assert(find(subdir.begin(),subdir.end(),"2006-06-23.log") != subdir.end());
00125 assert(find(subdir.begin(),subdir.end(),"2006-06-23.report") != subdir.end());
00126
00127 config.clear();
00128 logger.clear();
00129 vaulter.clear();
00130
00131 config.default_file("./test-vaulter.dir/file-4.conf");
00132 try {
00133 config.init(argc, argv);
00134 logger.init();
00135 vaulter.init();
00136 vaulter.select();
00137 vaulter.delete_oldest_archive();
00138
00139 }
00140 catch(error e) {
00141 ERR_OUT(e);
00142 thrown = true;
00143 }
00144 catch(...) {
00145 ERR_OUT(err_unknown);
00146 assert(0);
00147 }
00148 assert(!thrown);
00149 assert(vaulter.deleted_archives().size() == 1);
00150 assert(vaulter.deleted_archives()[0] == "2006-06-23");
00151
00152 subdir.path("./test-vaulter.dir/log.dir/log-3.dir");
00153 assert(find(subdir.begin(),subdir.end(),"2006-06-20.log") == subdir.end());
00154 assert(find(subdir.begin(),subdir.end(),"2006-06-20.report") != subdir.end());
00155 assert(find(subdir.begin(),subdir.end(),"2006-06-21.relink") == subdir.end());
00156 assert(find(subdir.begin(),subdir.end(),"2006-06-22.log") != subdir.end());
00157 assert(find(subdir.begin(),subdir.end(),"2006-06-22.report") == subdir.end());
00158 assert(find(subdir.begin(),subdir.end(),"2006-06-23.log") == subdir.end());
00159 assert(find(subdir.begin(),subdir.end(),"2006-06-23.report") == subdir.end());
00160
00161 config.clear();
00162 logger.clear();
00163 vaulter.clear();
00164
00165 config.default_file("./test-vaulter.dir/file-4.conf");
00166 try {
00167 config.init(argc, argv);
00168 logger.init();
00169 vaulter.init();
00170 vaulter.select();
00171 vaulter.delete_oldest_archive();
00172
00173 }
00174 catch(error e) {
00175 ERR_OUT(e);
00176 thrown = true;
00177 }
00178 catch(...) {
00179 ERR_OUT(err_unknown);
00180 assert(0);
00181 }
00182 assert(!thrown);
00183 assert(vaulter.deleted_archives().size() == 1);
00184 assert(vaulter.deleted_archives()[0] == "2006-06-24");
00185
00186 subdir.path("./test-vaulter.dir/log.dir/log-3.dir");
00187 assert(find(subdir.begin(),subdir.end(),"2006-06-20.log") == subdir.end());
00188 assert(find(subdir.begin(),subdir.end(),"2006-06-20.report") != subdir.end());
00189 assert(find(subdir.begin(),subdir.end(),"2006-06-21.relink") == subdir.end());
00190 assert(find(subdir.begin(),subdir.end(),"2006-06-22.log") != subdir.end());
00191 assert(find(subdir.begin(),subdir.end(),"2006-06-22.report") == subdir.end());
00192 assert(find(subdir.begin(),subdir.end(),"2006-06-23.log") == subdir.end());
00193 assert(find(subdir.begin(),subdir.end(),"2006-06-23.report") == subdir.end());
00194 }
00195
00196 int main(int argc, char const * argv[])
00197 {
00198 cleanup();
00199 setup();
00200 try {
00201 test_vaulter();
00202 }
00203 catch(error e) {
00204 std::cerr << e;
00205 assert(0);
00206 }
00207 catch(...) {
00208 std::cerr << err_unknown;
00209 assert(0);
00210 }
00211 cleanup();
00212 return(0);
00213 }
00214