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) | 20 #if defined (WEBRTC_ANDROID) |
21 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. | 21 // Fails on Android: https://bugs.chromium.org/p/webrtc/issues/detail?id=4364. |
22 #define MAYBE_FilesystemTest DISABLED_FilesystemTest | 22 #define MAYBE_FilesystemTest DISABLED_FilesystemTest |
23 #else | 23 #else |
24 #define MAYBE_FilesystemTest FilesystemTest | 24 #define MAYBE_FilesystemTest FilesystemTest |
25 #endif | 25 #endif |
26 | 26 |
27 // 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. |
28 TEST(MAYBE_FilesystemTest, GetTemporaryFolder) { | 28 TEST(MAYBE_FilesystemTest, GetTemporaryFolder) { |
29 Pathname path; | 29 Pathname path; |
30 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 30 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr)); |
31 } | 31 } |
32 | 32 |
33 // 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. |
34 TEST(MAYBE_FilesystemTest, TestOpenFile) { | 34 TEST(MAYBE_FilesystemTest, TestOpenFile) { |
35 Pathname path; | 35 Pathname path; |
36 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 36 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr)); |
37 path.SetPathname(Filesystem::TempFilename(path, "ut")); | 37 path.SetPathname(Filesystem::TempFilename(path, "ut")); |
38 | 38 |
39 FileStream* fs; | 39 FileStream* fs; |
40 char buf[256]; | 40 char buf[256]; |
41 size_t bytes; | 41 size_t bytes; |
42 | 42 |
43 fs = Filesystem::OpenFile(path, "wb"); | 43 fs = Filesystem::OpenFile(path, "wb"); |
44 ASSERT_TRUE(fs != NULL); | 44 ASSERT_TRUE(fs != nullptr); |
45 EXPECT_EQ(SR_SUCCESS, fs->Write("test", 4, &bytes, NULL)); | 45 EXPECT_EQ(SR_SUCCESS, fs->Write("test", 4, &bytes, nullptr)); |
46 EXPECT_EQ(4U, bytes); | 46 EXPECT_EQ(4U, bytes); |
47 delete fs; | 47 delete fs; |
48 | 48 |
49 EXPECT_TRUE(Filesystem::IsFile(path)); | 49 EXPECT_TRUE(Filesystem::IsFile(path)); |
50 | 50 |
51 fs = Filesystem::OpenFile(path, "rb"); | 51 fs = Filesystem::OpenFile(path, "rb"); |
52 ASSERT_TRUE(fs != NULL); | 52 ASSERT_TRUE(fs != nullptr); |
53 EXPECT_EQ(SR_SUCCESS, fs->Read(buf, sizeof(buf), &bytes, NULL)); | 53 EXPECT_EQ(SR_SUCCESS, fs->Read(buf, sizeof(buf), &bytes, nullptr)); |
54 EXPECT_EQ(4U, bytes); | 54 EXPECT_EQ(4U, bytes); |
55 delete fs; | 55 delete fs; |
56 | 56 |
57 EXPECT_TRUE(Filesystem::DeleteFile(path)); | 57 EXPECT_TRUE(Filesystem::DeleteFile(path)); |
58 EXPECT_FALSE(Filesystem::IsFile(path)); | 58 EXPECT_FALSE(Filesystem::IsFile(path)); |
59 } | 59 } |
60 | 60 |
61 // Test opening a non-existent file. | 61 // Test opening a non-existent file. |
62 TEST(MAYBE_FilesystemTest, TestOpenBadFile) { | 62 TEST(MAYBE_FilesystemTest, TestOpenBadFile) { |
63 Pathname path; | 63 Pathname path; |
64 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, NULL)); | 64 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr)); |
65 path.SetFilename("not an actual file"); | 65 path.SetFilename("not an actual file"); |
66 | 66 |
67 EXPECT_FALSE(Filesystem::IsFile(path)); | 67 EXPECT_FALSE(Filesystem::IsFile(path)); |
68 | 68 |
69 FileStream* fs = Filesystem::OpenFile(path, "rb"); | 69 FileStream* fs = Filesystem::OpenFile(path, "rb"); |
70 EXPECT_FALSE(fs != NULL); | 70 EXPECT_FALSE(fs != nullptr); |
71 } | 71 } |
72 | 72 |
73 // Test checking for free disk space. | 73 // Test checking for free disk space. |
74 TEST(MAYBE_FilesystemTest, TestGetDiskFreeSpace) { | 74 TEST(MAYBE_FilesystemTest, TestGetDiskFreeSpace) { |
75 // Note that we should avoid picking any file/folder which could be located | 75 // Note that we should avoid picking any file/folder which could be located |
76 // at the remotely mounted drive/device. | 76 // at the remotely mounted drive/device. |
77 Pathname path; | 77 Pathname path; |
78 ASSERT_TRUE(Filesystem::GetAppDataFolder(&path, true)); | 78 ASSERT_TRUE(Filesystem::GetAppDataFolder(&path, true)); |
79 | 79 |
80 int64_t free1 = 0; | 80 int64_t free1 = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
97 path.clear(); | 97 path.clear(); |
98 EXPECT_TRUE(path.empty()); | 98 EXPECT_TRUE(path.empty()); |
99 EXPECT_TRUE(Filesystem::GetDiskFreeSpace(path, &free3)); | 99 EXPECT_TRUE(Filesystem::GetDiskFreeSpace(path, &free3)); |
100 // Current working directory may not be where exe is. | 100 // Current working directory may not be where exe is. |
101 // EXPECT_LT(static_cast<int64_t>(free1 * .9), free3); | 101 // EXPECT_LT(static_cast<int64_t>(free1 * .9), free3); |
102 // EXPECT_LT(free3, static_cast<int64_t>(free1 * 1.1)); | 102 // EXPECT_LT(free3, static_cast<int64_t>(free1 * 1.1)); |
103 EXPECT_GT(free3, 0); | 103 EXPECT_GT(free3, 0); |
104 } | 104 } |
105 | 105 |
106 } // namespace rtc | 106 } // namespace rtc |
OLD | NEW |