summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_directory_reader.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/tests/test_directory_reader.cc')
-rw-r--r--ppapi/tests/test_directory_reader.cc131
1 files changed, 61 insertions, 70 deletions
diff --git a/ppapi/tests/test_directory_reader.cc b/ppapi/tests/test_directory_reader.cc
index 254a355..6f23bcaf 100644
--- a/ppapi/tests/test_directory_reader.cc
+++ b/ppapi/tests/test_directory_reader.cc
@@ -23,63 +23,63 @@ REGISTER_TEST_CASE(DirectoryReader);
namespace {
+typedef std::vector<pp::DirectoryEntry_Dev> Entries;
+
std::string IntegerToString(int value) {
char result[12];
sprintf(result, "%d", value);
return result;
}
-int32_t DeleteDirectoryRecursively(pp::FileRef* dir,
- TestCompletionCallback* callback) {
- if (!dir || !callback)
+} // namespace
+
+bool TestDirectoryReader::Init() {
+ return CheckTestingInterface() && EnsureRunningOverHTTP();
+}
+
+void TestDirectoryReader::RunTests(const std::string& filter) {
+ RUN_TEST(ReadEntries, filter);
+}
+
+int32_t TestDirectoryReader::DeleteDirectoryRecursively(pp::FileRef* dir) {
+ if (!dir)
return PP_ERROR_BADARGUMENT;
+ TestCompletionCallback callback(instance_->pp_instance(), force_async_);
+ TestCompletionCallbackWithOutput<Entries> output_callback(
+ instance_->pp_instance(), force_async_);
+
int32_t rv = PP_OK;
pp::DirectoryReader_Dev directory_reader(*dir);
- std::vector<pp::DirectoryEntry_Dev> entries;
- pp::DirectoryEntry_Dev entry;
- do {
- rv = directory_reader.GetNextEntry(&entry, *callback);
- if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback->WaitForResult();
- if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND)
- return rv;
- if (!entry.is_null())
- entries.push_back(entry);
- } while (!entry.is_null());
-
- for (std::vector<pp::DirectoryEntry_Dev>::const_iterator it = entries.begin();
+ rv = directory_reader.ReadEntries(output_callback);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = output_callback.WaitForResult();
+ if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND)
+ return rv;
+
+ Entries entries = output_callback.output();
+ for (Entries::const_iterator it = entries.begin();
it != entries.end(); ++it) {
pp::FileRef file_ref = it->file_ref();
if (it->file_type() == PP_FILETYPE_DIRECTORY) {
- rv = DeleteDirectoryRecursively(&file_ref, callback);
+ rv = DeleteDirectoryRecursively(&file_ref);
if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND)
return rv;
} else {
- rv = file_ref.Delete(*callback);
+ rv = file_ref.Delete(callback);
if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback->WaitForResult();
+ rv = callback.WaitForResult();
if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND)
return rv;
}
}
- rv = dir->Delete(*callback);
+ rv = dir->Delete(callback);
if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback->WaitForResult();
+ rv = callback.WaitForResult();
return rv;
}
-} // namespace
-
-bool TestDirectoryReader::Init() {
- return CheckTestingInterface() && EnsureRunningOverHTTP();
-}
-
-void TestDirectoryReader::RunTests(const std::string& filter) {
- RUN_TEST(GetNextFile, filter);
-}
-
-std::string TestDirectoryReader::TestGetNextFile() {
+std::string TestDirectoryReader::TestReadEntries() {
TestCompletionCallback callback(instance_->pp_instance(), force_async_);
pp::FileSystem file_system(
instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
@@ -97,7 +97,7 @@ std::string TestDirectoryReader::TestGetNextFile() {
const char* dir_prefix = "dir_";
pp::FileRef test_dir(file_system, test_dir_name);
- rv = DeleteDirectoryRecursively(&test_dir, &callback);
+ rv = DeleteDirectoryRecursively(&test_dir);
if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND)
return ReportError("DeleteDirectoryRecursively", rv);
@@ -144,31 +144,29 @@ std::string TestDirectoryReader::TestGetNextFile() {
expected_dir_names.insert(buffer);
}
- // Test that |GetNextEntry()| is able to enumerate all directories and files
- // that we created.
+ // Test that |ReadEntries()| is able to fetch all directories and files that
+ // we created.
{
+ TestCompletionCallbackWithOutput<Entries> output_callback(
+ instance_->pp_instance(), force_async_);
+
pp::DirectoryReader_Dev directory_reader(test_dir);
- std::vector<pp::DirectoryEntry_Dev> entries;
- pp::DirectoryEntry_Dev entry;
- do {
- rv = directory_reader.GetNextEntry(&entry, callback);
- if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
- return ReportError("DirectoryReader::GetNextEntry force_async", rv);
- if (rv == PP_OK_COMPLETIONPENDING)
- rv = callback.WaitForResult();
- if (rv != PP_OK)
- return ReportError("DirectoryReader::GetNextEntry", rv);
- if (!entry.is_null())
- entries.push_back(entry);
- } while (!entry.is_null());
+ rv = directory_reader.ReadEntries(output_callback);
+ if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
+ return ReportError("DirectoryReader::ReadEntries force_async", rv);
+ if (rv == PP_OK_COMPLETIONPENDING)
+ rv = output_callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("DirectoryReader::ReadEntries", rv);
+ Entries entries = output_callback.output();
size_t sum = expected_file_names.size() + expected_dir_names.size();
if (entries.size() != sum)
return "Expected " + IntegerToString(sum) + " entries, got " +
- IntegerToString(entries.size());
+ IntegerToString(entries.size());
- for (std::vector<pp::DirectoryEntry_Dev>::const_iterator it =
- entries.begin(); it != entries.end(); ++it) {
+ for (Entries::const_iterator it = entries.begin();
+ it != entries.end(); ++it) {
pp::FileRef file_ref = it->file_ref();
std::string file_path = file_ref.GetPath().AsString();
std::set<std::string>::iterator found =
@@ -190,34 +188,27 @@ std::string TestDirectoryReader::TestGetNextFile() {
return "Expected more file paths.";
}
- // Test cancellation of asynchronous |GetNextEntry()|.
+ // Test cancellation of asynchronous |ReadEntries()|.
{
- // Declaring |entry| here prevents memory corruption for some failure modes
- // and lets us to detect some other failures.
- pp::DirectoryEntry_Dev entry;
- callback.reset_run_count();
+ TestCompletionCallbackWithOutput<Entries> output_callback(
+ instance_->pp_instance(), force_async_);
+
// Note that the directory reader will be deleted immediately.
- rv = pp::DirectoryReader_Dev(test_dir).GetNextEntry(&entry, callback);
+ rv = pp::DirectoryReader_Dev(test_dir).ReadEntries(output_callback);
if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
- return ReportError("DirectoryReader::GetNextEntry force_async", rv);
- if (callback.run_count() > 0)
- return "DirectoryReader::GetNextEntry ran callback synchronously.";
+ return ReportError("DirectoryReader::ReadEntries force_async", rv);
+ if (output_callback.run_count() > 0)
+ return "DirectoryReader::ReadEntries ran callback synchronously.";
- // If |GetNextEntry()| is completing asynchronously, the callback should be
+ // If |ReadEntries()| is completing asynchronously, the callback should be
// aborted (i.e., called with |PP_ERROR_ABORTED| from the message loop)
// since the resource was destroyed.
if (rv == PP_OK_COMPLETIONPENDING) {
- // |GetNextEntry()| *may* have written to |entry| (e.g., synchronously,
- // before the resource was destroyed), but it must not write to it after
- // destruction.
- bool entry_is_null = entry.is_null();
- rv = callback.WaitForResult();
+ rv = output_callback.WaitForResult();
if (rv != PP_ERROR_ABORTED)
- return "DirectoryReader::GetNextEntry not aborted.";
- if (entry.is_null() != entry_is_null)
- return "DirectoryReader::GetNextEntry wrote result after destruction.";
+ return "DirectoryReader::ReadEntries not aborted.";
} else if (rv != PP_OK) {
- return ReportError("DirectoryReader::GetNextEntry", rv);
+ return ReportError("DirectoryReader::ReadEntries", rv);
}
}