io_utils.h 1.53 KB
Newer Older
1
// Copyright (C) 2015-2017 Internet Systems Consortium, Inc. ("ISC")
2
//
3 4 5
// 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/.
6 7 8 9 10

#ifndef TEST_IO_UTILS_H
#define TEST_IO_UTILS_H

#include <string>
11
#include <sys/stat.h>
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

namespace isc {
namespace test {

/// @brief Checks if specified file exists.
///
/// @param file_path Path to a file.
/// @return true if the file exists, false otherwise.
bool fileExists(const std::string& file_path);

/// @brief Reads contents of the specified file.
///
/// @param file_path Path to a file.
/// @return File contents.
std::string readFile(const std::string& file_path);

28 29 30 31 32 33 34
/// @brief Removes comments from a JSON file
///
/// Removes //, # and /* */ comments from the input file and writes its content
/// to another file. The comments are replaced with spaces, so the original
/// token locations should remain unaffected. This is rather naive
/// implementation, but it's probably sufficient for testing. It won't be able
/// to pick any trickier cases, like # or // appearing in strings, nested C++
35
/// comments etc at the exception of // in URLs.
36 37 38 39 40 41
///
/// @param input_file file to be stripped of comments
/// @return filename of a new file that has comments stripped from it
/// @throw BadValue if the input file cannot be opened
std::string decommentJSONfile(const std::string& input_file);

42
}; // end of isc::test namespace
43 44 45
}; // end of isc namespace

#endif // TEST_IO_UTILS_H