// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/archivist/archivist_fixture.h"

#include "flutter/fml/paths.h"

namespace impeller {
namespace testing {

ArchivistFixture::ArchivistFixture() {
  std::stringstream stream;
  stream << flutter::testing::GetCurrentTestName() << ".db";
  archive_file_name_ = fml::paths::JoinPaths(
      {flutter::testing::GetFixturesPath(), stream.str()});
}

ArchivistFixture::~ArchivistFixture() = default;

const std::string ArchivistFixture::GetArchiveFileName() const {
  return archive_file_name_;
}

void ArchivistFixture::SetUp() {
  DeleteArchiveFile();
}

void ArchivistFixture::TearDown() {
  // TODO: Tear this down. For now, I am inspecting the files for readability of
  // schema.
  // DeleteArchiveFile();
}

void ArchivistFixture::DeleteArchiveFile() const {
  fml::UnlinkFile(archive_file_name_.c_str());
}

}  // namespace testing
}  // namespace impeller

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "impeller/archivist/archivist_fixture.h"

#include "flutter/fml/paths.h"

namespace impeller {
namespace testing {

ArchivistFixture::ArchivistFixture() {
  std::stringstream stream;
  stream << "Test" << flutter::testing::GetCurrentTestName() << ".db";
  archive_file_name_ = stream.str();
}

ArchivistFixture::~ArchivistFixture() = default;

const std::string ArchivistFixture::GetArchiveFileName() const {
  return fml::paths::JoinPaths(
      {flutter::testing::GetFixturesPath(), archive_file_name_});
}

void ArchivistFixture::SetUp() {
  DeleteArchiveFile();
}

void ArchivistFixture::TearDown() {
  DeleteArchiveFile();
}

void ArchivistFixture::DeleteArchiveFile() const {
  auto fixtures = flutter::testing::OpenFixturesDirectory();
  if (fml::FileExists(fixtures, archive_file_name_.c_str())) {
    fml::UnlinkFile(fixtures, archive_file_name_.c_str());
  }
}

}  // namespace testing
}  // namespace impeller

Fix temporary database file deletion.
Fix temporary database file deletion.
