Skip to content

Commit

Permalink
fix(tests): PackageFileSystem tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Nana <[email protected]>
  • Loading branch information
na2axl committed May 29, 2024
1 parent 3adc8b0 commit 879aa48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/IO/PackageFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace SparkyStudios::Audio::Amplitude
{
_packageFile->Close();
_packageFile.reset(nullptr);
_initialized = false;
}

bool PackageFileSystem::TryFinalizeCloseFileSystem()
Expand Down
45 changes: 23 additions & 22 deletions tests/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,47 +370,48 @@ TEST_CASE("PackageFileSystem Tests", "[filesystem][amplitude]")

SECTION("can use an initialized filesystem")
{
fileSystem.SetBasePath(AM_OS_STRING("./samples/assets.ampk"));
PackageFileSystem fs;
fs.SetBasePath(AM_OS_STRING("./samples/assets.ampk"));

fileSystem.StartOpenFileSystem();
while (!fileSystem.TryFinalizeOpenFileSystem())
fs.StartOpenFileSystem();
while (!fs.TryFinalizeOpenFileSystem())
Thread::Sleep(1);

SECTION("can sets the base path")
{
REQUIRE(fileSystem.GetBasePath() == std::filesystem::current_path() / AM_OS_STRING("samples/assets.ampk"));
}

SECTION("can reopen already opened filesystem")
{
REQUIRE(fileSystem.TryFinalizeOpenFileSystem());

fileSystem.StartOpenFileSystem();
while (!fileSystem.TryFinalizeOpenFileSystem())
Thread::Sleep(1);

REQUIRE(fileSystem.TryFinalizeOpenFileSystem());
REQUIRE(fs.GetBasePath() == std::filesystem::current_path() / AM_OS_STRING("samples/assets.ampk"));
}

SECTION("can check if files exists")
{
REQUIRE(fileSystem.Exists(AM_OS_STRING("tests.config.amconfig")));
REQUIRE_FALSE(fileSystem.Exists(AM_OS_STRING("some_random_file.ext")));
REQUIRE(fs.Exists(AM_OS_STRING("tests.config.amconfig")));
REQUIRE_FALSE(fs.Exists(AM_OS_STRING("some_random_file.ext")));
}

SECTION("can open files")
{
REQUIRE(fileSystem.OpenFile(AM_OS_STRING("tests.config.amconfig"))->IsValid());
REQUIRE(fileSystem.OpenFile(AM_OS_STRING("some_random_file.ext")) == nullptr);
REQUIRE(fs.OpenFile(AM_OS_STRING("tests.config.amconfig"))->IsValid());
REQUIRE(fs.OpenFile(AM_OS_STRING("some_random_file.ext")) == nullptr);
}

SECTION("can close filesystem")
{
fileSystem.StartCloseFileSystem();
while (!fileSystem.TryFinalizeCloseFileSystem())
fs.StartCloseFileSystem();
while (!fs.TryFinalizeCloseFileSystem())
Thread::Sleep(1);

REQUIRE(fs.TryFinalizeCloseFileSystem());
}

SECTION("can reopen already opened filesystem")
{
REQUIRE(fs.TryFinalizeOpenFileSystem());

fs.StartOpenFileSystem();
while (!fs.TryFinalizeOpenFileSystem())
Thread::Sleep(1);

REQUIRE(fileSystem.TryFinalizeCloseFileSystem());
REQUIRE(fs.TryFinalizeOpenFileSystem());
}
}
}

0 comments on commit 879aa48

Please sign in to comment.