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

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

Issue 605513002: [NaCl SDK] nacl_io: Replace allocated ino with hash of path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits Created 6 years, 2 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
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc ('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
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 StringMap_t map; 464 StringMap_t map;
465 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_)); 465 ScopedRef<Html5FsForTesting> fs(new Html5FsForTesting(map, &ppapi_));
466 466
467 ScopedNode root; 467 ScopedNode root;
468 ASSERT_EQ(0, fs->Open(Path("/"), O_RDONLY, &root)); 468 ASSERT_EQ(0, fs->Open(Path("/"), O_RDONLY, &root));
469 469
470 ScopedNode node; 470 ScopedNode node;
471 ASSERT_EQ(0, fs->Open(Path("/file"), O_RDWR, &node)); 471 ASSERT_EQ(0, fs->Open(Path("/file"), O_RDWR, &node));
472 472
473 struct stat stat;
474 ASSERT_EQ(0, node->GetStat(&stat));
475 ino_t file1_ino = stat.st_ino;
476
473 // Should fail for regular files. 477 // Should fail for regular files.
474 const size_t kMaxDirents = 5; 478 const size_t kMaxDirents = 5;
475 dirent dirents[kMaxDirents]; 479 dirent dirents[kMaxDirents];
476 int bytes_read = 1; // Set to a non-zero value. 480 int bytes_read = 1; // Set to a non-zero value.
477 481
478 memset(&dirents[0], 0, sizeof(dirents)); 482 memset(&dirents[0], 0, sizeof(dirents));
479 EXPECT_EQ(ENOTDIR, 483 EXPECT_EQ(ENOTDIR,
480 node->GetDents(0, &dirents[0], sizeof(dirents), &bytes_read)); 484 node->GetDents(0, &dirents[0], sizeof(dirents), &bytes_read));
481 EXPECT_EQ(0, bytes_read); 485 EXPECT_EQ(0, bytes_read);
482 486
(...skipping 16 matching lines...) Expand all
499 dirnames.insert(dirents[i].d_name); 503 dirnames.insert(dirents[i].d_name);
500 } 504 }
501 505
502 EXPECT_EQ(1, dirnames.count("file")); 506 EXPECT_EQ(1, dirnames.count("file"));
503 EXPECT_EQ(1, dirnames.count(".")); 507 EXPECT_EQ(1, dirnames.count("."));
504 EXPECT_EQ(1, dirnames.count("..")); 508 EXPECT_EQ(1, dirnames.count(".."));
505 } 509 }
506 510
507 // Add another file... 511 // Add another file...
508 ASSERT_EQ(0, fs->Open(Path("/file2"), O_CREAT, &node)); 512 ASSERT_EQ(0, fs->Open(Path("/file2"), O_CREAT, &node));
513 ASSERT_EQ(0, node->GetStat(&stat));
514 ino_t file2_ino = stat.st_ino;
515
516 // These files SHOULD not hash to the same value but COULD.
517 EXPECT_NE(file1_ino, file2_ino);
509 518
510 // Read the root directory again. 519 // Read the root directory again.
511 memset(&dirents[0], 0, sizeof(dirents)); 520 memset(&dirents[0], 0, sizeof(dirents));
512 EXPECT_EQ(0, root->GetDents(0, &dirents[0], sizeof(dirents), &bytes_read)); 521 EXPECT_EQ(0, root->GetDents(0, &dirents[0], sizeof(dirents), &bytes_read));
513 522
514 { 523 {
515 size_t num_dirents = bytes_read / sizeof(dirent); 524 size_t num_dirents = bytes_read / sizeof(dirent);
516 EXPECT_EQ(4, num_dirents); 525 EXPECT_EQ(4, num_dirents);
517 EXPECT_EQ(sizeof(dirent) * num_dirents, bytes_read); 526 EXPECT_EQ(sizeof(dirent) * num_dirents, bytes_read);
518 527
519 std::multiset<std::string> dirnames; 528 std::multiset<std::string> dirnames;
520 for (size_t i = 0; i < num_dirents; ++i) { 529 for (size_t i = 0; i < num_dirents; ++i) {
521 EXPECT_EQ(sizeof(dirent), dirents[i].d_off); 530 EXPECT_EQ(sizeof(dirent), dirents[i].d_off);
522 EXPECT_EQ(sizeof(dirent), dirents[i].d_reclen); 531 EXPECT_EQ(sizeof(dirent), dirents[i].d_reclen);
523 dirnames.insert(dirents[i].d_name); 532 dirnames.insert(dirents[i].d_name);
533
534 if (!strcmp(dirents[i].d_name, "file")) {
535 EXPECT_EQ(dirents[i].d_ino, file1_ino);
536 }
537 if (!strcmp(dirents[i].d_name, "file2")) {
538 EXPECT_EQ(dirents[i].d_ino, file2_ino);
539 }
524 } 540 }
525 541
526 EXPECT_EQ(1, dirnames.count("file")); 542 EXPECT_EQ(1, dirnames.count("file"));
527 EXPECT_EQ(1, dirnames.count("file2")); 543 EXPECT_EQ(1, dirnames.count("file2"));
528 EXPECT_EQ(1, dirnames.count(".")); 544 EXPECT_EQ(1, dirnames.count("."));
529 EXPECT_EQ(1, dirnames.count("..")); 545 EXPECT_EQ(1, dirnames.count(".."));
530 } 546 }
531 } 547 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/html5fs/html5_fs_node.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698