OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 "webrtc/modules/audio_processing/transient/file_utils.h" | 11 #include "webrtc/modules/audio_processing/transient/file_utils.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 #include <string> | 14 #include <string> |
| 15 #include <memory> |
15 #include <vector> | 16 #include <vector> |
16 | 17 |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/base/scoped_ptr.h" | |
19 #include "webrtc/system_wrappers/include/file_wrapper.h" | 19 #include "webrtc/system_wrappers/include/file_wrapper.h" |
20 #include "webrtc/test/testsupport/fileutils.h" | 20 #include "webrtc/test/testsupport/fileutils.h" |
21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 static const uint8_t kPiBytesf[4] = {0xDB, 0x0F, 0x49, 0x40}; | 25 static const uint8_t kPiBytesf[4] = {0xDB, 0x0F, 0x49, 0x40}; |
26 static const uint8_t kEBytesf[4] = {0x54, 0xF8, 0x2D, 0x40}; | 26 static const uint8_t kEBytesf[4] = {0x54, 0xF8, 0x2D, 0x40}; |
27 static const uint8_t kAvogadroBytesf[4] = {0x2F, 0x0C, 0xFF, 0x66}; | 27 static const uint8_t kAvogadroBytesf[4] = {0x2F, 0x0C, 0xFF, 0x66}; |
28 | 28 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 EXPECT_EQ(0, ConvertByteArrayToDouble(kAvogadroBytes, &value)); | 116 EXPECT_EQ(0, ConvertByteArrayToDouble(kAvogadroBytes, &value)); |
117 EXPECT_DOUBLE_EQ(kAvogadro, value); | 117 EXPECT_DOUBLE_EQ(kAvogadro, value); |
118 } | 118 } |
119 | 119 |
120 #if defined(WEBRTC_IOS) | 120 #if defined(WEBRTC_IOS) |
121 #define MAYBE_ConvertFloatToByteArray DISABLED_ConvertFloatToByteArray | 121 #define MAYBE_ConvertFloatToByteArray DISABLED_ConvertFloatToByteArray |
122 #else | 122 #else |
123 #define MAYBE_ConvertFloatToByteArray ConvertFloatToByteArray | 123 #define MAYBE_ConvertFloatToByteArray ConvertFloatToByteArray |
124 #endif | 124 #endif |
125 TEST_F(TransientFileUtilsTest, MAYBE_ConvertFloatToByteArray) { | 125 TEST_F(TransientFileUtilsTest, MAYBE_ConvertFloatToByteArray) { |
126 rtc::scoped_ptr<uint8_t[]> bytes(new uint8_t[4]); | 126 std::unique_ptr<uint8_t[]> bytes(new uint8_t[4]); |
127 | 127 |
128 EXPECT_EQ(0, ConvertFloatToByteArray(kPi, bytes.get())); | 128 EXPECT_EQ(0, ConvertFloatToByteArray(kPi, bytes.get())); |
129 EXPECT_EQ(0, memcmp(bytes.get(), kPiBytesf, 4)); | 129 EXPECT_EQ(0, memcmp(bytes.get(), kPiBytesf, 4)); |
130 | 130 |
131 EXPECT_EQ(0, ConvertFloatToByteArray(kE, bytes.get())); | 131 EXPECT_EQ(0, ConvertFloatToByteArray(kE, bytes.get())); |
132 EXPECT_EQ(0, memcmp(bytes.get(), kEBytesf, 4)); | 132 EXPECT_EQ(0, memcmp(bytes.get(), kEBytesf, 4)); |
133 | 133 |
134 EXPECT_EQ(0, ConvertFloatToByteArray(kAvogadro, bytes.get())); | 134 EXPECT_EQ(0, ConvertFloatToByteArray(kAvogadro, bytes.get())); |
135 EXPECT_EQ(0, memcmp(bytes.get(), kAvogadroBytesf, 4)); | 135 EXPECT_EQ(0, memcmp(bytes.get(), kAvogadroBytesf, 4)); |
136 } | 136 } |
137 | 137 |
138 #if defined(WEBRTC_IOS) | 138 #if defined(WEBRTC_IOS) |
139 #define MAYBE_ConvertDoubleToByteArray DISABLED_ConvertDoubleToByteArray | 139 #define MAYBE_ConvertDoubleToByteArray DISABLED_ConvertDoubleToByteArray |
140 #else | 140 #else |
141 #define MAYBE_ConvertDoubleToByteArray ConvertDoubleToByteArray | 141 #define MAYBE_ConvertDoubleToByteArray ConvertDoubleToByteArray |
142 #endif | 142 #endif |
143 TEST_F(TransientFileUtilsTest, MAYBE_ConvertDoubleToByteArray) { | 143 TEST_F(TransientFileUtilsTest, MAYBE_ConvertDoubleToByteArray) { |
144 rtc::scoped_ptr<uint8_t[]> bytes(new uint8_t[8]); | 144 std::unique_ptr<uint8_t[]> bytes(new uint8_t[8]); |
145 | 145 |
146 EXPECT_EQ(0, ConvertDoubleToByteArray(kPi, bytes.get())); | 146 EXPECT_EQ(0, ConvertDoubleToByteArray(kPi, bytes.get())); |
147 EXPECT_EQ(0, memcmp(bytes.get(), kPiBytes, 8)); | 147 EXPECT_EQ(0, memcmp(bytes.get(), kPiBytes, 8)); |
148 | 148 |
149 EXPECT_EQ(0, ConvertDoubleToByteArray(kE, bytes.get())); | 149 EXPECT_EQ(0, ConvertDoubleToByteArray(kE, bytes.get())); |
150 EXPECT_EQ(0, memcmp(bytes.get(), kEBytes, 8)); | 150 EXPECT_EQ(0, memcmp(bytes.get(), kEBytes, 8)); |
151 | 151 |
152 EXPECT_EQ(0, ConvertDoubleToByteArray(kAvogadro, bytes.get())); | 152 EXPECT_EQ(0, ConvertDoubleToByteArray(kAvogadro, bytes.get())); |
153 EXPECT_EQ(0, memcmp(bytes.get(), kAvogadroBytes, 8)); | 153 EXPECT_EQ(0, memcmp(bytes.get(), kAvogadroBytes, 8)); |
154 } | 154 } |
155 | 155 |
156 #if defined(WEBRTC_IOS) | 156 #if defined(WEBRTC_IOS) |
157 #define MAYBE_ReadInt16BufferFromFile DISABLED_ReadInt16BufferFromFile | 157 #define MAYBE_ReadInt16BufferFromFile DISABLED_ReadInt16BufferFromFile |
158 #else | 158 #else |
159 #define MAYBE_ReadInt16BufferFromFile ReadInt16BufferFromFile | 159 #define MAYBE_ReadInt16BufferFromFile ReadInt16BufferFromFile |
160 #endif | 160 #endif |
161 TEST_F(TransientFileUtilsTest, MAYBE_ReadInt16BufferFromFile) { | 161 TEST_F(TransientFileUtilsTest, MAYBE_ReadInt16BufferFromFile) { |
162 std::string test_filename = kTestFileName; | 162 std::string test_filename = kTestFileName; |
163 | 163 |
164 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 164 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
165 | 165 |
166 file->OpenFile(test_filename.c_str(), | 166 file->OpenFile(test_filename.c_str(), |
167 true, // Read only. | 167 true, // Read only. |
168 true, // Loop. | 168 true, // Loop. |
169 false); // No text. | 169 false); // No text. |
170 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 170 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
171 << kTestFileName.c_str(); | 171 << kTestFileName.c_str(); |
172 | 172 |
173 const size_t kBufferLength = 12; | 173 const size_t kBufferLength = 12; |
174 rtc::scoped_ptr<int16_t[]> buffer(new int16_t[kBufferLength]); | 174 std::unique_ptr<int16_t[]> buffer(new int16_t[kBufferLength]); |
175 | 175 |
176 EXPECT_EQ(kBufferLength, ReadInt16BufferFromFile(file.get(), | 176 EXPECT_EQ(kBufferLength, ReadInt16BufferFromFile(file.get(), |
177 kBufferLength, | 177 kBufferLength, |
178 buffer.get())); | 178 buffer.get())); |
179 EXPECT_EQ(22377, buffer[4]); | 179 EXPECT_EQ(22377, buffer[4]); |
180 EXPECT_EQ(16389, buffer[7]); | 180 EXPECT_EQ(16389, buffer[7]); |
181 EXPECT_EQ(17631, buffer[kBufferLength - 1]); | 181 EXPECT_EQ(17631, buffer[kBufferLength - 1]); |
182 | 182 |
183 file->Rewind(); | 183 file->Rewind(); |
184 | 184 |
(...skipping 13 matching lines...) Expand all Loading... |
198 | 198 |
199 #if defined(WEBRTC_IOS) | 199 #if defined(WEBRTC_IOS) |
200 #define MAYBE_ReadInt16FromFileToFloatBuffer \ | 200 #define MAYBE_ReadInt16FromFileToFloatBuffer \ |
201 DISABLED_ReadInt16FromFileToFloatBuffer | 201 DISABLED_ReadInt16FromFileToFloatBuffer |
202 #else | 202 #else |
203 #define MAYBE_ReadInt16FromFileToFloatBuffer ReadInt16FromFileToFloatBuffer | 203 #define MAYBE_ReadInt16FromFileToFloatBuffer ReadInt16FromFileToFloatBuffer |
204 #endif | 204 #endif |
205 TEST_F(TransientFileUtilsTest, MAYBE_ReadInt16FromFileToFloatBuffer) { | 205 TEST_F(TransientFileUtilsTest, MAYBE_ReadInt16FromFileToFloatBuffer) { |
206 std::string test_filename = kTestFileName; | 206 std::string test_filename = kTestFileName; |
207 | 207 |
208 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 208 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
209 | 209 |
210 file->OpenFile(test_filename.c_str(), | 210 file->OpenFile(test_filename.c_str(), |
211 true, // Read only. | 211 true, // Read only. |
212 true, // Loop. | 212 true, // Loop. |
213 false); // No text. | 213 false); // No text. |
214 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 214 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
215 << kTestFileName.c_str(); | 215 << kTestFileName.c_str(); |
216 | 216 |
217 const size_t kBufferLength = 12; | 217 const size_t kBufferLength = 12; |
218 rtc::scoped_ptr<float[]> buffer(new float[kBufferLength]); | 218 std::unique_ptr<float[]> buffer(new float[kBufferLength]); |
219 | 219 |
220 EXPECT_EQ(kBufferLength, ReadInt16FromFileToFloatBuffer(file.get(), | 220 EXPECT_EQ(kBufferLength, ReadInt16FromFileToFloatBuffer(file.get(), |
221 kBufferLength, | 221 kBufferLength, |
222 buffer.get())); | 222 buffer.get())); |
223 | 223 |
224 EXPECT_DOUBLE_EQ(11544, buffer[0]); | 224 EXPECT_DOUBLE_EQ(11544, buffer[0]); |
225 EXPECT_DOUBLE_EQ(22377, buffer[4]); | 225 EXPECT_DOUBLE_EQ(22377, buffer[4]); |
226 EXPECT_DOUBLE_EQ(16389, buffer[7]); | 226 EXPECT_DOUBLE_EQ(16389, buffer[7]); |
227 EXPECT_DOUBLE_EQ(17631, buffer[kBufferLength - 1]); | 227 EXPECT_DOUBLE_EQ(17631, buffer[kBufferLength - 1]); |
228 | 228 |
(...skipping 16 matching lines...) Expand all Loading... |
245 | 245 |
246 #if defined(WEBRTC_IOS) | 246 #if defined(WEBRTC_IOS) |
247 #define MAYBE_ReadInt16FromFileToDoubleBuffer \ | 247 #define MAYBE_ReadInt16FromFileToDoubleBuffer \ |
248 DISABLED_ReadInt16FromFileToDoubleBuffer | 248 DISABLED_ReadInt16FromFileToDoubleBuffer |
249 #else | 249 #else |
250 #define MAYBE_ReadInt16FromFileToDoubleBuffer ReadInt16FromFileToDoubleBuffer | 250 #define MAYBE_ReadInt16FromFileToDoubleBuffer ReadInt16FromFileToDoubleBuffer |
251 #endif | 251 #endif |
252 TEST_F(TransientFileUtilsTest, MAYBE_ReadInt16FromFileToDoubleBuffer) { | 252 TEST_F(TransientFileUtilsTest, MAYBE_ReadInt16FromFileToDoubleBuffer) { |
253 std::string test_filename = kTestFileName; | 253 std::string test_filename = kTestFileName; |
254 | 254 |
255 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 255 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
256 | 256 |
257 file->OpenFile(test_filename.c_str(), | 257 file->OpenFile(test_filename.c_str(), |
258 true, // Read only. | 258 true, // Read only. |
259 true, // Loop. | 259 true, // Loop. |
260 false); // No text. | 260 false); // No text. |
261 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 261 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
262 << kTestFileName.c_str(); | 262 << kTestFileName.c_str(); |
263 | 263 |
264 const size_t kBufferLength = 12; | 264 const size_t kBufferLength = 12; |
265 rtc::scoped_ptr<double[]> buffer(new double[kBufferLength]); | 265 std::unique_ptr<double[]> buffer(new double[kBufferLength]); |
266 | 266 |
267 EXPECT_EQ(kBufferLength, ReadInt16FromFileToDoubleBuffer(file.get(), | 267 EXPECT_EQ(kBufferLength, ReadInt16FromFileToDoubleBuffer(file.get(), |
268 kBufferLength, | 268 kBufferLength, |
269 buffer.get())); | 269 buffer.get())); |
270 EXPECT_DOUBLE_EQ(11544, buffer[0]); | 270 EXPECT_DOUBLE_EQ(11544, buffer[0]); |
271 EXPECT_DOUBLE_EQ(22377, buffer[4]); | 271 EXPECT_DOUBLE_EQ(22377, buffer[4]); |
272 EXPECT_DOUBLE_EQ(16389, buffer[7]); | 272 EXPECT_DOUBLE_EQ(16389, buffer[7]); |
273 EXPECT_DOUBLE_EQ(17631, buffer[kBufferLength - 1]); | 273 EXPECT_DOUBLE_EQ(17631, buffer[kBufferLength - 1]); |
274 | 274 |
275 file->Rewind(); | 275 file->Rewind(); |
(...skipping 14 matching lines...) Expand all Loading... |
290 } | 290 } |
291 | 291 |
292 #if defined(WEBRTC_IOS) | 292 #if defined(WEBRTC_IOS) |
293 #define MAYBE_ReadFloatBufferFromFile DISABLED_ReadFloatBufferFromFile | 293 #define MAYBE_ReadFloatBufferFromFile DISABLED_ReadFloatBufferFromFile |
294 #else | 294 #else |
295 #define MAYBE_ReadFloatBufferFromFile ReadFloatBufferFromFile | 295 #define MAYBE_ReadFloatBufferFromFile ReadFloatBufferFromFile |
296 #endif | 296 #endif |
297 TEST_F(TransientFileUtilsTest, MAYBE_ReadFloatBufferFromFile) { | 297 TEST_F(TransientFileUtilsTest, MAYBE_ReadFloatBufferFromFile) { |
298 std::string test_filename = kTestFileNamef; | 298 std::string test_filename = kTestFileNamef; |
299 | 299 |
300 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 300 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
301 | 301 |
302 file->OpenFile(test_filename.c_str(), | 302 file->OpenFile(test_filename.c_str(), |
303 true, // Read only. | 303 true, // Read only. |
304 true, // Loop. | 304 true, // Loop. |
305 false); // No text. | 305 false); // No text. |
306 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 306 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
307 << kTestFileNamef.c_str(); | 307 << kTestFileNamef.c_str(); |
308 | 308 |
309 const size_t kBufferLength = 3; | 309 const size_t kBufferLength = 3; |
310 rtc::scoped_ptr<float[]> buffer(new float[kBufferLength]); | 310 std::unique_ptr<float[]> buffer(new float[kBufferLength]); |
311 | 311 |
312 EXPECT_EQ(kBufferLength, ReadFloatBufferFromFile(file.get(), | 312 EXPECT_EQ(kBufferLength, ReadFloatBufferFromFile(file.get(), |
313 kBufferLength, | 313 kBufferLength, |
314 buffer.get())); | 314 buffer.get())); |
315 EXPECT_FLOAT_EQ(kPi, buffer[0]); | 315 EXPECT_FLOAT_EQ(kPi, buffer[0]); |
316 EXPECT_FLOAT_EQ(kE, buffer[1]); | 316 EXPECT_FLOAT_EQ(kE, buffer[1]); |
317 EXPECT_FLOAT_EQ(kAvogadro, buffer[2]); | 317 EXPECT_FLOAT_EQ(kAvogadro, buffer[2]); |
318 | 318 |
319 file->Rewind(); | 319 file->Rewind(); |
320 | 320 |
(...skipping 11 matching lines...) Expand all Loading... |
332 } | 332 } |
333 | 333 |
334 #if defined(WEBRTC_IOS) | 334 #if defined(WEBRTC_IOS) |
335 #define MAYBE_ReadDoubleBufferFromFile DISABLED_ReadDoubleBufferFromFile | 335 #define MAYBE_ReadDoubleBufferFromFile DISABLED_ReadDoubleBufferFromFile |
336 #else | 336 #else |
337 #define MAYBE_ReadDoubleBufferFromFile ReadDoubleBufferFromFile | 337 #define MAYBE_ReadDoubleBufferFromFile ReadDoubleBufferFromFile |
338 #endif | 338 #endif |
339 TEST_F(TransientFileUtilsTest, MAYBE_ReadDoubleBufferFromFile) { | 339 TEST_F(TransientFileUtilsTest, MAYBE_ReadDoubleBufferFromFile) { |
340 std::string test_filename = kTestFileName; | 340 std::string test_filename = kTestFileName; |
341 | 341 |
342 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 342 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
343 | 343 |
344 file->OpenFile(test_filename.c_str(), | 344 file->OpenFile(test_filename.c_str(), |
345 true, // Read only. | 345 true, // Read only. |
346 true, // Loop. | 346 true, // Loop. |
347 false); // No text. | 347 false); // No text. |
348 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 348 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
349 << kTestFileName.c_str(); | 349 << kTestFileName.c_str(); |
350 | 350 |
351 const size_t kBufferLength = 3; | 351 const size_t kBufferLength = 3; |
352 rtc::scoped_ptr<double[]> buffer(new double[kBufferLength]); | 352 std::unique_ptr<double[]> buffer(new double[kBufferLength]); |
353 | 353 |
354 EXPECT_EQ(kBufferLength, ReadDoubleBufferFromFile(file.get(), | 354 EXPECT_EQ(kBufferLength, ReadDoubleBufferFromFile(file.get(), |
355 kBufferLength, | 355 kBufferLength, |
356 buffer.get())); | 356 buffer.get())); |
357 EXPECT_DOUBLE_EQ(kPi, buffer[0]); | 357 EXPECT_DOUBLE_EQ(kPi, buffer[0]); |
358 EXPECT_DOUBLE_EQ(kE, buffer[1]); | 358 EXPECT_DOUBLE_EQ(kE, buffer[1]); |
359 EXPECT_DOUBLE_EQ(kAvogadro, buffer[2]); | 359 EXPECT_DOUBLE_EQ(kAvogadro, buffer[2]); |
360 | 360 |
361 file->Rewind(); | 361 file->Rewind(); |
362 | 362 |
363 // The next test is for checking the case where there are not as much data as | 363 // The next test is for checking the case where there are not as much data as |
364 // needed in the file, but reads to the end, and it returns the number of | 364 // needed in the file, but reads to the end, and it returns the number of |
365 // doubles read. | 365 // doubles read. |
366 const size_t kBufferLenghtLargerThanFile = kBufferLength * 2; | 366 const size_t kBufferLenghtLargerThanFile = kBufferLength * 2; |
367 buffer.reset(new double[kBufferLenghtLargerThanFile]); | 367 buffer.reset(new double[kBufferLenghtLargerThanFile]); |
368 EXPECT_EQ(kBufferLength, ReadDoubleBufferFromFile(file.get(), | 368 EXPECT_EQ(kBufferLength, ReadDoubleBufferFromFile(file.get(), |
369 kBufferLenghtLargerThanFile, | 369 kBufferLenghtLargerThanFile, |
370 buffer.get())); | 370 buffer.get())); |
371 EXPECT_DOUBLE_EQ(kPi, buffer[0]); | 371 EXPECT_DOUBLE_EQ(kPi, buffer[0]); |
372 EXPECT_DOUBLE_EQ(kE, buffer[1]); | 372 EXPECT_DOUBLE_EQ(kE, buffer[1]); |
373 EXPECT_DOUBLE_EQ(kAvogadro, buffer[2]); | 373 EXPECT_DOUBLE_EQ(kAvogadro, buffer[2]); |
374 } | 374 } |
375 | 375 |
376 #if defined(WEBRTC_IOS) | 376 #if defined(WEBRTC_IOS) |
377 #define MAYBE_WriteInt16BufferToFile DISABLED_WriteInt16BufferToFile | 377 #define MAYBE_WriteInt16BufferToFile DISABLED_WriteInt16BufferToFile |
378 #else | 378 #else |
379 #define MAYBE_WriteInt16BufferToFile WriteInt16BufferToFile | 379 #define MAYBE_WriteInt16BufferToFile WriteInt16BufferToFile |
380 #endif | 380 #endif |
381 TEST_F(TransientFileUtilsTest, MAYBE_WriteInt16BufferToFile) { | 381 TEST_F(TransientFileUtilsTest, MAYBE_WriteInt16BufferToFile) { |
382 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 382 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
383 | 383 |
384 std::string kOutFileName = CreateTempFilename(test::OutputPath(), | 384 std::string kOutFileName = CreateTempFilename(test::OutputPath(), |
385 "utils_test"); | 385 "utils_test"); |
386 | 386 |
387 file->OpenFile(kOutFileName.c_str(), | 387 file->OpenFile(kOutFileName.c_str(), |
388 false, // Write mode. | 388 false, // Write mode. |
389 false, // No loop. | 389 false, // No loop. |
390 false); // No text. | 390 false); // No text. |
391 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 391 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
392 << kOutFileName.c_str(); | 392 << kOutFileName.c_str(); |
393 | 393 |
394 const size_t kBufferLength = 3; | 394 const size_t kBufferLength = 3; |
395 rtc::scoped_ptr<int16_t[]> written_buffer(new int16_t[kBufferLength]); | 395 std::unique_ptr<int16_t[]> written_buffer(new int16_t[kBufferLength]); |
396 rtc::scoped_ptr<int16_t[]> read_buffer(new int16_t[kBufferLength]); | 396 std::unique_ptr<int16_t[]> read_buffer(new int16_t[kBufferLength]); |
397 | 397 |
398 written_buffer[0] = 1; | 398 written_buffer[0] = 1; |
399 written_buffer[1] = 2; | 399 written_buffer[1] = 2; |
400 written_buffer[2] = 3; | 400 written_buffer[2] = 3; |
401 | 401 |
402 EXPECT_EQ(kBufferLength, WriteInt16BufferToFile(file.get(), | 402 EXPECT_EQ(kBufferLength, WriteInt16BufferToFile(file.get(), |
403 kBufferLength, | 403 kBufferLength, |
404 written_buffer.get())); | 404 written_buffer.get())); |
405 | 405 |
406 file->CloseFile(); | 406 file->CloseFile(); |
(...skipping 12 matching lines...) Expand all Loading... |
419 read_buffer.get(), | 419 read_buffer.get(), |
420 kBufferLength * sizeof(written_buffer[0]))); | 420 kBufferLength * sizeof(written_buffer[0]))); |
421 } | 421 } |
422 | 422 |
423 #if defined(WEBRTC_IOS) | 423 #if defined(WEBRTC_IOS) |
424 #define MAYBE_WriteFloatBufferToFile DISABLED_WriteFloatBufferToFile | 424 #define MAYBE_WriteFloatBufferToFile DISABLED_WriteFloatBufferToFile |
425 #else | 425 #else |
426 #define MAYBE_WriteFloatBufferToFile WriteFloatBufferToFile | 426 #define MAYBE_WriteFloatBufferToFile WriteFloatBufferToFile |
427 #endif | 427 #endif |
428 TEST_F(TransientFileUtilsTest, MAYBE_WriteFloatBufferToFile) { | 428 TEST_F(TransientFileUtilsTest, MAYBE_WriteFloatBufferToFile) { |
429 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 429 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
430 | 430 |
431 std::string kOutFileName = CreateTempFilename(test::OutputPath(), | 431 std::string kOutFileName = CreateTempFilename(test::OutputPath(), |
432 "utils_test"); | 432 "utils_test"); |
433 | 433 |
434 file->OpenFile(kOutFileName.c_str(), | 434 file->OpenFile(kOutFileName.c_str(), |
435 false, // Write mode. | 435 false, // Write mode. |
436 false, // No loop. | 436 false, // No loop. |
437 false); // No text. | 437 false); // No text. |
438 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 438 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
439 << kOutFileName.c_str(); | 439 << kOutFileName.c_str(); |
440 | 440 |
441 const size_t kBufferLength = 3; | 441 const size_t kBufferLength = 3; |
442 rtc::scoped_ptr<float[]> written_buffer(new float[kBufferLength]); | 442 std::unique_ptr<float[]> written_buffer(new float[kBufferLength]); |
443 rtc::scoped_ptr<float[]> read_buffer(new float[kBufferLength]); | 443 std::unique_ptr<float[]> read_buffer(new float[kBufferLength]); |
444 | 444 |
445 written_buffer[0] = static_cast<float>(kPi); | 445 written_buffer[0] = static_cast<float>(kPi); |
446 written_buffer[1] = static_cast<float>(kE); | 446 written_buffer[1] = static_cast<float>(kE); |
447 written_buffer[2] = static_cast<float>(kAvogadro); | 447 written_buffer[2] = static_cast<float>(kAvogadro); |
448 | 448 |
449 EXPECT_EQ(kBufferLength, WriteFloatBufferToFile(file.get(), | 449 EXPECT_EQ(kBufferLength, WriteFloatBufferToFile(file.get(), |
450 kBufferLength, | 450 kBufferLength, |
451 written_buffer.get())); | 451 written_buffer.get())); |
452 | 452 |
453 file->CloseFile(); | 453 file->CloseFile(); |
(...skipping 12 matching lines...) Expand all Loading... |
466 read_buffer.get(), | 466 read_buffer.get(), |
467 kBufferLength * sizeof(written_buffer[0]))); | 467 kBufferLength * sizeof(written_buffer[0]))); |
468 } | 468 } |
469 | 469 |
470 #if defined(WEBRTC_IOS) | 470 #if defined(WEBRTC_IOS) |
471 #define MAYBE_WriteDoubleBufferToFile DISABLED_WriteDoubleBufferToFile | 471 #define MAYBE_WriteDoubleBufferToFile DISABLED_WriteDoubleBufferToFile |
472 #else | 472 #else |
473 #define MAYBE_WriteDoubleBufferToFile WriteDoubleBufferToFile | 473 #define MAYBE_WriteDoubleBufferToFile WriteDoubleBufferToFile |
474 #endif | 474 #endif |
475 TEST_F(TransientFileUtilsTest, MAYBE_WriteDoubleBufferToFile) { | 475 TEST_F(TransientFileUtilsTest, MAYBE_WriteDoubleBufferToFile) { |
476 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 476 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
477 | 477 |
478 std::string kOutFileName = CreateTempFilename(test::OutputPath(), | 478 std::string kOutFileName = CreateTempFilename(test::OutputPath(), |
479 "utils_test"); | 479 "utils_test"); |
480 | 480 |
481 file->OpenFile(kOutFileName.c_str(), | 481 file->OpenFile(kOutFileName.c_str(), |
482 false, // Write mode. | 482 false, // Write mode. |
483 false, // No loop. | 483 false, // No loop. |
484 false); // No text. | 484 false); // No text. |
485 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 485 ASSERT_TRUE(file->Open()) << "File could not be opened:\n" |
486 << kOutFileName.c_str(); | 486 << kOutFileName.c_str(); |
487 | 487 |
488 const size_t kBufferLength = 3; | 488 const size_t kBufferLength = 3; |
489 rtc::scoped_ptr<double[]> written_buffer(new double[kBufferLength]); | 489 std::unique_ptr<double[]> written_buffer(new double[kBufferLength]); |
490 rtc::scoped_ptr<double[]> read_buffer(new double[kBufferLength]); | 490 std::unique_ptr<double[]> read_buffer(new double[kBufferLength]); |
491 | 491 |
492 written_buffer[0] = kPi; | 492 written_buffer[0] = kPi; |
493 written_buffer[1] = kE; | 493 written_buffer[1] = kE; |
494 written_buffer[2] = kAvogadro; | 494 written_buffer[2] = kAvogadro; |
495 | 495 |
496 EXPECT_EQ(kBufferLength, WriteDoubleBufferToFile(file.get(), | 496 EXPECT_EQ(kBufferLength, WriteDoubleBufferToFile(file.get(), |
497 kBufferLength, | 497 kBufferLength, |
498 written_buffer.get())); | 498 written_buffer.get())); |
499 | 499 |
500 file->CloseFile(); | 500 file->CloseFile(); |
(...skipping 15 matching lines...) Expand all Loading... |
516 | 516 |
517 #if defined(WEBRTC_IOS) | 517 #if defined(WEBRTC_IOS) |
518 #define MAYBE_ExpectedErrorReturnValues DISABLED_ExpectedErrorReturnValues | 518 #define MAYBE_ExpectedErrorReturnValues DISABLED_ExpectedErrorReturnValues |
519 #else | 519 #else |
520 #define MAYBE_ExpectedErrorReturnValues ExpectedErrorReturnValues | 520 #define MAYBE_ExpectedErrorReturnValues ExpectedErrorReturnValues |
521 #endif | 521 #endif |
522 TEST_F(TransientFileUtilsTest, MAYBE_ExpectedErrorReturnValues) { | 522 TEST_F(TransientFileUtilsTest, MAYBE_ExpectedErrorReturnValues) { |
523 std::string test_filename = kTestFileName; | 523 std::string test_filename = kTestFileName; |
524 | 524 |
525 double value; | 525 double value; |
526 rtc::scoped_ptr<int16_t[]> int16_buffer(new int16_t[1]); | 526 std::unique_ptr<int16_t[]> int16_buffer(new int16_t[1]); |
527 rtc::scoped_ptr<double[]> double_buffer(new double[1]); | 527 std::unique_ptr<double[]> double_buffer(new double[1]); |
528 rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 528 std::unique_ptr<FileWrapper> file(FileWrapper::Create()); |
529 | 529 |
530 EXPECT_EQ(-1, ConvertByteArrayToDouble(NULL, &value)); | 530 EXPECT_EQ(-1, ConvertByteArrayToDouble(NULL, &value)); |
531 EXPECT_EQ(-1, ConvertByteArrayToDouble(kPiBytes, NULL)); | 531 EXPECT_EQ(-1, ConvertByteArrayToDouble(kPiBytes, NULL)); |
532 | 532 |
533 EXPECT_EQ(-1, ConvertDoubleToByteArray(kPi, NULL)); | 533 EXPECT_EQ(-1, ConvertDoubleToByteArray(kPi, NULL)); |
534 | 534 |
535 // Tests with file not opened. | 535 // Tests with file not opened. |
536 EXPECT_EQ(0u, ReadInt16BufferFromFile(file.get(), 1, int16_buffer.get())); | 536 EXPECT_EQ(0u, ReadInt16BufferFromFile(file.get(), 1, int16_buffer.get())); |
537 EXPECT_EQ(0u, ReadInt16FromFileToDoubleBuffer(file.get(), | 537 EXPECT_EQ(0u, ReadInt16FromFileToDoubleBuffer(file.get(), |
538 1, | 538 1, |
(...skipping 27 matching lines...) Expand all Loading... |
566 EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 1, NULL)); | 566 EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 1, NULL)); |
567 EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 0, int16_buffer.get())); | 567 EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 0, int16_buffer.get())); |
568 | 568 |
569 EXPECT_EQ(0u, WriteDoubleBufferToFile(NULL, 1, double_buffer.get())); | 569 EXPECT_EQ(0u, WriteDoubleBufferToFile(NULL, 1, double_buffer.get())); |
570 EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 1, NULL)); | 570 EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 1, NULL)); |
571 EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 0, double_buffer.get())); | 571 EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 0, double_buffer.get())); |
572 } | 572 } |
573 | 573 |
574 } // namespace webrtc | 574 } // namespace webrtc |
575 | 575 |
OLD | NEW |