-
Notifications
You must be signed in to change notification settings - Fork 3
/
CDB-test.cpp
42 lines (30 loc) · 991 Bytes
/
CDB-test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "CDB.hpp"
#include "osutil.hpp"
#include <glog/logging.h>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string>
using namespace std::string_literals;
int main(int argc, char* argv[])
{
auto const config_dir = osutil::get_config_dir();
auto const no_database = config_dir / "unable-to-open-database";
CDB no_db;
CHECK(!no_db.open(no_database));
CHECK(!no_db.contains("foo"));
CDB accept_dom;
auto const accept_dom_path = config_dir / "accept_domains";
CHECK(accept_dom.open(accept_dom_path.c_str()));
// Ug, should not need c_str() here:
std::ifstream in(accept_dom_path.c_str(), std::ios::in | std::ios::binary);
if (!in.is_open())
std::perror(
("error while opening file "s + accept_dom_path.string()).c_str());
std::string line;
getline(in, line);
if (in.bad())
perror(("error while reading file "s + accept_dom_path.string()).c_str());
in.close();
CHECK(accept_dom.contains(line));
}