| 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 <vector> | 
| 15 | 16 | 
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" | 
| 17 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" | 
| 18 #include "webrtc/system_wrappers/include/file_wrapper.h" | 19 #include "webrtc/system_wrappers/include/file_wrapper.h" | 
| 19 #include "webrtc/test/testsupport/fileutils.h" | 20 #include "webrtc/test/testsupport/fileutils.h" | 
| 20 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" | 
| 21 | 22 | 
| 22 namespace webrtc { | 23 namespace webrtc { | 
| 23 | 24 | 
| 24 static const uint8_t kPiBytesf[4] = {0xDB, 0x0F, 0x49, 0x40}; | 25 static const uint8_t kPiBytesf[4] = {0xDB, 0x0F, 0x49, 0x40}; | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 38 | 39 | 
| 39 class TransientFileUtilsTest: public ::testing::Test { | 40 class TransientFileUtilsTest: public ::testing::Test { | 
| 40  protected: | 41  protected: | 
| 41   TransientFileUtilsTest() | 42   TransientFileUtilsTest() | 
| 42       : kTestFileName( | 43       : kTestFileName( | 
| 43             test::ResourcePath("audio_processing/transient/double-utils", | 44             test::ResourcePath("audio_processing/transient/double-utils", | 
| 44                                "dat")), | 45                                "dat")), | 
| 45         kTestFileNamef( | 46         kTestFileNamef( | 
| 46             test::ResourcePath("audio_processing/transient/float-utils", | 47             test::ResourcePath("audio_processing/transient/float-utils", | 
| 47                                "dat")) {} | 48                                "dat")) {} | 
|  | 49 | 
|  | 50   ~TransientFileUtilsTest() override { | 
|  | 51     CleanupTempFiles(); | 
|  | 52   } | 
|  | 53 | 
|  | 54   std::string CreateTempFilename(const std::string& dir, | 
|  | 55       const std::string& prefix) { | 
|  | 56     std::string filename = test::TempFilename(dir, prefix); | 
|  | 57     temp_filenames_.push_back(filename); | 
|  | 58     return filename; | 
|  | 59   } | 
|  | 60 | 
|  | 61   void CleanupTempFiles() { | 
|  | 62     for (const std::string& filename : temp_filenames_) { | 
|  | 63       remove(filename.c_str()); | 
|  | 64     } | 
|  | 65     temp_filenames_.clear(); | 
|  | 66   } | 
|  | 67 | 
| 48   // This file (used in some tests) contains binary data. The data correspond to | 68   // This file (used in some tests) contains binary data. The data correspond to | 
| 49   // the double representation of the constants: Pi, E, and the Avogadro's | 69   // the double representation of the constants: Pi, E, and the Avogadro's | 
| 50   // Number; | 70   // Number; | 
| 51   // appended in that order. | 71   // appended in that order. | 
| 52   const std::string kTestFileName; | 72   const std::string kTestFileName; | 
| 53 | 73 | 
| 54   // This file (used in some tests) contains binary data. The data correspond to | 74   // This file (used in some tests) contains binary data. The data correspond to | 
| 55   // the float representation of the constants: Pi, E, and the Avogadro's | 75   // the float representation of the constants: Pi, E, and the Avogadro's | 
| 56   // Number; | 76   // Number; | 
| 57   // appended in that order. | 77   // appended in that order. | 
| 58   const std::string kTestFileNamef; | 78   const std::string kTestFileNamef; | 
|  | 79 | 
|  | 80   // List of temporary filenames created by CreateTempFilename. | 
|  | 81   std::vector<std::string> temp_filenames_; | 
| 59 }; | 82 }; | 
| 60 | 83 | 
| 61 #if defined(WEBRTC_IOS) | 84 #if defined(WEBRTC_IOS) | 
| 62 #define MAYBE_ConvertByteArrayToFloat DISABLED_ConvertByteArrayToFloat | 85 #define MAYBE_ConvertByteArrayToFloat DISABLED_ConvertByteArrayToFloat | 
| 63 #else | 86 #else | 
| 64 #define MAYBE_ConvertByteArrayToFloat ConvertByteArrayToFloat | 87 #define MAYBE_ConvertByteArrayToFloat ConvertByteArrayToFloat | 
| 65 #endif | 88 #endif | 
| 66 TEST_F(TransientFileUtilsTest, MAYBE_ConvertByteArrayToFloat) { | 89 TEST_F(TransientFileUtilsTest, MAYBE_ConvertByteArrayToFloat) { | 
| 67   float value = 0.0; | 90   float value = 0.0; | 
| 68 | 91 | 
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 351 } | 374 } | 
| 352 | 375 | 
| 353 #if defined(WEBRTC_IOS) | 376 #if defined(WEBRTC_IOS) | 
| 354 #define MAYBE_WriteInt16BufferToFile DISABLED_WriteInt16BufferToFile | 377 #define MAYBE_WriteInt16BufferToFile DISABLED_WriteInt16BufferToFile | 
| 355 #else | 378 #else | 
| 356 #define MAYBE_WriteInt16BufferToFile WriteInt16BufferToFile | 379 #define MAYBE_WriteInt16BufferToFile WriteInt16BufferToFile | 
| 357 #endif | 380 #endif | 
| 358 TEST_F(TransientFileUtilsTest, MAYBE_WriteInt16BufferToFile) { | 381 TEST_F(TransientFileUtilsTest, MAYBE_WriteInt16BufferToFile) { | 
| 359   rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 382   rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 
| 360 | 383 | 
| 361   std::string kOutFileName = test::TempFilename(test::OutputPath(), | 384   std::string kOutFileName = CreateTempFilename(test::OutputPath(), | 
| 362                                                 "utils_test"); | 385                                                 "utils_test"); | 
| 363 | 386 | 
| 364   file->OpenFile(kOutFileName.c_str(), | 387   file->OpenFile(kOutFileName.c_str(), | 
| 365                  false,   // Write mode. | 388                  false,   // Write mode. | 
| 366                  false,   // No loop. | 389                  false,   // No loop. | 
| 367                  false);  // No text. | 390                  false);  // No text. | 
| 368   ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 391   ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 
| 369       << kOutFileName.c_str(); | 392       << kOutFileName.c_str(); | 
| 370 | 393 | 
| 371   const size_t kBufferLength = 3; | 394   const size_t kBufferLength = 3; | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 398 } | 421 } | 
| 399 | 422 | 
| 400 #if defined(WEBRTC_IOS) | 423 #if defined(WEBRTC_IOS) | 
| 401 #define MAYBE_WriteFloatBufferToFile DISABLED_WriteFloatBufferToFile | 424 #define MAYBE_WriteFloatBufferToFile DISABLED_WriteFloatBufferToFile | 
| 402 #else | 425 #else | 
| 403 #define MAYBE_WriteFloatBufferToFile WriteFloatBufferToFile | 426 #define MAYBE_WriteFloatBufferToFile WriteFloatBufferToFile | 
| 404 #endif | 427 #endif | 
| 405 TEST_F(TransientFileUtilsTest, MAYBE_WriteFloatBufferToFile) { | 428 TEST_F(TransientFileUtilsTest, MAYBE_WriteFloatBufferToFile) { | 
| 406   rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 429   rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 
| 407 | 430 | 
| 408   std::string kOutFileName = test::TempFilename(test::OutputPath(), | 431   std::string kOutFileName = CreateTempFilename(test::OutputPath(), | 
| 409                                                 "utils_test"); | 432                                                 "utils_test"); | 
| 410 | 433 | 
| 411   file->OpenFile(kOutFileName.c_str(), | 434   file->OpenFile(kOutFileName.c_str(), | 
| 412                  false,   // Write mode. | 435                  false,   // Write mode. | 
| 413                  false,   // No loop. | 436                  false,   // No loop. | 
| 414                  false);  // No text. | 437                  false);  // No text. | 
| 415   ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 438   ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 
| 416       << kOutFileName.c_str(); | 439       << kOutFileName.c_str(); | 
| 417 | 440 | 
| 418   const size_t kBufferLength = 3; | 441   const size_t kBufferLength = 3; | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
| 445 } | 468 } | 
| 446 | 469 | 
| 447 #if defined(WEBRTC_IOS) | 470 #if defined(WEBRTC_IOS) | 
| 448 #define MAYBE_WriteDoubleBufferToFile DISABLED_WriteDoubleBufferToFile | 471 #define MAYBE_WriteDoubleBufferToFile DISABLED_WriteDoubleBufferToFile | 
| 449 #else | 472 #else | 
| 450 #define MAYBE_WriteDoubleBufferToFile WriteDoubleBufferToFile | 473 #define MAYBE_WriteDoubleBufferToFile WriteDoubleBufferToFile | 
| 451 #endif | 474 #endif | 
| 452 TEST_F(TransientFileUtilsTest, MAYBE_WriteDoubleBufferToFile) { | 475 TEST_F(TransientFileUtilsTest, MAYBE_WriteDoubleBufferToFile) { | 
| 453   rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 476   rtc::scoped_ptr<FileWrapper> file(FileWrapper::Create()); | 
| 454 | 477 | 
| 455   std::string kOutFileName = test::TempFilename(test::OutputPath(), | 478   std::string kOutFileName = CreateTempFilename(test::OutputPath(), | 
| 456                                                 "utils_test"); | 479                                                 "utils_test"); | 
| 457 | 480 | 
| 458   file->OpenFile(kOutFileName.c_str(), | 481   file->OpenFile(kOutFileName.c_str(), | 
| 459                  false,   // Write mode. | 482                  false,   // Write mode. | 
| 460                  false,   // No loop. | 483                  false,   // No loop. | 
| 461                  false);  // No text. | 484                  false);  // No text. | 
| 462   ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 485   ASSERT_TRUE(file->Open()) << "File could not be opened:\n" | 
| 463       << kOutFileName.c_str(); | 486       << kOutFileName.c_str(); | 
| 464 | 487 | 
| 465   const size_t kBufferLength = 3; | 488   const size_t kBufferLength = 3; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 543   EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 1, NULL)); | 566   EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 1, NULL)); | 
| 544   EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 0, int16_buffer.get())); | 567   EXPECT_EQ(0u, WriteInt16BufferToFile(file.get(), 0, int16_buffer.get())); | 
| 545 | 568 | 
| 546   EXPECT_EQ(0u, WriteDoubleBufferToFile(NULL, 1, double_buffer.get())); | 569   EXPECT_EQ(0u, WriteDoubleBufferToFile(NULL, 1, double_buffer.get())); | 
| 547   EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 1, NULL)); | 570   EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 1, NULL)); | 
| 548   EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 0, double_buffer.get())); | 571   EXPECT_EQ(0u, WriteDoubleBufferToFile(file.get(), 0, double_buffer.get())); | 
| 549 } | 572 } | 
| 550 | 573 | 
| 551 }  // namespace webrtc | 574 }  // namespace webrtc | 
| 552 | 575 | 
| OLD | NEW | 
|---|