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 |
(...skipping 12 matching lines...) Expand all Loading... |
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, nullptr)); | 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. | |
34 TEST(MAYBE_FilesystemTest, TestOpenFile) { | |
35 Pathname path; | |
36 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr)); | |
37 path.SetPathname(Filesystem::TempFilename(path, "ut")); | |
38 | |
39 FileStream* fs; | |
40 char buf[256]; | |
41 size_t bytes; | |
42 | |
43 fs = Filesystem::OpenFile(path, "wb"); | |
44 ASSERT_TRUE(fs != nullptr); | |
45 EXPECT_EQ(SR_SUCCESS, fs->Write("test", 4, &bytes, nullptr)); | |
46 EXPECT_EQ(4U, bytes); | |
47 delete fs; | |
48 | |
49 EXPECT_TRUE(Filesystem::IsFile(path)); | |
50 | |
51 fs = Filesystem::OpenFile(path, "rb"); | |
52 ASSERT_TRUE(fs != nullptr); | |
53 EXPECT_EQ(SR_SUCCESS, fs->Read(buf, sizeof(buf), &bytes, nullptr)); | |
54 EXPECT_EQ(4U, bytes); | |
55 delete fs; | |
56 | |
57 EXPECT_TRUE(Filesystem::DeleteFile(path)); | |
58 EXPECT_FALSE(Filesystem::IsFile(path)); | |
59 } | |
60 | |
61 // Test opening a non-existent file. | |
62 TEST(MAYBE_FilesystemTest, TestOpenBadFile) { | |
63 Pathname path; | |
64 EXPECT_TRUE(Filesystem::GetTemporaryFolder(path, true, nullptr)); | |
65 path.SetFilename("not an actual file"); | |
66 | |
67 EXPECT_FALSE(Filesystem::IsFile(path)); | |
68 | |
69 FileStream* fs = Filesystem::OpenFile(path, "rb"); | |
70 EXPECT_FALSE(fs != nullptr); | |
71 } | |
72 | |
73 } // namespace rtc | 33 } // namespace rtc |
OLD | NEW |