| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 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 | 5 |
| 6 #include <errno.h> | 6 #include <errno.h> |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <gmock/gmock.h> | 9 #include <gmock/gmock.h> |
| 10 #include <ppapi/c/ppb_file_io.h> | 10 #include <ppapi/c/ppb_file_io.h> |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // Close. | 159 // Close. |
| 160 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_)); | 160 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_)); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void MountHtml5FsNodeTest::InitFilesystem() { | 163 void MountHtml5FsNodeTest::InitFilesystem() { |
| 164 StringMap_t map; | 164 StringMap_t map; |
| 165 mnt_ = new MountHtml5FsMock(map, ppapi_); | 165 mnt_ = new MountHtml5FsMock(map, ppapi_); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void MountHtml5FsNodeTest::InitNode() { | 168 void MountHtml5FsNodeTest::InitNode() { |
| 169 node_ = mnt_->Open(Path(path_), O_CREAT | O_RDWR); | 169 ASSERT_EQ(0, mnt_->Open(Path(path_), O_CREAT | O_RDWR, &node_)); |
| 170 ASSERT_NE((MountNode*)NULL, node_); | 170 ASSERT_NE((MountNode*)NULL, node_); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Node test where the filesystem is opened synchronously; that is, the | 173 // Node test where the filesystem is opened synchronously; that is, the |
| 174 // creation of the mount blocks until the filesystem is ready. | 174 // creation of the mount blocks until the filesystem is ready. |
| 175 class MountHtml5FsNodeSyncTest : public MountHtml5FsNodeTest { | 175 class MountHtml5FsNodeSyncTest : public MountHtml5FsNodeTest { |
| 176 public: | 176 public: |
| 177 void SetUpForFileType(PP_FileType file_type); | 177 void SetUpForFileType(PP_FileType file_type); |
| 178 | 178 |
| 179 virtual void SetUp(); | 179 virtual void SetUp(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 371 } |
| 372 | 372 |
| 373 TEST_F(MountHtml5FsNodeSyncTest, Write) { | 373 TEST_F(MountHtml5FsNodeSyncTest, Write) { |
| 374 const int offset = 10; | 374 const int offset = 10; |
| 375 const int count = 20; | 375 const int count = 20; |
| 376 const char buffer[30] = {0}; | 376 const char buffer[30] = {0}; |
| 377 | 377 |
| 378 EXPECT_CALL(*fileio_, Write(fileio_resource_, offset, &buffer[0], count, _)) | 378 EXPECT_CALL(*fileio_, Write(fileio_resource_, offset, &buffer[0], count, _)) |
| 379 .WillOnce(Return(count)); | 379 .WillOnce(Return(count)); |
| 380 | 380 |
| 381 int result = node_->Write(offset, &buffer, count); | 381 int result = 0; |
| 382 EXPECT_EQ(0, node_->Write(offset, &buffer, count, &result)); |
| 382 EXPECT_EQ(count, result); | 383 EXPECT_EQ(count, result); |
| 383 } | 384 } |
| 384 | 385 |
| 385 TEST_F(MountHtml5FsNodeSyncTest, Read) { | 386 TEST_F(MountHtml5FsNodeSyncTest, Read) { |
| 386 const int offset = 10; | 387 const int offset = 10; |
| 387 const int count = 20; | 388 const int count = 20; |
| 388 char buffer[30] = {0}; | 389 char buffer[30] = {0}; |
| 389 | 390 |
| 390 EXPECT_CALL(*fileio_, Read(fileio_resource_, offset, &buffer[0], count, _)) | 391 EXPECT_CALL(*fileio_, Read(fileio_resource_, offset, &buffer[0], count, _)) |
| 391 .WillOnce(Return(count)); | 392 .WillOnce(Return(count)); |
| 392 | 393 |
| 393 int result = node_->Read(offset, &buffer, count); | 394 int result = 0; |
| 395 EXPECT_EQ(0, node_->Read(offset, &buffer, count, &result)); |
| 394 EXPECT_EQ(count, result); | 396 EXPECT_EQ(count, result); |
| 395 } | 397 } |
| 396 | 398 |
| 397 TEST_F(MountHtml5FsNodeSyncTest, GetStat) { | 399 TEST_F(MountHtml5FsNodeSyncTest, GetStat) { |
| 398 const int size = 123; | 400 const int size = 123; |
| 399 const int creation_time = 1000; | 401 const int creation_time = 1000; |
| 400 const int access_time = 2000; | 402 const int access_time = 2000; |
| 401 const int modified_time = 3000; | 403 const int modified_time = 3000; |
| 402 | 404 |
| 403 PP_FileInfo info; | 405 PP_FileInfo info; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 430 | 432 |
| 431 int result = node_->FTruncate(size); | 433 int result = node_->FTruncate(size); |
| 432 EXPECT_EQ(0, result); | 434 EXPECT_EQ(0, result); |
| 433 } | 435 } |
| 434 | 436 |
| 435 TEST_F(MountHtml5FsNodeSyncTest, GetDents) { | 437 TEST_F(MountHtml5FsNodeSyncTest, GetDents) { |
| 436 struct dirent dirents[2]; | 438 struct dirent dirents[2]; |
| 437 memset(&dirents[0], 0, sizeof(dirents)); | 439 memset(&dirents[0], 0, sizeof(dirents)); |
| 438 | 440 |
| 439 // Should fail for regular files. | 441 // Should fail for regular files. |
| 440 int result = node_->GetDents(0, &dirents[0], sizeof(dirent) * 2); | 442 int result_bytes = 0; |
| 441 ASSERT_EQ(-1, result); | 443 EXPECT_EQ(ENOTDIR, node_->GetDents(0, &dirents[0], sizeof(dirent) * 2, |
| 442 ASSERT_EQ(ENOTDIR, errno); | 444 &result_bytes)); |
| 445 ASSERT_EQ(0, result_bytes); |
| 443 } | 446 } |
| 444 | 447 |
| 445 TEST_F(MountHtml5FsNodeSyncDirTest, OpenAndClose) { | 448 TEST_F(MountHtml5FsNodeSyncDirTest, OpenAndClose) { |
| 446 } | 449 } |
| 447 | 450 |
| 448 TEST_F(MountHtml5FsNodeSyncDirTest, Write) { | 451 TEST_F(MountHtml5FsNodeSyncDirTest, Write) { |
| 449 const int offset = 10; | 452 const int offset = 10; |
| 450 const int count = 20; | 453 const int count = 20; |
| 451 const char buffer[30] = {0}; | 454 const char buffer[30] = {0}; |
| 452 | 455 |
| 453 // Should fail for directories. | 456 // Should fail for directories. |
| 454 int result = node_->Write(offset, &buffer, count); | 457 int result_bytes = 0; |
| 455 ASSERT_EQ(-1, result); | 458 EXPECT_EQ(EISDIR, node_->Write(offset, &buffer, count, &result_bytes)); |
| 456 EXPECT_EQ(EISDIR, errno); | 459 ASSERT_EQ(0, result_bytes); |
| 457 } | 460 } |
| 458 | 461 |
| 459 TEST_F(MountHtml5FsNodeSyncDirTest, Read) { | 462 TEST_F(MountHtml5FsNodeSyncDirTest, Read) { |
| 460 const int offset = 10; | 463 const int offset = 10; |
| 461 const int count = 20; | 464 const int count = 20; |
| 462 char buffer[30] = {0}; | 465 char buffer[30] = {0}; |
| 463 | 466 |
| 464 // Should fail for directories. | 467 // Should fail for directories. |
| 465 int result = node_->Read(offset, &buffer, count); | 468 int result_bytes = 0; |
| 466 ASSERT_EQ(-1, result); | 469 EXPECT_EQ(EISDIR, node_->Read(offset, &buffer, count, &result_bytes)); |
| 467 EXPECT_EQ(EISDIR, errno); | 470 ASSERT_EQ(0, result_bytes); |
| 468 } | 471 } |
| 469 | 472 |
| 470 TEST_F(MountHtml5FsNodeSyncDirTest, GetStat) { | 473 TEST_F(MountHtml5FsNodeSyncDirTest, GetStat) { |
| 471 const int creation_time = 1000; | 474 const int creation_time = 1000; |
| 472 const int access_time = 2000; | 475 const int access_time = 2000; |
| 473 const int modified_time = 3000; | 476 const int modified_time = 3000; |
| 474 | 477 |
| 475 PP_FileInfo info; | 478 PP_FileInfo info; |
| 476 info.size = 0; | 479 info.size = 0; |
| 477 info.type = PP_FILETYPE_DIRECTORY; | 480 info.type = PP_FILETYPE_DIRECTORY; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 491 EXPECT_EQ(S_IFDIR | S_IWRITE | S_IREAD, statbuf.st_mode); | 494 EXPECT_EQ(S_IFDIR | S_IWRITE | S_IREAD, statbuf.st_mode); |
| 492 EXPECT_EQ(0, statbuf.st_size); | 495 EXPECT_EQ(0, statbuf.st_size); |
| 493 EXPECT_EQ(access_time, statbuf.st_atime); | 496 EXPECT_EQ(access_time, statbuf.st_atime); |
| 494 EXPECT_EQ(modified_time, statbuf.st_mtime); | 497 EXPECT_EQ(modified_time, statbuf.st_mtime); |
| 495 EXPECT_EQ(creation_time, statbuf.st_ctime); | 498 EXPECT_EQ(creation_time, statbuf.st_ctime); |
| 496 } | 499 } |
| 497 | 500 |
| 498 TEST_F(MountHtml5FsNodeSyncDirTest, FTruncate) { | 501 TEST_F(MountHtml5FsNodeSyncDirTest, FTruncate) { |
| 499 const int size = 123; | 502 const int size = 123; |
| 500 // Should fail for directories. | 503 // Should fail for directories. |
| 501 int result = node_->FTruncate(size); | 504 EXPECT_EQ(EISDIR, node_->FTruncate(size)); |
| 502 ASSERT_EQ(-1, result); | |
| 503 EXPECT_EQ(EISDIR, errno); | |
| 504 } | 505 } |
| 505 | 506 |
| 506 TEST_F(MountHtml5FsNodeSyncDirTest, GetDents) { | 507 TEST_F(MountHtml5FsNodeSyncDirTest, GetDents) { |
| 507 const int fileref_resource_1 = 238; | 508 const int fileref_resource_1 = 238; |
| 508 const int fileref_resource_2 = 239; | 509 const int fileref_resource_2 = 239; |
| 509 | 510 |
| 510 const int fileref_name_id_1 = 240; | 511 const int fileref_name_id_1 = 240; |
| 511 const char fileref_name_cstr_1[] = "bar"; | 512 const char fileref_name_cstr_1[] = "bar"; |
| 512 PP_Var fileref_name_1; | 513 PP_Var fileref_name_1; |
| 513 fileref_name_1.type = PP_VARTYPE_STRING; | 514 fileref_name_1.type = PP_VARTYPE_STRING; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 535 EXPECT_CALL(*var, VarToUtf8(IsEqualToVar(fileref_name_2), _)) | 536 EXPECT_CALL(*var, VarToUtf8(IsEqualToVar(fileref_name_2), _)) |
| 536 .WillOnce(Return(fileref_name_cstr_2)); | 537 .WillOnce(Return(fileref_name_cstr_2)); |
| 537 | 538 |
| 538 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_1)); | 539 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_1)); |
| 539 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_2)); | 540 EXPECT_CALL(*ppapi_, ReleaseResource(fileref_resource_2)); |
| 540 | 541 |
| 541 struct dirent dirents[2]; | 542 struct dirent dirents[2]; |
| 542 memset(&dirents[0], 0, sizeof(dirents)); | 543 memset(&dirents[0], 0, sizeof(dirents)); |
| 543 // +2 to test a size that is not a multiple of sizeof(dirent). | 544 // +2 to test a size that is not a multiple of sizeof(dirent). |
| 544 // Expect it to round down. | 545 // Expect it to round down. |
| 545 int result = node_->GetDents(0, &dirents[0], sizeof(dirent) * 2 + 2); | 546 int result_bytes = 0; |
| 547 EXPECT_EQ( |
| 548 0, |
| 549 node_->GetDents(0, &dirents[0], sizeof(dirent) * 2 + 2, &result_bytes)); |
| 546 | 550 |
| 547 ASSERT_EQ(sizeof(dirent) * 2, result); | 551 ASSERT_EQ(sizeof(dirent) * 2, result_bytes); |
| 548 EXPECT_LT(0, dirents[0].d_ino); // 0 is an invalid inode number. | 552 EXPECT_LT(0, dirents[0].d_ino); // 0 is an invalid inode number. |
| 549 EXPECT_EQ(sizeof(dirent), dirents[0].d_off); | 553 EXPECT_EQ(sizeof(dirent), dirents[0].d_off); |
| 550 EXPECT_EQ(sizeof(dirent), dirents[0].d_reclen); | 554 EXPECT_EQ(sizeof(dirent), dirents[0].d_reclen); |
| 551 EXPECT_STREQ(fileref_name_cstr_1, dirents[0].d_name); | 555 EXPECT_STREQ(fileref_name_cstr_1, dirents[0].d_name); |
| 552 EXPECT_LT(0, dirents[1].d_ino); // 0 is an invalid inode number. | 556 EXPECT_LT(0, dirents[1].d_ino); // 0 is an invalid inode number. |
| 553 EXPECT_EQ(sizeof(dirent), dirents[1].d_off); | 557 EXPECT_EQ(sizeof(dirent), dirents[1].d_off); |
| 554 EXPECT_EQ(sizeof(dirent), dirents[1].d_reclen); | 558 EXPECT_EQ(sizeof(dirent), dirents[1].d_reclen); |
| 555 EXPECT_STREQ(fileref_name_cstr_2, dirents[1].d_name); | 559 EXPECT_STREQ(fileref_name_cstr_2, dirents[1].d_name); |
| 556 } | 560 } |
| OLD | NEW |