Skip to content

Commit

Permalink
feat(data): add StandardArchive::initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 29, 2024
1 parent f51baee commit 2910005
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/include/cubos/core/data/fs/standard_archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ namespace cubos::core::data
/// @param readOnly True if the archive is read-only, false otherwise.
StandardArchive(const std::filesystem::path& osPath, bool isDirectory, bool readOnly);

/// @brief Checks if the archive was successfully initialized.
/// @return True if the archive was successfully initialized, false otherwise.
bool initialized() const;

std::size_t create(std::size_t parent, std::string_view name, bool directory = false) override;
bool destroy(std::size_t id) override;
std::string name(std::size_t id) const override;
Expand Down
5 changes: 5 additions & 0 deletions core/src/data/fs/standard_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ void StandardArchive::generate(std::size_t parent)
}
}

bool StandardArchive::initialized() const
{
return !mFiles.empty();
}

std::size_t StandardArchive::create(std::size_t parent, std::string_view name, bool directory)
{
INIT_OR_RETURN(0);
Expand Down
4 changes: 4 additions & 0 deletions core/tests/data/fs/standard_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ using cubos::core::memory::Stream;
static void assertInitializationFailed(StandardArchive& archive)
{
REQUIRE_FALSE(archive.directory(1)); // Independently of it was created as a directory or not.
REQUIRE_FALSE(archive.initialized());
REQUIRE(archive.parent(1) == 0);
REQUIRE(archive.sibling(1) == 0);
REQUIRE(archive.child(1) == 0);
Expand Down Expand Up @@ -62,6 +63,7 @@ TEST_CASE("data::StandardArchive") // NOLINT(readability-function-size)

// Check if the structure is correct.
CHECK(archive.readOnly() == readOnly);
CHECK(archive.initialized());
CHECK(archive.parent(1) == 0);
CHECK(archive.sibling(1) == 0);
CHECK(archive.child(1) == 0);
Expand Down Expand Up @@ -133,6 +135,7 @@ TEST_CASE("data::StandardArchive") // NOLINT(readability-function-size)
{
archive = std::make_unique<StandardArchive>(path, true, false);
CHECK_FALSE(archive->readOnly());
CHECK(archive->initialized());

// Check initial structure.
CHECK(archive->parent(1) == 0);
Expand Down Expand Up @@ -220,6 +223,7 @@ TEST_CASE("data::StandardArchive") // NOLINT(readability-function-size)
// Create a read-only archive on the generated directory.
archive = std::make_unique<StandardArchive>(path, true, true);
CHECK(archive->readOnly());
CHECK(archive->initialized());

// Check root.
CHECK(archive->directory(1));
Expand Down

0 comments on commit 2910005

Please sign in to comment.