rvm  1.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-vaulter-005.cc
Go to the documentation of this file.
1 #include "config.h"
2 
3 #include <iostream>
4 #include <fstream>
5 #include <iomanip>
6 #include <string>
7 #include <cassert>
8 
9 #include "error.h"
10 #include "fs.h"
11 #include "vaulter.h"
12 #include "test-vaulter-setup.h"
13 
14 #define ERR_OUT(e) std::cerr << e
15 // #define ERR_OUT(e)
16 
17 void test_vaulter(void)
18 {
19  char const * argv[256] = { 0 };
20  int argc = 0;
21  bool thrown = false;
22 
23  argv[argc++] = "<program>";
24  argv[argc++] = "--archive";
25  argv[argc++] = "--timestamp";
26  argv[argc++] = "2003-09-21";
27 
28  config.default_file("./test-vaulter.dir/file-1.conf");
29  try {
30  config.init(argc, argv);
31  logger.init();
32  vaulter.init();
33  vaulter.select();
34  assert(vaulter.vault() == "./test-vaulter.dir/group-1/vault-1");
35 
37  assert(vaulter.deleted_archives().size() == 1);
38  assert(vaulter.deleted_archives()[0] == "2003-09-15");
39 
41  assert(vaulter.deleted_archives().size() == 2);
42  assert(vaulter.deleted_archives()[0] == "2003-09-15");
43  assert(vaulter.deleted_archives()[1] == "2003-09-18.incomplete");
44 
45  }
46  catch(error e) {
47  ERR_OUT(e);
48  thrown = true;
49  }
50  catch(...) {
52  assert(0);
53  }
54  assert(!thrown);
55 
56  std::cerr << std::endl;
57  std::cerr << " You should see an error message here:" << std::endl;
58  std::cerr << "-----------------------------------------" << std::endl;
59  try {
61  }
62  catch(error e) {
63  ERR_OUT(e);
64  thrown = true;
65  }
66  catch(...) {
68  assert(0);
69  }
70  std::cerr << "-----------------------------------------" << std::endl;
71  std::cerr << std::endl;
72  assert(thrown);
73 
74  assert(vaulter.deleted_archives().size() == 2);
75  assert(vaulter.deleted_archives()[0] == "2003-09-15");
76  assert(vaulter.deleted_archives()[1] == "2003-09-18.incomplete");
77  assert(vaulter.get_archive_list().size() == 1);
78  assert(vaulter.get_archive_list()[0] == "2003-09-21");
79 
80  thrown = false;
81  try {
82  logger.clear();
83  }
84  catch(error e) {
85  ERR_OUT(e);
86  thrown = true;
87  }
88  catch(...) {
90  assert(0);
91  }
92  assert(!thrown);
93 
94 }
95 
96 int main(int argc, char const * argv[])
97 {
98  cleanup();
99  setup();
100  try {
101  test_vaulter();
102  }
103  catch(error e) {
104  std::cerr << e;
105  assert(0);
106  }
107  catch(...) {
108  std::cerr << err_unknown;
109  assert(0);
110  }
111  cleanup();
112  return(0);
113 }
114 
void init(int argc, char const *argv[])
Initialize the configuration manager from rvm's command line options.
Definition: rconfig.cc:1218
log_manager logger
The global log manager.
Definition: logger.cc:138
void init(void)
Initialize the vault manager.
Definition: vaulter.cc:40
void setup(void)
Definition: test-logger.cc:62
#define ERR_OUT(e)
const std::vector< std::string > & deleted_archives(void) const
Return a list of deleted archives.
Definition: vaulter.cc:754
void default_file(const std::string &a_path)
Set the default configuration filename.
Definition: rconfig.cc:1484
void cleanup(void)
Definition: test-fs.cc:63
#define err_unknown
Definition: error.h:114
int main(int argc, char const *argv[])
void select(void)
Select a vault.
Definition: vaulter.cc:59
const subdirectory get_archive_list(void)
Return a list of archive directories in the selected vault.
Definition: vaulter.cc:262
An error class.
Definition: error.h:72
const std::string vault(void) const
Return the path to the selected vault.
Definition: vaulter.cc:291
void clear(void)
Clear the log manager.
Definition: logger.cc:32
void init(void)
Initialize the log manager.
Definition: logger.cc:42
configuration_manager config
The global configuration manager instance.
Definition: rconfig.cc:3364
void test_vaulter(void)
void delete_oldest_archive(void)
Find the oldest archive in the vault and delete it.
Definition: vaulter.cc:433
vault_manager vaulter
The global vault manager.
Definition: vaulter.cc:772