Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_node.cc

Issue 2156503002: [NaCl SDK] Expose Google Drive to nacl_io. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_node.cc
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_node.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_node.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42877ae9aa9448bc44b41d6301c4130f6e5f5b45
--- /dev/null
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_node.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fake_ppapi/fake_node.h"
+
+#include <algorithm>
+
+#include <ppapi/c/pp_completion_callback.h>
+#include <ppapi/c/pp_errors.h>
+
+#include "gtest/gtest.h"
+
+FakeNode::FakeNode(const PP_FileInfo& info) : info_(info) {}
+
+FakeNode::FakeNode(const PP_FileInfo& info,
+ const std::vector<uint8_t>& contents)
+ : info_(info), contents_(contents) {}
+
+FakeNode::FakeNode(const PP_FileInfo& info, const std::string& contents)
+ : info_(info) {
+ std::copy(contents.begin(), contents.end(), std::back_inserter(contents_));
+}
+
+int32_t FakeNode::Read(int64_t offset, char* buffer, int32_t bytes_to_read) {
+ if (offset < 0)
+ return PP_ERROR_FAILED;
+
+ bytes_to_read =
+ std::max(0, std::min<int32_t>(bytes_to_read, contents_.size() - offset));
+ memcpy(buffer, contents_.data() + offset, bytes_to_read);
+ return bytes_to_read;
+}
+
+int32_t FakeNode::Write(int64_t offset,
+ const char* buffer,
+ int32_t bytes_to_write) {
+ if (offset < 0)
+ return PP_ERROR_FAILED;
+
+ size_t new_size = offset + bytes_to_write;
+ if (new_size > contents_.size())
+ contents_.resize(new_size);
+
+ memcpy(contents_.data() + offset, buffer, bytes_to_write);
+ info_.size = new_size;
+ return bytes_to_write;
+}
+
+int32_t FakeNode::Append(const char* buffer, int32_t bytes_to_write) {
+ return Write(contents_.size(), buffer, bytes_to_write);
+}
+
+int32_t FakeNode::SetLength(int64_t length) {
+ contents_.resize(length);
+ info_.size = length;
+ return PP_OK;
+}
+
+void FakeNode::GetInfo(PP_FileInfo* out_info) {
+ *out_info = info_;
+}
+
+bool FakeNode::IsRegular() const {
+ return info_.type == PP_FILETYPE_REGULAR;
+}
+
+bool FakeNode::IsDirectory() const {
+ return info_.type == PP_FILETYPE_DIRECTORY;
+}

Powered by Google App Engine
This is Rietveld 408576698