summaryrefslogtreecommitdiffstats
path: root/src/lib/util/unittests/testdata.h
blob: ee7c1c57536ae2aaf5d1d1c3fbbf94663178e76c (plain)
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
43
44
45
46
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef UTIL_UNITTESTS_TESTDATA_H
#define UTIL_UNITTESTS_TESTDATA_H 1

/**
 * \file testdata.h
 * \brief Manipulating test data files.
 *
 * This utility defines functions that help test case handle test data
 * stored in a file.
 */

namespace isc {
namespace util {
namespace unittests {
/// Add a path (directory) that \c openTestData() will search for test data
/// files.
void addTestDataPath(const std::string& path);

/// Open a file specified by 'datafile' using the data paths registered via
/// addTestDataPath().  On success, ifs will be ready for reading the data
/// stored in 'datafile'.  If the data file cannot be open with any of the
/// registered paths, a runtime_error exception will be thrown.
///
/// \note Care should be taken if you want to reuse the same single \c ifs
/// for multiple input data.  Some standard C++ library implementations retain
/// the failure bit if the first stream reaches the end of the first file,
/// and make the second call to \c ifstream::open() fail.  The safest way
/// is to use a different \c ifstream object for a new call to this function;
/// alternatively make sure you explicitly clear the error bit by calling
/// \c ifstream::clear() on \c ifs.
void openTestData(const char* const datafile, std::ifstream& ifs);
}
}
}

#endif // UTIL_UNITTESTS_TESTDATA_H

// Local Variables:
// mode: c++
// End: