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 // #define ERR_OUT(e) 00016 00017 void test_vaulter(void) 00018 { 00019 char const * argv[256] = { 0 }; 00020 int argc = 0; 00021 bool thrown = false; 00022 00023 argv[argc++] = "<program>"; 00024 argv[argc++] = "--archive"; 00025 argv[argc++] = "--timestamp"; 00026 argv[argc++] = "2003-09-21"; 00027 00028 config.default_file("./test-vaulter.dir/file-1.conf"); 00029 try { 00030 config.init(argc, argv); 00031 logger.init(); 00032 vaulter.init(); 00033 vaulter.select(); 00034 assert(vaulter.vault() == "./test-vaulter.dir/group-1/vault-1"); 00035 00036 vaulter.delete_oldest_archive(); 00037 assert(vaulter.deleted_archives().size() == 1); 00038 assert(vaulter.deleted_archives()[0] == "2003-09-15"); 00039 00040 vaulter.delete_oldest_archive(); 00041 assert(vaulter.deleted_archives().size() == 2); 00042 assert(vaulter.deleted_archives()[0] == "2003-09-15"); 00043 assert(vaulter.deleted_archives()[1] == "2003-09-18.incomplete"); 00044 00045 } 00046 catch(error e) { 00047 ERR_OUT(e); 00048 thrown = true; 00049 } 00050 catch(...) { 00051 ERR_OUT(err_unknown); 00052 assert(0); 00053 } 00054 assert(!thrown); 00055 00056 std::cerr << std::endl; 00057 std::cerr << " You should see an error message here:" << std::endl; 00058 std::cerr << "-----------------------------------------" << std::endl; 00059 try { 00060 vaulter.delete_oldest_archive(); 00061 } 00062 catch(error e) { 00063 ERR_OUT(e); 00064 thrown = true; 00065 } 00066 catch(...) { 00067 ERR_OUT(err_unknown); 00068 assert(0); 00069 } 00070 std::cerr << "-----------------------------------------" << std::endl; 00071 std::cerr << std::endl; 00072 assert(thrown); 00073 00074 assert(vaulter.deleted_archives().size() == 2); 00075 assert(vaulter.deleted_archives()[0] == "2003-09-15"); 00076 assert(vaulter.deleted_archives()[1] == "2003-09-18.incomplete"); 00077 assert(vaulter.get_archive_list().size() == 1); 00078 assert(vaulter.get_archive_list()[0] == "2003-09-21"); 00079 00080 thrown = false; 00081 try { 00082 logger.clear(); 00083 } 00084 catch(error e) { 00085 ERR_OUT(e); 00086 thrown = true; 00087 } 00088 catch(...) { 00089 ERR_OUT(err_unknown); 00090 assert(0); 00091 } 00092 assert(!thrown); 00093 00094 } 00095 00096 int main(int argc, char const * argv[]) 00097 { 00098 cleanup(); 00099 setup(); 00100 try { 00101 test_vaulter(); 00102 } 00103 catch(error e) { 00104 std::cerr << e; 00105 assert(0); 00106 } 00107 catch(...) { 00108 std::cerr << err_unknown; 00109 assert(0); 00110 } 00111 cleanup(); 00112 return(0); 00113 } 00114