Skip to content
Draft
Show file tree
Hide file tree
Changes from 6 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"
#include "storage/src/android/storage_internal_android.h"

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_
34 changes: 34 additions & 0 deletions storage/src/android/storage_reference_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
#include "app/src/include/firebase/app.h"
#include "app/src/util_android.h"
#include "storage/src/android/controller_android.h"
#include "storage/src/android/list_result_android.h" // Defines the android internal::ListResultInternal
#include "storage/src/android/metadata_android.h"
#include "storage/src/android/storage_android.h"
// firebase/storage/storage_reference.h is included via storage_reference_android.h
// app/src/future_manager.h is included via storage_reference_android.h -> reference_counted_future_impl.h
#include "storage/src/include/firebase/storage.h"
#include "storage/src/include/firebase/storage/common.h"
#include "storage/storage_resources.h"
Expand Down Expand Up @@ -734,6 +737,37 @@ jint StorageReferenceInternal::CppByteUploaderReadBytes(
return data_read;
}

Future<ListResult> StorageReferenceInternal::ListAll() {
StorageReference self(this); // Public self for future context
ReferenceCountedFutureImpl* ref_future =
future()->Alloc<ListResult>(kStorageReferenceFnCount);
Future<ListResult> future = MakeFuture(ref_future, self);

internal::ListResultInternal* list_pimpl =
new internal::ListResultInternal(this, nullptr); // 'this' is StorageReferenceInternal* (Android)

ListResult result_to_complete(list_pimpl);

ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
return future;
}

Future<ListResult> StorageReferenceInternal::List(const char* page_token) {
StorageReference self(this); // Public self for future context
ReferenceCountedFutureImpl* ref_future =
future()->Alloc<ListResult>(kStorageReferenceFnCount);
Future<ListResult> future = MakeFuture(ref_future, self);

// page_token is ignored for stub.
internal::ListResultInternal* list_pimpl =
new internal::ListResultInternal(this, nullptr);

ListResult result_to_complete(list_pimpl);

ref_future->Complete(self.AsHandle(), kErrorNone, "", result_to_complete);
return future;
}

} // namespace internal
} // namespace storage
} // namespace firebase
4 changes: 4 additions & 0 deletions storage/src/android/storage_reference_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "app/src/util_android.h"
#include "storage/src/android/storage_android.h"
#include "storage/src/include/firebase/storage/storage_reference.h"
#include "firebase/storage/list_result.h" // Added for ListResult return type

namespace firebase {
namespace storage {
Expand Down Expand Up @@ -153,6 +154,9 @@ class StorageReferenceInternal {
// StorageInternal instance we are associated with.
StorageInternal* storage_internal() const { return storage_; }

virtual Future<ListResult> ListAll();
virtual Future<ListResult> List(const char* page_token);

private:
static void FutureCallback(JNIEnv* env, jobject result,
util::FutureResult result_code,
Expand Down
Loading
Loading