Skip to content
Snippets Groups Projects
Select Git revision
  • da523f3d6fb1784863693f1a678839df16f5084f
  • develop default protected
  • feature/gmsh-reader
  • origin/stage/bouguettaia
  • feature/kinetic-schemes
  • feature/reconstruction
  • feature/local-dt-fsi
  • feature/composite-scheme-sources
  • feature/composite-scheme-other-fluxes
  • feature/serraille
  • feature/variational-hydro
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • master protected
  • feature/escobar-smoother
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

conanfile.py

Blame
    • Stéphane Del Pino's avatar
      da523f3d
      git subrepo commit packages/CLI11 · da523f3d
      Stéphane Del Pino authored
      subrepo:
        subdir:   "packages/CLI11"
        merged:   "76d2cde65"
      upstream:
        origin:   "git@github.com:CLIUtils/CLI11.git"
        branch:   "master"
        commit:   "76d2cde65"
      git-subrepo:
        version:  "0.4.0"
        origin:   "git@github.com:ingydotnet/git-subrepo.git"
        commit:   "5d6aba9"
      da523f3d
      History
      git subrepo commit packages/CLI11
      Stéphane Del Pino authored
      subrepo:
        subdir:   "packages/CLI11"
        merged:   "76d2cde65"
      upstream:
        origin:   "git@github.com:CLIUtils/CLI11.git"
        branch:   "master"
        commit:   "76d2cde65"
      git-subrepo:
        version:  "0.4.0"
        origin:   "git@github.com:ingydotnet/git-subrepo.git"
        commit:   "5d6aba9"
    test_OFStream.cpp 2.62 KiB
    #include <catch2/catch_test_macros.hpp>
    #include <catch2/matchers/catch_matchers_all.hpp>
    
    #include <language/utils/OFStream.hpp>
    #include <utils/Messenger.hpp>
    #include <utils/Stringify.hpp>
    
    #include <filesystem>
    
    #ifdef __linux__
    #include <fcntl.h>
    #include <linux/fs.h>
    #include <sys/ioctl.h>
    #endif   // __linux__
    
    // clazy:excludeall=non-pod-global-static
    
    TEST_CASE("OFStream", "[language]")
    {
      SECTION("ofstream")
      {
        const std::string basename =
          std::filesystem::path{PUGS_BINARY_DIR}.append("tests").append("ofstream_dir").append("ofstream_");
        const std::string filename = basename + stringify(parallel::rank());
    
        // Ensures that the file is closed after this line
        std::make_shared<OFStream>(filename) << "foo" << 3 << " bar\n";
    
        if (parallel::rank() == 0) {
          REQUIRE(std::filesystem::is_regular_file(filename));
    
          std::ifstream is(filename);
    
          char file_content[10];
          for (size_t i = 0; i < 10; ++i) {
            char c = is.get();
    
            file_content[i] = c;
            if (c == '\n') {
              file_content[i + 1] = '\0';
              REQUIRE(i == 8);
    
              c = is.get();
              REQUIRE(is.eof());
              break;
            }
          }
    
          std::string content = file_content;
          REQUIRE(content == "foo3 bar\n");
    
          std::filesystem::remove(filename);
        }
    
        REQUIRE(not std::filesystem::exists(filename));
      }
    
    #ifdef __linux__
      SECTION("invalid filename")
      {
        if (parallel::rank() == 0) {
          const std::string filename      = "tests/badpath/invalidpath/ofstream";
          std::filesystem::path directory = std::filesystem::path{filename}.parent_path();
          std::filesystem::create_directories(directory);
          std::filesystem::permissions(directory,
                                       std::filesystem::perms::owner_all | std::filesystem::perms::group_all |
                                         std::filesystem::perms::others_all,
                                       std::filesystem::perm_options::remove);
    
          int fd    = open("tests/badpath/invalidpath", O_DIRECTORY);
          int flags = FS_IMMUTABLE_FL;
          ioctl(fd, FS_IOC_SETFLAGS, &flags);
          REQUIRE_THROWS_WITH(std::make_shared<OFStream>(filename), "error: cannot create file " + filename);
    
          flags = 0;
          ioctl(fd, FS_IOC_SETFLAGS, &flags);
    
          std::filesystem::permissions(directory,
                                       std::filesystem::perms::owner_all | std::filesystem::perms::group_all |
                                         std::filesystem::perms::others_all,
                                       std::filesystem::perm_options::add);
          std::filesystem::remove_all("tests/badpath");
        }
      }
    #endif   // __linux__
    }