OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/base/fileutils.h" | 13 #include "webrtc/base/fileutils.h" |
14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
15 #include "webrtc/base/pathutils.h" | 15 #include "webrtc/base/pathutils.h" |
16 #include "webrtc/base/stream.h" | 16 #include "webrtc/base/stream.h" |
17 | 17 |
18 namespace rtc { | 18 namespace rtc { |
19 | 19 |
| 20 #if defined (WEBRTC_ANDROID) |
| 21 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
| 22 #define MAYBE_FilesystemTest DISABLED_FilesystemTest |
| 23 #else |
| 24 #define MAYBE_FilesystemTest FilesystemTest |
| 25 #endif |
| 26 |
20 // Make sure we can get a temp folder for the later tests. | 27 // Make sure we can get a temp folder for the later tests. |
21 TEST(FilesystemTest, GetTemporaryFolder) { | 28 TEST(MAYBE_FilesystemTest, GetTemporaryFolder) { |
22 Pathname path; | 29 Pathname path; |
23 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 30 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); |
24 } | 31 } |
25 | 32 |
26 // Test creating a temp file, reading it back in, and deleting it. | 33 // Test creating a temp file, reading it back in, and deleting it. |
27 TEST(FilesystemTest, TestOpenFile) { | 34 TEST(MAYBE_FilesystemTest, TestOpenFile) { |
28 Pathname path; | 35 Pathname path; |
29 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 36 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); |
30 path.SetPathname(Filesystem::TempFilename(path, "ut")); | 37 path.SetPathname(Filesystem::TempFilename(path, "ut")); |
31 | 38 |
32 FileStream* fs; | 39 FileStream* fs; |
33 char buf[256]; | 40 char buf[256]; |
34 size_t bytes; | 41 size_t bytes; |
35 | 42 |
36 fs = Filesystem::OpenFile(path, "wb"); | 43 fs = Filesystem::OpenFile(path, "wb"); |
37 ASSERT_TRUE(fs != NULL); | 44 ASSERT_TRUE(fs != NULL); |
38 EXPECT_EQ(SR_SUCCESS, fs->Write("test", 4, &bytes, NULL)); | 45 EXPECT_EQ(SR_SUCCESS, fs->Write("test", 4, &bytes, NULL)); |
39 EXPECT_EQ(4U, bytes); | 46 EXPECT_EQ(4U, bytes); |
40 delete fs; | 47 delete fs; |
41 | 48 |
42 EXPECT_TRUE(Filesystem::IsFile(path)); | 49 EXPECT_TRUE(Filesystem::IsFile(path)); |
43 | 50 |
44 fs = Filesystem::OpenFile(path, "rb"); | 51 fs = Filesystem::OpenFile(path, "rb"); |
45 ASSERT_TRUE(fs != NULL); | 52 ASSERT_TRUE(fs != NULL); |
46 EXPECT_EQ(SR_SUCCESS, fs->Read(buf, sizeof(buf), &bytes, NULL)); | 53 EXPECT_EQ(SR_SUCCESS, fs->Read(buf, sizeof(buf), &bytes, NULL)); |
47 EXPECT_EQ(4U, bytes); | 54 EXPECT_EQ(4U, bytes); |
48 delete fs; | 55 delete fs; |
49 | 56 |
50 EXPECT_TRUE(Filesystem::DeleteFile(path)); | 57 EXPECT_TRUE(Filesystem::DeleteFile(path)); |
51 EXPECT_FALSE(Filesystem::IsFile(path)); | 58 EXPECT_FALSE(Filesystem::IsFile(path)); |
52 } | 59 } |
53 | 60 |
54 // Test opening a non-existent file. | 61 // Test opening a non-existent file. |
55 TEST(FilesystemTest, TestOpenBadFile) { | 62 TEST(MAYBE_FilesystemTest, TestOpenBadFile) { |
56 Pathname path; | 63 Pathname path; |
57 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 64 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); |
58 path.SetFilename("not an actual file"); | 65 path.SetFilename("not an actual file"); |
59 | 66 |
60 EXPECT_FALSE(Filesystem::IsFile(path)); | 67 EXPECT_FALSE(Filesystem::IsFile(path)); |
61 | 68 |
62 FileStream* fs = Filesystem::OpenFile(path, "rb"); | 69 FileStream* fs = Filesystem::OpenFile(path, "rb"); |
63 EXPECT_FALSE(fs != NULL); | 70 EXPECT_FALSE(fs != NULL); |
64 } | 71 } |
65 | 72 |
66 // Test that CreatePrivateFile fails for existing files and succeeds for | 73 // Test that CreatePrivateFile fails for existing files and succeeds for |
67 // non-existent ones. | 74 // non-existent ones. |
68 TEST(FilesystemTest, TestCreatePrivateFile) { | 75 TEST(MAYBE_FilesystemTest, TestCreatePrivateFile) { |
69 Pathname path; | 76 Pathname path; |
70 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 77 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); |
71 path.SetFilename("private_file_test"); | 78 path.SetFilename("private_file_test"); |
72 | 79 |
73 // First call should succeed because the file doesn't exist yet. | 80 // First call should succeed because the file doesn't exist yet. |
74 EXPECT_TRUE(Filesystem::CreatePrivateFile(path)); | 81 EXPECT_TRUE(Filesystem::CreatePrivateFile(path)); |
75 // Next call should fail, because now it exists. | 82 // Next call should fail, because now it exists. |
76 EXPECT_FALSE(Filesystem::CreatePrivateFile(path)); | 83 EXPECT_FALSE(Filesystem::CreatePrivateFile(path)); |
77 | 84 |
78 // Verify that we have permission to open the file for reading and writing. | 85 // Verify that we have permission to open the file for reading and writing. |
79 std::unique_ptr<FileStream> fs(Filesystem::OpenFile(path, "wb")); | 86 std::unique_ptr<FileStream> fs(Filesystem::OpenFile(path, "wb")); |
80 EXPECT_TRUE(fs.get() != NULL); | 87 EXPECT_TRUE(fs.get() != NULL); |
81 // Have to close the file on Windows before it will let us delete it. | 88 // Have to close the file on Windows before it will let us delete it. |
82 fs.reset(); | 89 fs.reset(); |
83 | 90 |
84 // Verify that we have permission to delete the file. | 91 // Verify that we have permission to delete the file. |
85 EXPECT_TRUE(Filesystem::DeleteFile(path)); | 92 EXPECT_TRUE(Filesystem::DeleteFile(path)); |
86 } | 93 } |
87 | 94 |
88 // Test checking for free disk space. | 95 // Test checking for free disk space. |
89 TEST(FilesystemTest, TestGetDiskFreeSpace) { | 96 TEST(MAYBE_FilesystemTest, TestGetDiskFreeSpace) { |
90 // Note that we should avoid picking any file/folder which could be located | 97 // Note that we should avoid picking any file/folder which could be located |
91 // at the remotely mounted drive/device. | 98 // at the remotely mounted drive/device. |
92 Pathname path; | 99 Pathname path; |
93 ASSERT_TRUE(Filesystem::GetAppDataFolder(&path, true)); | 100 ASSERT_TRUE(Filesystem::GetAppDataFolder(&path, true)); |
94 | 101 |
95 int64_t free1 = 0; | 102 int64_t free1 = 0; |
96 EXPECT_TRUE(Filesystem::IsFolder(path)); | 103 EXPECT_TRUE(Filesystem::IsFolder(path)); |
97 EXPECT_FALSE(Filesystem::IsFile(path)); | 104 EXPECT_FALSE(Filesystem::IsFile(path)); |
98 EXPECT_TRUE(Filesystem::GetDiskFreeSpace(path, &free1)); | 105 EXPECT_TRUE(Filesystem::GetDiskFreeSpace(path, &free1)); |
99 EXPECT_GT(free1, 0); | 106 EXPECT_GT(free1, 0); |
(...skipping 12 matching lines...) Expand all Loading... |
112 path.clear(); | 119 path.clear(); |
113 EXPECT_TRUE(path.empty()); | 120 EXPECT_TRUE(path.empty()); |
114 EXPECT_TRUE(Filesystem::GetDiskFreeSpace(path, &free3)); | 121 EXPECT_TRUE(Filesystem::GetDiskFreeSpace(path, &free3)); |
115 // Current working directory may not be where exe is. | 122 // Current working directory may not be where exe is. |
116 // EXPECT_LT(static_cast<int64_t>(free1 * .9), free3); | 123 // EXPECT_LT(static_cast<int64_t>(free1 * .9), free3); |
117 // EXPECT_LT(free3, static_cast<int64_t>(free1 * 1.1)); | 124 // EXPECT_LT(free3, static_cast<int64_t>(free1 * 1.1)); |
118 EXPECT_GT(free3, 0); | 125 EXPECT_GT(free3, 0); |
119 } | 126 } |
120 | 127 |
121 // Tests that GetCurrentDirectory() returns something. | 128 // Tests that GetCurrentDirectory() returns something. |
122 TEST(FilesystemTest, TestGetCurrentDirectory) { | 129 TEST(MAYBE_FilesystemTest, TestGetCurrentDirectory) { |
123 EXPECT_FALSE(Filesystem::GetCurrentDirectory().empty()); | 130 EXPECT_FALSE(Filesystem::GetCurrentDirectory().empty()); |
124 } | 131 } |
125 | 132 |
126 // Tests that GetAppPathname returns something. | 133 // Tests that GetAppPathname returns something. |
127 TEST(FilesystemTest, TestGetAppPathname) { | 134 TEST(MAYBE_FilesystemTest, TestGetAppPathname) { |
128 Pathname path; | 135 Pathname path; |
129 EXPECT_TRUE(Filesystem::GetAppPathname(&path)); | 136 EXPECT_TRUE(Filesystem::GetAppPathname(&path)); |
130 EXPECT_FALSE(path.empty()); | 137 EXPECT_FALSE(path.empty()); |
131 } | 138 } |
132 | 139 |
133 } // namespace rtc | 140 } // namespace rtc |
OLD | NEW |