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_vaulter1(void)
00018 {
00019 char *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-16";
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 logger.clear();
00035 assert(vaulter.vault() == "./test-vaulter.dir/group-1/vault-2");
00036 }
00037 catch(error e) {
00038 ERR_OUT(e);
00039 thrown = true;
00040 }
00041 catch(...) {
00042 ERR_OUT(err_unknown);
00043 assert(0);
00044 }
00045 assert(!thrown);
00046 }
00047
00048 void test_vaulter2(void)
00049 {
00050 char *argv[256] = { 0 };
00051 int argc = 0;
00052 bool thrown = false;
00053
00054 argv[argc++] = "<program>";
00055 argv[argc++] = "--archive";
00056 argv[argc++] = "--timestamp";
00057 argv[argc++] = "2003-09-18";
00058
00059 config.default_file("./test-vaulter.dir/file-1.conf");
00060 try {
00061 config.init(argc, argv);
00062 logger.init();
00063 vaulter.init();
00064 vaulter.select();
00065 logger.clear();
00066 assert(vaulter.vault() == "./test-vaulter.dir/group-1/vault-1");
00067 }
00068 catch(error e) {
00069 ERR_OUT(e);
00070 thrown = true;
00071 }
00072 catch(...) {
00073 ERR_OUT(err_unknown);
00074 assert(0);
00075 }
00076 assert(!thrown);
00077 }
00078
00079 void test_vaulter3(void)
00080 {
00081 char *argv[256] = { 0 };
00082 int argc = 0;
00083 bool thrown = false;
00084
00085 argv[argc++] = "<program>";
00086 argv[argc++] = "--archive";
00087 argv[argc++] = "--timestamp";
00088 argv[argc++] = "2003-09-18";
00089
00090 config.default_file("./test-vaulter.dir/file-1.conf");
00091 try {
00092 config.init(argc, argv);
00093 logger.init();
00094 vaulter.init();
00095 vaulter.select();
00096 logger.clear();
00097 assert(vaulter.vault() == "./test-vaulter.dir/group-1/vault-1");
00098
00099 subdirectory subdir = vaulter.get_archive_list();
00100 subdirectory::iterator sdi;
00101
00102 for (sdi = subdir.begin(); sdi != subdir.end(); sdi++) {
00103 assert((*sdi).find(".corrupt") == std::string::npos);
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 }
00116
00117 int main(int argc, char *argv[])
00118 {
00119 cleanup();
00120 setup();
00121 try {
00122 test_vaulter1();
00123 test_vaulter2();
00124 test_vaulter3();
00125 }
00126 catch(error e) {
00127 std::cerr << e;
00128 assert(0);
00129 }
00130 catch(...) {
00131 std::cerr << err_unknown;
00132 assert(0);
00133 }
00134 cleanup();
00135 return(0);
00136 }
00137