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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/html5_fs_test.cc

Issue 2467223003: [NaCl SDK] Refactor FakeHtml5FsFilesystem and FakeHtml5FsNode. (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include <gmock/gmock.h> 11 #include <ppapi/c/pp_file_info.h>
12 #include <ppapi/c/ppb_file_io.h>
13 #include <ppapi/c/pp_directory_entry.h>
14 #include <ppapi/c/pp_errors.h>
15 #include <ppapi/c/pp_instance.h>
16 #if defined(WIN32)
17 #include <windows.h> // For Sleep()
18 #endif
19 12
13 #include "fake_ppapi/fake_node.h"
20 #include "fake_ppapi/fake_pepper_interface_html5_fs.h" 14 #include "fake_ppapi/fake_pepper_interface_html5_fs.h"
21 #include "nacl_io/kernel_handle.h" 15 #include "nacl_io/kernel_handle.h"
22 #include "nacl_io/html5fs/html5_fs.h" 16 #include "nacl_io/html5fs/html5_fs.h"
23 #include "nacl_io/osdirent.h" 17 #include "nacl_io/osdirent.h"
24 #include "nacl_io/osunistd.h"
25 #include "nacl_io/pepper_interface_delegate.h" 18 #include "nacl_io/pepper_interface_delegate.h"
26 #include "sdk_util/scoped_ref.h" 19 #include "sdk_util/scoped_ref.h"
27 #include "mock_util.h" 20 #include "mock_util.h"
28 #include "pepper_interface_mock.h" 21 #include "pepper_interface_mock.h"
29 22
30 using namespace nacl_io; 23 using namespace nacl_io;
31 using namespace sdk_util; 24 using namespace sdk_util;
32 25
33 using ::testing::_; 26 using ::testing::_;
34 using ::testing::DoAll; 27 using ::testing::DoAll;
35 using ::testing::Invoke; 28 using ::testing::Invoke;
36 using ::testing::Mock; 29 using ::testing::Mock;
37 using ::testing::Return; 30 using ::testing::Return;
38 31
39 namespace { 32 namespace {
40 33
41 class Html5FsForTesting : public Html5Fs { 34 class Html5FsForTesting : public Html5Fs {
42 public: 35 public:
43 Html5FsForTesting(StringMap_t& string_map, PepperInterface* ppapi, 36 Html5FsForTesting(StringMap_t& string_map,
37 PepperInterface* ppapi,
44 int expected_error = 0) { 38 int expected_error = 0) {
45 FsInitArgs args; 39 FsInitArgs args;
46 args.string_map = string_map; 40 args.string_map = string_map;
47 args.ppapi = ppapi; 41 args.ppapi = ppapi;
48 Error error = Init(args); 42 Error error = Init(args);
49 EXPECT_EQ(expected_error, error); 43 EXPECT_EQ(expected_error, error);
50 } 44 }
51 45
52 bool Exists(const char* filename) { 46 bool Exists(const char* filename) {
53 ScopedNode node; 47 ScopedNode node;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 for (int i = 0; filesystem_type_strings[i] != NULL; ++i) { 95 for (int i = 0; filesystem_type_strings[i] != NULL; ++i) {
102 const char* filesystem_type_string = filesystem_type_strings[i]; 96 const char* filesystem_type_string = filesystem_type_strings[i];
103 PP_FileSystemType expected_filesystem_type = filesystem_type_values[i]; 97 PP_FileSystemType expected_filesystem_type = filesystem_type_values[i];
104 98
105 for (int j = 0; expected_size_strings[j] != NULL; ++j) { 99 for (int j = 0; expected_size_strings[j] != NULL; ++j) {
106 const char* expected_size_string = expected_size_strings[j]; 100 const char* expected_size_string = expected_size_strings[j];
107 int64_t expected_expected_size = expected_size_values[j]; 101 int64_t expected_expected_size = expected_size_values[j];
108 102
109 ppapi_.SetFileSystemInterfaceDelegate(filesystem_mock); 103 ppapi_.SetFileSystemInterfaceDelegate(filesystem_mock);
110 104
111 ON_CALL(*filesystem_mock, Create(_, _)).WillByDefault( 105 ON_CALL(*filesystem_mock, Create(_, _))
112 Invoke(filesystem_fake, &FakeFileSystemInterface::Create)); 106 .WillByDefault(
107 Invoke(filesystem_fake, &FakeFileSystemInterface::Create));
113 108
114 EXPECT_CALL(*filesystem_mock, 109 EXPECT_CALL(*filesystem_mock,
115 Create(ppapi_.GetInstance(), expected_filesystem_type)); 110 Create(ppapi_.GetInstance(), expected_filesystem_type));
116 111
117 EXPECT_CALL(*filesystem_mock, Open(_, expected_expected_size, _)) 112 EXPECT_CALL(*filesystem_mock, Open(_, expected_expected_size, _))
118 .WillOnce(DoAll(CallCallback<2>(int32_t(PP_OK)), 113 .WillOnce(DoAll(CallCallback<2>(int32_t(PP_OK)),
119 Return(int32_t(PP_OK_COMPLETIONPENDING)))); 114 Return(int32_t(PP_OK_COMPLETIONPENDING))));
120 115
121 StringMap_t map; 116 StringMap_t map;
122 map["type"] = filesystem_type_string; 117 map["type"] = filesystem_type_string;
(...skipping 13 matching lines...) Expand all
136 ScopedRef<Html5FsForTesting> fs( 131 ScopedRef<Html5FsForTesting> fs(
137 new Html5FsForTesting(map, &ppapi_, EINVAL)); 132 new Html5FsForTesting(map, &ppapi_, EINVAL));
138 } 133 }
139 134
140 { 135 {
141 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL)); 136 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo", NULL));
142 PP_Resource filesystem = ppapi_html5_.GetFileSystemInterface()->Create( 137 PP_Resource filesystem = ppapi_html5_.GetFileSystemInterface()->Create(
143 ppapi_html5_.GetInstance(), PP_FILESYSTEMTYPE_LOCALPERSISTENT); 138 ppapi_html5_.GetInstance(), PP_FILESYSTEMTYPE_LOCALPERSISTENT);
144 139
145 ASSERT_EQ(int32_t(PP_OK), ppapi_html5_.GetFileSystemInterface()->Open( 140 ASSERT_EQ(int32_t(PP_OK), ppapi_html5_.GetFileSystemInterface()->Open(
146 filesystem, 0, PP_BlockUntilComplete())); 141 filesystem, 0, PP_BlockUntilComplete()));
147 142
148 StringMap_t map; 143 StringMap_t map;
149 char buffer[30]; 144 char buffer[30];
150 snprintf(buffer, 30, "%d", filesystem); 145 snprintf(buffer, 30, "%d", filesystem);
151 map["filesystem_resource"] = buffer; 146 map["filesystem_resource"] = buffer;
152 ScopedRef<Html5FsForTesting> fs( 147 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
153 new Html5FsForTesting(map, &ppapi_));
154 148
155 ASSERT_TRUE(fs->Exists("/foo")); 149 ASSERT_TRUE(fs->Exists("/foo"));
156 150
157 ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem); 151 ppapi_html5_.GetCoreInterface()->ReleaseResource(filesystem);
158 } 152 }
159 } 153 }
160 154
161 TEST_F(Html5FsTest, MountSubtree) { 155 TEST_F(Html5FsTest, MountSubtree) {
162 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddEmptyFile("/foo/bar", 156 EXPECT_TRUE(
163 NULL)); 157 ppapi_html5_.filesystem_template()->AddEmptyFile("/foo/bar", NULL));
164 StringMap_t map; 158 StringMap_t map;
165 map["SOURCE"] = "/foo"; 159 map["SOURCE"] = "/foo";
166 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); 160 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
167 161
168 ASSERT_TRUE(fs->Exists("/bar")); 162 ASSERT_TRUE(fs->Exists("/bar"));
169 ASSERT_FALSE(fs->Exists("/foo/bar")); 163 ASSERT_FALSE(fs->Exists("/foo/bar"));
170 } 164 }
171 165
172 TEST_F(Html5FsTest, Mkdir) { 166 TEST_F(Html5FsTest, Mkdir) {
173 StringMap_t map; 167 StringMap_t map;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 243
250 EXPECT_FALSE(fs->Exists("/foo")); 244 EXPECT_FALSE(fs->Exists("/foo"));
251 245
252 Path path("/foo"); 246 Path path("/foo");
253 ScopedNode node; 247 ScopedNode node;
254 ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node)); 248 ASSERT_EQ(0, fs->Open(path, O_CREAT | O_RDWR, &node));
255 249
256 // Write some data. 250 // Write some data.
257 const char* contents = "contents"; 251 const char* contents = "contents";
258 int bytes_written = 0; 252 int bytes_written = 0;
259 EXPECT_EQ(0, node->Write(HandleAttr(), contents, strlen(contents), 253 EXPECT_EQ(
260 &bytes_written)); 254 0, node->Write(HandleAttr(), contents, strlen(contents), &bytes_written));
261 EXPECT_EQ(strlen(contents), bytes_written); 255 EXPECT_EQ(strlen(contents), bytes_written);
262 256
263 // Create again. 257 // Create again.
264 ASSERT_EQ(0, fs->Open(path, O_CREAT, &node)); 258 ASSERT_EQ(0, fs->Open(path, O_CREAT, &node));
265 259
266 // Check that the file still has data. 260 // Check that the file still has data.
267 off_t size; 261 off_t size;
268 EXPECT_EQ(0, node->GetSize(&size)); 262 EXPECT_EQ(0, node->GetSize(&size));
269 EXPECT_EQ(strlen(contents), size); 263 EXPECT_EQ(strlen(contents), size);
270 264
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 EXPECT_EQ(EISDIR, node->Write(attr, &buffer[0], sizeof(buffer), &bytes_read)); 356 EXPECT_EQ(EISDIR, node->Write(attr, &buffer[0], sizeof(buffer), &bytes_read));
363 } 357 }
364 358
365 TEST_F(Html5FsTest, GetStat) { 359 TEST_F(Html5FsTest, GetStat) {
366 const int creation_time = 1000; 360 const int creation_time = 1000;
367 const int access_time = 2000; 361 const int access_time = 2000;
368 const int modified_time = 3000; 362 const int modified_time = 3000;
369 const char* contents = "contents"; 363 const char* contents = "contents";
370 364
371 // Create fake file. 365 // Create fake file.
372 FakeHtml5FsNode* fake_node; 366 FakeNode* fake_node;
373 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddFile( 367 EXPECT_TRUE(ppapi_html5_.filesystem_template()->AddFile("/file", contents,
374 "/file", contents, &fake_node)); 368 &fake_node));
375 fake_node->set_creation_time(creation_time); 369 fake_node->set_creation_time(creation_time);
376 fake_node->set_last_access_time(access_time); 370 fake_node->set_last_access_time(access_time);
377 fake_node->set_last_modified_time(modified_time); 371 fake_node->set_last_modified_time(modified_time);
378 372
379 // Create fake directory. 373 // Create fake directory.
380 EXPECT_TRUE( 374 EXPECT_TRUE(
381 ppapi_html5_.filesystem_template()->AddDirectory("/dir", &fake_node)); 375 ppapi_html5_.filesystem_template()->AddDirectory("/dir", &fake_node));
382 fake_node->set_creation_time(creation_time); 376 fake_node->set_creation_time(creation_time);
383 fake_node->set_last_access_time(access_time); 377 fake_node->set_last_access_time(access_time);
384 fake_node->set_last_modified_time(modified_time); 378 fake_node->set_last_modified_time(modified_time);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 EXPECT_EQ(dirents[i].d_ino, file2_ino); 541 EXPECT_EQ(dirents[i].d_ino, file2_ino);
548 } 542 }
549 } 543 }
550 544
551 EXPECT_EQ(1, dirnames.count("file")); 545 EXPECT_EQ(1, dirnames.count("file"));
552 EXPECT_EQ(1, dirnames.count("file2")); 546 EXPECT_EQ(1, dirnames.count("file2"));
553 EXPECT_EQ(1, dirnames.count(".")); 547 EXPECT_EQ(1, dirnames.count("."));
554 EXPECT_EQ(1, dirnames.count("..")); 548 EXPECT_EQ(1, dirnames.count(".."));
555 } 549 }
556 } 550 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698