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

Side by Side Diff: tests/fake_browser_ppapi/fake_file_io.cc

Issue 6218004: Resource64->32, NaCl side. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: First Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright 2010 The Native Client Authors. All rights reserved. 2 * Copyright 2010 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file. 4 * be found in the LICENSE file.
5 */ 5 */
6 6
7 #include "native_client/tests/fake_browser_ppapi/fake_file_io.h" 7 #include "native_client/tests/fake_browser_ppapi/fake_file_io.h"
8 8
9 #include <stdio.h> 9 #include <stdio.h>
10 10
11 #include "native_client/src/include/nacl_macros.h" 11 #include "native_client/src/include/nacl_macros.h"
12 #include "native_client/src/include/portability.h" 12 #include "native_client/src/include/portability.h"
13 #include "native_client/src/include/portability_io.h" 13 #include "native_client/src/include/portability_io.h"
14 14
15 #include "native_client/tests/fake_browser_ppapi/fake_file_ref.h" 15 #include "native_client/tests/fake_browser_ppapi/fake_file_ref.h"
16 #include "native_client/tests/fake_browser_ppapi/fake_resource.h" 16 #include "native_client/tests/fake_browser_ppapi/fake_resource.h"
17 #include "native_client/tests/fake_browser_ppapi/utility.h" 17 #include "native_client/tests/fake_browser_ppapi/utility.h"
18 18
19 #include "ppapi/c/pp_errors.h" 19 #include "ppapi/c/pp_errors.h"
20 #include "ppapi/c/pp_completion_callback.h" 20 #include "ppapi/c/pp_completion_callback.h"
21 #include "ppapi/c/pp_resource.h" 21 #include "ppapi/c/pp_resource.h"
22 22
23 using fake_browser_ppapi::DebugPrintf; 23 using fake_browser_ppapi::DebugPrintf;
24 24
25 namespace fake_browser_ppapi { 25 namespace fake_browser_ppapi {
26 26
27 namespace { 27 namespace {
28 28
29 PP_Resource Create(PP_Module module_id) { 29 PP_Resource Create(PP_Module module_id) {
30 DebugPrintf("FileIO::Create: module_id=%"NACL_PRId64"\n", module_id); 30 DebugPrintf("FileIO::Create: module_id=%"NACL_PRId32"\n", module_id);
31 FileIO* file_io = new FileIO(module_id); 31 FileIO* file_io = new FileIO(module_id);
32 PP_Resource resource_id = TrackResource(file_io); 32 PP_Resource resource_id = TrackResource(file_io);
33 DebugPrintf("FileIO::Create: resource_id=%"NACL_PRId64"\n", resource_id); 33 DebugPrintf("FileIO::Create: resource_id=%"NACL_PRId32"\n", resource_id);
34 return resource_id; 34 return resource_id;
35 } 35 }
36 36
37 PP_Bool IsFileIO(PP_Resource resource_id) { 37 PP_Bool IsFileIO(PP_Resource resource_id) {
38 DebugPrintf("FileIO::IsFileIO: resource_id=%"NACL_PRId64"\n", resource_id); 38 DebugPrintf("FileIO::IsFileIO: resource_id=%"NACL_PRId32"\n", resource_id);
39 NACL_UNIMPLEMENTED(); 39 NACL_UNIMPLEMENTED();
40 return PP_FALSE; 40 return PP_FALSE;
41 } 41 }
42 42
43 int32_t Open(PP_Resource file_io_id, 43 int32_t Open(PP_Resource file_io_id,
44 PP_Resource file_ref_id, 44 PP_Resource file_ref_id,
45 int32_t open_flags, 45 int32_t open_flags,
46 struct PP_CompletionCallback callback) { 46 struct PP_CompletionCallback callback) {
47 DebugPrintf("FileIO::Open: file_io_id=%"NACL_PRId64 47 DebugPrintf("FileIO::Open: file_io_id=%"NACL_PRId32
48 " file_ref_id=%"NACL_PRId64" open_flags=%"NACL_PRId32"\n", 48 " file_ref_id=%"NACL_PRId32" open_flags=%"NACL_PRId32"\n",
49 file_io_id, file_ref_id, open_flags); 49 file_io_id, file_ref_id, open_flags);
50 FileIO* file_io = GetResource(file_io_id)->AsFileIO(); 50 FileIO* file_io = GetResource(file_io_id)->AsFileIO();
51 FileRef* file_ref = GetResource(file_ref_id)->AsFileRef(); 51 FileRef* file_ref = GetResource(file_ref_id)->AsFileRef();
52 if (file_io == NULL || file_ref == NULL) 52 if (file_io == NULL || file_ref == NULL)
53 return PP_ERROR_BADRESOURCE; 53 return PP_ERROR_BADRESOURCE;
54 54
55 // Open the file and store the file descriptor. 55 // Open the file and store the file descriptor.
56 // At this point, the plugin only uses read-only access mode. Note that 56 // At this point, the plugin only uses read-only access mode. Note that
57 // PPAPI file access flags are not the same as OPEN's file access modes. 57 // PPAPI file access flags are not the same as OPEN's file access modes.
58 CHECK(open_flags == PP_FILEOPENFLAG_READ); 58 CHECK(open_flags == PP_FILEOPENFLAG_READ);
59 const char* file_path = file_ref->path().c_str(); 59 const char* file_path = file_ref->path().c_str();
60 int file_desc = OPEN(file_path, O_RDONLY); 60 int file_desc = OPEN(file_path, O_RDONLY);
61 file_io->set_file_desc(file_desc); 61 file_io->set_file_desc(file_desc);
62 DebugPrintf("FileIO::Open: file=%s file_desc=%d\n", file_path, file_desc); 62 DebugPrintf("FileIO::Open: file=%s file_desc=%d\n", file_path, file_desc);
63 if (file_desc <= NACL_NO_FILE_DESC) 63 if (file_desc <= NACL_NO_FILE_DESC)
64 return PP_ERROR_FAILED; 64 return PP_ERROR_FAILED;
65 65
66 // Invoke the callback right away to simplify mocking. 66 // Invoke the callback right away to simplify mocking.
67 if (callback.func == NULL) 67 if (callback.func == NULL)
68 return PP_ERROR_BADARGUMENT; 68 return PP_ERROR_BADARGUMENT;
69 PP_RunCompletionCallback(&callback, PP_OK); 69 PP_RunCompletionCallback(&callback, PP_OK);
70 return PP_ERROR_WOULDBLOCK; // Fake successful async call. 70 return PP_ERROR_WOULDBLOCK; // Fake successful async call.
71 } 71 }
72 72
73 int32_t Query(PP_Resource file_io_id, 73 int32_t Query(PP_Resource file_io_id,
74 PP_FileInfo_Dev* info, 74 PP_FileInfo_Dev* info,
75 struct PP_CompletionCallback callback) { 75 struct PP_CompletionCallback callback) {
76 DebugPrintf("FileIO::Query: file_io_id=%"NACL_PRId64"\n", file_io_id); 76 DebugPrintf("FileIO::Query: file_io_id=%"NACL_PRId32"\n", file_io_id);
77 UNREFERENCED_PARAMETER(info); 77 UNREFERENCED_PARAMETER(info);
78 UNREFERENCED_PARAMETER(callback); 78 UNREFERENCED_PARAMETER(callback);
79 NACL_UNIMPLEMENTED(); 79 NACL_UNIMPLEMENTED();
80 return PP_ERROR_BADRESOURCE; 80 return PP_ERROR_BADRESOURCE;
81 } 81 }
82 82
83 int32_t Touch(PP_Resource file_io_id, 83 int32_t Touch(PP_Resource file_io_id,
84 PP_Time last_access_time, 84 PP_Time last_access_time,
85 PP_Time last_modified_time, 85 PP_Time last_modified_time,
86 struct PP_CompletionCallback callback) { 86 struct PP_CompletionCallback callback) {
87 DebugPrintf("FileIO::Touch: file_io_id=%"NACL_PRId64"\n", file_io_id); 87 DebugPrintf("FileIO::Touch: file_io_id=%"NACL_PRId32"\n", file_io_id);
88 UNREFERENCED_PARAMETER(last_access_time); 88 UNREFERENCED_PARAMETER(last_access_time);
89 UNREFERENCED_PARAMETER(last_modified_time); 89 UNREFERENCED_PARAMETER(last_modified_time);
90 UNREFERENCED_PARAMETER(callback); 90 UNREFERENCED_PARAMETER(callback);
91 NACL_UNIMPLEMENTED(); 91 NACL_UNIMPLEMENTED();
92 return PP_ERROR_BADRESOURCE; 92 return PP_ERROR_BADRESOURCE;
93 } 93 }
94 94
95 int32_t Read(PP_Resource file_io_id, 95 int32_t Read(PP_Resource file_io_id,
96 int64_t offset, 96 int64_t offset,
97 char* buffer, 97 char* buffer,
98 int32_t bytes_to_read, 98 int32_t bytes_to_read,
99 struct PP_CompletionCallback callback) { 99 struct PP_CompletionCallback callback) {
100 DebugPrintf("FileIO::Read: file_io_id=%"NACL_PRId64"\n", file_io_id); 100 DebugPrintf("FileIO::Read: file_io_id=%"NACL_PRId32"\n", file_io_id);
101 UNREFERENCED_PARAMETER(offset); 101 UNREFERENCED_PARAMETER(offset);
102 UNREFERENCED_PARAMETER(buffer); 102 UNREFERENCED_PARAMETER(buffer);
103 UNREFERENCED_PARAMETER(bytes_to_read); 103 UNREFERENCED_PARAMETER(bytes_to_read);
104 UNREFERENCED_PARAMETER(callback); 104 UNREFERENCED_PARAMETER(callback);
105 NACL_UNIMPLEMENTED(); 105 NACL_UNIMPLEMENTED();
106 return PP_ERROR_BADRESOURCE; 106 return PP_ERROR_BADRESOURCE;
107 } 107 }
108 108
109 int32_t Write(PP_Resource file_io_id, 109 int32_t Write(PP_Resource file_io_id,
110 int64_t offset, 110 int64_t offset,
111 const char* buffer, 111 const char* buffer,
112 int32_t bytes_to_write, 112 int32_t bytes_to_write,
113 struct PP_CompletionCallback callback) { 113 struct PP_CompletionCallback callback) {
114 DebugPrintf("FileIO::Write: file_io_id=%"NACL_PRId64"\n", file_io_id); 114 DebugPrintf("FileIO::Write: file_io_id=%"NACL_PRId32"\n", file_io_id);
115 UNREFERENCED_PARAMETER(offset); 115 UNREFERENCED_PARAMETER(offset);
116 UNREFERENCED_PARAMETER(buffer); 116 UNREFERENCED_PARAMETER(buffer);
117 UNREFERENCED_PARAMETER(bytes_to_write); 117 UNREFERENCED_PARAMETER(bytes_to_write);
118 UNREFERENCED_PARAMETER(callback); 118 UNREFERENCED_PARAMETER(callback);
119 NACL_UNIMPLEMENTED(); 119 NACL_UNIMPLEMENTED();
120 return PP_ERROR_BADRESOURCE; 120 return PP_ERROR_BADRESOURCE;
121 } 121 }
122 122
123 int32_t SetLength(PP_Resource file_io_id, 123 int32_t SetLength(PP_Resource file_io_id,
124 int64_t length, 124 int64_t length,
125 struct PP_CompletionCallback callback) { 125 struct PP_CompletionCallback callback) {
126 DebugPrintf("FileIO::SetLength: file_io_id=%"NACL_PRId64"\n", file_io_id); 126 DebugPrintf("FileIO::SetLength: file_io_id=%"NACL_PRId32"\n", file_io_id);
127 UNREFERENCED_PARAMETER(length); 127 UNREFERENCED_PARAMETER(length);
128 UNREFERENCED_PARAMETER(callback); 128 UNREFERENCED_PARAMETER(callback);
129 NACL_UNIMPLEMENTED(); 129 NACL_UNIMPLEMENTED();
130 return PP_ERROR_BADRESOURCE; 130 return PP_ERROR_BADRESOURCE;
131 } 131 }
132 132
133 int32_t Flush(PP_Resource file_io_id, 133 int32_t Flush(PP_Resource file_io_id,
134 struct PP_CompletionCallback callback) { 134 struct PP_CompletionCallback callback) {
135 DebugPrintf("FileIO::Flush: file_io=%"NACL_PRId64"\n", file_io_id); 135 DebugPrintf("FileIO::Flush: file_io=%"NACL_PRId32"\n", file_io_id);
136 UNREFERENCED_PARAMETER(callback); 136 UNREFERENCED_PARAMETER(callback);
137 NACL_UNIMPLEMENTED(); 137 NACL_UNIMPLEMENTED();
138 return PP_ERROR_BADRESOURCE; 138 return PP_ERROR_BADRESOURCE;
139 } 139 }
140 140
141 void Close(PP_Resource file_io_id) { 141 void Close(PP_Resource file_io_id) {
142 DebugPrintf("FileIO::Close: file_io=%"NACL_PRId64"\n", file_io_id); 142 DebugPrintf("FileIO::Close: file_io=%"NACL_PRId32"\n", file_io_id);
143 NACL_UNIMPLEMENTED(); 143 NACL_UNIMPLEMENTED();
144 } 144 }
145 145
146 } // namespace 146 } // namespace
147 147
148 148
149 const PPB_FileIO_Dev* FileIO::GetInterface() { 149 const PPB_FileIO_Dev* FileIO::GetInterface() {
150 static const PPB_FileIO_Dev file_io_interface = { 150 static const PPB_FileIO_Dev file_io_interface = {
151 Create, 151 Create,
152 IsFileIO, 152 IsFileIO,
153 Open, 153 Open,
154 Query, 154 Query,
155 Touch, 155 Touch,
156 Read, 156 Read,
157 Write, 157 Write,
158 SetLength, 158 SetLength,
159 Flush, 159 Flush,
160 Close 160 Close
161 }; 161 };
162 return &file_io_interface; 162 return &file_io_interface;
163 } 163 }
164 164
165 } // namespace fake_browser_ppapi 165 } // namespace fake_browser_ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698