| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/tests/test_directory_reader.h" | 5 #include "ppapi/tests/test_directory_reader.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
| 12 #include "ppapi/c/ppb_file_io.h" | 12 #include "ppapi/c/ppb_file_io.h" |
| 13 #include "ppapi/cpp/dev/directory_entry_dev.h" | 13 #include "ppapi/cpp/directory_entry.h" |
| 14 #include "ppapi/cpp/dev/directory_reader_dev.h" | 14 #include "ppapi/cpp/directory_reader.h" |
| 15 #include "ppapi/cpp/file_io.h" | 15 #include "ppapi/cpp/file_io.h" |
| 16 #include "ppapi/cpp/file_ref.h" | 16 #include "ppapi/cpp/file_ref.h" |
| 17 #include "ppapi/cpp/file_system.h" | 17 #include "ppapi/cpp/file_system.h" |
| 18 #include "ppapi/cpp/instance.h" | 18 #include "ppapi/cpp/instance.h" |
| 19 #include "ppapi/tests/test_utils.h" | 19 #include "ppapi/tests/test_utils.h" |
| 20 #include "ppapi/tests/testing_instance.h" | 20 #include "ppapi/tests/testing_instance.h" |
| 21 | 21 |
| 22 REGISTER_TEST_CASE(DirectoryReader); | 22 REGISTER_TEST_CASE(DirectoryReader); |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 typedef std::vector<pp::DirectoryEntry_Dev> Entries; | 26 typedef std::vector<pp::DirectoryEntry> Entries; |
| 27 | 27 |
| 28 std::string IntegerToString(int value) { | 28 std::string IntegerToString(int value) { |
| 29 char result[12]; | 29 char result[12]; |
| 30 sprintf(result, "%d", value); | 30 sprintf(result, "%d", value); |
| 31 return result; | 31 return result; |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 bool TestDirectoryReader::Init() { | 36 bool TestDirectoryReader::Init() { |
| 37 return CheckTestingInterface() && EnsureRunningOverHTTP(); | 37 return CheckTestingInterface() && EnsureRunningOverHTTP(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void TestDirectoryReader::RunTests(const std::string& filter) { | 40 void TestDirectoryReader::RunTests(const std::string& filter) { |
| 41 RUN_CALLBACK_TEST(TestDirectoryReader, ReadEntries, filter); | 41 RUN_CALLBACK_TEST(TestDirectoryReader, ReadEntries, filter); |
| 42 } | 42 } |
| 43 | 43 |
| 44 int32_t TestDirectoryReader::DeleteDirectoryRecursively(pp::FileRef* dir) { | 44 int32_t TestDirectoryReader::DeleteDirectoryRecursively(pp::FileRef* dir) { |
| 45 if (!dir) | 45 if (!dir) |
| 46 return PP_ERROR_BADARGUMENT; | 46 return PP_ERROR_BADARGUMENT; |
| 47 | 47 |
| 48 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 48 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
| 49 TestCompletionCallbackWithOutput<Entries> output_callback( | 49 TestCompletionCallbackWithOutput<Entries> output_callback( |
| 50 instance_->pp_instance(), callback_type()); | 50 instance_->pp_instance(), callback_type()); |
| 51 | 51 |
| 52 pp::DirectoryReader_Dev directory_reader(*dir); | 52 pp::DirectoryReader directory_reader(*dir); |
| 53 output_callback.WaitForResult( | 53 output_callback.WaitForResult( |
| 54 directory_reader.ReadEntries(output_callback.GetCallback())); | 54 directory_reader.ReadEntries(output_callback.GetCallback())); |
| 55 int32_t rv = output_callback.result(); | 55 int32_t rv = output_callback.result(); |
| 56 if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND) | 56 if (rv != PP_OK && rv != PP_ERROR_FILENOTFOUND) |
| 57 return rv; | 57 return rv; |
| 58 | 58 |
| 59 Entries entries = output_callback.output(); | 59 Entries entries = output_callback.output(); |
| 60 for (Entries::const_iterator it = entries.begin(); | 60 for (Entries::const_iterator it = entries.begin(); |
| 61 it != entries.end(); ++it) { | 61 it != entries.end(); ++it) { |
| 62 pp::FileRef file_ref = it->file_ref(); | 62 pp::FileRef file_ref = it->file_ref(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 expected_dir_names.insert(buffer); | 125 expected_dir_names.insert(buffer); |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Test that |ReadEntries()| is able to fetch all directories and files that | 128 // Test that |ReadEntries()| is able to fetch all directories and files that |
| 129 // we created. | 129 // we created. |
| 130 { | 130 { |
| 131 TestCompletionCallbackWithOutput<Entries> output_callback( | 131 TestCompletionCallbackWithOutput<Entries> output_callback( |
| 132 instance_->pp_instance(), callback_type()); | 132 instance_->pp_instance(), callback_type()); |
| 133 | 133 |
| 134 pp::DirectoryReader_Dev directory_reader(test_dir); | 134 pp::DirectoryReader directory_reader(test_dir); |
| 135 output_callback.WaitForResult( | 135 output_callback.WaitForResult( |
| 136 directory_reader.ReadEntries(output_callback.GetCallback())); | 136 directory_reader.ReadEntries(output_callback.GetCallback())); |
| 137 CHECK_CALLBACK_BEHAVIOR(output_callback); | 137 CHECK_CALLBACK_BEHAVIOR(output_callback); |
| 138 ASSERT_EQ(PP_OK, output_callback.result()); | 138 ASSERT_EQ(PP_OK, output_callback.result()); |
| 139 | 139 |
| 140 Entries entries = output_callback.output(); | 140 Entries entries = output_callback.output(); |
| 141 size_t sum = expected_file_names.size() + expected_dir_names.size(); | 141 size_t sum = expected_file_names.size() + expected_dir_names.size(); |
| 142 if (entries.size() != sum) | 142 if (entries.size() != sum) |
| 143 return "Expected " + IntegerToString(sum) + " entries, got " + | 143 return "Expected " + IntegerToString(sum) + " entries, got " + |
| 144 IntegerToString(entries.size()); | 144 IntegerToString(entries.size()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 165 if (!expected_file_names.empty() || !expected_dir_names.empty()) | 165 if (!expected_file_names.empty() || !expected_dir_names.empty()) |
| 166 return "Expected more file paths."; | 166 return "Expected more file paths."; |
| 167 } | 167 } |
| 168 | 168 |
| 169 // Test cancellation of asynchronous |ReadEntries()|. | 169 // Test cancellation of asynchronous |ReadEntries()|. |
| 170 TestCompletionCallbackWithOutput<Entries> output_callback( | 170 TestCompletionCallbackWithOutput<Entries> output_callback( |
| 171 instance_->pp_instance(), callback_type()); | 171 instance_->pp_instance(), callback_type()); |
| 172 { | 172 { |
| 173 | 173 |
| 174 // Note that the directory reader will be deleted immediately. | 174 // Note that the directory reader will be deleted immediately. |
| 175 rv = pp::DirectoryReader_Dev(test_dir).ReadEntries( | 175 rv = pp::DirectoryReader(test_dir).ReadEntries( |
| 176 output_callback.GetCallback()); | 176 output_callback.GetCallback()); |
| 177 } | 177 } |
| 178 output_callback.WaitForAbortResult(rv); | 178 output_callback.WaitForAbortResult(rv); |
| 179 CHECK_CALLBACK_BEHAVIOR(output_callback); | 179 CHECK_CALLBACK_BEHAVIOR(output_callback); |
| 180 | 180 |
| 181 PASS(); | 181 PASS(); |
| 182 } | 182 } |
| OLD | NEW |