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

Unified Diff: ppapi/native_client/tests/ppapi_browser/ppb_file_io/test_open.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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: ppapi/native_client/tests/ppapi_browser/ppb_file_io/test_open.cc
===================================================================
--- ppapi/native_client/tests/ppapi_browser/ppb_file_io/test_open.cc (revision 0)
+++ ppapi/native_client/tests/ppapi_browser/ppb_file_io/test_open.cc (revision 0)
@@ -0,0 +1,172 @@
+// Copyright (c) 2011 The Native Client 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 "native_client/src/third_party/ppapi/c/pp_errors.h"
+#include "native_client/src/third_party/ppapi/c/ppb_core.h"
+#include "native_client/src/third_party/ppapi/c/ppb_file_io.h"
+#include "native_client/src/third_party/ppapi/c/ppb_file_ref.h"
+#include "native_client/src/third_party/ppapi/c/ppb_file_system.h"
+#include "native_client/src/third_party/ppapi/c/ppb_url_loader.h"
+#include "native_client/tests/ppapi_browser/ppb_file_io/common.h"
+#include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
+#include "native_client/tests/ppapi_test_lib/test_interface.h"
+
+namespace {
+
+using common::BoundPPAPIFunc;
+using common::FileIOTester;
+using common::InitFileInfo;
+using common::TestCallbackData;
+using common::TestSequenceElement;
+
+class TestOpenExistingFileSequenceElement : public TestSequenceElement {
+ public:
+ TestOpenExistingFileSequenceElement(const std::string& name,
+ int32_t expected_return_value,
+ int32_t expected_result, int32_t flags)
+ : TestSequenceElement(name, expected_return_value, expected_result),
+ flags_(flags) {}
+ virtual ~TestOpenExistingFileSequenceElement() {}
+
+ private:
+ virtual BoundPPAPIFunc GetCompletionCallbackInitiatingPPAPIFunction(
+ TestCallbackData* callback_data) {
+ return std::tr1::bind(PPBFileIO()->Open, callback_data->existing_file_io,
+ callback_data->existing_file_ref, flags_,
+ std::tr1::placeholders::_1);
+ }
+ virtual void Setup(TestCallbackData* callback_data) {
+ // We make sure the file io is closed before each test.
+ PPBFileIO()->Close(callback_data->existing_file_io);
+ }
+
+ const int32_t flags_;
+};
+
+class TestOpenNonExistingFileSequenceElement : public TestSequenceElement {
+ public:
+ TestOpenNonExistingFileSequenceElement(const std::string& name,
+ int32_t expected_return_value,
+ int32_t expected_result, int32_t flags)
+ : TestSequenceElement(name, expected_return_value, expected_result),
+ flags_(flags) {}
+ virtual ~TestOpenNonExistingFileSequenceElement() {}
+
+ private:
+ virtual BoundPPAPIFunc GetCompletionCallbackInitiatingPPAPIFunction(
+ TestCallbackData* callback_data) {
+ return std::tr1::bind(PPBFileIO()->Open,
+ callback_data->non_existing_file_io,
+ callback_data->non_existing_file_ref, flags_,
+ std::tr1::placeholders::_1);
+ }
+ virtual void Setup(TestCallbackData* callback_data) {
+ // We make sure the file io is closed before each test.
+ PPBFileIO()->Close(callback_data->non_existing_file_io);
+ }
+
+ const int32_t flags_;
+};
+
+class DeleteFile : public TestSequenceElement {
+ public:
+ DeleteFile()
+ : TestSequenceElement("DeleteFile", PP_OK_COMPLETIONPENDING, PP_OK) {}
+
+ private:
+ virtual BoundPPAPIFunc GetCompletionCallbackInitiatingPPAPIFunction(
+ TestCallbackData* callback_data) {
+ return std::tr1::bind(PPBFileRef()->Delete,
+ callback_data->non_existing_file_ref,
+ std::tr1::placeholders::_1);
+ }
+};
+
+void TestOpenNonExistingFile(PP_FileSystemType system_type) {
+ PP_FileInfo file_info = { 0 };
+ InitFileInfo(system_type, &file_info);
+
+ FileIOTester tester(file_info);
+ tester.AddSequenceElement(
+ new TestOpenNonExistingFileSequenceElement("TestOpenForRead",
+ PP_OK_COMPLETIONPENDING,
+ PP_ERROR_FILENOTFOUND,
+ PP_FILEOPENFLAG_READ));
+ tester.AddSequenceElement(
+ new TestOpenNonExistingFileSequenceElement("TestOpenForWrite",
+ PP_OK_COMPLETIONPENDING,
+ PP_ERROR_FILENOTFOUND,
+ PP_FILEOPENFLAG_WRITE));
+ tester.AddSequenceElement(
+ new TestOpenNonExistingFileSequenceElement("TestOpenForWriteCreate",
+ PP_OK_COMPLETIONPENDING,
+ PP_OK,
+ PP_FILEOPENFLAG_CREATE |
+ PP_FILEOPENFLAG_WRITE));
+ tester.AddSequenceElement(new DeleteFile);
+ tester.AddSequenceElement(
+ new TestOpenNonExistingFileSequenceElement(
+ "TestOpenForWriteCreateExclusive",
+ PP_OK_COMPLETIONPENDING,
+ PP_OK,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE |
+ PP_FILEOPENFLAG_EXCLUSIVE));
+ tester.Run();
+}
+
+void TestOpenExistingFile(PP_FileSystemType system_type) {
+ PP_FileInfo file_info = { 0 };
+ InitFileInfo(system_type, &file_info);
+
+ FileIOTester tester(file_info);
+ tester.AddSequenceElement(
+ new TestOpenExistingFileSequenceElement("TestOpenForRead",
+ PP_OK_COMPLETIONPENDING, PP_OK,
+ PP_FILEOPENFLAG_READ));
+ tester.AddSequenceElement(
+ new TestOpenExistingFileSequenceElement("TestOpenForWrite",
+ PP_OK_COMPLETIONPENDING, PP_OK,
+ PP_FILEOPENFLAG_WRITE));
+ tester.AddSequenceElement(
+ new TestOpenExistingFileSequenceElement("TestOpenTruncate",
+ PP_ERROR_BADARGUMENT,
+ PP_ERROR_FAILED,
+ PP_FILEOPENFLAG_TRUNCATE));
+ tester.AddSequenceElement(
+ new TestOpenExistingFileSequenceElement("TestOpenForWriteCreateExclusive",
+ PP_OK_COMPLETIONPENDING,
+ PP_ERROR_FILEEXISTS,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE |
+ PP_FILEOPENFLAG_EXCLUSIVE));
+ tester.AddSequenceElement(
+ new TestOpenExistingFileSequenceElement("TestOpenForWriteCreate",
+ PP_OK_COMPLETIONPENDING, PP_OK,
+ PP_FILEOPENFLAG_WRITE |
+ PP_FILEOPENFLAG_CREATE));
+ tester.Run();
+}
+
+} // namespace
+
+void TestOpenExistingFileLocalPersistent() {
+ TestOpenExistingFile(PP_FILESYSTEMTYPE_LOCALPERSISTENT);
+ TEST_PASSED;
+}
+
+void TestOpenExistingFileLocalTemporary() {
+ TestOpenExistingFile(PP_FILESYSTEMTYPE_LOCALTEMPORARY);
+ TEST_PASSED;
+}
+
+void TestOpenNonExistingFileLocalPersistent() {
+ TestOpenNonExistingFile(PP_FILESYSTEMTYPE_LOCALPERSISTENT);
+ TEST_PASSED;
+}
+
+void TestOpenNonExistingFileLocalTemporary() {
+ TestOpenNonExistingFile(PP_FILESYSTEMTYPE_LOCALTEMPORARY);
+ TEST_PASSED;
+}

Powered by Google App Engine
This is Rietveld 408576698