what to say about this
[ghsmtp.git] / CDB-test.cpp
blob2d1fff6d11e741d0aec35b150ac8110524be0123
1 #include "CDB.hpp"
3 #include "osutil.hpp"
5 #include <glog/logging.h>
7 #include <cstdio>
8 #include <fstream>
9 #include <iostream>
10 #include <string>
12 using namespace std::string_literals;
14 int main(int argc, char* argv[])
16 auto const config_dir = osutil::get_config_dir();
18 auto const no_database = config_dir / "unable-to-open-database";
19 CDB no_db;
20 CHECK(!no_db.open(no_database));
21 CHECK(!no_db.contains("foo"));
23 CDB accept_dom;
24 auto const accept_dom_path = config_dir / "accept_domains";
26 CHECK(accept_dom.open(accept_dom_path.c_str()));
28 // Ug, should not need c_str() here:
29 std::ifstream in(accept_dom_path.c_str(), std::ios::in | std::ios::binary);
31 if (!in.is_open())
32 std::perror(
33 ("error while opening file "s + accept_dom_path.string()).c_str());
35 std::string line;
36 getline(in, line);
37 if (in.bad())
38 perror(("error while reading file "s + accept_dom_path.string()).c_str());
39 in.close();
41 CHECK(accept_dom.contains(line));