Kea 2.5.8
testdata.cc
Go to the documentation of this file.
1// Copyright (C) 2011-2024 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 for (auto const& it : getDataPaths()) {
38 string data_path = it;
39 if (data_path.empty() || *data_path.rbegin() != '/') {
40 data_path.push_back('/');
41 }
42 ifs.open((data_path + datafile).c_str(), ios_base::in);
43 if (!ifs.fail()) {
44 return;
45 }
46 }
47
48 throw runtime_error("failed to open data file in data paths: " +
49 string(datafile));
50}
51
52}
53}
54}
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.