| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/dir_reader_posix.h" | 5 #include "base/dir_reader_posix.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <stdio.h> | 8 #include <stdio.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <unistd.h> | 11 #include <unistd.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 #if defined(OS_ANDROID) | 16 #if defined(OS_ANDROID) |
| 17 #include "base/os_compat_android.h" | 17 #include "base/os_compat_android.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 | 21 |
| 22 TEST(DirReaderPosixUnittest, Read) { | 22 TEST(DirReaderPosixUnittest, Read) { |
| 23 static const unsigned kNumFiles = 100; | 23 static const unsigned kNumFiles = 100; |
| 24 | 24 |
| 25 if (DirReaderPosix::IsFallback()) | 25 if (DirReaderPosix::IsFallback()) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 char kDirTemplate[] = "/tmp/org.chromium.dir-reader-posix-XXXXXX"; | 28 char kDirTemplate[] = "/tmp/org.chromium.dir-reader-posix-XXXXXX"; |
| 29 const char* dir = mkdtemp(kDirTemplate); | 29 const char* dir = mkdtemp(kDirTemplate); |
| 30 CHECK(dir); | 30 ASSERT_TRUE(dir); |
| 31 | 31 |
| 32 const int prev_wd = open(".", O_RDONLY | O_DIRECTORY); | 32 const int prev_wd = open(".", O_RDONLY | O_DIRECTORY); |
| 33 CHECK_GE(prev_wd, 0); | 33 DCHECK_GE(prev_wd, 0); |
| 34 | 34 |
| 35 PCHECK(chdir(dir) == 0); | 35 PCHECK(chdir(dir) == 0); |
| 36 | 36 |
| 37 for (unsigned i = 0; i < kNumFiles; i++) { | 37 for (unsigned i = 0; i < kNumFiles; i++) { |
| 38 char buf[16]; | 38 char buf[16]; |
| 39 snprintf(buf, sizeof(buf), "%d", i); | 39 snprintf(buf, sizeof(buf), "%d", i); |
| 40 const int fd = open(buf, O_CREAT | O_RDONLY | O_EXCL, 0600); | 40 const int fd = open(buf, O_CREAT | O_RDONLY | O_EXCL, 0600); |
| 41 PCHECK(fd >= 0); | 41 PCHECK(fd >= 0); |
| 42 PCHECK(close(fd) == 0); | 42 PCHECK(close(fd) == 0); |
| 43 } | 43 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 PCHECK(fchdir(prev_wd) == 0); | 84 PCHECK(fchdir(prev_wd) == 0); |
| 85 PCHECK(close(prev_wd) == 0); | 85 PCHECK(close(prev_wd) == 0); |
| 86 | 86 |
| 87 EXPECT_TRUE(seen_dot); | 87 EXPECT_TRUE(seen_dot); |
| 88 EXPECT_TRUE(seen_dotdot); | 88 EXPECT_TRUE(seen_dotdot); |
| 89 EXPECT_EQ(kNumFiles, seen.size()); | 89 EXPECT_EQ(kNumFiles, seen.size()); |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace base | 92 } // namespace base |
| OLD | NEW |