Kea 2.7.6
sandbox.h
Go to the documentation of this file.
1// Copyright (C) 2019-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#ifndef SANDBOX_H
8#define SANDBOX_H
9
11
12#include <iostream>
13#include <string>
14#include <cstdlib>
15#include <cstdio>
16#include <unistd.h>
17#include <ftw.h>
18
19namespace isc {
20namespace test {
21
28class Sandbox {
29private:
31 std::string path_;
32
36 static int rmFile(const char *fpath, const struct stat *, int , struct FTW *) {
37 return(remove(fpath));
38 }
39
40public:
43 char tmpl[] = {P_tmpdir "/kea-XXXXXX"};
44 path_ = mkdtemp(tmpl);
45 }
46
49 // Delete content of path_ recursively.
50 if (nftw(path_.c_str(), Sandbox::rmFile, 10, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) < 0) {
51 auto msg = "Some error occurred while deleting unit test sandbox " + path_;
52 std::perror(msg.c_str());
53 exit(1);
54 }
55 }
56
60 std::string join(std::string file) {
61 return (path_ + "/" + file);
62 }
63};
64
65
66} // end of isc::test namespace
67} // end of isc namespace
68
69#endif // SANDBOX_H
A Sandbox class that provides access to unit test unique temporary folder.
Definition sandbox.h:28
~Sandbox()
Destructor, it deletes temporary folder with its content.
Definition sandbox.h:48
Sandbox()
Sandbox constructor.
Definition sandbox.h:42
std::string join(std::string file)
Join sandbox path with indicated file subpath.
Definition sandbox.h:60
Defines the logger used by the top-level component of kea-lfc.