LCOV - code coverage report
Current view: top level - tests/unit/helpers - temporary_file.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 16 23 69.6 %
Date: 2024-04-30 13:21:35 Functions: 5 7 71.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain
       3             :   Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany
       4             : 
       5             :   This software was partially supported by the
       6             :   EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu).
       7             : 
       8             :   This software was partially supported by the
       9             :   ADA-FS project under the SPPEXA project funded by the DFG.
      10             : 
      11             :   This file is part of GekkoFS.
      12             : 
      13             :   GekkoFS is free software: you can redistribute it and/or modify
      14             :   it under the terms of the GNU General Public License as published by
      15             :   the Free Software Foundation, either version 3 of the License, or
      16             :   (at your option) any later version.
      17             : 
      18             :   GekkoFS is distributed in the hope that it will be useful,
      19             :   but WITHOUT ANY WARRANTY; without even the implied warranty of
      20             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      21             :   GNU General Public License for more details.
      22             : 
      23             :   You should have received a copy of the GNU General Public License
      24             :   along with GekkoFS.  If not, see <https://www.gnu.org/licenses/>.
      25             : 
      26             :   SPDX-License-Identifier: GPL-3.0-or-later
      27             : */
      28             : 
      29             : #include "helpers.hpp"
      30             : 
      31             : namespace fs = std::filesystem;
      32             : 
      33             : namespace helpers {
      34             : 
      35           3 : temporary_file::temporary_file(fs::path filename)
      36           6 :     : filename_(std::move(filename)), ofs_(filename_) {}
      37             : 
      38           3 : temporary_file::temporary_file(fs::path filename, const std::string_view& text)
      39           3 :     : filename_(std::move(filename)), ofs_(filename_) {
      40           3 :     write(text);
      41           3 : }
      42             : 
      43           6 : temporary_file::~temporary_file() {
      44           6 :     ofs_.close();
      45           6 :     fs::remove(filename_);
      46           6 : }
      47             : 
      48             : void
      49           5 : temporary_file::write(const std::string_view& text) {
      50           5 :     ofs_ << text;
      51           5 :     ofs_.flush();
      52           5 : }
      53             : 
      54             : void
      55           0 : temporary_file::write(const std::vector<char>& data) {
      56           0 :     for(const auto n : data) {
      57           0 :         ofs_ << n;
      58             :     }
      59           0 :     ofs_.flush();
      60           0 : }
      61             : 
      62             : fs::path
      63           7 : temporary_file::filename() const {
      64           7 :     return filename_;
      65             : }
      66             : 
      67             : std::size_t
      68           0 : temporary_file::size() const {
      69           0 :     return fs::file_size(filename_);
      70             : }
      71             : 
      72             : } // namespace helpers

Generated by: LCOV version 1.16