Kea 2.2.0
testdata.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <string>
10#include <stdexcept>
11#include <fstream>
12#include <vector>
13
15
16using namespace std;
17
18namespace {
19vector<string>&
20getDataPaths() {
21 static vector<string> data_path;
22 return (data_path);
23}
24}
25
26namespace isc {
27namespace util {
28namespace unittests {
29
30void
31addTestDataPath(const string& path) {
32 getDataPaths().push_back(path);
33}
34
35void
36openTestData(const char* const datafile, ifstream& ifs) {
37 vector<string>::const_iterator it = getDataPaths().begin();
38 for (; it != getDataPaths().end(); ++it) {
39 string data_path = *it;
40 if (data_path.empty() || *data_path.rbegin() != '/') {
41 data_path.push_back('/');
42 }
43 ifs.open((data_path + datafile).c_str(), ios_base::in);
44 if (!ifs.fail()) {
45 return;
46 }
47 }
48
49 throw runtime_error("failed to open data file in data paths: " +
50 string(datafile));
51}
52
53}
54}
55}
void addTestDataPath(const string &path)
Add a path (directory) that openTestData() will search for test data files.
Definition: testdata.cc:31
void openTestData(const char *const datafile, ifstream &ifs)
Open a file specified by 'datafile' using the data paths registered via addTestDataPath().
Definition: testdata.cc:36
Defines the logger used by the top-level component of kea-lfc.
Manipulating test data files.