File: TemporaryFiles.h

package info (click to toggle)
odc 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,252 kB
  • sloc: cpp: 21,453; f90: 2,610; python: 382; sh: 365; makefile: 30; sql: 25
file content (48 lines) | stat: -rw-r--r-- 1,359 bytes parent folder | download | duplicates (3)
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
/*
 * (C) Copyright 1996-2012 ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence Version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 * In applying this licence, ECMWF does not waive the privileges and immunities
 * granted to it by virtue of its status as an intergovernmental organisation nor
 * does it submit to any jurisdiction.
 */

#ifndef odc_tests_TemporaryODB_H
#define odc_tests_TemporaryODB_H

#include "eckit/filesystem/PathName.h"

#include "odc/Writer.h"

//----------------------------------------------------------------------------------------------------------------------

/// A class to be used as a fixture, which writes a temporary ODB file using the supplied
/// initialisation function, and then ensures that it is correctly cleaned up at the
/// end of the test.


class TemporaryFile {

public: // methods

    TemporaryFile() :
        path_(eckit::PathName::unique("_temporary_testing_file")) {}

    virtual ~TemporaryFile() {
        if (path_.exists()) {
            path_.unlink();
        }
    }

    const eckit::PathName& path() const { return path_; }

private: // members

    eckit::PathName path_;
};


//----------------------------------------------------------------------------------------------------------------------

#endif // odc_tests_TemporaryODB_H