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

Side by Side Diff: webrtc/base/file_unittest.cc

Issue 2360303004: Default constructor for file (Closed)
Patch Set: Nit Created 4 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 | « webrtc/base/file.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 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 return true; 49 return true;
50 } 50 }
51 51
52 class FileTest : public ::testing::Test { 52 class FileTest : public ::testing::Test {
53 protected: 53 protected:
54 std::string path_; 54 std::string path_;
55 void SetUp() { 55 void SetUp() {
56 path_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), "test_file"); 56 path_ = webrtc::test::TempFilename(webrtc::test::OutputPath(), "test_file");
57 ASSERT_FALSE(path_.empty()); 57 ASSERT_FALSE(path_.empty());
58 } 58 }
59 rtc::File OpenTempFile() { return rtc::File::Open(path_); } 59 void TearDown() { RemoveFile(path_); }
60 void TearDown() { rtc::RemoveFile(path_); }
61 }; 60 };
62 61
62 TEST_F(FileTest, DefaultConstructor) {
63 File file;
64 uint8_t buffer[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
65
66 EXPECT_FALSE(file.IsOpen());
67 EXPECT_EQ(0u, file.Write(buffer, 10));
68 EXPECT_FALSE(file.Seek(0));
69 EXPECT_EQ(0u, file.Read(buffer, 10));
70 EXPECT_EQ(0u, file.WriteAt(buffer, 10, 0));
71 EXPECT_EQ(0u, file.ReadAt(buffer, 10, 0));
72 EXPECT_FALSE(file.Close());
73 }
74
63 TEST_F(FileTest, DoubleClose) { 75 TEST_F(FileTest, DoubleClose) {
64 File file = OpenTempFile(); 76 File file = File::Open(path_);
65 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); 77 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
66 78
67 EXPECT_TRUE(file.Close()); 79 EXPECT_TRUE(file.Close());
68 EXPECT_FALSE(file.Close()); 80 EXPECT_FALSE(file.Close());
69 } 81 }
70 82
71 TEST_F(FileTest, SimpleReadWrite) { 83 TEST_F(FileTest, SimpleReadWrite) {
72 File file = OpenTempFile(); 84 File file = File::Open(path_);
73 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); 85 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
74 86
75 uint8_t data[100] = {0}; 87 uint8_t data[100] = {0};
76 uint8_t out[100] = {0}; 88 uint8_t out[100] = {0};
77 for (int i = 0; i < 100; ++i) { 89 for (int i = 0; i < 100; ++i) {
78 data[i] = i; 90 data[i] = i;
79 } 91 }
80 92
81 EXPECT_EQ(10u, file.Write(data, 10)); 93 EXPECT_EQ(10u, file.Write(data, 10));
82 94
(...skipping 11 matching lines...) Expand all
94 EXPECT_TRUE(file.Seek(1)); 106 EXPECT_TRUE(file.Seek(1));
95 EXPECT_EQ(50u, file.Write(data, 50)); 107 EXPECT_EQ(50u, file.Write(data, 50));
96 EXPECT_EQ(50u, file.Write(data + 50, 50)); 108 EXPECT_EQ(50u, file.Write(data + 50, 50));
97 109
98 EXPECT_TRUE(file.Seek(1)); 110 EXPECT_TRUE(file.Seek(1));
99 EXPECT_EQ(100u, file.Read(out, 100)); 111 EXPECT_EQ(100u, file.Read(out, 100));
100 EXPECT_TRUE(VerifyBuffer(out, 100, 0)); 112 EXPECT_TRUE(VerifyBuffer(out, 100, 0));
101 } 113 }
102 114
103 TEST_F(FileTest, ReadWriteClose) { 115 TEST_F(FileTest, ReadWriteClose) {
104 File file = OpenTempFile(); 116 File file = File::Open(path_);
105 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); 117 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
106 118
107 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 119 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
108 uint8_t out[10] = {0}; 120 uint8_t out[10] = {0};
109 EXPECT_EQ(10u, file.Write(data, 10)); 121 EXPECT_EQ(10u, file.Write(data, 10));
110 EXPECT_TRUE(file.Close()); 122 EXPECT_TRUE(file.Close());
111 123
112 File file2 = OpenTempFile(); 124 File file2 = File::Open(path_);
113 ASSERT_TRUE(file2.IsOpen()) << "Error: " << LastError(); 125 ASSERT_TRUE(file2.IsOpen()) << "Error: " << LastError();
114 EXPECT_EQ(10u, file2.Read(out, 10)); 126 EXPECT_EQ(10u, file2.Read(out, 10));
115 EXPECT_TRUE(VerifyBuffer(out, 10, 0)); 127 EXPECT_TRUE(VerifyBuffer(out, 10, 0));
116 } 128 }
117 129
118 TEST_F(FileTest, RandomAccessRead) { 130 TEST_F(FileTest, RandomAccessRead) {
119 File file = OpenTempFile(); 131 File file = File::Open(path_);
120 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); 132 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
121 133
122 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 134 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
123 uint8_t out[10] = {0}; 135 uint8_t out[10] = {0};
124 EXPECT_EQ(10u, file.Write(data, 10)); 136 EXPECT_EQ(10u, file.Write(data, 10));
125 137
126 EXPECT_EQ(4u, file.ReadAt(out, 4, 0)); 138 EXPECT_EQ(4u, file.ReadAt(out, 4, 0));
127 EXPECT_TRUE(VerifyBuffer(out, 4, 0)); 139 EXPECT_TRUE(VerifyBuffer(out, 4, 0));
128 140
129 EXPECT_EQ(4u, file.ReadAt(out, 4, 4)); 141 EXPECT_EQ(4u, file.ReadAt(out, 4, 4));
130 EXPECT_TRUE(VerifyBuffer(out, 4, 4)); 142 EXPECT_TRUE(VerifyBuffer(out, 4, 4));
131 143
132 EXPECT_EQ(5u, file.ReadAt(out, 5, 5)); 144 EXPECT_EQ(5u, file.ReadAt(out, 5, 5));
133 EXPECT_TRUE(VerifyBuffer(out, 5, 5)); 145 EXPECT_TRUE(VerifyBuffer(out, 5, 5));
134 } 146 }
135 147
136 TEST_F(FileTest, RandomAccessReadWrite) { 148 TEST_F(FileTest, RandomAccessReadWrite) {
137 File file = OpenTempFile(); 149 File file = File::Open(path_);
138 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError(); 150 ASSERT_TRUE(file.IsOpen()) << "Error: " << LastError();
139 151
140 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 152 uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
141 uint8_t out[10] = {0}; 153 uint8_t out[10] = {0};
142 EXPECT_EQ(10u, file.Write(data, 10)); 154 EXPECT_EQ(10u, file.Write(data, 10));
143 EXPECT_TRUE(file.Seek(4)); 155 EXPECT_TRUE(file.Seek(4));
144 156
145 EXPECT_EQ(4u, file.WriteAt(data, 4, 4)); 157 EXPECT_EQ(4u, file.WriteAt(data, 4, 4));
146 EXPECT_EQ(4u, file.ReadAt(out, 4, 4)); 158 EXPECT_EQ(4u, file.ReadAt(out, 4, 4));
147 EXPECT_TRUE(VerifyBuffer(out, 4, 0)); 159 EXPECT_TRUE(VerifyBuffer(out, 4, 0));
148 160
149 EXPECT_EQ(2u, file.WriteAt(data, 2, 8)); 161 EXPECT_EQ(2u, file.WriteAt(data, 2, 8));
150 EXPECT_EQ(2u, file.ReadAt(out, 2, 8)); 162 EXPECT_EQ(2u, file.ReadAt(out, 2, 8));
151 EXPECT_TRUE(VerifyBuffer(out, 2, 0)); 163 EXPECT_TRUE(VerifyBuffer(out, 2, 0));
152 } 164 }
153 165
154 } // namespace rtc 166 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/file.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698