Skip to content

StorageReference List stubs #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: feature/storagereference_list
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ set(android_SRCS
src/android/controller_android.cc
src/android/metadata_android.cc
src/android/storage_android.cc
src/android/storage_reference_android.cc)
src/android/storage_reference_android.cc
src/android/list_result_android.cc)

# Source files used by the iOS implementation.
set(ios_SRCS
Expand All @@ -47,7 +48,8 @@ set(ios_SRCS
src/ios/metadata_ios.mm
src/ios/storage_ios.mm
src/ios/storage_reference_ios.mm
src/ios/util_ios.mm)
src/ios/util_ios.mm
src/ios/list_result_ios.mm)

# Source files used by the desktop implementation.
set(desktop_SRCS
Expand All @@ -58,7 +60,8 @@ set(desktop_SRCS
src/desktop/rest_operation.cc
src/desktop/storage_desktop.cc
src/desktop/storage_path.cc
src/desktop/storage_reference_desktop.cc)
src/desktop/storage_reference_desktop.cc
src/desktop/list_result_desktop.cc)

if(ANDROID)
set(storage_platform_SRCS
Expand Down
72 changes: 72 additions & 0 deletions storage/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "firebase/auth.h"
#include "firebase/internal/platform.h"
#include "firebase/storage.h"
#include "firebase/storage/list_result.h"
#include "firebase/util.h"
#include "firebase_test_framework.h" // NOLINT

Expand Down Expand Up @@ -1622,4 +1623,75 @@ TEST_F(FirebaseStorageTest, TestInvalidatingReferencesWhenDeletingApp) {
InitializeAppAndAuth();
}

// Test the StorageReference::ListAll() method.
// This test currently only verifies that the stubbed method returns an empty result.
TEST_F(FirebaseStorageTest, TestListAll) {
if (skip_tests_) return;

firebase::storage::Storage* storage = storage_; // Use the member variable
firebase::storage::StorageReference reference = storage->GetReference();

firebase::Future<firebase::storage::ListResult> future = reference.ListAll();
WaitForCompletion(future, "ListAll");

ASSERT_EQ(future.status(), firebase::kFutureStatusComplete);
ASSERT_EQ(future.error(), firebase::storage::kErrorNone);

const firebase::storage::ListResult* result = future.result();
ASSERT_NE(result, nullptr);
if (result != nullptr) {
EXPECT_TRUE(result->items.empty());
EXPECT_TRUE(result->prefixes.empty());
EXPECT_TRUE(result->page_token.empty());
}
}

// Test the StorageReference::List() method with no page token.
// This test currently only verifies that the stubbed method returns an empty result.
TEST_F(FirebaseStorageTest, TestListNoPageToken) {
if (skip_tests_) return;

firebase::storage::Storage* storage = storage_; // Use the member variable
firebase::storage::StorageReference reference = storage->GetReference();

firebase::Future<firebase::storage::ListResult> future = reference.List();
WaitForCompletion(future, "List (no page token)");

ASSERT_EQ(future.status(), firebase::kFutureStatusComplete);
ASSERT_EQ(future.error(), firebase::storage::kErrorNone);

const firebase::storage::ListResult* result = future.result();
ASSERT_NE(result, nullptr);
if (result != nullptr) {
EXPECT_TRUE(result->items.empty());
EXPECT_TRUE(result->prefixes.empty());
EXPECT_TRUE(result->page_token.empty());
}
}

// Test the StorageReference::List() method with a page token.
// This test currently only verifies that the stubbed method returns an empty result
// and that the page token is passed (though not used by the stub).
TEST_F(FirebaseStorageTest, TestListWithPageToken) {
if (skip_tests_) return;

firebase::storage::Storage* storage = storage_; // Use the member variable
firebase::storage::StorageReference reference = storage->GetReference();
const char* page_token = "test_page_token";

firebase::Future<firebase::storage::ListResult> future = reference.List(page_token);
WaitForCompletion(future, "List (with page token)");

ASSERT_EQ(future.status(), firebase::kFutureStatusComplete);
ASSERT_EQ(future.error(), firebase::storage::kErrorNone);

const firebase::storage::ListResult* result = future.result();
ASSERT_NE(result, nullptr);
if (result != nullptr) {
EXPECT_TRUE(result->items.empty());
EXPECT_TRUE(result->prefixes.empty());
EXPECT_TRUE(result->page_token.empty());
}
}

} // namespace firebase_testapp_automated
21 changes: 21 additions & 0 deletions storage/src/android/list_result_android.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// File: storage/src/android/list_result_android.cc
#include "storage/src/android/list_result_android.h"

namespace firebase {
namespace storage {
namespace internal {

ListResultInternal::ListResultInternal(
StorageReferenceInternal* platform_sri,
const ListResultInternal* other_to_copy_from)
: platform_sri_(platform_sri) {
if (other_to_copy_from) {
items_ = other_to_copy_from->items_;
prefixes_ = other_to_copy_from->prefixes_;
page_token_ = other_to_copy_from->page_token_;
}
}

} // namespace internal
} // namespace storage
} // namespace firebase
46 changes: 46 additions & 0 deletions storage/src/android/list_result_android.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// File: storage/src/android/list_result_android.h
#ifndef FIREBASE_STORAGE_CLIENT_CPP_SRC_ANDROID_LIST_RESULT_ANDROID_H_
#define FIREBASE_STORAGE_CLIENT_CPP_SRC_ANDROID_LIST_RESULT_ANDROID_H_

#include <string>
#include <vector>

#include "firebase/storage/storage_reference.h"
#include "storage/src/android/storage_reference_android.h" // Defines firebase::storage::internal::StorageReferenceInternal for android
#include "storage/src/android/storage_internal_android.h" // Defines firebase::storage::internal::StorageInternal for android

namespace firebase {
namespace storage {
namespace internal {

class ListResultInternal {
public:
explicit ListResultInternal(
StorageReferenceInternal* platform_sri,
const ListResultInternal* other_to_copy_from = nullptr);

const std::vector<StorageReference>& items() const { return items_; }
const std::vector<StorageReference>& prefixes() const { return prefixes_; }
const std::string& page_token() const { return page_token_; }

StorageReferenceInternal* storage_reference_internal() const {
return platform_sri_;
}
StorageInternal* associated_storage_internal() const {
return platform_sri_ ? platform_sri_->storage_internal() : nullptr;
}

private:
ListResultInternal& operator=(const ListResultInternal&);

StorageReferenceInternal* platform_sri_;
std::vector<StorageReference> items_;
std::vector<StorageReference> prefixes_;
std::string page_token_;
};

} // namespace internal
} // namespace storage
} // namespace firebase

#endif // FIREBASE_STORAGE_CLIENT_CPP_SRC_ANDROID_LIST_RESULT_ANDROID_H_
1 change: 1 addition & 0 deletions storage/src/android/storage_reference_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "app/src/include/firebase/app.h"
#include "app/src/util_android.h"
#include "storage/src/android/controller_android.h"
// Removed: #include "storage/src/android/list_result_android.h"
#include "storage/src/android/metadata_android.h"
#include "storage/src/android/storage_android.h"
#include "storage/src/include/firebase/storage.h"
Expand Down
1 change: 1 addition & 0 deletions storage/src/android/storage_reference_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "app/src/reference_counted_future_impl.h"
#include "app/src/util_android.h"
#include "storage/src/android/storage_android.h"
// Removed: #include "storage/src/common/list_result_internal.h"
#include "storage/src/include/firebase/storage/storage_reference.h"

namespace firebase {
Expand Down
Loading
Loading