Index: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h |
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h |
index 97fa5c878b735b573356f4b901d28de3c7d91592..5d8006d4f7dc0456a817b3f0518affe2671fbf1d 100644 |
--- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h |
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_html5_fs.h |
@@ -11,11 +11,16 @@ |
#include <ppapi/c/pp_directory_entry.h> |
+#include "nacl_io/pepper_interface_dummy.h" |
+#include "sdk_util/macros.h" |
+ |
#include "fake_ppapi/fake_core_interface.h" |
+#include "fake_ppapi/fake_filesystem.h" |
+#include "fake_ppapi/fake_file_io_interface.h" |
+#include "fake_ppapi/fake_file_ref_interface.h" |
+#include "fake_ppapi/fake_file_system_interface.h" |
#include "fake_ppapi/fake_var_interface.h" |
#include "fake_ppapi/fake_var_manager.h" |
-#include "nacl_io/pepper_interface_dummy.h" |
-#include "sdk_util/macros.h" |
// This class is a fake implementation of the interfaces necessary to access |
// the HTML5 Filesystem from NaCl. |
@@ -31,155 +36,10 @@ |
// NOTE: This pepper interface creates an instance resource that can only be |
// used with FakePepperInterfaceHtml5Fs, not other fake pepper implementations. |
-class FakeHtml5FsNode { |
- public: |
- FakeHtml5FsNode(const PP_FileInfo& info); |
- FakeHtml5FsNode(const PP_FileInfo& info, |
- const std::vector<uint8_t>& contents); |
- FakeHtml5FsNode(const PP_FileInfo& info, const std::string& contents); |
- |
- int32_t Read(int64_t offset, char* buffer, int32_t bytes_to_read); |
- int32_t Write(int64_t offset, const char* buffer, int32_t bytes_to_write); |
- int32_t Append(const char* buffer, int32_t bytes_to_write); |
- int32_t SetLength(int64_t length); |
- void GetInfo(PP_FileInfo* out_info); |
- bool IsRegular() const; |
- bool IsDirectory() const; |
- PP_FileType file_type() const { return info_.type; } |
- |
- // These times are not modified by the fake implementation. |
- void set_creation_time(PP_Time time) { info_.creation_time = time; } |
- void set_last_access_time(PP_Time time) { info_.last_access_time = time; } |
- void set_last_modified_time(PP_Time time) { info_.last_modified_time = time; } |
- |
- const std::vector<uint8_t>& contents() const { return contents_; } |
- |
- private: |
- PP_FileInfo info_; |
- std::vector<uint8_t> contents_; |
-}; |
- |
-class FakeHtml5FsFilesystem { |
- public: |
- typedef std::string Path; |
- |
- struct DirectoryEntry { |
- Path path; |
- const FakeHtml5FsNode* node; |
- }; |
- typedef std::vector<DirectoryEntry> DirectoryEntries; |
- |
- FakeHtml5FsFilesystem(); |
- explicit FakeHtml5FsFilesystem(PP_FileSystemType type); |
- FakeHtml5FsFilesystem(const FakeHtml5FsFilesystem& filesystem, |
- PP_FileSystemType type); |
- |
- void Clear(); |
- bool AddEmptyFile(const Path& path, FakeHtml5FsNode** out_node); |
- bool AddFile(const Path& path, |
- const std::string& contents, |
- FakeHtml5FsNode** out_node); |
- bool AddFile(const Path& path, |
- const std::vector<uint8_t>& contents, |
- FakeHtml5FsNode** out_node); |
- bool AddDirectory(const Path& path, FakeHtml5FsNode** out_node); |
- bool RemoveNode(const Path& path); |
- |
- FakeHtml5FsNode* GetNode(const Path& path); |
- bool GetDirectoryEntries(const Path& path, |
- DirectoryEntries* out_dir_entries) const; |
- PP_FileSystemType filesystem_type() const { return filesystem_type_; } |
- static Path GetParentPath(const Path& path); |
- |
- private: |
- typedef std::map<Path, FakeHtml5FsNode> NodeMap; |
- NodeMap node_map_; |
- PP_FileSystemType filesystem_type_; |
-}; |
- |
-class FakeFileIoInterface : public nacl_io::FileIoInterface { |
- public: |
- explicit FakeFileIoInterface(FakeCoreInterface* core_interface); |
- |
- virtual PP_Resource Create(PP_Resource instance); |
- virtual int32_t Open(PP_Resource file_io, |
- PP_Resource file_ref, |
- int32_t open_flags, |
- PP_CompletionCallback callback); |
- virtual int32_t Query(PP_Resource file_io, |
- PP_FileInfo* info, |
- PP_CompletionCallback callback); |
- virtual int32_t Read(PP_Resource file_io, |
- int64_t offset, |
- char* buffer, |
- int32_t bytes_to_read, |
- PP_CompletionCallback callback); |
- virtual int32_t Write(PP_Resource file_io, |
- int64_t offset, |
- const char* buffer, |
- int32_t bytes_to_write, |
- PP_CompletionCallback callback); |
- virtual int32_t SetLength(PP_Resource file_io, |
- int64_t length, |
- PP_CompletionCallback callback); |
- virtual int32_t Flush(PP_Resource file_io, PP_CompletionCallback callback); |
- virtual void Close(PP_Resource file_io); |
- |
- private: |
- FakeCoreInterface* core_interface_; // Weak reference. |
- |
- DISALLOW_COPY_AND_ASSIGN(FakeFileIoInterface); |
-}; |
- |
-class FakeFileRefInterface : public nacl_io::FileRefInterface { |
- public: |
- FakeFileRefInterface(FakeCoreInterface* core_interface, |
- FakeVarInterface* var_interface); |
- |
- virtual PP_Resource Create(PP_Resource file_system, const char* path); |
- virtual PP_Var GetName(PP_Resource file_ref); |
- virtual int32_t MakeDirectory(PP_Resource directory_ref, |
- PP_Bool make_parents, |
- PP_CompletionCallback callback); |
- virtual int32_t Delete(PP_Resource file_ref, PP_CompletionCallback callback); |
- virtual int32_t Query(PP_Resource file_ref, |
- PP_FileInfo* info, |
- PP_CompletionCallback callback); |
- virtual int32_t ReadDirectoryEntries(PP_Resource file_ref, |
- const PP_ArrayOutput& output, |
- PP_CompletionCallback callback); |
- virtual int32_t Rename(PP_Resource file_ref, |
- PP_Resource new_file_ref, |
- PP_CompletionCallback callback); |
- |
- private: |
- FakeCoreInterface* core_interface_; // Weak reference. |
- FakeVarInterface* var_interface_; // Weak reference. |
- FakeVarManager* var_manager_; // Weak reference |
- |
- DISALLOW_COPY_AND_ASSIGN(FakeFileRefInterface); |
-}; |
- |
-class FakeFileSystemInterface : public nacl_io::FileSystemInterface { |
- public: |
- FakeFileSystemInterface(FakeCoreInterface* core_interface); |
- |
- virtual PP_Bool IsFileSystem(PP_Resource resource); |
- virtual PP_Resource Create(PP_Instance instance, PP_FileSystemType type); |
- virtual int32_t Open(PP_Resource file_system, |
- int64_t expected_size, |
- PP_CompletionCallback callback); |
- |
- private: |
- FakeCoreInterface* core_interface_; // Weak reference. |
- |
- DISALLOW_COPY_AND_ASSIGN(FakeFileSystemInterface); |
-}; |
- |
class FakePepperInterfaceHtml5Fs : public nacl_io::PepperInterfaceDummy { |
public: |
FakePepperInterfaceHtml5Fs(); |
- explicit FakePepperInterfaceHtml5Fs(const FakeHtml5FsFilesystem& filesystem); |
+ explicit FakePepperInterfaceHtml5Fs(const FakeFilesystem& filesystem); |
~FakePepperInterfaceHtml5Fs(); |
virtual PP_Instance GetInstance() { return instance_; } |
@@ -189,7 +49,7 @@ class FakePepperInterfaceHtml5Fs : public nacl_io::PepperInterfaceDummy { |
virtual nacl_io::FileIoInterface* GetFileIoInterface(); |
virtual nacl_io::VarInterface* GetVarInterface(); |
- FakeHtml5FsFilesystem* filesystem_template() { return &filesystem_template_; } |
+ FakeFilesystem* filesystem_template() { return &filesystem_template_; } |
private: |
void Init(); |
@@ -198,7 +58,7 @@ class FakePepperInterfaceHtml5Fs : public nacl_io::PepperInterfaceDummy { |
FakeCoreInterface core_interface_; |
FakeVarInterface var_interface_; |
FakeVarManager var_manager_; |
- FakeHtml5FsFilesystem filesystem_template_; |
+ FakeFilesystem filesystem_template_; |
FakeFileSystemInterface file_system_interface_; |
FakeFileRefInterface file_ref_interface_; |
FakeFileIoInterface file_io_interface_; |