OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 std::string test_string_lfcr_; | 114 std::string test_string_lfcr_; |
115 std::string test_string_lflf_; | 115 std::string test_string_lflf_; |
116 std::string test_string_short_; | 116 std::string test_string_short_; |
117 std::string test_string_empty_; | 117 std::string test_string_empty_; |
118 }; | 118 }; |
119 | 119 |
120 TEST_F(FileTextReaderTest, StartAtBeginning) { | 120 TEST_F(FileTextReaderTest, StartAtBeginning) { |
121 FileTextReader reader(file_pointers_[0]); | 121 FileTextReader reader(file_pointers_[0]); |
122 EXPECT_EQ(0U, reader.position()); | 122 EXPECT_EQ(0U, reader.position()); |
123 EXPECT_EQ(file_pointers_[0], reader.input()); | 123 EXPECT_EQ(file_pointers_[0], reader.input()); |
124 EXPECT_EQ(false, reader.IsAtEnd()); | 124 EXPECT_FALSE(reader.IsAtEnd()); |
125 } | 125 } |
126 | 126 |
127 TEST_F(FileTextReaderTest, TestPeekString) { | 127 TEST_F(FileTextReaderTest, TestPeekString) { |
128 FileTextReader reader(file_pointers_[0]); | 128 FileTextReader reader(file_pointers_[0]); |
129 EXPECT_EQ(test_string_one_.substr(0, 6), reader.PeekString(6)); | 129 EXPECT_EQ(test_string_one_.substr(0, 6), reader.PeekString(6)); |
130 EXPECT_EQ(0U, reader.position()); | 130 EXPECT_EQ(0U, reader.position()); |
131 EXPECT_EQ(false, reader.IsAtEnd()); | 131 EXPECT_FALSE(reader.IsAtEnd()); |
132 } | 132 } |
133 | 133 |
134 TEST_F(FileTextReaderTest, ReadsSingleCharacter) { | 134 TEST_F(FileTextReaderTest, ReadsSingleCharacter) { |
135 FileTextReader reader(file_pointers_[0]); | 135 FileTextReader reader(file_pointers_[0]); |
136 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); | 136 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); |
137 EXPECT_EQ(1U, reader.position()); | 137 EXPECT_EQ(1U, reader.position()); |
138 EXPECT_EQ(false, reader.IsAtEnd()); | 138 EXPECT_FALSE(reader.IsAtEnd()); |
139 EXPECT_EQ(test_string_one_.substr(1, 2), reader.PeekString(2)); | 139 EXPECT_EQ(test_string_one_.substr(1, 2), reader.PeekString(2)); |
140 EXPECT_EQ(1U, reader.position()); | 140 EXPECT_EQ(1U, reader.position()); |
141 } | 141 } |
142 | 142 |
143 TEST_F(FileTextReaderTest, ReadsMultipleCharacters) { | 143 TEST_F(FileTextReaderTest, ReadsMultipleCharacters) { |
144 FileTextReader reader(file_pointers_[0]); | 144 FileTextReader reader(file_pointers_[0]); |
145 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); | 145 EXPECT_EQ(test_string_one_.substr(0, 1)[0], reader.ReadChar()); |
146 EXPECT_EQ(test_string_one_.substr(1, 1)[0], reader.ReadChar()); | 146 EXPECT_EQ(test_string_one_.substr(1, 1)[0], reader.ReadChar()); |
147 EXPECT_EQ(2U, reader.position()); | 147 EXPECT_EQ(2U, reader.position()); |
148 EXPECT_EQ(false, reader.IsAtEnd()); | 148 EXPECT_FALSE(reader.IsAtEnd()); |
149 EXPECT_EQ(test_string_one_.substr(2, 2), reader.PeekString(2)); | 149 EXPECT_EQ(test_string_one_.substr(2, 2), reader.PeekString(2)); |
150 EXPECT_EQ(2U, reader.position()); | 150 EXPECT_EQ(2U, reader.position()); |
151 } | 151 } |
152 | 152 |
153 TEST_F(FileTextReaderTest, ReadsFile) { | 153 TEST_F(FileTextReaderTest, ReadsFile) { |
154 FileTextReader reader(file_pointers_[0]); | 154 FileTextReader reader(file_pointers_[0]); |
155 EXPECT_EQ(test_string_one_.substr(0, 7), reader.ReadString(7)); | 155 EXPECT_EQ(test_string_one_.substr(0, 7), reader.ReadString(7)); |
156 EXPECT_EQ(7U, reader.position()); | 156 EXPECT_EQ(7U, reader.position()); |
157 EXPECT_EQ(false, reader.IsAtEnd()); | 157 EXPECT_FALSE(reader.IsAtEnd()); |
158 EXPECT_EQ(test_string_one_.substr(7, 2), reader.PeekString(2)); | 158 EXPECT_EQ(test_string_one_.substr(7, 2), reader.PeekString(2)); |
159 EXPECT_EQ(7U, reader.position()); | 159 EXPECT_EQ(7U, reader.position()); |
160 } | 160 } |
161 | 161 |
162 TEST_F(FileTextReaderTest, EmptyFile) { | 162 TEST_F(FileTextReaderTest, EmptyFile) { |
163 FileTextReader reader(file_pointers_[8]); | 163 FileTextReader reader(file_pointers_[8]); |
164 EXPECT_EQ("", reader.PeekString(1)); | 164 EXPECT_EQ("", reader.PeekString(1)); |
165 EXPECT_EQ(0U, reader.position()); | 165 EXPECT_EQ(0U, reader.position()); |
166 EXPECT_EQ(true, reader.IsAtEnd()); | 166 EXPECT_TRUE(reader.IsAtEnd()); |
167 EXPECT_EQ(0, reader.ReadChar()); | 167 EXPECT_EQ(0, reader.ReadChar()); |
168 EXPECT_EQ(true, reader.IsAtEnd()); | 168 EXPECT_TRUE(reader.IsAtEnd()); |
169 } | 169 } |
170 | 170 |
171 TEST_F(FileTextReaderTest, TinyFile) { | 171 TEST_F(FileTextReaderTest, TinyFile) { |
172 FileTextReader reader(file_pointers_[7]); | 172 FileTextReader reader(file_pointers_[7]); |
173 EXPECT_EQ(test_string_short_.substr(0, 1), reader.PeekString(1)); | 173 EXPECT_EQ(test_string_short_.substr(0, 1), reader.PeekString(1)); |
174 EXPECT_EQ(0U, reader.position()); | 174 EXPECT_EQ(0U, reader.position()); |
175 EXPECT_EQ(false, reader.IsAtEnd()); | 175 EXPECT_FALSE(reader.IsAtEnd()); |
176 EXPECT_EQ(test_string_short_[0], reader.ReadChar()); | 176 EXPECT_EQ(test_string_short_[0], reader.ReadChar()); |
177 EXPECT_EQ(true, reader.IsAtEnd()); | 177 EXPECT_TRUE(reader.IsAtEnd()); |
178 } | 178 } |
179 | 179 |
180 TEST_F(FileTextReaderTest, ReadsToEnd) { | 180 TEST_F(FileTextReaderTest, ReadsToEnd) { |
181 FileTextReader reader(file_pointers_[2]); | 181 FileTextReader reader(file_pointers_[2]); |
182 EXPECT_EQ(test_string_lf_, reader.ReadToEnd()); | 182 EXPECT_EQ(test_string_lf_, reader.ReadToEnd()); |
183 EXPECT_EQ(test_string_lf_.size(), reader.position()); | 183 EXPECT_EQ(test_string_lf_.size(), reader.position()); |
184 EXPECT_EQ(true, reader.IsAtEnd()); | 184 EXPECT_TRUE(reader.IsAtEnd()); |
185 EXPECT_EQ("", reader.ReadString(1)); | 185 EXPECT_EQ("", reader.ReadString(1)); |
186 EXPECT_EQ(true, reader.IsAtEnd()); | 186 EXPECT_TRUE(reader.IsAtEnd()); |
187 EXPECT_EQ(test_string_lf_.size(), reader.position()); | 187 EXPECT_EQ(test_string_lf_.size(), reader.position()); |
188 } | 188 } |
189 | 189 |
190 | 190 |
191 TEST_F(FileTextReaderTest, ReadsLinefeedFile) { | 191 TEST_F(FileTextReaderTest, ReadsLinefeedFile) { |
192 FileTextReader reader(file_pointers_[2]); | 192 FileTextReader reader(file_pointers_[2]); |
193 std::string line = reader.ReadLine(); | 193 std::string line = reader.ReadLine(); |
194 EXPECT_EQ(test_string_one_, line); | 194 EXPECT_EQ(test_string_one_, line); |
195 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 195 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
196 EXPECT_EQ(false, reader.IsAtEnd()); | 196 EXPECT_FALSE(reader.IsAtEnd()); |
197 EXPECT_EQ(test_string_lf_.substr(test_string_one_.size() + 1, 2), | 197 EXPECT_EQ(test_string_lf_.substr(test_string_one_.size() + 1, 2), |
198 reader.PeekString(2)); | 198 reader.PeekString(2)); |
199 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 199 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
200 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 200 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
201 EXPECT_EQ(true, reader.IsAtEnd()); | 201 EXPECT_TRUE(reader.IsAtEnd()); |
202 EXPECT_EQ(test_string_lf_.size(), reader.position()); | 202 EXPECT_EQ(test_string_lf_.size(), reader.position()); |
203 } | 203 } |
204 | 204 |
205 TEST_F(FileTextReaderTest, ReadsCarriageReturnFile) { | 205 TEST_F(FileTextReaderTest, ReadsCarriageReturnFile) { |
206 FileTextReader reader(file_pointers_[3]); | 206 FileTextReader reader(file_pointers_[3]); |
207 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 207 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
208 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 208 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
209 EXPECT_EQ(false, reader.IsAtEnd()); | 209 EXPECT_FALSE(reader.IsAtEnd()); |
210 EXPECT_EQ(test_string_cr_.substr(test_string_one_.size() + 1, 2), | 210 EXPECT_EQ(test_string_cr_.substr(test_string_one_.size() + 1, 2), |
211 reader.PeekString(2)); | 211 reader.PeekString(2)); |
212 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 212 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
213 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 213 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
214 EXPECT_EQ(true, reader.IsAtEnd()); | 214 EXPECT_TRUE(reader.IsAtEnd()); |
215 EXPECT_EQ(test_string_cr_.size(), reader.position()); | 215 EXPECT_EQ(test_string_cr_.size(), reader.position()); |
216 } | 216 } |
217 | 217 |
218 | 218 |
219 TEST_F(FileTextReaderTest, ReadsCarriageReturnLinefeedFile) { | 219 TEST_F(FileTextReaderTest, ReadsCarriageReturnLinefeedFile) { |
220 FileTextReader reader(file_pointers_[4]); | 220 FileTextReader reader(file_pointers_[4]); |
221 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 221 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
222 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); | 222 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); |
223 EXPECT_EQ(false, reader.IsAtEnd()); | 223 EXPECT_FALSE(reader.IsAtEnd()); |
224 EXPECT_EQ(test_string_crlf_.substr(test_string_one_.size() + 2, 2), | 224 EXPECT_EQ(test_string_crlf_.substr(test_string_one_.size() + 2, 2), |
225 reader.PeekString(2)); | 225 reader.PeekString(2)); |
226 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); | 226 EXPECT_EQ(test_string_one_.size() + 2, reader.position()); |
227 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 227 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
228 EXPECT_EQ(true, reader.IsAtEnd()); | 228 EXPECT_TRUE(reader.IsAtEnd()); |
229 EXPECT_EQ(test_string_crlf_.size(), reader.position()); | 229 EXPECT_EQ(test_string_crlf_.size(), reader.position()); |
230 } | 230 } |
231 | 231 |
232 TEST_F(FileTextReaderTest, ReadsLinefeedCarriageReturnFile) { | 232 TEST_F(FileTextReaderTest, ReadsLinefeedCarriageReturnFile) { |
233 FileTextReader reader(file_pointers_[5]); | 233 FileTextReader reader(file_pointers_[5]); |
234 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 234 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
235 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 235 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
236 EXPECT_EQ(false, reader.IsAtEnd()); | 236 EXPECT_FALSE(reader.IsAtEnd()); |
237 EXPECT_EQ(test_string_lfcr_.substr(test_string_one_.size() + 1, 2), | 237 EXPECT_EQ(test_string_lfcr_.substr(test_string_one_.size() + 1, 2), |
238 reader.PeekString(2)); | 238 reader.PeekString(2)); |
239 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 239 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
240 EXPECT_EQ("", reader.ReadLine()); | 240 EXPECT_EQ("", reader.ReadLine()); |
241 EXPECT_EQ(false, reader.IsAtEnd()); | 241 EXPECT_FALSE(reader.IsAtEnd()); |
242 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 242 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
243 EXPECT_EQ(false, reader.IsAtEnd()); | 243 EXPECT_FALSE(reader.IsAtEnd()); |
244 EXPECT_EQ("", reader.ReadLine()); | 244 EXPECT_EQ("", reader.ReadLine()); |
245 EXPECT_EQ(true, reader.IsAtEnd()); | 245 EXPECT_TRUE(reader.IsAtEnd()); |
246 EXPECT_EQ(test_string_lfcr_.size(), reader.position()); | 246 EXPECT_EQ(test_string_lfcr_.size(), reader.position()); |
247 } | 247 } |
248 | 248 |
249 TEST_F(FileTextReaderTest, ReadsLinefeedLinefeedFile) { | 249 TEST_F(FileTextReaderTest, ReadsLinefeedLinefeedFile) { |
250 FileTextReader reader(file_pointers_[6]); | 250 FileTextReader reader(file_pointers_[6]); |
251 EXPECT_EQ(test_string_one_, reader.ReadLine()); | 251 EXPECT_EQ(test_string_one_, reader.ReadLine()); |
252 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 252 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
253 EXPECT_EQ(false, reader.IsAtEnd()); | 253 EXPECT_FALSE(reader.IsAtEnd()); |
254 EXPECT_EQ(test_string_lflf_.substr(test_string_one_.size() + 1, 2), | 254 EXPECT_EQ(test_string_lflf_.substr(test_string_one_.size() + 1, 2), |
255 reader.PeekString(2)); | 255 reader.PeekString(2)); |
256 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); | 256 EXPECT_EQ(test_string_one_.size() + 1, reader.position()); |
257 EXPECT_EQ("", reader.ReadLine()); | 257 EXPECT_EQ("", reader.ReadLine()); |
258 EXPECT_EQ(false, reader.IsAtEnd()); | 258 EXPECT_FALSE(reader.IsAtEnd()); |
259 EXPECT_EQ(test_string_two_, reader.ReadLine()); | 259 EXPECT_EQ(test_string_two_, reader.ReadLine()); |
260 EXPECT_EQ(false, reader.IsAtEnd()); | 260 EXPECT_FALSE(reader.IsAtEnd()); |
261 EXPECT_EQ("", reader.ReadLine()); | 261 EXPECT_EQ("", reader.ReadLine()); |
262 EXPECT_EQ(true, reader.IsAtEnd()); | 262 EXPECT_TRUE(reader.IsAtEnd()); |
263 EXPECT_EQ(test_string_lflf_.size(), reader.position()); | 263 EXPECT_EQ(test_string_lflf_.size(), reader.position()); |
264 } | 264 } |
265 | 265 |
266 } // namespace o3d | 266 } // namespace o3d |
OLD | NEW |