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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2014-2018 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 LEASE_FILE_IO_H
#define LEASE_FILE_IO_H

#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace isc {
namespace dhcp {
namespace test {

/// @brief This class contains functions to perform IO operations on files.
///
/// This class is solely used by unit tests. Some tests often need files
/// as an input. This class allows for easy creation of text files that can
/// be later used by unit tests. It also provides method to read the contents
/// of the existing file and remove existing file (cleanup after unit test).
class LeaseFileIO {
public:
    /// @brief Constructor
    ///
    /// @param filename Absolute path to the file.
    /// @param recreate A boolean flag indicating if the new file should
    /// be created, even if one exists.
    LeaseFileIO(const std::string& filename, const bool recreate = true);

    /// @brief Destructor.
    ~LeaseFileIO();

    /// @brief Check if test file exists on disk.
    bool exists() const;

    /// @brief Reads whole lease file.
    ///
    /// @return Contents of the file.
    std::string readFile() const;

    /// @brief Removes existing file (if any).
    void removeFile() const;

    /// @brief Creates file with contents.
    ///
    /// @param contents Contents of the file.
    void writeFile(const std::string& contents) const;

    /// @brief Absolute path to the file used in the tests.
    std::string testfile_;

    /// @brief Indicates if the file should be recreated during object
    /// construction and removed during destruction.
    bool recreate_;

};

}
}
}

#endif // LEASE_FILE_IO_H